ATLAS Offline Software
Loading...
Searching...
No Matches
TrigCaloDataAccessSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
12
13
15
17 m_autoRetrieveTools = false;
18 m_checkToolDeps = false;
19
20 ATH_CHECK( m_larDecoder.retrieve() );
21 ATH_CHECK( m_tileDecoder.retrieve() );
22 ATH_CHECK( m_robDataProvider.retrieve() );
23 ATH_CHECK( m_bcidAvgKey.initialize() );
24 ATH_CHECK( m_onOffIdMappingKey.initialize() );
25 ATH_CHECK( m_larRoIMapKey.initialize() );
26 ATH_CHECK( m_febRodMappingKey.initialize() );
27 ATH_CHECK( m_regionSelector_TTEM.retrieve() );
28 ATH_CHECK( m_mcsymKey.initialize() );
29 ATH_CHECK( m_bcContKey.initialize() );
30 ATH_CHECK( m_caloMgrKey.initialize());
34 ATH_CHECK( m_regionSelector_TILE.retrieve() );
37 ATH_CHECK( m_tileHid2RESrcIDKey.initialize() );
38
39 return StatusCode::SUCCESS;
40}
41
43
44 m_vrodid32fullDet.clear();
45 m_vrodid32fullDetHG.clear();
46 for (HLTCaloEventCache& cache : m_hLTCaloSlot) {
47 if (cache.larContainer) ATH_CHECK( cache.larContainer->finalize() );
48 if (cache.tileContainer) ATH_CHECK( cache.tileContainer->finalize() );
49 if (cache.d0cells) cache.d0cells->clear();
50 if (cache.fullcont) {
51 for (unsigned int i : m_insertedCells) delete cache.fullcont->at(i);
52 }
53 }
54
55 return StatusCode::SUCCESS;
56}
57
59 for (LArCell* cell : *coll) {
60 cell->setEnergyFast(0.0);
61 }
62}
63
65 for (TileCell* cell: *col) {
66 cell->setEnergy_nonvirt(0.0F, 0.0F, 0, CaloGain::INVALIDGAIN);
67 cell->setTime_nonvirt(-100.0F);
68 cell->setQuality_nonvirt(static_cast<unsigned char>(255), 0, 0);
69 cell->setQuality_nonvirt(static_cast<unsigned char>(255), 0, 1);
70 }
71}
72
73StatusCode TrigCaloDataAccessSvc::loadCollections ( const EventContext& context,
74 const IRoiDescriptor& roi,
75 const DETID detID,
76 const int sampling,
77 LArTT_Selector<LArCellCont>& loadedCells ) {
78
79 std::vector<IdentifierHash> requestHashIDs;
80
81 ATH_MSG_DEBUG( "LArTT requested for event " << context << " and RoI " << roi );
82 ATH_CHECK( prepareLArCollections(context, roi, sampling, detID) );
83
84 {
85 // this has to be guarded because getTT called on the LArCollection bu other threads updates internal map
86 std::scoped_lock lock{m_hLTCaloSlot.get( context )->mutex};
87 switch ( detID ) {
88 case TTEM: {m_regionSelector_TTEM->lookup(context)->HashIDList( sampling, roi, requestHashIDs ); break; }
89 case TTHEC: {m_regionSelector_TTHEC->lookup(context)->HashIDList( sampling, roi, requestHashIDs ); break; }
90 case FCALEM: {m_regionSelector_FCALEM->lookup(context)->HashIDList( sampling, roi, requestHashIDs ); break; }
91 case FCALHAD: {m_regionSelector_FCALHAD->lookup(context)->HashIDList( sampling, roi, requestHashIDs ); break; }
92 default: break;
93 }
94 }
95
96 ATH_MSG_DEBUG( "requestHashIDs.size() in LoadColl = " << requestHashIDs.size() << " hash checksum "
97 << std::accumulate( requestHashIDs.begin(), requestHashIDs.end(), IdentifierHash( 0 ),
98 []( IdentifierHash h1, IdentifierHash h2 ){ return h1+h2; } ) );
99 if ( msgLvl( MSG::VERBOSE ) ) {
100 for( unsigned int i = 0 ; i < requestHashIDs.size() ; i++ )
101 ATH_MSG_VERBOSE( "m_rIds[" << i << "]=" << requestHashIDs[i] );
102 }
104 loadedCells.setContainer( m_hLTCaloSlot.get( context )->larContainer.get() );
105 loadedCells.setMap( *roimap );
106
107 {
108 // this has to be guarded because getTT called on the LArCollection bu other threads updates internal map
109 std::scoped_lock lock{m_hLTCaloSlot.get( context )->mutex};
110 loadedCells.setRoIs( requestHashIDs );
111 }
112 return StatusCode::SUCCESS;
113}
114
115StatusCode TrigCaloDataAccessSvc::loadCollections ( const EventContext& context,
116 const IRoiDescriptor& roi,
117 std::vector<const TileCell*>& loadedCells ) {
118 std::vector<IdentifierHash> requestHashIDs;
119
120 ATH_MSG_DEBUG( "Tile requested for event " << context << " and RoI " << roi );
121 ATH_CHECK( prepareTileCollections(context, roi) );
122
123 {
124 // this has to be guarded because getTT called on the LArCollection bu other threads updates internal map
125 std::scoped_lock lock{m_hLTCaloSlot.get( context )->mutex};
126
127 m_regionSelector_TILE->lookup(context)->HashIDList( roi, requestHashIDs );
128 }
129 ATH_MSG_DEBUG( "requestHashIDs.size() in LoadColl = " << requestHashIDs.size() << " hash checksum "
130 << std::accumulate( requestHashIDs.begin(), requestHashIDs.end(), IdentifierHash( 0 ),
131 []( IdentifierHash h1, IdentifierHash h2 ){ return h1+h2; } ) );
132 if ( msgLvl( MSG::VERBOSE ) ) {
133 for( unsigned int i = 0 ; i < requestHashIDs.size() ; i++ )
134 ATH_MSG_VERBOSE( "requestHashIDs[" << i << "]=" << requestHashIDs[i] );
135 }
136
137 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
138 const TileCellCont* tilecell = cache->tileContainer.get();
139
140 loadedCells.clear();
141 for (size_t i = 0; i < requestHashIDs.size(); ++i){
142 // Find the collection to dump
143 const auto it = tilecell->find(requestHashIDs[i]);
144 if (it == tilecell->end()) continue;
145
146 TileCellCollection* col = *it;
147 if ( col == nullptr ) continue;
148
149 for (const TileCell* cell : *col) {
150 loadedCells.push_back( cell );
151 }
152 }
153
154 return StatusCode::SUCCESS;
155}
156
157
158StatusCode TrigCaloDataAccessSvc::loadFullCollections ( const EventContext& context,
159 CaloConstCellContainer& cont ) {
160
161 // Gets all data
162 m_robDataProvider->addROBData( context, m_vrodid32fullDet );
163 m_robDataProvider->addROBData( context, m_vrodid32tile );
164
166
168
169 m_hLTCaloSlot.get(context)->lastFSEvent = context.evt();
170
171 std::scoped_lock lock{m_getCollMutex};
172
173 const CaloCellContainer* cont_to_copy = m_hLTCaloSlot.get(context)->fullcont.get() ;
174 cont.clear();
175 cont.reserve( cont_to_copy->size() );
176 for( const CaloCell* c : *cont_to_copy ) {
177 cont.push_back_fast( c );
178 }
179 cont.setIsOrdered(true);
180 cont.setIsOrderedAndComplete(true);
181
182 return StatusCode::SUCCESS;
183}
184
185
186StatusCode TrigCaloDataAccessSvc::prepareLArFullCollections( const EventContext& context) {
187
188 std::call_once(m_lateInitFlag, &TrigCaloDataAccessSvc::lateInit, this, context);
189
190 ATH_MSG_DEBUG( "Full Col " << " requested for event " << context );
191
192 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
193
194 auto lockTime = Monitored::Timer ( "TIME_locking_LAr_FullDet" );
195 std::scoped_lock lock{cache->mutex};
196
197 lockTime.stop();
198
199 // If the full event was already unpacked, don't need to unpack RoI
200 if ( cache->lastFSEvent == context.evt() ) return StatusCode::SUCCESS;
201 cache->larContainer->eventNumber( context.evt() ) ;
202
203 if ( m_applyOffsetCorrection && cache->larContainer->lumiBCIDCheck( context ) ) {
206 if ( avg.cptr() && onoff.cptr() ) {
207 cache->larContainer->updateBCID( *avg, **onoff );
208 }
209 }
210
211 const LArDeadOTXFromSC* deadHandle = nullptr;
212 if ( m_correctDead ){
214 if ( !deadHdl.isValid() ){
215 ATH_MSG_WARNING("Should not try to use LArDEADOTXFromSC" );
216 } else {
217 deadHandle = deadHdl.cptr();
218 }
219 }
220
221 for(std::vector<uint32_t>& vrodid32fullDet : m_vrodid32fullDetHG) {
222 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> robFrags;
223 m_robDataProvider->addROBData( context, vrodid32fullDet );
224 m_robDataProvider->getROBData( context, vrodid32fullDet, robFrags );
225
226 convertROBs( robFrags, cache->larContainer.get(), cache->larRodBlockStructure_per_slot,
227 cache->rodMinorVersion, cache->robBlockType, deadHandle );
228
229 if ( vrodid32fullDet.size() != robFrags.size() ) {
230 ATH_MSG_DEBUG( "Missing ROBs, requested " << vrodid32fullDet.size() << " obtained " << robFrags.size() );
231 clearMissing( vrodid32fullDet, robFrags, cache->larContainer.get() );
232 }
233 } // end of for m_vrodid32fullDetHG.size()
234
235 Monitored::Group( m_monTool, lockTime );
236 return StatusCode::SUCCESS;
237}
238
239StatusCode TrigCaloDataAccessSvc::prepareTileFullCollections( const EventContext& context) {
240
241 std::call_once(m_lateInitFlag, &TrigCaloDataAccessSvc::lateInit, this, context);
242
243 ATH_MSG_DEBUG( "Full Col " << " requested for event " << context );
244
245 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
246
247 auto lockTime = Monitored::Timer ( "TIME_locking_LAr_FullDet" );
248 std::scoped_lock lock{cache->mutex};
249 lockTime.stop();
250
251 // If the full event was already unpacked, don't need to unpack RoI
252 if ( cache->lastFSEvent == context.evt() ) return StatusCode::SUCCESS;
253 if ( cache->tileContainer->eventNumber() != context.evt() ) {
254 cache->d0cells->clear();
255 }
256 cache->tileContainer->eventNumber( context.evt() );
257
258 convertROBs( context, m_rIdstile, cache->tileContainer.get(), cache->d0cells.get() );
259
260 Monitored::Group( m_monTool, lockTime );
261 return StatusCode::SUCCESS;
262}
263
264void TrigCaloDataAccessSvc::lateInit(const EventContext& context) { // non-const this thing
265
266 ATH_MSG_DEBUG( "Performing late init" );
267
268 // preparing full container list of ROBs - tile will be included soon
269 std::vector<uint32_t> vrodid32lar;
270 std::vector<uint32_t> vrodid32em;
271 std::vector<uint32_t> vrodid32hec;
272 std::vector<uint32_t> vrodid32hec0;
273 std::vector<uint32_t> vrodid32hec1;
274 std::vector<uint32_t> vrodid32hec2;
275 std::vector<uint32_t> vrodid32hec3;
276 std::vector<uint32_t> vrodid32fcalem;
277 std::vector<uint32_t> vrodid32fcalhad;
278
279 TrigRoiDescriptor tmproi(true);
280 std::vector<uint32_t> vrodid32tile;
281 std::vector<IdentifierHash> rIdstile;
282 // TTEM
283 m_regionSelector_TTEM->lookup(context)->ROBIDList(-1,tmproi,vrodid32em);
284 // TTHEC
285 m_regionSelector_TTHEC->lookup(context)->ROBIDList(0,tmproi,vrodid32hec0);
286 m_regionSelector_TTHEC->lookup(context)->ROBIDList(1,tmproi,vrodid32hec1);
287 m_regionSelector_TTHEC->lookup(context)->ROBIDList(2,tmproi,vrodid32hec2);
288 m_regionSelector_TTHEC->lookup(context)->ROBIDList(3,tmproi,vrodid32hec3);
289 // FCALHAD
290 m_regionSelector_FCALEM->lookup(context)->ROBIDList(-1,tmproi,vrodid32fcalem);
291 m_regionSelector_FCALHAD->lookup(context)->ROBIDList(-1,tmproi,vrodid32fcalhad);
292 m_regionSelector_TILE->lookup(context)->ROBIDList(tmproi,vrodid32tile);
293 m_regionSelector_TILE->lookup(context)->HashIDList(tmproi,rIdstile);
294
295 m_vrodid32tile.resize( vrodid32tile.size() );
296 m_rIdstile.resize(rIdstile.size() );
297 // Tile RODs and ID coming from the Tile tables are not unique
298 // iii and iij are local variables helping to clear non-unique IDs
299 auto iii = std::unique_copy(vrodid32tile.begin(),vrodid32tile.end(),m_vrodid32tile.begin());
300 auto iij = std::unique_copy(rIdstile.begin(),rIdstile.end(),m_rIdstile.begin());
301 std::sort( m_vrodid32tile.begin(), iii );
302 std::sort( m_rIdstile.begin(), iij );
303 iii = std::unique_copy(m_vrodid32tile.begin(),iii,m_vrodid32tile.begin());
304 iij = std::unique_copy(m_rIdstile.begin(),iij,m_rIdstile.begin());
305 m_vrodid32tile.resize( std::distance(m_vrodid32tile.begin(), iii) );
306 m_rIdstile.resize( std::distance(m_rIdstile.begin(), iij) );
307
308 vrodid32lar.insert(vrodid32lar.end(),vrodid32em.begin(),vrodid32em.end());
309 vrodid32hec.insert(vrodid32hec.end(),vrodid32hec0.begin(),vrodid32hec0.end());
310 vrodid32lar.insert(vrodid32lar.end(),vrodid32hec.begin(),vrodid32hec.end());
311 vrodid32lar.insert(vrodid32lar.end(),vrodid32fcalhad.begin(),vrodid32fcalhad.end());
312 vrodid32lar.insert(vrodid32lar.end(),vrodid32fcalem.begin(),vrodid32fcalem.end());
313 m_vrodid32fullDet.insert(m_vrodid32fullDet.end(), vrodid32lar.begin(), vrodid32lar.end() );
314
315
322
323 const unsigned int nFebs=70;
324 const unsigned int high_granu = (unsigned int)ceilf(m_vrodid32fullDet.size()/((float)nFebs) );
325 unsigned int jj=0;
326 unsigned int kk=0;
327 m_vrodid32fullDetHG.resize(high_granu);
328 for( unsigned int ii=0; ii<m_vrodid32fullDet.size();ii++){
329 if ( kk >= nFebs ) {
330 kk-=nFebs;
331 jj++;
332 }
333 m_vrodid32fullDetHG[jj].push_back(m_vrodid32fullDet[ii]);
334 kk++;
335 }
337 const CaloDetDescrManager* theCaloDDM = *caloMgrHandle;
338 const CaloCell_ID* theCaloCCIDM = theCaloDDM->getCaloCell_ID();
339 const unsigned int hashMax = theCaloCCIDM->calo_cell_hash_max();
340
341 // Prepare cache containers to be used for LAr unpacking.
342 size_t slot = 0;
343 for (HLTCaloEventCache& cache : m_hLTCaloSlot) {
344 cache.larContainer = std::make_unique<LArCellCont>();
345 cache.larRodBlockStructure_per_slot = nullptr;
346
347 cache.larContainer->initialize(**roimap, **onoff, **mcsym, **febrod, **larBadChan, *theCaloDDM).
348 orThrow("Cannot initialize LAr container", name());
349
350 std::vector<CaloCell*> local_cell_copy;
351 local_cell_copy.reserve(200000);
352 const LArCellCont* larcell = cache.larContainer.get();
353 const LArBadChannelCont& badchannel = **larBadChan;
354
355 cache.lastFSEvent = 0xFFFFFFFF;
356 auto cachefullcont = std::make_unique<CaloCellContainer>(SG::VIEW_ELEMENTS);
357 cachefullcont->reserve(190000);
358
359 for(unsigned int lcidx=0; lcidx < larcell->size(); lcidx++){
360 LArCellCollection* lcc = larcell->at(lcidx);
361 for(unsigned int lccidx=0; lccidx<lcc->size(); lccidx++){
362 CaloCell* cell = lcc->at(lccidx);
363 if ( cell && cell->caloDDE() ) {
364 const LArBadChannel& bc = badchannel.offlineStatus(cell->ID());
365 const bool bad = !bc.good() &&
366 // only consider specific problems
367 (bc.deadReadout() || bc.deadPhys() || bc.highNoiseHG() ||
369
370 if ( !bad ) local_cell_copy.push_back( cell );
371 }
372 } // end of loop over cells
373 } // end of loop over collection
374
375 // This should stay here as this will be enabled when tile is ready to be decoded as well
376
377 auto tilecell = std::make_unique<TileCellCont>();
378 tilecell->setHashIdToROD( *tileHid2RESrcID );
379 tilecell->initialize().orThrow("Cannot initialize Tile container", name());
380
381 for (unsigned int i=0; i<4; i++) {
382 m_tileDecoder->loadRw2Cell ( i, tilecell->Rw2CellMap(i) );
383 m_tileDecoder->loadRw2Pmt ( i, tilecell->Rw2PmtMap (i) );
384 }
385 m_tileDecoder->loadMBTS( tilecell->MBTS_map(), tilecell->MBTS_channel() );
386
387 const std::vector<unsigned int>* mbts_rods = tilecell->MBTS_RODs();
388 for(size_t i = 0 ; i < mbts_rods->size(); i++) {
389 m_mbts_add_rods.insert(m_mbts_add_rods.end(), mbts_rods->begin(), mbts_rods->end());
390 }
391 sort(m_mbts_add_rods.begin(),m_mbts_add_rods.end());
393
394 auto d0cellsp = std::make_unique<TileROD_Decoder::D0CellsHLT>();
395 for (unsigned int lcidx=0; lcidx < tilecell->size(); lcidx++){
396 TileCellCollection* lcc = tilecell->at(lcidx);
397 for (unsigned int lccidx=0; lccidx<lcc->size(); lccidx++){
398 CaloCell* cell = lcc->at(lccidx);
399 if ( cell ) local_cell_copy.push_back( cell );
400 } // end of loop over cells
401
402 TileRawChannelCollection::ID frag_id = ((*lcc).identify() & 0x0FFF);
403 const int ros = (frag_id >> 8);
404 if ( ros == 1 ) { //treatment for d0Cells in barrel
405 const int drawer = (frag_id & 0xFF);
406 TileCellCollection::iterator pCell = lcc->begin();
407 pCell+=2;
408 d0cellsp->m_cells[drawer] = *pCell;
409 }
410 } // end of loop over collection
411 cache.tileContainer = std::move(tilecell);
412
413 // d0merge cells
414 cache.d0cells = std::move(d0cellsp);
415
416 // For the moment the container has to be completed by hand (again, because of tile)
417 for(unsigned int i=0; i<hashMax; i++){
418 cachefullcont->push_back_fast(nullptr);
419 }
420
421 for(unsigned int i=0; i<local_cell_copy.size(); i++){
422 unsigned int j = local_cell_copy.at(i)->caloDDE()->calo_hash();
423 if ( j < hashMax ) {
424 cachefullcont->at(j) = local_cell_copy.at(i);
425 }
426 }
427 for(unsigned int i=0;i<hashMax;i++)
428 if ( cachefullcont->at(i) == nullptr ){
429 Identifier id = theCaloCCIDM->cell_id(i);
430 if ( id!=0 ){
431 const CaloDetDescrElement* el = theCaloDDM->get_element(id);
432 if ( el->is_tile() ) {
433 cachefullcont->at(i) = new TileCell(el,0,0,0,0,CaloGain::TILEHIGHHIGH);
434 } else {
435 cachefullcont->at(i) = new LArCell(el,0,0,0,CaloGain::LARHIGHGAIN);
436 }
437
438 if (slot==0) m_insertedCells.push_back(i);
439 }
440 }
441
442 cachefullcont->setHasCalo(CaloCell_ID::LAREM);
443 cachefullcont->setHasCalo(CaloCell_ID::LARHEC);
444 cachefullcont->setHasCalo(CaloCell_ID::LARFCAL);
445 cachefullcont->setHasCalo(CaloCell_ID::TILE); //lying... But this needs to be checked later
446
447 // make sure this "map" container has a good hashID
448 cachefullcont->order();
449
450 if ( hashMax != cachefullcont->size() ) {
451 ATH_MSG_ERROR("Problem in the size of the full container");
452 }
453
454 cachefullcont->setIsOrdered(true);
455 cachefullcont->setIsOrderedAndComplete(true);
456 cache.fullcont = std::move(cachefullcont);
457
458 local_cell_copy.clear();
459 ++slot;
460 }
461}
462
463void TrigCaloDataAccessSvc::convertROBs( const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& robFrags,
464 LArCellCont* larcell, LArRodBlockStructure*& larRodBlockStructure_per_slot,
465 uint16_t rodMinorVersion, uint32_t robBlockType, const LArDeadOTXFromSC* deadHandle ) {
466
467 for ( auto rob: robFrags ) {
468 uint32_t sourceID = rob->source_id();
469 const auto it = larcell->find( sourceID );
470 //TB The find also switches the state of the collection to "decoded" so repeated decoding is avoided
471
472 if ( it != larcell->end() && ( *it )->size() != 0 ) { // Already decoded collection
473
474 // TB if we have entered here it means the decoding did not occur yet ( or failed )
475 //
476 LArCellCollection* coll = *it;
477 ATH_MSG_DEBUG( "ROB of ID " << sourceID << " to be decoded" );
478
479 std::scoped_lock decoderLock{m_lardecoderProtect};
480 //TB next two lines seem danger, as they seem to rely on the decoder state
481 const HWIdentifier& feb_id_local = larcell->findsec( sourceID );
482 m_larDecoder->setsecfeb( feb_id_local );
483 if ( ! m_larDecoder->check_valid( rob, msg() ) ){
484 ATH_MSG_WARNING( "Error reading bytestream"<<
485 "event: Bad ROB block ( eformat checks ) : 0x"
486 << std::hex << sourceID << std::dec );
487 // Data seems corrupted
488 reset_LArCol ( coll );
489
490 } else {
491 // Get Rod Data and size of fragment
492 const uint32_t* roddata = 0;
493 rob->rod_data( roddata );
494 const size_t roddatasize = rob->rod_ndata();
495 if ( roddatasize < 3 ) {
496 ATH_MSG_WARNING( "Error reading bytestream"<<
497 "event: Empty ROD block ( less than 3 words ) : 0x"
498 << std::hex << sourceID << std::dec );
499 // Data seems corrupted
500 reset_LArCol ( coll );
501 } else {
502 //TB the converter has state
503 m_larDecoder->fillCollectionHLT( *rob, roddata, roddatasize, *coll, larRodBlockStructure_per_slot, rodMinorVersion, robBlockType );
504 if ( deadHandle ){
505 if ( deadHandle->isThisOTXdead(feb_id_local) ) {
506 const std::vector<float>& corr = deadHandle->correctionFromThisOTXdead(feb_id_local);
507 // The sizes here are guaranteed by construction
508 for(size_t i=0;i<128;i++) {
509 (*coll)[i+128]->set(corr[i],0,0,0x1000,CaloGain::LARHIGHGAIN);
510 }
511 }
512 HWIdentifier feb_id_local2(larRodBlockStructure_per_slot->getFEBID());
513 if ( deadHandle->isThisOTXdead(feb_id_local2) ) {
514 const std::vector<float>& corr = deadHandle->correctionFromThisOTXdead(feb_id_local2);
515 // The sizes here are guaranteed by construction
516 for(size_t i=0;i<128;i++) {
517 (*coll)[i]->set(corr[i],0,0,0x1000,CaloGain::LARHIGHGAIN);
518 }
519 }
520 }
521
522 if ( m_applyOffsetCorrection ) larcell->applyBCIDCorrection( sourceID );
523 }
524
525 }
526 } else {
527 ATH_MSG_VERBOSE( "ROB of ID " << sourceID << " already decoded" );
528 }
529 }
530 ATH_MSG_DEBUG( "finished decoding" );
531}
532
533void TrigCaloDataAccessSvc::convertROBs( const EventContext& context,
534 const std::vector<IdentifierHash>& rIds,
535 TileCellCont* tilecell,
537
538 TileCellCollection* mbts = tilecell->MBTS_collection();
539 const TileHid2RESrcID* hid2re = tilecell->getHashIdToROD();
540
541 std::vector<unsigned int> tile{0};
542 // Tile likes rob by rob
543 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> robFrags;
544 for (size_t i = 0; i < rIds.size(); ++i){
545 tile[0] = tilecell->find_rod(rIds[i]);
546 m_robDataProvider->getROBData(context,tile,robFrags);
547 // Find the collection to fill
548 const auto it = tilecell->find(rIds[i]);
549 if (it == tilecell->end()) continue;
550
551 TileCellCollection* col = *it;
552 if ( !robFrags.empty() && col != nullptr ) {
553 const size_t roddatasize = robFrags[0]->rod_ndata();
554 // insert data into vector (to be removed soon)
555 if (roddatasize < 3) {
556 ATH_MSG_WARNING( "Error reading bytestream"<<
557 "event: Empty ROD block (less than 3 words) : 0x"
558 << std::hex << tile[0] << std::dec );
559 if ( !tilecell->cached(rIds[i])){
560 // resets collection
561 reset_TileCol(col);
562 }
563 robFrags.clear();
564 } else {
565 std::scoped_lock decoderLock{m_tiledecoderProtect};
566 if ( !tilecell->cached(rIds[i]) ) {
567 m_tileDecoder->fillCollectionHLT(robFrags[0],*col,*d0cells,mbts,hid2re);
568 }
569 m_tileDecoder->mergeD0cellsHLT(*d0cells,*col);
570 robFrags.clear();
571 }
572 } // end of if robFrags.size
573 } // End of for through RobFrags
574
575 ATH_MSG_DEBUG( "finished decoding" );
576}
577
578void TrigCaloDataAccessSvc::missingROBs( const std::vector<uint32_t>& request,
579 const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& response,
580 std::set<uint32_t>& missing ) const {
581
582 std::set<uint32_t> receivedROBsSet;
583 for ( auto rob: response ) {
584 receivedROBsSet.insert( rob->source_id() );
585 }
586
587 std::set<uint32_t> requestedROBsSet( request.begin(), request.end() );
588 std::set_difference( requestedROBsSet.begin(), requestedROBsSet.end(),
589 receivedROBsSet.begin(), receivedROBsSet.end(),
590 std::inserter( missing, missing.begin() ) );
591}
592
593
594void TrigCaloDataAccessSvc::clearMissing( const std::vector<uint32_t>& request,
595 const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& response,
596 LArCellCont* larcell ) {
597 std::set<uint32_t> missing;
598 missingROBs( request, response, missing );
599 for ( uint32_t robID : missing ) {
600 const auto it = larcell->find( robID );
601 if ( it != larcell->end() && not (*it)->empty() ) { // Already decoded collection
602 reset_LArCol ( *it );
603 }
604 }
605}
606
607
608StatusCode TrigCaloDataAccessSvc::prepareLArCollections( const EventContext& context,
609 const IRoiDescriptor& roi,
610 const int sampling,
611 DETID detector ) {
612
613 std::call_once(m_lateInitFlag, &TrigCaloDataAccessSvc::lateInit, this, context);
614
615 // If the full event was already unpacked, don't need to unpack RoI
616 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
617 if ( cache->lastFSEvent == context.evt() ) return StatusCode::SUCCESS;
618
619 std::vector<uint32_t> requestROBs;
620
621 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> robFrags;
622 switch ( detector ) {
623 case TTEM: {m_regionSelector_TTEM->lookup(context)->ROBIDList( sampling, roi, requestROBs ); break; }
624 case TTHEC: {m_regionSelector_TTHEC->lookup(context)->ROBIDList( sampling, roi, requestROBs ); break; }
625 case FCALEM: {m_regionSelector_FCALEM->lookup(context)->ROBIDList( sampling, roi, requestROBs ); break; }
626 case FCALHAD: {m_regionSelector_FCALHAD->lookup(context)->ROBIDList( sampling, roi, requestROBs ); break; }
627 default: break;
628 }
629
630 m_robDataProvider->addROBData( context, requestROBs );
631 m_robDataProvider->getROBData( context, requestROBs, robFrags );
632 if ( robFrags.empty() && !requestROBs.empty() ) {
633 return StatusCode::SUCCESS;
634 }
635
636 auto lockTime = Monitored::Timer ( "TIME_locking_LAr_RoI" );
637 std::scoped_lock lock{cache->mutex};
638 lockTime.stop();
639
640 // TB, what would happen from now inside the collection unapcking
641 // if this event number is different than the one for each collection the unpacking will happen,
642 // if it is the same the unpacking will not be repeated
643 // same in prepareLArFullCollections
644 cache->larContainer->eventNumber( context.evt() );
645 if ( m_applyOffsetCorrection && cache->larContainer->lumiBCIDCheck( context ) ) {
648 if ( avg.cptr() && onoff.cptr() ) cache->larContainer->updateBCID( *avg, **onoff );
649 }
650
651 const LArDeadOTXFromSC* deadHandle = nullptr;
652 if ( m_correctDead ){
654 if ( !deadHdl.isValid() ){
655 ATH_MSG_WARNING("Should not try to use LArDEADOTXFromSC" );
656 } else {
657 deadHandle = deadHdl.cptr();
658 }
659 }
660
661 convertROBs( robFrags, cache->larContainer.get(), cache->larRodBlockStructure_per_slot,
662 cache->rodMinorVersion, cache->robBlockType, deadHandle );
663
664 if ( requestROBs.size() != robFrags.size() ) {
665 ATH_MSG_DEBUG( "Missing ROBs, requested " << requestROBs.size() << " obtained " << robFrags.size() );
666 clearMissing( requestROBs, robFrags, cache->larContainer.get() );
667 }
668 auto roiROBs = Monitored::Scalar( "roiROBs_LAr", robFrags.size() );
669 auto roiEta = Monitored::Scalar( "roiEta_LAr", roi.eta() );
670 auto roiPhi = Monitored::Scalar( "roiPhi_LAr", roi.phi() );
671
672 Monitored::Group( m_monTool, lockTime, roiEta, roiPhi, roiROBs );
673 return StatusCode::SUCCESS;
674}
675
676StatusCode TrigCaloDataAccessSvc::prepareTileCollections( const EventContext& context,
677 const IRoiDescriptor& roi) {
678
679 std::call_once(m_lateInitFlag, &TrigCaloDataAccessSvc::lateInit, this, context);
680
681 // If the full event was already unpacked, don't need to unpack RoI
682 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
683 if ( cache->lastFSEvent == context.evt() ) return StatusCode::SUCCESS;
684
685 std::vector<uint32_t> requestROBs;
686 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> robFrags;
687 std::vector<IdentifierHash> rIds;
688 m_regionSelector_TILE->lookup(context)->ROBIDList( 0, roi, requestROBs );
689 m_regionSelector_TILE->lookup(context)->HashIDList(roi, rIds);
690 m_robDataProvider->addROBData( context, requestROBs );
691
692 std::scoped_lock lock{cache->mutex};
693 if ( cache->tileContainer->eventNumber() != context.evt() ) {
694 cache->d0cells->clear();
695 }
696 cache->tileContainer->eventNumber( context.evt() );
697
698 convertROBs( context, rIds, cache->tileContainer.get(), cache->d0cells.get() );
699
700 return StatusCode::SUCCESS;
701}
702
703StatusCode TrigCaloDataAccessSvc::prepareMBTSCollections( const EventContext& context) {
704
705 std::call_once(m_lateInitFlag, &TrigCaloDataAccessSvc::lateInit, this, context);
706
707 // If the full event was already unpacked, don't need to unpack RoI
708 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
709 if ( cache->lastFSEvent == context.evt() ) return StatusCode::SUCCESS;
710
711 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> robFrags;
712 m_robDataProvider->addROBData( context, m_mbts_add_rods );
713
714 std::scoped_lock lock{cache->mutex};
715 if ( cache->tileContainer->eventNumber() != context.evt() ) {
716 cache->d0cells->clear();
717 }
718 cache->tileContainer->eventNumber( context.evt() );
719
720 const std::vector<unsigned int>* ids = cache->tileContainer->MBTS_IDs();
721 std::vector<IdentifierHash> tileIds;
722 tileIds.reserve(ids->size());
723 for (size_t i=0; i<ids->size(); i++) {
724 tileIds.push_back( (*ids)[i] );
725 }
726 convertROBs( context, tileIds, cache->tileContainer.get(), cache->d0cells.get() );
727
728 return StatusCode::SUCCESS;
729}
730
731
732
733StatusCode TrigCaloDataAccessSvc::loadMBTS ( const EventContext& context,
734 std::vector<const TileCell*>& loadedCells ) {
735
736 ATH_MSG_DEBUG( "MBTS requested for event " << context );
738
739 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
740 {
741 std::scoped_lock lock{cache->mutex};
742 TileCellCollection* mbts = cache->tileContainer->MBTS_collection();
743 loadedCells.reserve(mbts->size());
744 for (size_t i=0; i<mbts->size(); ++i) {
745 loadedCells.push_back(mbts->at(i));
746 }
747 }
748 return StatusCode::SUCCESS;
749
750}
#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.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
LArBadXCont< LArBadChannel > LArBadChannelCont
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.
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.
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 deadReadout() const
bool highNoiseHG() const
bool problematicForUnknownReason() const
bool highNoiseMG() const
bool highNoiseLG() const
bool deadPhys() 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:42
void applyBCIDCorrection(unsigned int rodid)
method to apply correction based on the luminosity to the energy
HWIdentifier findsec(unsigned int id) const
Each Collection contains data from 2 FEBs.
const std::vector< LArCellCollection * >::const_iterator find(const HWIdentifier &id) const
Finds a collection by its LArReadoutModuleID.
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.
unsigned int find_rod(const unsigned int &id) const
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)
const TileHid2RESrcID * getHashIdToROD() const
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
SG::ReadCondHandleKey< TileHid2RESrcID > m_tileHid2RESrcIDKey
StatusCode prepareLArFullCollections(const EventContext &context)
SG::ReadHandleKey< CaloBCIDAverage > m_bcidAvgKey
void lateInit(const EventContext &context)
void reset_TileCol(TileCellCollection *col)
void convertROBs(const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &robFrags, LArCellCont *larcell, LArRodBlockStructure *&larRodBlockStructure, uint16_t rodMinorVersion, uint32_t robBlockType, const LArDeadOTXFromSC *dead)
StatusCode prepareMBTSCollections(const EventContext &context)
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
ToolHandle< IRegSelTool > m_regionSelector_FCALEM
SG::ReadHandleKey< LArDeadOTXFromSC > m_deadOTXFromSCKey
virtual StatusCode loadMBTS(const EventContext &context, std::vector< const TileCell * > &loadedCells) override
SG::ReadCondHandleKey< LArRoIMap > m_larRoIMapKey
std::vector< std::vector< uint32_t > > m_vrodid32fullDetHG
ToolHandle< IRegSelTool > m_regionSelector_TTEM
StatusCode prepareTileFullCollections(const EventContext &context)
SG::SlotSpecificObj< HLTCaloEventCache > m_hLTCaloSlot
StatusCode prepareLArCollections(const EventContext &context, const IRoiDescriptor &roi, const int sampling, DETID detector)
LAr TT collections preparation code.
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
ToolHandle< IRegSelTool > m_regionSelector_FCALHAD
ToolHandle< IRegSelTool > m_regionSelector_TILE
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
SG::ReadCondHandleKey< LArMCSym > m_mcsymKey
StatusCode prepareTileCollections(const EventContext &context, const IRoiDescriptor &roi)
void reset_LArCol(LArCellCollection *coll)
virtual StatusCode finalize() override
std::vector< IdentifierHash > m_rIdstile
virtual StatusCode loadFullCollections(const EventContext &context, CaloConstCellContainer &cont) override
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
@ INVALIDGAIN
Definition CaloGain.h:18
@ TILEHIGHHIGH
Definition CaloGain.h:15
@ LARHIGHGAIN
Definition CaloGain.h:18
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
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