ATLAS Offline Software
TrigLArNoiseBurstRecoAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 
12 #include "hltinterface/IInfoRegister.h"
13 #include "hltinterface/ContainerFactory.h"
14 
15 #include <boost/property_tree/ptree.hpp>
16 
17 using namespace TrigCompositeUtils;
18 
20  ISvcLocator* pSvcLocator ) :
21  AthReentrantAlgorithm( name, pSvcLocator ), m_IsObject(nullptr), m_timeTagPosToClear(240), m_publishTime(180), m_name_of_is("LArISInfo_NoiseBurstAlg"), m_timeTagPosRec(0) {
22 }
23 
24 
26 
28  ATH_CHECK( m_knownBadFEBsVecKey.initialize() );
29  ATH_CHECK( m_knownMNBFEBsVecKey.initialize() );
31  ATH_CHECK(m_noisyROTool.retrieve());
32 
33 
34  if ( not m_monTool.name().empty() )
35  CHECK( m_monTool.retrieve() );
36 
37  // prepare mask
38  m_mask = 0x0;
44 
45  // No TDAQ structure, no publishing anyway
46  try {
47  auto cfact = hltinterface::ContainerFactory::getInstance();
48  if ( cfact ) {
49  // construct the LAr noise burst container and register it
50  ATH_MSG_DEBUG ( "Got the factory for TDAQ interface, will try to register vectors" );
51  m_IsObject = cfact->constructContainer(m_name_of_is,"LArNoiseBurstCandidates");
52  m_evntPos = cfact->addIntVector(m_IsObject,"Flag",hltinterface::GenericHLTContainer::LASTVALUE);
53  m_timeTagPos = cfact->addIntVector(m_IsObject,"TimeStamp",hltinterface::GenericHLTContainer::LASTVALUE);
54  m_timeTagPosns = cfact->addIntVector(m_IsObject,"TimeStamp_ns",hltinterface::GenericHLTContainer::LASTVALUE);
55  ATH_MSG_DEBUG ( "Registering container in IS with name /HLTObjects/" << m_name_of_is );
56  hltinterface::IInfoRegister::instance()->registerObject("/HLTObjects/",m_IsObject);
57  } // if cfact
58  }
59  catch (std::exception& ex ) {
60  ATH_MSG_WARNING ( "Cannot use ISInfo publication. got exception " << ex.what() );
61  m_IsObject = nullptr;
62  m_timeTagPosRec=0;
63  }
64  // some initial value to clean up stuff
65 
66  ATH_MSG_INFO("TrigLArNoiseBurstRecoAlg initialization completed successfully.");
67  return StatusCode::SUCCESS;
68 }
69 
70 StatusCode TrigLArNoiseBurstRecoAlg::execute( const EventContext& context ) const {
71 
72  ATH_MSG_DEBUG ( "Executing " << name() << "..." );
73 
74  bool monitor = !m_monTool.name().empty();
75  auto timer = Monitored::Timer("TIME_larnoisetool");
77  std::string bitWise_flags("bitWise_flags");
78 
79  const EventIDBase& EIHandle = context.eventID();
80  long int thisTimeStamp = (EIHandle).time_stamp();
81  long int thisTimeStampns = (EIHandle).time_stamp_ns_offset();
82  uint32_t thisLB = (EIHandle).lumi_block();
83  unsigned long long thisEv = (EIHandle).event_number();
84  ATH_MSG_DEBUG ( name() << " processing EN : " << thisEv << " in LB : " << thisLB << " TS : " << thisTimeStamp << " TSNS : " << thisTimeStampns );
85 
86  // get cells
88  ATH_CHECK( cellsHandle.isValid() );
89  ATH_MSG_DEBUG ( "Cells handle size: " << cellsHandle->size() << "..." );
90 
91  // necessary conditions
92  std::set<unsigned int> bf;
93  std::vector<HWIdentifier> MNBfeb;
95  const LArBadFebCont* badCont=*badHdl;
96  if(badCont) {
97  for(const LArBadFebCont::BadChanEntry& badchan : *badCont) {
98  bf.insert(badchan.first);
99  }
100  }
101 
103  const LArBadFebCont* MNBCont=*MNBHdl;
104  if(MNBCont) {
105  for(const LArBadFebCont::BadChanEntry& badchan : *MNBCont) {
106  MNBfeb.push_back(HWIdentifier(badchan.first));
107  }
108  }
109 
110  // no cells, no discussion
111  // should record, before amything, the answer
112  if ( !(cellsHandle.cptr()) ) return StatusCode::FAILURE;
113  unsigned int flag = 0;
114  bool pass=false;
115  ATH_MSG_DEBUG ("Got cell container, will process it");
116  std::unique_ptr<LArNoisyROSummary> noisyRO = m_noisyROTool->process(cellsHandle.cptr(), &bf, &MNBfeb);
117  ATH_MSG_DEBUG("processed it");
118  if ( monitor ) { // input
119  auto bitWise = Monitored::Scalar<std::string>(bitWise_flags,"Input");
120  fill(m_monTool,bitWise);
121  }
122  if ( noisyRO->BadFEBFlaggedPartitions() ) {
123  ATH_MSG_DEBUG("Passed : BadFEBFlaggedPartitions");
124  flag |= 0x1;
125  if ( monitor ) {
126  auto bitWise = Monitored::Scalar<std::string>(bitWise_flags,"BadFEBFlaggedPartitions");
127  fill(m_monTool,bitWise);
128  }
129  }
130  if ( noisyRO->BadFEB_WFlaggedPartitions() ) {
131  ATH_MSG_DEBUG("Passed : BadFEB_WFlaggedPartitions");
132  flag |= 0x8;
133  if ( monitor ) {
134  auto bitWise = Monitored::Scalar<std::string>(bitWise_flags,"BadFEB_WFlaggedPartitions");
135  fill(m_monTool,bitWise);
136  }
137  }
138  if ( noisyRO->SatTightFlaggedPartitions() ) {
139  ATH_MSG_DEBUG("Passed : SatTightFlaggedPartitions");
140  flag |= 0x2;
141  if ( monitor ) {
142  auto bitWise = Monitored::Scalar<std::string>(bitWise_flags,"SatTightFlaggedPartitions");
143  fill(m_monTool,bitWise);
144  }
145  }
146  if ( noisyRO->MNBLooseFlaggedPartitions() ) {
147  ATH_MSG_DEBUG("Passed : MNBLooseFlaggedPartions");
148  flag |= 0x10;
149  if ( monitor ) {
150  auto bitWise = Monitored::Scalar<std::string>(bitWise_flags,"MNBLooseFlaggedPartions");
151  fill(m_monTool,bitWise);
152  }
153  }
154  if ( noisyRO->MNBTightFlaggedPartitions() ) {
155  ATH_MSG_DEBUG("Passed : MNBTightFlaggedPartions");
156  flag |= 0x20;
157  if ( monitor ) {
158  auto bitWise = Monitored::Scalar<std::string>(bitWise_flags,"MNBTightFlaggedPartions");
159  fill(m_monTool,bitWise);
160  }
161  }
162  if ( noisyRO->MNBTight_PsVetoFlaggedPartitions() ) {
163  ATH_MSG_DEBUG("Passed : MNBTight_PSVetoFlaggedPartions");
164  flag |= 0x40;
165  if ( monitor ) {
166  auto bitWise = Monitored::Scalar<std::string>(bitWise_flags,"MNBTight_PsVetoFlaggedPartions");
167  fill(m_monTool,bitWise);
168  }
169  }
170 
171  if ( (flag & m_mask) != 0x0 ) {
172  ATH_MSG_DEBUG("LAr Noise detected !");
173  pass = true;
174  if ( monitor ) {
175  auto bitWise = Monitored::Scalar<std::string>(bitWise_flags,"Output");
176  fill(m_monTool,bitWise);
177  }
178  }
179  else {
180  ATH_MSG_DEBUG("LAr Noise not detected!");
181  }
182 
183  // publish the found values in IS
184  if ( pass && (m_IsObject != nullptr) ) {
185  // lock the IS publishing
186  std::lock_guard<std::mutex> lock( m_pubIS_mtx );
187  boost::property_tree::ptree event_tree;
188  event_tree.put("eventNumber",thisEv);
189  event_tree.put("LBNumber",thisLB);
190  try{
191  hltinterface::IInfoRegister::instance()->beginEvent(event_tree);
192 
193  if ( ( thisTimeStamp - m_timeTagPosRec) > m_timeTagPosToClear ) {
194 
195  std::vector<long>& ee = m_IsObject->getIntVecField(m_evntPos);
196  std::vector<long>& tt = m_IsObject->getIntVecField(m_timeTagPos);
197  std::vector<long>& ttn = m_IsObject->getIntVecField(m_timeTagPosns);
198 
199  int toBeCleared = 0;
200  for(unsigned int dd=0;dd<tt.size();dd++){
201  if ( ( thisTimeStamp - tt[dd] ) < m_publishTime ) {
202  toBeCleared = (int)dd-1;
203  break;
204  }
205  }
206 
207  if ( toBeCleared > 0 ) {
208  ee.erase(ee.begin(),ee.begin()+(toBeCleared) );
209  tt.erase(tt.begin(),tt.begin()+(toBeCleared) );
210  ttn.erase(ttn.begin(),ttn.begin()+(toBeCleared) );
211  }
212  m_timeTagPosRec = thisTimeStamp ; // records to remember when things were cleared
213  } // thisTimeStamp if check
214 
215  m_IsObject->appendField(m_evntPos,std::vector<long>{flag});
216  m_IsObject->appendField(m_timeTagPos,std::vector<long>{(long int)thisTimeStamp});
217  m_IsObject->appendField(m_timeTagPosns,std::vector<long>{(long int)thisTimeStampns});
218  hltinterface::IInfoRegister::instance()->endEvent(event_tree);
219  }catch(const std::exception &ex){
220  ATH_MSG_INFO("Caught exception while calling hltinterface::IInfoRegister::instance()->endEvent for event " << thisEv
221  <<" at LB " << thisLB
222  <<". Exception was "<<ex.what());
223  }
224  } // if m_IsObject
225  SG::WriteHandle<bool> outputHandle (m_noiseBurstDetected, context );
226  auto output = std::make_unique<bool>(pass);
227  ATH_CHECK( outputHandle.record(std::move(output) ) );
228 
229  return StatusCode::SUCCESS;
230 }
TrigLArNoiseBurstRecoAlg::m_badFEBFlaggedPartitions
Gaudi::Property< bool > m_badFEBFlaggedPartitions
Definition: TrigLArNoiseBurstRecoAlg.h:45
TrigLArNoiseBurstRecoAlg::m_timeTagPosns
size_t m_timeTagPosns
Definition: TrigLArNoiseBurstRecoAlg.h:63
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
LArNoisyROSummary::MNBTight_PsVetoFlaggedPartitions
uint8_t MNBTight_PsVetoFlaggedPartitions() const
Definition: LArNoisyROSummary.h:130
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
TrigCompositeUtils.h
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
TrigLArNoiseBurstRecoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TrigLArNoiseBurstRecoAlg.cxx:70
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TrigLArNoiseBurstRecoAlg::m_noiseBurstDetected
SG::WriteHandleKey< bool > m_noiseBurstDetected
Definition: TrigLArNoiseBurstRecoAlg.h:41
TrigLArNoiseBurstRecoAlg::m_timeTagPosToClear
long int m_timeTagPosToClear
Definition: TrigLArNoiseBurstRecoAlg.h:58
LArBadXCont
Conditions-Data class holding LAr Bad Channel or Bad Feb information.
Definition: LArBadChannelCont.h:28
LArNoisyROSummary::SatTightFlaggedPartitions
uint8_t SatTightFlaggedPartitions() const
Definition: LArNoisyROSummary.h:121
TrigLArNoiseBurstRecoAlg::m_knownBadFEBsVecKey
SG::ReadCondHandleKey< LArBadFebCont > m_knownBadFEBsVecKey
Definition: TrigLArNoiseBurstRecoAlg.h:39
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
TrigLArNoiseBurstRecoAlg::m_evntPos
size_t m_evntPos
Definition: TrigLArNoiseBurstRecoAlg.h:61
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TrigLArNoiseBurstRecoAlg::m_noisyROTool
ToolHandle< ILArNoisyROTool > m_noisyROTool
Definition: TrigLArNoiseBurstRecoAlg.h:43
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
TrigLArNoiseBurstRecoAlg::m_timeTagPos
size_t m_timeTagPos
Definition: TrigLArNoiseBurstRecoAlg.h:62
LArNoisyROSummary::MNBTightFlaggedPartitions
uint8_t MNBTightFlaggedPartitions() const
Definition: LArNoisyROSummary.h:127
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
master.flag
bool flag
Definition: master.py:29
TrigLArNoiseBurstRecoAlg::initialize
virtual StatusCode initialize() override
Definition: TrigLArNoiseBurstRecoAlg.cxx:25
calibdata.exception
exception
Definition: calibdata.py:496
LArNoisyROSummary::MNBLooseFlaggedPartitions
uint8_t MNBLooseFlaggedPartitions() const
Definition: LArNoisyROSummary.h:124
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
LArBadXCont::BadChanEntry
std::pair< ChanId_t, LArBC_t > BadChanEntry
Definition: LArBadChannelCont.h:31
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
TrigLArNoiseBurstRecoAlg::m_publishTime
long int m_publishTime
Definition: TrigLArNoiseBurstRecoAlg.h:59
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TrigLArNoiseBurstRecoAlg::m_name_of_is
std::string m_name_of_is
Definition: TrigLArNoiseBurstRecoAlg.h:60
TrigLArNoiseBurstRecoAlg::m_pubIS_mtx
std::mutex m_pubIS_mtx
Definition: TrigLArNoiseBurstRecoAlg.h:55
fill
void fill(H5::Group &out_file, size_t iterations)
Definition: test-hdf5-writer.cxx:95
merge.output
output
Definition: merge.py:17
ptree
boost::property_tree::ptree ptree
Definition: JsonFileLoader.cxx:16
TrigLArNoiseBurstRecoAlg::m_mNBTight_PsVetoFlaggedPartitions
Gaudi::Property< bool > m_mNBTight_PsVetoFlaggedPartitions
Definition: TrigLArNoiseBurstRecoAlg.h:49
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
LArNoisyROSummary.h
TrigLArNoiseBurstRecoAlg::m_mNBTightFlaggedPartitions
Gaudi::Property< bool > m_mNBTightFlaggedPartitions
Definition: TrigLArNoiseBurstRecoAlg.h:48
TrigLArNoiseBurstRecoAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: TrigLArNoiseBurstRecoAlg.h:51
TrigLArNoiseBurstRecoAlg::m_mNBLooseFlaggedPartitions
Gaudi::Property< bool > m_mNBLooseFlaggedPartitions
Definition: TrigLArNoiseBurstRecoAlg.h:47
library_scraper.dd
list dd
Definition: library_scraper.py:46
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
TrigLArNoiseBurstRecoAlg::m_mask
unsigned int m_mask
Definition: TrigLArNoiseBurstRecoAlg.h:52
TrigLArNoiseBurstRecoAlg.h
TrigLArNoiseBurstRecoAlg::m_satTightFlaggedPartitions
Gaudi::Property< bool > m_satTightFlaggedPartitions
Definition: TrigLArNoiseBurstRecoAlg.h:46
TrigLArNoiseBurstRecoAlg::TrigLArNoiseBurstRecoAlg
TrigLArNoiseBurstRecoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigLArNoiseBurstRecoAlg.cxx:19
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArNoisyROSummary::BadFEB_WFlaggedPartitions
uint8_t BadFEB_WFlaggedPartitions() const
Definition: LArNoisyROSummary.h:115
plotBeamSpotMon.mon
mon
Definition: plotBeamSpotMon.py:67
HLTIdentifier.h
TrigLArNoiseBurstRecoAlg::m_cellContainerKey
SG::ReadHandleKey< CaloCellContainer > m_cellContainerKey
Definition: TrigLArNoiseBurstRecoAlg.h:38
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
TileDCSDataPlotter.tt
tt
Definition: TileDCSDataPlotter.py:874
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrigRoiDescriptorCollection.h
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
LArNoisyROSummary::BadFEBFlaggedPartitions
uint8_t BadFEBFlaggedPartitions() const
Definition: LArNoisyROSummary.h:112
TrigLArNoiseBurstRecoAlg::m_IsObject
std::shared_ptr< hltinterface::GenericHLTContainer > m_IsObject
Definition: TrigLArNoiseBurstRecoAlg.h:56
TrigLArNoiseBurstRecoAlg::m_knownMNBFEBsVecKey
SG::ReadCondHandleKey< LArBadFebCont > m_knownMNBFEBsVecKey
Definition: TrigLArNoiseBurstRecoAlg.h:40