ATLAS Offline Software
Loading...
Searching...
No Matches
TrigCaloDataAccessSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
9
10#include <sstream>
11#include <type_traits>
12
13TrigCaloDataAccessSvc::TrigCaloDataAccessSvc( const std::string& name, ISvcLocator* pSvcLocator )
14 : base_class( name, pSvcLocator ),
15 m_bcidAvgKey("CaloBCIDAverage"),
16 m_correctDead(false),
17 m_lateInitDone(false), m_nSlots(0)
18{
19}
20
22
24 m_autoRetrieveTools = false;
25 m_checkToolDeps = false;
26
27 CHECK( m_larDecoder.retrieve() );
28 CHECK( m_tileDecoder.retrieve() );
29 CHECK( m_robDataProvider.retrieve() );
30 CHECK( m_bcidAvgKey.initialize() );
31 CHECK( m_onOffIdMappingKey.initialize() );
32 CHECK( m_larRoIMapKey.initialize() );
33 CHECK( m_febRodMappingKey.initialize() );
34 CHECK( m_regionSelector_TTEM.retrieve() );
35 CHECK( m_mcsymKey.initialize() );
36 CHECK( m_bcContKey.initialize() );
37 CHECK( m_caloMgrKey.initialize());
38 CHECK( m_regionSelector_TTHEC.retrieve() );
39 CHECK( m_regionSelector_FCALEM.retrieve() );
40 CHECK( m_regionSelector_FCALHAD.retrieve() );
41 CHECK( m_regionSelector_TILE.retrieve() );
44 ATH_CHECK( m_tileHid2RESrcIDKey.initialize() );
45
46 return StatusCode::SUCCESS;
47}
48
50
51 std::lock_guard<std::mutex> lock( m_initMutex ); // use the initMutex to finalize
52 if ( m_lateInitDone ) { // otherwise nothing to delete
53 m_vrodid32fullDet.clear();
54 for( size_t ii=0;ii<m_vrodid32fullDetHG.size();ii++) { m_vrodid32fullDetHG[ii].clear(); }
55 m_vrodid32fullDetHG.clear();
56 for ( size_t slot = 0; slot < m_nSlots; ++ slot ) {
57 EventContext ec;
58 ec.setSlot( slot );
59 HLTCaloEventCache *cache = m_hLTCaloSlot.get( ec );
60 CHECK( cache->larContainer->finalize() );
61 delete cache->larContainer;
62 CHECK( cache->tileContainer->finalize() );
63 delete cache->tileContainer;
64 cache->d0cells->clear();
65 delete cache->d0cells;
66 cache->lastFSEvent = 0xFFFFFFFF;
67 for (unsigned int i : m_insertedCells) delete cache->fullcont->at(i);
68 delete cache->fullcont;
69 } // end of for slots
70 } // end of m_lateInitDone
71 m_lateInitDone=false;
72 return StatusCode::SUCCESS;
73}
74
75
76unsigned int TrigCaloDataAccessSvc::prepareFullCollections( const EventContext& context ) {
77
78 return prepareLArFullCollections( context );
79
80}
81
82
83StatusCode TrigCaloDataAccessSvc::loadCollections ( const EventContext& context,
84 const IRoiDescriptor& roi,
85 const DETID detID,
86 const int sampling,
87 LArTT_Selector<LArCellCont>& loadedCells ) {
88
89 std::vector<IdentifierHash> requestHashIDs;
90
91 ATH_MSG_DEBUG( "LArTT requested for event " << context << " and RoI " << roi );
92 unsigned int sc = prepareLArCollections( context, roi, sampling, detID );
93
94 if ( sc ) return StatusCode::FAILURE;
95
96 {
97 // this has to be guarded because getTT called on the LArCollection bu other threads updates internal map
98 std::lock_guard<std::mutex> getCollClock{ m_hLTCaloSlot.get( context )->mutex };
99 switch ( detID ) {
100 case TTEM: {m_regionSelector_TTEM->lookup(context)->HashIDList( sampling, roi, requestHashIDs ); break; }
101 case TTHEC: {m_regionSelector_TTHEC->lookup(context)->HashIDList( sampling, roi, requestHashIDs ); break; }
102 case FCALEM: {m_regionSelector_FCALEM->lookup(context)->HashIDList( sampling, roi, requestHashIDs ); break; }
103 case FCALHAD: {m_regionSelector_FCALHAD->lookup(context)->HashIDList( sampling, roi, requestHashIDs ); break; }
104 default: break;
105 }
106 }
107
108 ATH_MSG_DEBUG( "requestHashIDs.size() in LoadColl = " << requestHashIDs.size() << " hash checksum "
109 << std::accumulate( requestHashIDs.begin(), requestHashIDs.end(), IdentifierHash( 0 ),
110 []( IdentifierHash h1, IdentifierHash h2 ){ return h1+h2; } ) );
111 if ( msgLvl( MSG::VERBOSE ) ) {
112 for( unsigned int i = 0 ; i < requestHashIDs.size() ; i++ )
113 ATH_MSG_VERBOSE( "m_rIds[" << i << "]=" << requestHashIDs[i] );
114 }
116 loadedCells.setContainer( ( m_hLTCaloSlot.get( context )->larContainer ) );
117 loadedCells.setMap( *roimap );
118
119 {
120 // this has to be guarded because getTT called on the LArCollection bu other threads updates internal map
121 std::lock_guard<std::mutex> getCollClock{ m_hLTCaloSlot.get( context )->mutex };
122 loadedCells.setRoIs( requestHashIDs );
123 }
124 if ( sc ) return StatusCode::FAILURE;
125 else return StatusCode::SUCCESS;
126}
127
128StatusCode TrigCaloDataAccessSvc::loadCollections ( const EventContext& context,
129 const IRoiDescriptor& roi,
130 std::vector<const TileCell*>& loadedCells ) {
131 std::vector<IdentifierHash> requestHashIDs;
132
133 ATH_MSG_DEBUG( "Tile requested for event " << context << " and RoI " << roi );
134 unsigned int sc = prepareTileCollections( context, roi );
135
136 if ( sc ) return StatusCode::FAILURE;
137
138 {
139 // this has to be guarded because getTT called on the LArCollection bu other threads updates internal map
140 std::lock_guard<std::mutex> getCollClock{ m_hLTCaloSlot.get( context )->mutex };
141 m_regionSelector_TILE->lookup(context)->HashIDList( roi, requestHashIDs );
142 }
143 ATH_MSG_DEBUG( "requestHashIDs.size() in LoadColl = " << requestHashIDs.size() << " hash checksum "
144 << std::accumulate( requestHashIDs.begin(), requestHashIDs.end(), IdentifierHash( 0 ),
145 []( IdentifierHash h1, IdentifierHash h2 ){ return h1+h2; } ) );
146 if ( msgLvl( MSG::VERBOSE ) ) {
147 for( unsigned int i = 0 ; i < requestHashIDs.size() ; i++ )
148 ATH_MSG_VERBOSE( "requestHashIDs[" << i << "]=" << requestHashIDs[i] );
149 }
150 size_t listIDsize = requestHashIDs.size();
151 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
152 TileCellCont* tilecell = cache->tileContainer;
153 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> robFrags;
154 loadedCells.clear(); // should reserve
155 for (size_t i = 0; i < listIDsize; ++i){
156 // Find the collection to dump
157 const std::vector<TileCellCollection*>::const_iterator it =
158 (tilecell->find(requestHashIDs[i]));
159 TileCellCollection* col = *it;
160 if ( col == nullptr ) continue;
161 TileCellCollection::const_iterator itt = (*it)->begin();
162 TileCellCollection::const_iterator End = (*it)->end();
163 for (;itt!=End;++itt){
164 const TileCell* cell = (const TileCell*)*itt;
165 loadedCells.push_back( cell );
166 } // End of for printout cells
167 }
168
169 return StatusCode::SUCCESS;
170}
171
172
173StatusCode TrigCaloDataAccessSvc::loadFullCollections ( const EventContext& context,
174 CaloConstCellContainer& cont ) {
175
176 // Gets all data
177 m_robDataProvider->addROBData( context, m_vrodid32fullDet );
178 m_robDataProvider->addROBData( context, m_vrodid32tile );
179
180 unsigned int sc = prepareLArFullCollections( context );
181 ATH_CHECK( sc == 0 );
182
183 sc = prepareTileFullCollections( context );
184 ATH_CHECK( sc == 0 );
185
186 m_hLTCaloSlot.get(context)->lastFSEvent = context.evt();
187
188 std::lock_guard<std::mutex> getCollClock{ m_getCollMutex };
189 CaloCellContainer* cont_to_copy = m_hLTCaloSlot.get(context)->fullcont ;
190 cont.clear();
191 cont.reserve( cont_to_copy->size() );
192 for( const CaloCell* c : *cont_to_copy ) cont.push_back_fast( c );
193 cont.setIsOrdered(true);
194 cont.setIsOrderedAndComplete(true);
195
196 ATH_CHECK( sc == 0 );
197
198 return StatusCode::SUCCESS;
199}
200
201
202unsigned int TrigCaloDataAccessSvc::prepareLArFullCollections( const EventContext& context) {
203
204 ATH_MSG_DEBUG( "Full Col " << " requested for event " << context );
205 if ( !m_lateInitDone && lateInit(context) ) {
206 ATH_MSG_ERROR("Could not execute late init");
207 return 0x1; // dummy code
208 }
209
210 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
211
212 auto lockTime = Monitored::Timer ( "TIME_locking_LAr_FullDet" );
213 std::lock_guard<std::mutex> collectionLock { cache->mutex };
214 lockTime.stop();
215
216 if ( cache->lastFSEvent == context.evt() ) return 0x0; // dummy code
217 cache->larContainer->eventNumber( context.evt() ) ;
218 if ( m_applyOffsetCorrection && cache->larContainer->lumiBCIDCheck( context ) ) {
221 const CaloBCIDAverage* avgPtr = avg.cptr();
222 const LArOnOffIdMapping* onoffPtr = onoff.cptr();
223 if ( avgPtr && onoffPtr ) cache->larContainer->updateBCID( *avgPtr, *onoffPtr );
224 }
225
226
227 unsigned int status(0);
228
229 const LArDeadOTXFromSC* deadHandle = nullptr;
230 if ( m_correctDead ){
232 if ( !deadHdl.isValid() ){
233 ATH_MSG_WARNING("Should not try to use LArDEADOTXFromSC" );
234 } else {
235 deadHandle = deadHdl.cptr();
236 }
237 }
238
239 for( size_t ii=0;ii<m_vrodid32fullDetHG.size();ii++) {
240 std::vector<uint32_t>& vrodid32fullDet = m_vrodid32fullDetHG[ii];
241 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> robFrags;
242 m_robDataProvider->addROBData( context, vrodid32fullDet );
243 m_robDataProvider->getROBData( context, vrodid32fullDet, robFrags );
244
245 status |= convertROBs( robFrags, ( cache->larContainer ), (cache->larRodBlockStructure_per_slot), cache->rodMinorVersion, cache->robBlockType, deadHandle );
246
247 if ( vrodid32fullDet.size() != robFrags.size() ) {
248 ATH_MSG_DEBUG( "Missing ROBs, requested " << vrodid32fullDet.size() << " obtained " << robFrags.size() );
249 //status |= 0x1; // dummy code
250 clearMissing( vrodid32fullDet, robFrags, ( cache->larContainer ) );
251 }
252 } // end of for m_vrodid32fullDetHG.size()
253
254 int detid(0);
255 auto detidMon = Monitored::Scalar<int>( "det", detid );
256
257 Monitored::Group( m_monTool, lockTime, detidMon );
258 return status;
259}
260
261unsigned int TrigCaloDataAccessSvc::prepareTileFullCollections( const EventContext& context) {
262
263 ATH_MSG_DEBUG( "Full Col " << " requested for event " << context );
264 if ( !m_lateInitDone && lateInit(context) ) {
265 ATH_MSG_ERROR("Could not execute late init");
266 return 0x1; // dummy code
267 }
268
269 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
270
271 auto lockTime = Monitored::Timer ( "TIME_locking_LAr_FullDet" );
272 std::lock_guard<std::mutex> collectionLock { cache->mutex };
273 lockTime.stop();
274
275 if ( cache->lastFSEvent == context.evt() ) return 0x0;
276 if ( cache->tileContainer->eventNumber() != context.evt() )
277 cache->d0cells->clear();
278 cache->tileContainer->eventNumber( context.evt() );
279
280 unsigned int status(0);
281 convertROBs( context, m_rIdstile, cache->tileContainer, cache->d0cells );
282
283 int detid(0);
284 auto detidMon = Monitored::Scalar<int>( "det", detid );
285
286 Monitored::Group( m_monTool, lockTime, detidMon );
287 return status;
288}
289
290unsigned int TrigCaloDataAccessSvc::lateInit(const EventContext& context) { // non-const this thing
291
292 std::lock_guard<std::mutex> lock( m_initMutex );
293 if ( m_lateInitDone )
294 return 0x0; // dummy code
295
296 ATH_MSG_DEBUG( "Performing late init" );
297
298 // allocate collections
300
301 // preparing full container list of ROBs - tile will be included soon
302 std::vector<uint32_t> vrodid32lar;
303 std::vector<uint32_t> vrodid32em;
304 std::vector<uint32_t> vrodid32hec;
305 std::vector<uint32_t> vrodid32hec0;
306 std::vector<uint32_t> vrodid32hec1;
307 std::vector<uint32_t> vrodid32hec2;
308 std::vector<uint32_t> vrodid32hec3;
309 std::vector<uint32_t> vrodid32fcalem;
310 std::vector<uint32_t> vrodid32fcalhad;
311
312 TrigRoiDescriptor tmproi(true);
313 std::vector<uint32_t> vrodid32tile;
314 std::vector<IdentifierHash> rIdstile;
315 // TTEM
316 m_regionSelector_TTEM->lookup(context)->ROBIDList(-1,tmproi,vrodid32em);
317 // TTHEC
318 m_regionSelector_TTHEC->lookup(context)->ROBIDList(0,tmproi,vrodid32hec0);
319 m_regionSelector_TTHEC->lookup(context)->ROBIDList(1,tmproi,vrodid32hec1);
320 m_regionSelector_TTHEC->lookup(context)->ROBIDList(2,tmproi,vrodid32hec2);
321 m_regionSelector_TTHEC->lookup(context)->ROBIDList(3,tmproi,vrodid32hec3);
322 // FCALHAD
323 m_regionSelector_FCALEM->lookup(context)->ROBIDList(-1,tmproi,vrodid32fcalem);
324 m_regionSelector_FCALHAD->lookup(context)->ROBIDList(-1,tmproi,vrodid32fcalhad);
325 m_regionSelector_TILE->lookup(context)->ROBIDList(tmproi,vrodid32tile);
326 m_regionSelector_TILE->lookup(context)->HashIDList(tmproi,rIdstile);
327
328 m_vrodid32tile.resize( vrodid32tile.size() );
329 m_rIdstile.resize(rIdstile.size() );
330 // Tile RODs and ID coming from the Tile tables are not unique
331 // iii and iij are local variables helping to clear non-unique IDs
332 auto iii = std::unique_copy(vrodid32tile.begin(),vrodid32tile.end(),m_vrodid32tile.begin());
333 auto iij = std::unique_copy(rIdstile.begin(),rIdstile.end(),m_rIdstile.begin());
334 std::sort( m_vrodid32tile.begin(), iii );
335 std::sort( m_rIdstile.begin(), iij );
336 iii = std::unique_copy(m_vrodid32tile.begin(),iii,m_vrodid32tile.begin());
337 iij = std::unique_copy(m_rIdstile.begin(),iij,m_rIdstile.begin());
338 m_vrodid32tile.resize( std::distance(m_vrodid32tile.begin(), iii) );
339 m_rIdstile.resize( std::distance(m_rIdstile.begin(), iij) );
340
341 vrodid32lar.insert(vrodid32lar.end(),vrodid32em.begin(),vrodid32em.end());
342 vrodid32hec.insert(vrodid32hec.end(),vrodid32hec0.begin(),vrodid32hec0.end());
343 vrodid32lar.insert(vrodid32lar.end(),vrodid32hec.begin(),vrodid32hec.end());
344 vrodid32lar.insert(vrodid32lar.end(),vrodid32fcalhad.begin(),vrodid32fcalhad.end());
345 vrodid32lar.insert(vrodid32lar.end(),vrodid32fcalem.begin(),vrodid32fcalem.end());
346 m_vrodid32fullDet.insert(m_vrodid32fullDet.end(), vrodid32lar.begin(), vrodid32lar.end() );
347
348
355
356 unsigned int nFebs=70;
357 unsigned int high_granu = (unsigned int)ceilf(m_vrodid32fullDet.size()/((float)nFebs) );
358 unsigned int jj=0;
359 unsigned int kk=0;
360 m_vrodid32fullDetHG.resize(high_granu);
361 for( unsigned int ii=0; ii<m_vrodid32fullDet.size();ii++){
362 if ( kk >= nFebs ) {
363 kk-=nFebs;
364 jj++;
365 }
366 std::vector<uint32_t> & vec = m_vrodid32fullDetHG.at(jj);
367 vec.push_back(m_vrodid32fullDet[ii]);
368 kk++;
369 }
371 const CaloDetDescrManager* theCaloDDM = *caloMgrHandle;
372 const CaloCell_ID* theCaloCCIDM = theCaloDDM->getCaloCell_ID();
373 unsigned int hashMax = theCaloCCIDM->calo_cell_hash_max();
374
375 // Prepare cache containers to be used for LAr unpacking.
376 for ( size_t slot = 0; slot < m_nSlots; ++ slot ) {
377 EventContext ec;
378 ec.setSlot( slot );
379 HLTCaloEventCache *cache = m_hLTCaloSlot.get( ec );
380 cache->larContainer = new LArCellCont();
381 cache->larRodBlockStructure_per_slot = nullptr;
382 if ( cache->larContainer->initialize( **roimap, **onoff, **mcsym, **febrod, **larBadChan, *theCaloDDM).isFailure() )
383 return 0x1; // dummy code
384 std::vector<CaloCell*> local_cell_copy;
385 local_cell_copy.reserve(200000);
386 LArCellCont* larcell = cache->larContainer;
387 cache->lastFSEvent = 0xFFFFFFFF;
389 cachefullcont->reserve(190000);
390 const LArBadChannelCont& badchannel = **larBadChan;
391 for(unsigned int lcidx=0; lcidx < larcell->size(); lcidx++){
392 LArCellCollection* lcc = larcell->at(lcidx);
393 unsigned int lccsize = lcc->size();
394 for(unsigned int lccidx=0; lccidx<lccsize; lccidx++){
395 CaloCell* cell = ((*lcc).at(lccidx));
396 if ( cell && cell->caloDDE() ) {
397 LArBadChannel bc = badchannel.offlineStatus(cell->ID());
398 bool good(true);
399 if (! bc.good() ){
400 // cell has some specific problems
401 if ( bc.unstable() ) good=false;
402 if ( bc.highNoiseHG() ) good=false;
403 if ( bc.highNoiseMG() ) good=false;
404 if ( bc.highNoiseLG() ) good=false;
405 if ( bc.problematicForUnknownReason() ) good=false;
406 }
407 if ( good ) local_cell_copy.push_back( cell );
408 }
409 } // end of loop over cells
410 } // end of loop over collection
411
412// This should stay here as this will be enabled when tile is ready to be decoded as well
413 TileCellCont* tilecell = new TileCellCont();
414 cache->tileContainer = tilecell;
415 tilecell->setHashIdToROD( *tileHid2RESrcID );
416 if( tilecell->initialize().isFailure() ) return 0x1; //dummy code
417 for (unsigned int i=0;i<4;i++) {
418 m_tileDecoder->loadRw2Cell ( i, tilecell->Rw2CellMap(i) );
419 m_tileDecoder->loadRw2Pmt ( i, tilecell->Rw2PmtMap (i) );
420 }
421 m_tileDecoder->loadMBTS( tilecell->MBTS_map(), tilecell->MBTS_channel() );
422 m_mbts_rods = tilecell->MBTS_RODs();
423 for(size_t i = 0 ; i < m_mbts_rods->size(); i++)
424 m_mbts_add_rods.insert(m_mbts_add_rods.end(),(*m_mbts_rods).begin(),(*m_mbts_rods).end());
425 sort(m_mbts_add_rods.begin(),m_mbts_add_rods.end());
428 for(unsigned int lcidx=0; lcidx < tilecell->size(); lcidx++){
429 TileCellCollection* lcc = tilecell->at(lcidx);
430 unsigned int lccsize = lcc->size();
431 for(unsigned int lccidx=0; lccidx<lccsize; lccidx++){
432 CaloCell* cell = ((*lcc).at(lccidx));
433 if ( cell ) local_cell_copy.push_back( cell );
434 } // end of loop over cells
435 TileRawChannelCollection::ID frag_id = ((*lcc).identify() & 0x0FFF);
436 int ros = (frag_id >> 8);
437 if ( ros == 1 ) { //treatment for d0Cells in barrel
438 int drawer = (frag_id & 0xFF);
439 TileCellCollection::iterator pCell = lcc->begin();
440 pCell+=2;
441 d0cellsp->m_cells[drawer] = *pCell;
442 }
443 } // end of loop over collection
444
445 // d0merge cells
446 cache->d0cells = d0cellsp;
447
448 // For the moment the container has to be completed by hand (again, because of tile)
449 for(unsigned int i=0;i<hashMax;i++){
450 cachefullcont->push_back_fast(nullptr);
451 }
452
453 unsigned int localcellMax = local_cell_copy.size();
454 for(unsigned int i=0;i<localcellMax;i++){
455 unsigned int j = local_cell_copy.at(i)->caloDDE()->calo_hash();
456 if ( j < hashMax ) {
457 cachefullcont->at(j) = local_cell_copy.at(i);
458 }
459 }
460 for(unsigned int i=0;i<hashMax;i++)
461 if ( cachefullcont->at(i) == nullptr ){
462 Identifier id = theCaloCCIDM->cell_id(i);
463 if ( id!=0 ){
464 const CaloDetDescrElement* el = theCaloDDM->get_element(id);
465 if ( el->is_tile() ) {
466 cachefullcont->at(i) = new TileCell(el,0,0,0,0,CaloGain::TILEHIGHHIGH);
467 } else {
468 cachefullcont->at(i) = new LArCell(el,0,0,0,(CaloGain::CaloGain)0);
469 }
470
471 if (slot==0) m_insertedCells.push_back(i);
472 }
473 }
474
475 cachefullcont->setHasCalo(CaloCell_ID::LAREM);
476 cachefullcont->setHasCalo(CaloCell_ID::LARHEC);
477 cachefullcont->setHasCalo(CaloCell_ID::LARFCAL);
478 cachefullcont->setHasCalo(CaloCell_ID::TILE); //lying... But this needs to be checked later
479
480 // make sure this "map" container has a good hashID
481 cachefullcont->order();
482
483 if ( hashMax != cachefullcont->size() )
484 ATH_MSG_ERROR("Problem in the size of the full container");
485 cachefullcont->setIsOrdered(true);
486 cachefullcont->setIsOrderedAndComplete(true);
487 cache->fullcont = cachefullcont;
488
489 local_cell_copy.clear();
490 }
491 m_lateInitDone = true;
492 return 0x0;
493}
494
495unsigned int TrigCaloDataAccessSvc::convertROBs( const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& robFrags,
496 LArCellCont* larcell, LArRodBlockStructure*& larRodBlockStructure_per_slot,
497 uint16_t rodMinorVersion, uint32_t robBlockType, const LArDeadOTXFromSC* deadHandle ) {
498
499 unsigned int status(0);
500 for ( auto rob: robFrags ) {
501 uint32_t sourceID = rob->source_id();
502 const std::vector<LArCellCollection*>::const_iterator it = larcell->find( sourceID );
503 //TB The find also switches the state of the collection to "decoded" so repeated decoding is avoided
504
505 if ( it != larcell->end() && ( *it )->size() != 0 ) { // Already decoded collection
506
507 // TB if we have entered here it means the decoding did not occur yet ( or failed )
508 //
509 LArCellCollection* coll = *it;
510 ATH_MSG_DEBUG( "ROB of ID " << sourceID << " to be decoded" );
511
512 std::lock_guard<std::mutex> decoderLock( m_lardecoderProtect );
513 //TB next two lines seem danger, as they seem to rely on the decoder state
514 const HWIdentifier& feb_id_local = larcell->findsec( sourceID );
515 m_larDecoder->setsecfeb( feb_id_local );
516 if ( ! m_larDecoder->check_valid( rob, msg() ) ){
517 ATH_MSG_WARNING( "Error reading bytestream"<<
518 "event: Bad ROB block ( eformat checks ) : 0x"
519 << std::hex << sourceID << std::dec );
520 // Data seems corrupted
521 //status |= 0x1; // dummy code
522 reset_LArCol ( coll );
523
524 } else {
525 // Get Rod Data and size of fragment
526 const uint32_t* roddata = 0;
527 rob->rod_data( roddata );
528 size_t roddatasize = rob->rod_ndata();
529 if ( roddatasize < 3 ) {
530 ATH_MSG_WARNING( "Error reading bytestream"<<
531 "event: Empty ROD block ( less than 3 words ) : 0x"
532 << std::hex << sourceID << std::dec );
533 // Data seems corrupted
534 //status |= 0x1; // dummy code
535 reset_LArCol ( coll );
536 } else { // End of if small size
537 //TB the converter has state
538 m_larDecoder->fillCollectionHLT( *rob, roddata, roddatasize, *coll, larRodBlockStructure_per_slot, rodMinorVersion, robBlockType );
539 if ( deadHandle ){
540 if ( deadHandle->isThisOTXdead(feb_id_local) ) {
541 const std::vector<float>& corr = deadHandle->correctionFromThisOTXdead(feb_id_local);
542 // The sizes here are guaranteed by construction
543 for(size_t i=0;i<128;i++) {
544 (*coll)[i+128]->set(corr[i],0,0,0x1000,CaloGain::LARHIGHGAIN);
545 }
546 }
547 HWIdentifier feb_id_local2(larRodBlockStructure_per_slot->getFEBID());
548 if ( deadHandle->isThisOTXdead(feb_id_local2) ) {
549 const std::vector<float>& corr = deadHandle->correctionFromThisOTXdead(feb_id_local2);
550 // The sizes here are guaranteed by construction
551 for(size_t i=0;i<128;i++) (*coll)[i]->set(corr[i],0,0,0x1000,CaloGain::LARHIGHGAIN);
552
553 }
554 }
555
556 // Accumulates inferior byte from ROD Decoder
557 // TB the converter has state
558 //status |= (m_larDecoder->report_error());
559
560 if ( m_applyOffsetCorrection ) larcell->applyBCIDCorrection( sourceID );
561 }
562
563 }
564 } else {
565 ATH_MSG_VERBOSE( "ROB of ID " << sourceID << " already decoded" );
566 }
567 }
568 ATH_MSG_DEBUG( "finished decoding" );
569 return status;
570}
571
572unsigned int TrigCaloDataAccessSvc::convertROBs( const EventContext& context,
573 const std::vector<IdentifierHash>& rIds,
574 TileCellCont* tilecell,
576 unsigned int status(0);
577 TileCellCollection* mbts = tilecell->MBTS_collection();
578 const TileHid2RESrcID* hid2re = tilecell->getHashIdToROD();
579
580 size_t listIDsize = rIds.size();
581 std::vector<unsigned int> tile; tile.push_back(0);
582 // Tile likes rob by rob
583 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> robFrags1;
584 for (size_t i = 0; i < listIDsize; ++i){
585 tile[0] = tilecell->find_rod(rIds[i]);
586 m_robDataProvider->getROBData(context,tile,robFrags1);
587 // Number of ROBs smaller than requested is below
588 //if ( robFrags1.empty() ) m_error|=0x10000000;
589 // Find the collection to fill
590 const std::vector<TileCellCollection*>::const_iterator it =
591 (tilecell->find(rIds[i]));
592 TileCellCollection* col = *it;
593 if ( robFrags1.size()!=0 && col != nullptr ) {
594 size_t roddatasize = robFrags1[0]->rod_ndata();
595 // insert data into vector (to be removed soon)
596 if (roddatasize < 3) {
597 ATH_MSG_WARNING( "Error reading bytestream"<<
598 "event: Empty ROD block (less than 3 words) : 0x"
599 << std::hex << tile[0] << std::dec );
600 msg(MSG::WARNING) << "Error reading bytestream "
601 << "event: Empty ROD block (less than 3 words) : 0x"
602 << std::hex << tile[0] << std::dec << endmsg;
603 // Data seems corrupted
604 //m_error|=0x20000000;
605 if ( !tilecell->cached(rIds[i])){
606 // resets collection
607 reset_TileCol(col);
608 }
609 robFrags1.clear();
610 } else {// End of if small size
611 std::lock_guard<std::mutex> decoderLock { m_tiledecoderProtect };
612 if ( !tilecell->cached(rIds[i]))
613 m_tileDecoder->fillCollectionHLT(robFrags1[0],*col,*d0cells,mbts,hid2re);
614 m_tileDecoder->mergeD0cellsHLT(*d0cells,*col);
615 // Accumulates superior byte from ROD Decoder
616 //m_error|=m_tileDecoder->report_error();
617 robFrags1.clear();
618 } // end of else
619 } // end of if robFrags1.size
620 } // End of for through RobFrags
621
622 ATH_MSG_DEBUG( "finished decoding" );
623 return status;
624}
625
626void TrigCaloDataAccessSvc::missingROBs( const std::vector<uint32_t>& request,
627 const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& response,
628 std::set<uint32_t>& missing ) const {
629
630 std::set<uint32_t> receivedROBsSet;
631 for ( auto rob: response )
632 receivedROBsSet.insert( rob->source_id() );
633 std::set<uint32_t> requestedROBsSet( request.begin(), request.end() );
634
635 std::set_difference( requestedROBsSet.begin(), requestedROBsSet.end(),
636 receivedROBsSet.begin(), receivedROBsSet.end(),
637 std::inserter( missing, missing.begin() ) );
638}
639
640
641void TrigCaloDataAccessSvc::clearMissing( const std::vector<uint32_t>& request,
642 const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& response,
643 LArCellCont* larcell ) {
644 std::set<uint32_t> missing;
645 missingROBs( request, response, missing );
646 for ( uint32_t robID : missing ) {
647 const std::vector<LArCellCollection*>::const_iterator it = larcell->find( robID );
648 if ( it != larcell->end() && ( *it )->size()!=0 ) { // Already decoded collection
649 reset_LArCol ( *it );
650 }
651 }
652}
653
654
655unsigned int TrigCaloDataAccessSvc::prepareLArCollections( const EventContext& context,
656 const IRoiDescriptor& roi,
657 const int sampling,
658 DETID detector ) {
659
660 // If the full event was already unpacked, don't need to unpack RoI
661 if ( !m_lateInitDone && lateInit(context) ) {
662 return 0x1; // dummy code
663 }
664 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
665 if ( cache->lastFSEvent == context.evt() ) return 0x0;
666
667 std::vector<uint32_t> requestROBs;
668
669 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> robFrags;
670 switch ( detector ) {
671 case TTEM: {m_regionSelector_TTEM->lookup(context)->ROBIDList( sampling, roi, requestROBs ); break; }
672 case TTHEC: {m_regionSelector_TTHEC->lookup(context)->ROBIDList( sampling, roi, requestROBs ); break; }
673 case FCALEM: {m_regionSelector_FCALEM->lookup(context)->ROBIDList( sampling, roi, requestROBs ); break; }
674 case FCALHAD: {m_regionSelector_FCALHAD->lookup(context)->ROBIDList( sampling, roi, requestROBs ); break; }
675 default: break;
676 }
677
678 m_robDataProvider->addROBData( context, requestROBs );
679 m_robDataProvider->getROBData( context, requestROBs, robFrags );
680 if ( robFrags.empty() && (!requestROBs.empty()) ) {
681 return 0x0; // dummy code
682 }
683
684 auto lockTime = Monitored::Timer ( "TIME_locking_LAr_RoI" );
685 std::lock_guard<std::mutex> collectionLock { cache->mutex };
686 lockTime.stop();
687
688 // TB, what would happen from now inside the collection unapcking
689 // if this event number is different than the one for each collection the unpacking will happen,
690 // if it is the same the unpacking will not be repeated
691 // same in prepareLArFullCollections
692 cache->larContainer->eventNumber( context.evt() );
693 if ( m_applyOffsetCorrection && cache->larContainer->lumiBCIDCheck( context ) ) {
696 const CaloBCIDAverage* avgPtr = avg.cptr();
697 const LArOnOffIdMapping* onoffPtr = onoff.cptr();
698 if ( avgPtr && onoffPtr ) cache->larContainer->updateBCID( *avgPtr, *onoffPtr );
699 }
700
701 const LArDeadOTXFromSC* deadHandle = nullptr;
702 if ( m_correctDead ){
704 if ( !deadHdl.isValid() ){
705 ATH_MSG_WARNING("Should not try to use LArDEADOTXFromSC" );
706 } else {
707 deadHandle = deadHdl.cptr();
708 }
709 }
710
711 unsigned int status = convertROBs( robFrags, ( cache->larContainer ), (cache->larRodBlockStructure_per_slot), cache->rodMinorVersion, cache->robBlockType, deadHandle );
712
713 if ( requestROBs.size() != robFrags.size() ) {
714 ATH_MSG_DEBUG( "Missing ROBs, requested " << requestROBs.size() << " obtained " << robFrags.size() );
715 //status |= 0x1; // dummy code
716 clearMissing( requestROBs, robFrags, ( cache->larContainer ) );
717 }
718 auto roiROBs = Monitored::Scalar( "roiROBs_LAr", robFrags.size() );
719 auto roiEta = Monitored::Scalar( "roiEta_LAr", roi.eta() );
720 auto roiPhi = Monitored::Scalar( "roiPhi_LAr", roi.phi() );
721
722 Monitored::Group( m_monTool, lockTime, roiEta, roiPhi, roiROBs );
723 return status;
724}
725
726unsigned int TrigCaloDataAccessSvc::prepareTileCollections( const EventContext& context,
727 const IRoiDescriptor& roi) {
728
729 // If the full event was already unpacked, don't need to unpack RoI
730 if ( !m_lateInitDone && lateInit(context) ) {
731 return 0x1; // dummy code
732 }
733 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
734 if ( cache->lastFSEvent == context.evt() ) return 0x0;
735
736 std::vector<uint32_t> requestROBs;
737 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> robFrags;
738 std::vector<IdentifierHash> rIds;
739 m_regionSelector_TILE->lookup(context)->ROBIDList( 0, roi, requestROBs );
740 m_regionSelector_TILE->lookup(context)->HashIDList(roi, rIds);
741 m_robDataProvider->addROBData( context, requestROBs );
742
743
744 std::lock_guard<std::mutex> collectionLock { cache->mutex };
745 if ( cache->tileContainer->eventNumber() != context.evt() )
746 cache->d0cells->clear();
747 cache->tileContainer->eventNumber( context.evt() );
748
749 unsigned int status = convertROBs( context, rIds, cache->tileContainer, cache->d0cells );
750
751 return status;
752}
753
754unsigned int TrigCaloDataAccessSvc::prepareMBTSCollections( const EventContext& context) {
755
756 // If the full event was already unpacked, don't need to unpack RoI
757 if ( !m_lateInitDone && lateInit(context) ) {
758 return 0x0; // dummy code
759 }
760 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
761 if ( cache->lastFSEvent == context.evt() ) return 0x0;
762
763 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> robFrags;
764 m_robDataProvider->addROBData( context, m_mbts_add_rods );
765 std::lock_guard<std::mutex> collectionLock { cache->mutex };
766 TileCellCont* tilecell = cache->tileContainer;
767 if ( cache->tileContainer->eventNumber() != context.evt() )
768 cache->d0cells->clear();
769 cache->tileContainer->eventNumber( context.evt() );
770
771 const std::vector<unsigned int>* ids = tilecell->MBTS_IDs();
772 std::vector<IdentifierHash> tileIds;
773 for(size_t i=0;i<ids->size(); i++) tileIds.push_back( (*ids)[i] );
774 unsigned int status = convertROBs( context, tileIds, cache->tileContainer, cache->d0cells );
775
776 return status;
777}
778
779
780
781StatusCode TrigCaloDataAccessSvc::loadMBTS ( const EventContext& context,
782 std::vector<const TileCell*>& loadedCells ) {
783
784 ATH_MSG_DEBUG( "MBTS requested for event " << context );
785 unsigned int sc = prepareMBTSCollections(context);
786
787 if ( sc ) return StatusCode::FAILURE;
788
789 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
790 std::lock_guard<std::mutex> collectionLock { cache->mutex };
791 TileCellCont* tilecell = cache->tileContainer;
792 TileCellCollection* mbts = tilecell->MBTS_collection();
793 loadedCells.reserve(mbts->size());
794 for (size_t i=0;i<mbts->size(); ++i)
795 loadedCells.push_back(mbts->at(i));
796 return StatusCode::SUCCESS;
797
798}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Definition of CaloDetDescrManager.
std::vector< size_t > vec
#define CHECK(...)
Evaluate an expression and check for errors.
LArBadXCont< LArBadChannel > LArBadChannelCont
static Double_t sc
MDT_Response response
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Header file to be included by clients of the Monitored infrastructure.
DETID
An enum to define subdetector names.
Definition RegSelEnums.h:23
@ FCALEM
Definition RegSelEnums.h:35
@ TTHEC
Definition RegSelEnums.h:29
@ FCALHAD
Definition RegSelEnums.h:36
@ TTEM
Definition RegSelEnums.h:28
Container class for CaloCell.
void push_back_fast(CaloCell *)
reimplementation of push_back to gain speed in readin
void order()
order container
void setHasCalo(const CaloCell_ID::SUBCALO caloNum)
set which calo has been filled.
void setIsOrderedAndComplete(const bool ordered)
indicate that the container is complete and in order
void setIsOrdered(const bool ordered)
indicates that the container is ordered
size_type calo_cell_hash_max() const
cell 'global' hash table max size
Identifier cell_id(const int subCalo, const int barec_or_posneg, const int sampling_or_fcalmodule, const int region_or_dummy, const int eta, const int phi) const
Make a cell (== channel) ID from constituting fields and subCalo index; for (Mini)FCAL,...
Helper class for offline cell identifiers.
Definition CaloCell_ID.h:34
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
CaloCellContainer that can accept const cell pointers.
void setIsOrderedAndComplete(bool ordered)
indicate that the container is complete and in order
void setIsOrdered(bool ordered)
indicates that the container is ordered
void push_back_fast(const CaloCell *cell)
reimplementation of push_back to gain speed in readin
This class groups all DetDescr information related to a CaloCell.
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
This class provides the client interface for accessing the detector description information common to...
const CaloCell_ID * getCaloCell_ID() const
get calo cell ID helper
void clear()
Erase all the elements in the collection.
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
Definition DataVector.h:838
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
const T * at(size_type n) const
Access an element, as an rvalue.
DataModel_detail::iterator< DataVector > iterator
Standard iterator.
Definition DataVector.h:842
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
Describes the API of the Region of Ineterest geometry.
virtual double eta() const =0
virtual double phi() const =0
Methods to retrieve data members.
This is a "hash" representation of an Identifier.
bool highNoiseHG() const
bool problematicForUnknownReason() const
bool unstable() const
bool highNoiseMG() const
bool highNoiseLG() const
bool good() const
Returns true if no problems at all (all bits at zero)
LArBC_t offlineStatus(const Identifier id) const
Query the status of a particular channel by offline ID This is the main client access method.
Container Class for LArCell in a ROB used by EF.
Class which contains statically allocated LArCellCollections.
Definition LArCellCont.h:40
StatusCode initialize(const LArRoIMap &roiMap, const LArOnOffIdMapping &onOffMap, const LArMCSym &mcsym, const LArFebRodMapping &febrod, const LArBadChannelCont &badchannel, const CaloDetDescrManager &ddm)
initialize method.
const std::vector< LArCellCollection * >::const_iterator find(const HWIdentifier &id) const
Finds a collection by its LArReadoutModuleID.
void applyBCIDCorrection(const unsigned int &rodid)
method to apply correction based on the luminosity to the energy
void eventNumber(const unsigned int eN)
sets Event Number
Definition LArCellCont.h:83
void updateBCID(const CaloBCIDAverage &, const LArOnOffIdMapping &)
update BCID dependent correction table for MT case
HWIdentifier findsec(const unsigned int &id) const
Each Collection contains data from 2 FEBs.
StatusCode finalize(void)
finalize method.
bool lumiBCIDCheck(const EventContext &context)
Data object for LAr calorimeter readout cell.
Definition LArCell.h:53
const std::vector< float > & correctionFromThisOTXdead(HWIdentifier febid) const
bool isThisOTXdead(HWIdentifier febid) const
void setRoIs(const VEC_TT_ID &ids)
void setMap(const LArRoIMap *map)
void setContainer(const CONTAINER *c)
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
A monitored timer.
const_pointer_type cptr()
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
This class builds the Tile cells.
StatusCode initialize(void)
const std::vector< int > & Rw2PmtMap(int section)
int MBTS_channel(void)
void eventNumber(const unsigned int eN)
unsigned int find_rod(const unsigned int &id) const
const std::vector< int > & Rw2CellMap(int section)
const std::vector< TileCellCollection * >::const_iterator find(const unsigned int &id) const
Finds a collection.
const TileCellCollection * MBTS_collection(void) const
bool cached(const unsigned int &rodid)
void setHashIdToROD(const TileHid2RESrcID *p)
StatusCode finalize(void)
const TileHid2RESrcID * getHashIdToROD() const
const std::vector< unsigned int > * MBTS_IDs()
const std::vector< unsigned int > * MBTS_RODs()
std::map< unsigned int, unsigned int > & MBTS_map(void)
This class provides conversion between fragment ID and RESrcID.
PublicToolHandle< TileROD_Decoder > m_tileDecoder
std::vector< unsigned int > m_mbts_add_rods
ToolHandle< IRegSelTool > m_regionSelector_TTHEC
unsigned int prepareLArFullCollections(const EventContext &context)
SG::ReadCondHandleKey< TileHid2RESrcID > m_tileHid2RESrcIDKey
SG::ReadHandleKey< CaloBCIDAverage > m_bcidAvgKey
void reset_TileCol(TileCellCollection *col)
void clearMissing(const std::vector< uint32_t > &request, const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &response, LArCellCont *larcell)
clear fragments of the collection for which ROBs were not available
SG::ReadCondHandleKey< LArFebRodMapping > m_febRodMappingKey
Gaudi::Property< bool > m_applyOffsetCorrection
SG::ReadCondHandleKey< LArOnOffIdMapping > m_onOffIdMappingKey
std::vector< uint32_t > m_vrodid32tile
SG::ReadCondHandleKey< LArBadChannelCont > m_bcContKey
PublicToolHandle< LArRodDecoder > m_larDecoder
ToolHandle< GenericMonitoringTool > m_monTool
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
virtual StatusCode initialize() override
virtual StatusCode loadCollections(const EventContext &context, const IRoiDescriptor &roi, const DETID detID, const int sampling, LArTT_Selector< LArCellCont > &loadedCells) override
TrigCaloDataAccessSvc(const std::string &name, ISvcLocator *pSvcLocator)
ToolHandle< IRegSelTool > m_regionSelector_FCALEM
unsigned int lateInit(const EventContext &context)
SG::ReadHandleKey< LArDeadOTXFromSC > m_deadOTXFromSCKey
virtual StatusCode loadMBTS(const EventContext &context, std::vector< const TileCell * > &loadedCells) override
unsigned int prepareTileFullCollections(const EventContext &context)
SG::ReadCondHandleKey< LArRoIMap > m_larRoIMapKey
std::vector< std::vector< uint32_t > > m_vrodid32fullDetHG
ToolHandle< IRegSelTool > m_regionSelector_TTEM
SG::SlotSpecificObj< HLTCaloEventCache > m_hLTCaloSlot
std::vector< unsigned int > m_insertedCells
void missingROBs(const std::vector< uint32_t > &request, const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &response, std::set< uint32_t > &missing) const
fill the set of missing robs given the request and response from RoBDatProvider
std::vector< uint32_t > m_vrodid32fullDet
const std::vector< unsigned int > * m_mbts_rods
ToolHandle< IRegSelTool > m_regionSelector_FCALHAD
unsigned int prepareLArCollections(const EventContext &context, const IRoiDescriptor &roi, const int sampling, DETID detector)
LAr TT collections preparation code.
ToolHandle< IRegSelTool > m_regionSelector_TILE
unsigned int convertROBs(const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &robFrags, LArCellCont *larcell, LArRodBlockStructure *&larRodBlockStructure, uint16_t rodMinorVersion, uint32_t robBlockType, const LArDeadOTXFromSC *dead)
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
unsigned int prepareFullCollections(const EventContext &context)
SG::ReadCondHandleKey< LArMCSym > m_mcsymKey
void reset_LArCol(LArCellCollection *coll)
virtual StatusCode finalize() override
unsigned int prepareTileCollections(const EventContext &context, const IRoiDescriptor &roi)
std::vector< IdentifierHash > m_rIdstile
virtual StatusCode loadFullCollections(const EventContext &context, CaloConstCellContainer &cont) override
unsigned int prepareMBTSCollections(const EventContext &context)
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
@ TILEHIGHHIGH
Definition CaloGain.h:15
@ LARHIGHGAIN
Definition CaloGain.h:18
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
size_t getNSlots()
Return the number of event slots.
DataModel_detail::iterator< DVL > unique(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of unique for DataVector/List.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
convience structure to keep together a collection and auxiliar full collection selectors
MsgStream & msg
Definition testRead.cxx:32