ATLAS Offline Software
Loading...
Searching...
No Matches
TrigLArNoiseBurstRecoAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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
17using 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
27 ATH_CHECK( m_cellContainerKey.initialize() );
28 ATH_CHECK( m_knownBadFEBsVecKey.initialize() );
29 ATH_CHECK( m_knownMNBFEBsVecKey.initialize() );
30 ATH_CHECK( m_noiseBurstDetected.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
70StatusCode 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");
76 auto mon = Monitored::Group(m_monTool,timer);
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(context, cellsHandle.cptr(), &bf, &MNBfeb, nullptr);
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>(std::move(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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
LArBadXCont< LArBadFeb > LArBadFebCont
Header file to be included by clients of the Monitored infrastructure.
An algorithm that can be simultaneously executed in multiple threads.
std::pair< ChanId_t, LArBadFeb > BadChanEntry
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
A monitored timer.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ToolHandle< GenericMonitoringTool > m_monTool
virtual StatusCode initialize() override
Gaudi::Property< bool > m_satTightFlaggedPartitions
SG::WriteHandleKey< bool > m_noiseBurstDetected
Gaudi::Property< bool > m_mNBTight_PsVetoFlaggedPartitions
SG::ReadHandleKey< CaloCellContainer > m_cellContainerKey
ToolHandle< ILArNoisyROTool > m_noisyROTool
SG::ReadCondHandleKey< LArBadFebCont > m_knownBadFEBsVecKey
Gaudi::Property< bool > m_mNBTightFlaggedPartitions
SG::ReadCondHandleKey< LArBadFebCont > m_knownMNBFEBsVecKey
std::shared_ptr< hltinterface::GenericHLTContainer > m_IsObject
Gaudi::Property< bool > m_badFEBFlaggedPartitions
virtual StatusCode execute(const EventContext &context) const override
TrigLArNoiseBurstRecoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< bool > m_mNBLooseFlaggedPartitions
void fill(H5::Group &out_file, size_t iterations)