ATLAS Offline Software
RoIBuilder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 // STL includes:
7 #include <iomanip>
8 #include <vector>
9 
10 // Gaudi/Athena includes:
12 
14 
15 // eformat include:
16 #include "eformat/SourceIdentifier.h"
17 
18 // TrigT1 includes:
20 
21 
22 
23 
24 
25 // Local includes:
26 #include "RoIBuilder.h"
27 #include "RoIBDefs.h"
28 
29 namespace ROIB {
30 
31  //--------------
32  // Constructor
33  //--------------
34  RoIBuilder::RoIBuilder( const std::string& name, ISvcLocator* pSvcLocator )
35  : AthAlgorithm( name, pSvcLocator ) {
36 
37  // Property setting general behaviour:
38 
39  }
40 
41  //---------------------------------
42  // initialize()
43  //---------------------------------
45 
46  ATH_MSG_INFO( "========================================" );
47  ATH_MSG_INFO( "Initialisation for RoIBuilder algorithm." );
48  ATH_MSG_INFO( "========================================" );
49  // Print system info
50  if( ! m_doCalo ) {
51  ATH_MSG_WARNING( "Inputs from LVL1 Calo systems switched off" );
52  }
53  if( ! m_doMuon ) {
54  ATH_MSG_WARNING("Inputs from LVL1 Muon systems switched off" );
55  }
56 
58 
59  if ( m_doCalo ) {
60  CHECK( not m_caloEMTauLocation.empty() );
61  CHECK( not m_caloJetEnergyLocation.empty() );
62  } else {
65  }
66  CHECK( m_caloEMTauLocation.initialize() );
67  CHECK( m_caloJetEnergyLocation.initialize() );
68 
69 
70  if ( m_doMuon ) {
71  CHECK( not m_muctpiSLinkLocation.key().empty() );
72  } else {
74  }
76 
78  CHECK( m_roibRDOLocation.initialize() );
79 
80  return StatusCode::SUCCESS;
81  }
82 
83  //----------------------------------------------
84  // execute() method called once per event
85  //----------------------------------------------
87 
88  // Exec message
89  ATH_MSG_DEBUG( "============================" );
90  ATH_MSG_DEBUG( "Execution of RoIB algorithm." );
91  ATH_MSG_DEBUG( "============================" );
92 
93  //
94  // Get the official event ID:
95  //
96 
97  auto eventInfoHandle = SG::makeHandle( m_eventInfoKey );
98  CHECK( eventInfoHandle.isValid() );
99  const xAOD::EventInfo* thisEvent = eventInfoHandle.cptr();
100  // Note we are loosing precision here as we cast from 64 to 32 bits integer
101  // but this is constraint imposed by: Trigger/TrigT1/TrigT1Result/TrigT1Result/Header.h
102  const int evtNum = static_cast<int>(thisEvent->eventNumber());
103  ATH_MSG_VERBOSE( "Event number is: " << evtNum );
104 
105 
107  // //
108  // CTP RoI //
109  // //
111 
112  // create the header
113  Header ctp_rdo_header( eformat::helper::SourceIdentifier( eformat::TDAQ_CTP,
114  0 ).code() );
115 
116  // create zero data trailer
117  Trailer ctp_rdo_trailer( 0 );
118 
119  // create data element
120  std::vector< unsigned int > ctp_rdo_data;
121 
122  bool ctp_simulation_error = false;
123  auto ctpSlinkHandle = SG::makeHandle( m_ctpSLinkLocation );
124  CHECK( ctpSlinkHandle.isValid() );
125  const LVL1CTP::CTPSLink* ctp_slink = ctpSlinkHandle.cptr();
126 
127  // test for consistency
128  if ( ctp_slink->getCTPToRoIBWords().empty() ) {
129  ctp_simulation_error = true;
130  REPORT_MESSAGE( MSG::WARNING ) << "CTP size is zero. No header, trailer, data element";
131  } else if( ctp_slink->getDataElements().size() != ctp_slink->getNumWordsPerCTPSLink() ) {
132  ctp_simulation_error = true;
133  REPORT_MESSAGE( MSG::WARNING )
134  << "Found CTP size inconsistency: "
135  << ctp_slink->getDataElements().size() << "/"
136  //<< LVL1CTP::CTPSLink::wordsPerCTPSLink
137  << ctp_slink->getNumWordsPerCTPSLink()
138  << " (found/expected)";
139 
140  // get the data elements
141  if( msgLvl( MSG::DEBUG ) ) {
142  const std::vector< unsigned int > ctp_rdo_data_inc = ctp_slink->getDataElements();
143  for( size_t i(0); i < ctp_rdo_data_inc.size(); ++i ) {
144  ATH_MSG_DEBUG( "broken CTP RoI = " << std::setw( 2 ) << i << ' '
145  << MSG::hex << std::setfill('0') << std::setw( 8 )
146  << ctp_rdo_data_inc[i]
147  << MSG::dec << std::setfill(' ') );
148  }
149  }
150  } else {
151  ATH_MSG_VERBOSE( "Retrieved CTP result from TES with key: "
152  << m_ctpSLinkLocation );
153  }
154 
155  if( ctp_simulation_error ) {
156 
157  REPORT_MESSAGE( MSG::WARNING )
158  << "Creating empty CTP RDO with error code!";
159  ctp_rdo_trailer.setSimulationError();
160 
161  } else {
162 
163  // prepare header
164  ctp_rdo_header = Header(std::vector<uint32_t>(ctp_slink->getHeader()));
165 
166  // get the data elements
167  ctp_rdo_data = ctp_slink->getDataElements();
168  if( msgLvl( MSG::DEBUG ) ) {
169  for (size_t i(0); i < ctp_rdo_data.size(); ++i) {
170  ATH_MSG_DEBUG( "CTP RoI = " << MSG::dec << std::setw( 2 ) << i
171  << " 0x" << MSG::hex << std::setfill('0') << std::setw( 8 )
172  << ctp_rdo_data[i]
173  << MSG::dec << std::setfill(' ') );
174  }
175  }
176 
177  // prepare trailer
178  ctp_rdo_trailer = Trailer(std::vector<uint32_t>(ctp_slink->getTrailer()));
179  }
180 
181  // build result
182  CTPResult ctp_rdo_result( ctp_slink->getCTPVersionNumber(), std::move(ctp_rdo_header),
183  std::move(ctp_rdo_trailer), ctp_rdo_data ); //ctp_rdo_data is not moved because it needs to be converted
184  ATH_MSG_VERBOSE( "Dump CTPResult object:\n" + ctp_rdo_result.dump() );
185 
186  //
187  // Check whether the event was accepted or not:
188  //
189  bool accept = ctp_slink->getAccept();
190  ATH_MSG_DEBUG( "L1 Accept = " << accept );
191 
193  // //
194  // egamma RoI //
195  // //
197 
198  std::vector< EMTauResult > emtau_rdo_result_vector;
199 
200 
201  for( unsigned int slink = 0; slink < numEMTauSlinks; ++slink ) {
202 
203  eformat::helper::SourceIdentifier
204  emtau_source_id( eformat::TDAQ_CALO_CLUSTER_PROC_ROI, slink );
205  Header emtau_rdo_header( emtau_source_id.code(), evtNum );
206  std::vector< EMTauRoI > emtau_rdo_data;
207 
208  bool emtau_simulation_error = false;
209  const DataVector< LVL1CTP::SlinkWord >* emtau_slink = 0;
210 
211  if( m_doCalo ) {
212  ATH_MSG_VERBOSE("Reading " << m_caloEMTauLocation[slink].key() );
213  auto handle = SG::makeHandle( m_caloEMTauLocation[slink] );
214  CHECK( handle.isValid() );
215  emtau_slink = handle.cptr();
216 
217  unsigned int icnt = 0;
219  emtau_slink->begin();
221  emtau_slink->end();
222  for( ; itr != end; ++itr ) {
223  ++icnt;
224  if( ( icnt > ( wordsPerHeader + 1 ) ) &&
225  ( icnt <= ( emtau_slink->size() - wordsPerTrailer - 1 ) ) ) {
226 
227  EMTauRoI emtau_roi( ( *itr )->word() );
228  emtau_rdo_data.push_back( emtau_roi );
229  ATH_MSG_DEBUG( "EmTau RoI = " << MSG::hex << std::setw( 8 )
230  << emtau_roi.roIWord() );
231  }
232  }
233 
234  } else {
235  emtau_simulation_error = true;
236  ATH_MSG_VERBOSE( "Retrieved EMTau Slink from TES with key: " << m_caloEMTauLocation[slink] );
237  }
238 
239 
240 
241  Trailer emtau_rdo_trailer( 0, 0 );
242  if( ! emtau_simulation_error ) {
243  emtau_rdo_trailer.setNumDataWords( emtau_rdo_data.size() );
244  } else {
245  emtau_rdo_trailer.setSimulationError();
246  }
247 
248  EMTauResult emtau_rdo_result( std::move(emtau_rdo_header), std::move(emtau_rdo_trailer),
249  std::move(emtau_rdo_data) );
250 
251  emtau_rdo_result_vector.push_back( emtau_rdo_result );
252  }
253 
255  // //
256  // jet/energy RoI //
257  // //
259 
260  std::vector< JetEnergyResult > jetenergy_rdo_result_vector;
261 
262  for( unsigned int slink = 0; slink < numJetEnergySlinks; ++slink ) {
263 
264  eformat::helper::SourceIdentifier
265  jetenergy_source_id( eformat::TDAQ_CALO_JET_PROC_ROI, slink );
266  Header jetenergy_rdo_header( jetenergy_source_id.code(), evtNum );
267  std::vector< JetEnergyRoI > jetenergy_rdo_data;
268 
269  bool jetenergy_simulation_error = false;
270  const DataVector< LVL1CTP::SlinkWord >* jetenergy_slink = 0;
271 
272  if( m_doCalo ) {
273  auto handle = SG::makeHandle( m_caloJetEnergyLocation[slink] );
274  CHECK( handle.isValid() );
275  jetenergy_slink = handle.cptr();
276 
277  ATH_MSG_VERBOSE( "Retrieved JetEnergy Slink from TES with key: "
278  << m_caloJetEnergyLocation[slink] );
279 
280  unsigned int icnt = 0;
282  jetenergy_slink->begin();
284  jetenergy_slink->end();
285  for( ; itr != end; ++itr ) {
286 
287  ++icnt;
288  if( ( icnt > ( wordsPerHeader + 1 ) ) &&
289  ( icnt <= ( jetenergy_slink->size() - wordsPerTrailer - 1 ) ) ) {
290 
291  JetEnergyRoI jetenergy_roi( ( *itr )->word() );
292  jetenergy_rdo_data.push_back( jetenergy_roi );
293  ATH_MSG_DEBUG( "Jet/Energy RoI = " << MSG::hex << std::setw( 8 )
294  << jetenergy_roi.roIWord() );
295  }
296  }
297  } else {
298  jetenergy_simulation_error = true;
299  }
300 
301 
302 
303  // Now wrap up the jet energy triggers:
304  Trailer jetenergy_rdo_trailer( 0, 0 );
305  if( !jetenergy_simulation_error ) {
306  jetenergy_rdo_trailer.setNumDataWords( jetenergy_rdo_data.size() );
307  } else {
308  jetenergy_rdo_trailer.setSimulationError();
309  }
310 
311  JetEnergyResult jetenergy_rdo_result( std::move(jetenergy_rdo_header),
312  std::move(jetenergy_rdo_trailer),
313  std::move(jetenergy_rdo_data) );
314 
315  jetenergy_rdo_result_vector.push_back( jetenergy_rdo_result );
316  }
317 
319  // //
320  // muon RoI //
321  // //
323 
324  eformat::helper::SourceIdentifier
325  muon_source_id( eformat::TDAQ_MUON_CTP_INTERFACE, 0 );
326  Header muctpi_rdo_header( muon_source_id.code(), evtNum );
327  std::vector< MuCTPIRoI > muctpi_rdo_data;
328 
329  bool muctpi_simulation_error = false;
330  const L1MUINT::MuCTPIToRoIBSLink* muctpi_slink = 0;
331 
332  if( m_doMuon ) {
333  auto handle = SG::makeHandle( m_muctpiSLinkLocation );
334  CHECK( handle.isValid() );
335  muctpi_slink = handle.cptr();
336  ATH_MSG_VERBOSE( "Retrieved MuCTPI result from TES with key: "
338 
339  unsigned int icnt = 0;
340  std::vector< unsigned int >::const_iterator itr =
341  muctpi_slink->getMuCTPIToRoIBWords().begin();
342  std::vector< unsigned int >::const_iterator end =
343  muctpi_slink->getMuCTPIToRoIBWords().end();
344  for( ; itr != end; ++itr ) {
345 
346  ++icnt;
347  if( ( icnt > ( wordsPerHeader + 1 ) ) &&
348  ( icnt <= ( muctpi_slink->getMuCTPIToRoIBWords().size() -
349  wordsPerTrailer ) ) ) {
350 
351  MuCTPIRoI muctpi_roi( *itr );
352  muctpi_rdo_data.push_back( muctpi_roi );
353  ATH_MSG_DEBUG( "MuCTPI RoI = " << MSG::hex << std::setw( 8 )
354  << muctpi_roi.roIWord() );
355  }
356  }
357  } else {
358  muctpi_simulation_error = true;
359  }
360 
361 
362 
363  Trailer muctpi_rdo_trailer( 0, 0 );
364  if( ! muctpi_simulation_error ) {
365  muctpi_rdo_trailer.setNumDataWords( muctpi_rdo_data.size() );
366  } else {
367  muctpi_rdo_trailer.setSimulationError();
368  }
369 
370  MuCTPIResult muctpi_rdo_result( std::move(muctpi_rdo_header), std::move(muctpi_rdo_trailer),
371  std::move(muctpi_rdo_data) );
372 
373  //
374  // Finally create RoIB RDO object:
375  //
376  std::unique_ptr<RoIBResult> roib_rdo_result = std::make_unique< RoIBResult>(
377  std::move(muctpi_rdo_result),
378  std::move(ctp_rdo_result),
379  std::move(jetenergy_rdo_result_vector),
380  std::move(emtau_rdo_result_vector) );
381  if( msgLvl( MSG::DEBUG ) ) {
382  ATH_MSG_DEBUG( "RoIB Results:" );
383  roib_rdo_result->muCTPIResult().dumpData( msg( MSG::DEBUG ) );
384  // roib_rdo_result->eMTauResult();
385  // roib_rdo_result->jetEnergyResult();
386  ATH_MSG_DEBUG( roib_rdo_result->cTPResult().dump() );
387  }
388 
389  //
390  // Put RoIB RDO object into SG:
391  //
392  auto roibHandle = SG::makeHandle( m_roibRDOLocation );
393  CHECK( roibHandle.record( std::move( roib_rdo_result ) ) );
394  // no owerwrite possible with DataHandles
395 
396  return StatusCode::SUCCESS;
397  }
398 
399 } // namespace ROIB
ROIB::RoIBuilder::initialize
virtual StatusCode initialize() override
Definition: RoIBuilder.cxx:44
RoIBDefs.h
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
ROIB::RoIBuilder::RoIBuilder
RoIBuilder(const std::string &name, ISvcLocator *pSvcLocator)
Definition: RoIBuilder.cxx:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ROIB::RoIBuilder::m_caloJetEnergyLocation
SG::ReadHandleKeyArray< SlinkWordDV > m_caloJetEnergyLocation
Definition: RoIBuilder.h:64
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
ROIB::EMTauResult
Definition: EMTauResult.h:25
ROIB::RoIBuilder::m_ctpSLinkLocation
SG::ReadHandleKey< LVL1CTP::CTPSLink > m_ctpSLinkLocation
Definition: RoIBuilder.h:50
ROIB::RoIBuilder::m_doMuon
Gaudi::Property< bool > m_doMuon
Definition: RoIBuilder.h:47
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
RoIBuilder.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::renounce
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
Definition: AthCommonDataStore.h:380
ROIB::Trailer::setNumDataWords
void setNumDataWords(const unsigned int)
set number of data words
ROIB::Trailer::setSimulationError
void setSimulationError()
set error status to 0xffff0000 for ROD was not found in SG
AthCommonMsg< Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
ROIB::MuCTPIRoI
Class for storing the 32-bit muon RoI word.
Definition: MuCTPIRoI.h:39
ROIB::CTPResult
Class holding the LVL1 CTP result used by the RoIBuilder.
Definition: CTPResult.h:52
ROIB::JetEnergyRoI
Definition: JetEnergyRoI.h:20
AthCommonDataStore< AthCommonMsg< Algorithm > >::renounceArray
void renounceArray(SG::VarHandleKeyArray &handlesArray)
remove all handles from I/O resolution
Definition: AthCommonDataStore.h:364
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
ROIB::CTPResult::dump
const std::string dump() const
dump raw object content to string
Definition: CTPResult.cxx:56
ROIB
Namespace of the LVL1 RoIB simulation.
Definition: ILvl1ResultAccessTool.h:19
ROIB::RoIBuilder::execute
virtual StatusCode execute() override
Definition: RoIBuilder.cxx:86
ROIB::JetEnergyResult
Definition: JetEnergyResult.h:24
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
ROIB::RoIBuilder::m_caloEMTauLocation
SG::ReadHandleKeyArray< SlinkWordDV > m_caloEMTauLocation
Definition: RoIBuilder.h:57
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
ROIB::RoIBuilder::m_roibRDOLocation
SG::WriteHandleKey< RoIBResult > m_roibRDOLocation
Definition: RoIBuilder.h:73
histSizes.code
code
Definition: histSizes.py:129
lumiFormat.i
int i
Definition: lumiFormat.py:85
ROIB::MuCTPIRoI::roIWord
uint32_t roIWord() const
Method returning the RoI word.
Definition: MuCTPIRoI.cxx:35
ROIB::Header
Header models the LVL1 ROD Header.
Definition: TrigT1Result/TrigT1Result/Header.h:37
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
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
ROIB::EMTauRoI::roIWord
uint32_t roIWord() const
Definition: EMTauRoI.cxx:32
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
ROIB::RoIBuilder::m_muctpiSLinkLocation
SG::ReadHandleKey< L1MUINT::MuCTPIToRoIBSLink > m_muctpiSLinkLocation
Definition: RoIBuilder.h:69
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
ROIB::JetEnergyRoI::roIWord
uint32_t roIWord() const
Method returning the RoI word.
Definition: JetEnergyRoI.cxx:32
AthAlgorithm
Definition: AthAlgorithm.h:47
ROIB::MuCTPIResult
Class holding the RoIs from the MuCTPI collected by the RoIB.
Definition: MuCTPIResult.h:44
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
errorcheck.h
Helpers for checking error return status codes and reporting errors.
ROIB::Trailer
ROIB::Trailer models the LVL1 ROD Trailer.
Definition: Trailer.h:37
ROIB::RoIBuilder::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: RoIBuilder.h:55
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
ROIB::EMTauRoI
Definition: EMTauRoI.h:20
ROIB::RoIBuilder::m_doCalo
Gaudi::Property< bool > m_doCalo
Definition: RoIBuilder.h:46
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
PixelByteStreamErrors::Trailer
@ Trailer
Definition: PixelByteStreamErrors.h:13
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
TrigT1CTPDefs.h
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37