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
162
164
165 m_hLTCaloSlot.get(context)->lastFSEvent = context.evt();
166
167 std::scoped_lock lock{m_getCollMutex};
168
169 const CaloCellContainer* cont_to_copy = m_hLTCaloSlot.get(context)->fullcont.get() ;
170 cont.clear();
171 cont.reserve( cont_to_copy->size() );
172 for( const CaloCell* c : *cont_to_copy ) {
173 cont.push_back_fast( c );
174 }
175 cont.setIsOrdered(true);
176 cont.setIsOrderedAndComplete(true);
177
178 return StatusCode::SUCCESS;
179}
180
181
182StatusCode TrigCaloDataAccessSvc::prepareLArFullCollections( const EventContext& context) {
183
184 std::call_once(m_lateInitFlag, &TrigCaloDataAccessSvc::lateInit, this, context);
185
186 ATH_MSG_DEBUG( "Full Col " << " requested for event " << context );
187
188 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
189
190 auto lockTime = Monitored::Timer ( "TIME_locking_LAr_FullDet" );
191 std::scoped_lock lock{cache->mutex};
192
193 lockTime.stop();
194
195 // If the full event was already unpacked, don't need to unpack RoI
196 if ( cache->lastFSEvent == context.evt() ) return StatusCode::SUCCESS;
197 cache->larContainer->eventNumber( context.evt() ) ;
198
199 if ( m_applyOffsetCorrection && cache->larContainer->lumiBCIDCheck( context ) ) {
202 if ( avg.cptr() && onoff.cptr() ) {
203 cache->larContainer->updateBCID( *avg, **onoff );
204 }
205 }
206
207 const LArDeadOTXFromSC* deadHandle = nullptr;
208 if ( m_correctDead ){
210 if ( !deadHdl.isValid() ){
211 ATH_MSG_WARNING("Should not try to use LArDEADOTXFromSC" );
212 } else {
213 deadHandle = deadHdl.cptr();
214 }
215 }
216
217 for(std::vector<uint32_t>& vrodid32fullDet : m_vrodid32fullDetHG) {
218 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> robFrags;
219 m_robDataProvider->getROBData( context, vrodid32fullDet, robFrags );
220
221 convertROBs( robFrags, cache->larContainer.get(), cache->larRodBlockStructure_per_slot,
222 cache->rodMinorVersion, cache->robBlockType, deadHandle );
223
224 if ( vrodid32fullDet.size() != robFrags.size() ) {
225 ATH_MSG_DEBUG( "Missing ROBs, requested " << vrodid32fullDet.size() << " obtained " << robFrags.size() );
226 clearMissing( vrodid32fullDet, robFrags, cache->larContainer.get() );
227 }
228 } // end of for m_vrodid32fullDetHG.size()
229
230 Monitored::Group( m_monTool, lockTime );
231 return StatusCode::SUCCESS;
232}
233
234StatusCode TrigCaloDataAccessSvc::prepareTileFullCollections( const EventContext& context) {
235
236 std::call_once(m_lateInitFlag, &TrigCaloDataAccessSvc::lateInit, this, context);
237
238 ATH_MSG_DEBUG( "Full Col " << " requested for event " << context );
239
240 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
241
242 auto lockTime = Monitored::Timer ( "TIME_locking_LAr_FullDet" );
243 std::scoped_lock lock{cache->mutex};
244 lockTime.stop();
245
246 // If the full event was already unpacked, don't need to unpack RoI
247 if ( cache->lastFSEvent == context.evt() ) return StatusCode::SUCCESS;
248 if ( cache->tileContainer->eventNumber() != context.evt() ) {
249 cache->d0cells->clear();
250 }
251 cache->tileContainer->eventNumber( context.evt() );
252
253 convertROBs( context, m_rIdstile, cache->tileContainer.get(), cache->d0cells.get() );
254
255 Monitored::Group( m_monTool, lockTime );
256 return StatusCode::SUCCESS;
257}
258
259void TrigCaloDataAccessSvc::lateInit(const EventContext& context) { // non-const this thing
260
261 ATH_MSG_DEBUG( "Performing late init" );
262
263 // preparing full container list of ROBs - tile will be included soon
264 std::vector<uint32_t> vrodid32lar;
265 std::vector<uint32_t> vrodid32em;
266 std::vector<uint32_t> vrodid32hec;
267 std::vector<uint32_t> vrodid32hec0;
268 std::vector<uint32_t> vrodid32hec1;
269 std::vector<uint32_t> vrodid32hec2;
270 std::vector<uint32_t> vrodid32hec3;
271 std::vector<uint32_t> vrodid32fcalem;
272 std::vector<uint32_t> vrodid32fcalhad;
273
274 TrigRoiDescriptor tmproi(true);
275 std::vector<uint32_t> vrodid32tile;
276 std::vector<IdentifierHash> rIdstile;
277 // TTEM
278 m_regionSelector_TTEM->lookup(context)->ROBIDList(-1,tmproi,vrodid32em);
279 // TTHEC
280 m_regionSelector_TTHEC->lookup(context)->ROBIDList(0,tmproi,vrodid32hec0);
281 m_regionSelector_TTHEC->lookup(context)->ROBIDList(1,tmproi,vrodid32hec1);
282 m_regionSelector_TTHEC->lookup(context)->ROBIDList(2,tmproi,vrodid32hec2);
283 m_regionSelector_TTHEC->lookup(context)->ROBIDList(3,tmproi,vrodid32hec3);
284 // FCALHAD
285 m_regionSelector_FCALEM->lookup(context)->ROBIDList(-1,tmproi,vrodid32fcalem);
286 m_regionSelector_FCALHAD->lookup(context)->ROBIDList(-1,tmproi,vrodid32fcalhad);
287 m_regionSelector_TILE->lookup(context)->ROBIDList(tmproi,vrodid32tile);
288 m_regionSelector_TILE->lookup(context)->HashIDList(tmproi,rIdstile);
289
290 m_vrodid32tile.resize( vrodid32tile.size() );
291 m_rIdstile.resize(rIdstile.size() );
292 // Tile RODs and ID coming from the Tile tables are not unique
293 // iii and iij are local variables helping to clear non-unique IDs
294 auto iii = std::unique_copy(vrodid32tile.begin(),vrodid32tile.end(),m_vrodid32tile.begin());
295 auto iij = std::unique_copy(rIdstile.begin(),rIdstile.end(),m_rIdstile.begin());
296 std::sort( m_vrodid32tile.begin(), iii );
297 std::sort( m_rIdstile.begin(), iij );
298 iii = std::unique_copy(m_vrodid32tile.begin(),iii,m_vrodid32tile.begin());
299 iij = std::unique_copy(m_rIdstile.begin(),iij,m_rIdstile.begin());
300 m_vrodid32tile.resize( std::distance(m_vrodid32tile.begin(), iii) );
301 m_rIdstile.resize( std::distance(m_rIdstile.begin(), iij) );
302
303 vrodid32lar.insert(vrodid32lar.end(),vrodid32em.begin(),vrodid32em.end());
304 vrodid32hec.insert(vrodid32hec.end(),vrodid32hec0.begin(),vrodid32hec0.end());
305 vrodid32lar.insert(vrodid32lar.end(),vrodid32hec.begin(),vrodid32hec.end());
306 vrodid32lar.insert(vrodid32lar.end(),vrodid32fcalhad.begin(),vrodid32fcalhad.end());
307 vrodid32lar.insert(vrodid32lar.end(),vrodid32fcalem.begin(),vrodid32fcalem.end());
308 m_vrodid32fullDet.insert(m_vrodid32fullDet.end(), vrodid32lar.begin(), vrodid32lar.end() );
309
310
317
318 const unsigned int nFebs=70;
319 const unsigned int high_granu = (unsigned int)ceilf(m_vrodid32fullDet.size()/((float)nFebs) );
320 unsigned int jj=0;
321 unsigned int kk=0;
322 m_vrodid32fullDetHG.resize(high_granu);
323 for( unsigned int ii=0; ii<m_vrodid32fullDet.size();ii++){
324 if ( kk >= nFebs ) {
325 kk-=nFebs;
326 jj++;
327 }
328 m_vrodid32fullDetHG[jj].push_back(m_vrodid32fullDet[ii]);
329 kk++;
330 }
332 const CaloDetDescrManager* theCaloDDM = *caloMgrHandle;
333 const CaloCell_ID* theCaloCCIDM = theCaloDDM->getCaloCell_ID();
334 const unsigned int hashMax = theCaloCCIDM->calo_cell_hash_max();
335
336 // Prepare cache containers to be used for LAr unpacking.
337 size_t slot = 0;
338 for (HLTCaloEventCache& cache : m_hLTCaloSlot) {
339 cache.larContainer = std::make_unique<LArCellCont>();
340 cache.larRodBlockStructure_per_slot = nullptr;
341
342 cache.larContainer->initialize(**roimap, **onoff, **mcsym, **febrod, **larBadChan, *theCaloDDM).
343 orThrow("Cannot initialize LAr container", name());
344
345 std::vector<CaloCell*> local_cell_copy;
346 local_cell_copy.reserve(200000);
347 const LArCellCont* larcell = cache.larContainer.get();
348 const LArBadChannelCont& badchannel = **larBadChan;
349
350 cache.lastFSEvent = 0xFFFFFFFF;
351 auto cachefullcont = std::make_unique<CaloCellContainer>(SG::VIEW_ELEMENTS);
352 cachefullcont->reserve(190000);
353
354 for(unsigned int lcidx=0; lcidx < larcell->size(); lcidx++){
355 LArCellCollection* lcc = larcell->at(lcidx);
356 for(unsigned int lccidx=0; lccidx<lcc->size(); lccidx++){
357 CaloCell* cell = lcc->at(lccidx);
358 if ( cell && cell->caloDDE() ) {
359 const LArBadChannel& bc = badchannel.offlineStatus(cell->ID());
360 const bool bad = !bc.good() &&
361 // only consider specific problems
362 (bc.deadReadout() || bc.deadPhys() || bc.highNoiseHG() ||
364
365 if ( !bad ) local_cell_copy.push_back( cell );
366 }
367 } // end of loop over cells
368 } // end of loop over collection
369
370 // This should stay here as this will be enabled when tile is ready to be decoded as well
371
372 auto tilecell = std::make_unique<TileCellCont>();
373 tilecell->setHashIdToROD( *tileHid2RESrcID );
374 tilecell->initialize().orThrow("Cannot initialize Tile container", name());
375
376 for (unsigned int i=0; i<4; i++) {
377 m_tileDecoder->loadRw2Cell ( i, tilecell->Rw2CellMap(i) );
378 m_tileDecoder->loadRw2Pmt ( i, tilecell->Rw2PmtMap (i) );
379 }
380 m_tileDecoder->loadMBTS( tilecell->MBTS_map(), tilecell->MBTS_channel() );
381
382 auto d0cellsp = std::make_unique<TileROD_Decoder::D0CellsHLT>();
383 for (unsigned int lcidx=0; lcidx < tilecell->size(); lcidx++){
384 TileCellCollection* lcc = tilecell->at(lcidx);
385 for (unsigned int lccidx=0; lccidx<lcc->size(); lccidx++){
386 CaloCell* cell = lcc->at(lccidx);
387 if ( cell ) local_cell_copy.push_back( cell );
388 } // end of loop over cells
389
390 TileRawChannelCollection::ID frag_id = ((*lcc).identify() & 0x0FFF);
391 const int ros = (frag_id >> 8);
392 if ( ros == 1 ) { //treatment for d0Cells in barrel
393 const int drawer = (frag_id & 0xFF);
394 TileCellCollection::iterator pCell = lcc->begin();
395 pCell+=2;
396 d0cellsp->m_cells[drawer] = *pCell;
397 }
398 } // end of loop over collection
399 cache.tileContainer = std::move(tilecell);
400
401 // d0merge cells
402 cache.d0cells = std::move(d0cellsp);
403
404 // For the moment the container has to be completed by hand (again, because of tile)
405 for(unsigned int i=0; i<hashMax; i++){
406 cachefullcont->push_back_fast(nullptr);
407 }
408
409 for(unsigned int i=0; i<local_cell_copy.size(); i++){
410 unsigned int j = local_cell_copy.at(i)->caloDDE()->calo_hash();
411 if ( j < hashMax ) {
412 cachefullcont->at(j) = local_cell_copy.at(i);
413 }
414 }
415 for(unsigned int i=0;i<hashMax;i++)
416 if ( cachefullcont->at(i) == nullptr ){
417 Identifier id = theCaloCCIDM->cell_id(i);
418 if ( id!=0 ){
419 const CaloDetDescrElement* el = theCaloDDM->get_element(id);
420 if ( el->is_tile() ) {
421 cachefullcont->at(i) = new TileCell(el,0,0,0,0,CaloGain::TILEHIGHHIGH);
422 } else {
423 cachefullcont->at(i) = new LArCell(el,0,0,0,CaloGain::LARHIGHGAIN);
424 }
425
426 if (slot==0) m_insertedCells.push_back(i);
427 }
428 }
429
430 cachefullcont->setHasCalo(CaloCell_ID::LAREM);
431 cachefullcont->setHasCalo(CaloCell_ID::LARHEC);
432 cachefullcont->setHasCalo(CaloCell_ID::LARFCAL);
433 cachefullcont->setHasCalo(CaloCell_ID::TILE); //lying... But this needs to be checked later
434
435 // make sure this "map" container has a good hashID
436 cachefullcont->order();
437
438 if ( hashMax != cachefullcont->size() ) {
439 ATH_MSG_ERROR("Problem in the size of the full container");
440 }
441
442 cachefullcont->setIsOrdered(true);
443 cachefullcont->setIsOrderedAndComplete(true);
444 cache.fullcont = std::move(cachefullcont);
445
446 local_cell_copy.clear();
447 ++slot;
448 }
449}
450
451void TrigCaloDataAccessSvc::convertROBs( const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& robFrags,
452 LArCellCont* larcell, LArRodBlockStructure*& larRodBlockStructure_per_slot,
453 uint16_t rodMinorVersion, uint32_t robBlockType, const LArDeadOTXFromSC* deadHandle ) {
454
455 for ( auto rob: robFrags ) {
456 uint32_t sourceID = rob->source_id();
457 const auto it = larcell->find( sourceID );
458 //TB The find also switches the state of the collection to "decoded" so repeated decoding is avoided
459
460 if ( it != larcell->end() && ( *it )->size() != 0 ) { // Already decoded collection
461
462 // TB if we have entered here it means the decoding did not occur yet ( or failed )
463 //
464 LArCellCollection* coll = *it;
465 ATH_MSG_DEBUG( "ROB of ID " << sourceID << " to be decoded" );
466
467 std::scoped_lock decoderLock{m_lardecoderProtect};
468 //TB next two lines seem danger, as they seem to rely on the decoder state
469 const HWIdentifier& feb_id_local = larcell->findsec( sourceID );
470 m_larDecoder->setsecfeb( feb_id_local );
471 if ( ! m_larDecoder->check_valid( rob, msg() ) ){
472 ATH_MSG_WARNING( "Error reading bytestream"<<
473 "event: Bad ROB block ( eformat checks ) : 0x"
474 << std::hex << sourceID << std::dec );
475 // Data seems corrupted
476 reset_LArCol ( coll );
477
478 } else {
479 // Get Rod Data and size of fragment
480 const uint32_t* roddata = 0;
481 rob->rod_data( roddata );
482 const size_t roddatasize = rob->rod_ndata();
483 if ( roddatasize < 3 ) {
484 ATH_MSG_WARNING( "Error reading bytestream"<<
485 "event: Empty ROD block ( less than 3 words ) : 0x"
486 << std::hex << sourceID << std::dec );
487 // Data seems corrupted
488 reset_LArCol ( coll );
489 } else {
490 //TB the converter has state
491 m_larDecoder->fillCollectionHLT( *rob, roddata, roddatasize, *coll, larRodBlockStructure_per_slot, rodMinorVersion, robBlockType );
492 if ( deadHandle ){
493 if ( deadHandle->isThisOTXdead(feb_id_local) ) {
494 const std::vector<float>& corr = deadHandle->correctionFromThisOTXdead(feb_id_local);
495 // The sizes here are guaranteed by construction
496 for(size_t i=0;i<128;i++) {
497 (*coll)[i+128]->set(corr[i],0,0,0x1000,CaloGain::LARHIGHGAIN);
498 }
499 }
500 HWIdentifier feb_id_local2(larRodBlockStructure_per_slot->getFEBID());
501 if ( deadHandle->isThisOTXdead(feb_id_local2) ) {
502 const std::vector<float>& corr = deadHandle->correctionFromThisOTXdead(feb_id_local2);
503 // The sizes here are guaranteed by construction
504 for(size_t i=0;i<128;i++) {
505 (*coll)[i]->set(corr[i],0,0,0x1000,CaloGain::LARHIGHGAIN);
506 }
507 }
508 }
509
510 if ( m_applyOffsetCorrection ) larcell->applyBCIDCorrection( sourceID );
511 }
512
513 }
514 } else {
515 ATH_MSG_VERBOSE( "ROB of ID " << sourceID << " already decoded" );
516 }
517 }
518 ATH_MSG_DEBUG( "finished decoding" );
519}
520
521void TrigCaloDataAccessSvc::convertROBs( const EventContext& context,
522 const std::vector<IdentifierHash>& rIds,
523 TileCellCont* tilecell,
525
526 TileCellCollection* mbts = tilecell->MBTS_collection();
527 const TileHid2RESrcID* hid2re = tilecell->getHashIdToROD();
528
529 std::vector<unsigned int> tile{0};
530 // Tile likes rob by rob
531 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> robFrags;
532 for (size_t i = 0; i < rIds.size(); ++i){
533 tile[0] = tilecell->find_rod(rIds[i]);
534 m_robDataProvider->getROBData(context,tile,robFrags);
535 // Find the collection to fill
536 const auto it = tilecell->find(rIds[i]);
537 if (it == tilecell->end()) continue;
538
539 TileCellCollection* col = *it;
540 if ( !robFrags.empty() && col != nullptr ) {
541 const size_t roddatasize = robFrags[0]->rod_ndata();
542 // insert data into vector (to be removed soon)
543 if (roddatasize < 3) {
544 ATH_MSG_WARNING( "Error reading bytestream"<<
545 "event: Empty ROD block (less than 3 words) : 0x"
546 << std::hex << tile[0] << std::dec );
547 if ( !tilecell->cached(rIds[i])){
548 // resets collection
549 reset_TileCol(col);
550 }
551 robFrags.clear();
552 } else {
553 std::scoped_lock decoderLock{m_tiledecoderProtect};
554 if ( !tilecell->cached(rIds[i]) ) {
555 m_tileDecoder->fillCollectionHLT(robFrags[0],*col,*d0cells,mbts,hid2re);
556 }
557 m_tileDecoder->mergeD0cellsHLT(*d0cells,*col);
558 robFrags.clear();
559 }
560 } // end of if robFrags.size
561 } // End of for through RobFrags
562
563 ATH_MSG_DEBUG( "finished decoding" );
564}
565
566void TrigCaloDataAccessSvc::missingROBs( const std::vector<uint32_t>& request,
567 const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& response,
568 std::set<uint32_t>& missing ) const {
569
570 std::set<uint32_t> receivedROBsSet;
571 for ( auto rob: response ) {
572 receivedROBsSet.insert( rob->source_id() );
573 }
574
575 std::set<uint32_t> requestedROBsSet( request.begin(), request.end() );
576 std::set_difference( requestedROBsSet.begin(), requestedROBsSet.end(),
577 receivedROBsSet.begin(), receivedROBsSet.end(),
578 std::inserter( missing, missing.begin() ) );
579}
580
581
582void TrigCaloDataAccessSvc::clearMissing( const std::vector<uint32_t>& request,
583 const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& response,
584 LArCellCont* larcell ) {
585 std::set<uint32_t> missing;
586 missingROBs( request, response, missing );
587 for ( uint32_t robID : missing ) {
588 const auto it = larcell->find( robID );
589 if ( it != larcell->end() && not (*it)->empty() ) { // Already decoded collection
590 reset_LArCol ( *it );
591 }
592 }
593}
594
595
596StatusCode TrigCaloDataAccessSvc::prepareLArCollections( const EventContext& context,
597 const IRoiDescriptor& roi,
598 const int sampling,
599 DETID detector ) {
600
601 std::call_once(m_lateInitFlag, &TrigCaloDataAccessSvc::lateInit, this, context);
602
603 // If the full event was already unpacked, don't need to unpack RoI
604 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
605 if ( cache->lastFSEvent == context.evt() ) return StatusCode::SUCCESS;
606
607 std::vector<uint32_t> requestROBs;
608
609 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> robFrags;
610 switch ( detector ) {
611 case TTEM: {m_regionSelector_TTEM->lookup(context)->ROBIDList( sampling, roi, requestROBs ); break; }
612 case TTHEC: {m_regionSelector_TTHEC->lookup(context)->ROBIDList( sampling, roi, requestROBs ); break; }
613 case FCALEM: {m_regionSelector_FCALEM->lookup(context)->ROBIDList( sampling, roi, requestROBs ); break; }
614 case FCALHAD: {m_regionSelector_FCALHAD->lookup(context)->ROBIDList( sampling, roi, requestROBs ); break; }
615 default: break;
616 }
617
618 m_robDataProvider->getROBData( context, requestROBs, robFrags );
619 if ( robFrags.empty() && !requestROBs.empty() ) {
620 return StatusCode::SUCCESS;
621 }
622
623 auto lockTime = Monitored::Timer ( "TIME_locking_LAr_RoI" );
624 std::scoped_lock lock{cache->mutex};
625 lockTime.stop();
626
627 // TB, what would happen from now inside the collection unapcking
628 // if this event number is different than the one for each collection the unpacking will happen,
629 // if it is the same the unpacking will not be repeated
630 // same in prepareLArFullCollections
631 cache->larContainer->eventNumber( context.evt() );
632 if ( m_applyOffsetCorrection && cache->larContainer->lumiBCIDCheck( context ) ) {
635 if ( avg.cptr() && onoff.cptr() ) cache->larContainer->updateBCID( *avg, **onoff );
636 }
637
638 const LArDeadOTXFromSC* deadHandle = nullptr;
639 if ( m_correctDead ){
641 if ( !deadHdl.isValid() ){
642 ATH_MSG_WARNING("Should not try to use LArDEADOTXFromSC" );
643 } else {
644 deadHandle = deadHdl.cptr();
645 }
646 }
647
648 convertROBs( robFrags, cache->larContainer.get(), cache->larRodBlockStructure_per_slot,
649 cache->rodMinorVersion, cache->robBlockType, deadHandle );
650
651 if ( requestROBs.size() != robFrags.size() ) {
652 ATH_MSG_DEBUG( "Missing ROBs, requested " << requestROBs.size() << " obtained " << robFrags.size() );
653 clearMissing( requestROBs, robFrags, cache->larContainer.get() );
654 }
655 auto roiROBs = Monitored::Scalar( "roiROBs_LAr", robFrags.size() );
656 auto roiEta = Monitored::Scalar( "roiEta_LAr", roi.eta() );
657 auto roiPhi = Monitored::Scalar( "roiPhi_LAr", roi.phi() );
658
659 Monitored::Group( m_monTool, lockTime, roiEta, roiPhi, roiROBs );
660 return StatusCode::SUCCESS;
661}
662
663StatusCode TrigCaloDataAccessSvc::prepareTileCollections( const EventContext& context,
664 const IRoiDescriptor& roi) {
665
666 std::call_once(m_lateInitFlag, &TrigCaloDataAccessSvc::lateInit, this, context);
667
668 // If the full event was already unpacked, don't need to unpack RoI
669 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
670 if ( cache->lastFSEvent == context.evt() ) return StatusCode::SUCCESS;
671
672 std::vector<uint32_t> requestROBs;
673 std::vector<IdentifierHash> rIds;
674 m_regionSelector_TILE->lookup(context)->ROBIDList( 0, roi, requestROBs );
675 m_regionSelector_TILE->lookup(context)->HashIDList(roi, rIds);
676
677 std::scoped_lock lock{cache->mutex};
678 if ( cache->tileContainer->eventNumber() != context.evt() ) {
679 cache->d0cells->clear();
680 }
681 cache->tileContainer->eventNumber( context.evt() );
682
683 convertROBs( context, rIds, cache->tileContainer.get(), cache->d0cells.get() );
684
685 return StatusCode::SUCCESS;
686}
687
688StatusCode TrigCaloDataAccessSvc::prepareMBTSCollections( const EventContext& context) {
689
690 std::call_once(m_lateInitFlag, &TrigCaloDataAccessSvc::lateInit, this, context);
691
692 // If the full event was already unpacked, don't need to unpack RoI
693 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
694 if ( cache->lastFSEvent == context.evt() ) return StatusCode::SUCCESS;
695
696 std::scoped_lock lock{cache->mutex};
697 if ( cache->tileContainer->eventNumber() != context.evt() ) {
698 cache->d0cells->clear();
699 }
700 cache->tileContainer->eventNumber( context.evt() );
701
702 const std::vector<unsigned int>* ids = cache->tileContainer->MBTS_IDs();
703 std::vector<IdentifierHash> tileIds;
704 tileIds.reserve(ids->size());
705 for (size_t i=0; i<ids->size(); i++) {
706 tileIds.push_back( (*ids)[i] );
707 }
708 convertROBs( context, tileIds, cache->tileContainer.get(), cache->d0cells.get() );
709
710 return StatusCode::SUCCESS;
711}
712
713
714
715StatusCode TrigCaloDataAccessSvc::loadMBTS ( const EventContext& context,
716 std::vector<const TileCell*>& loadedCells ) {
717
718 ATH_MSG_DEBUG( "MBTS requested for event " << context );
720
721 HLTCaloEventCache* cache = m_hLTCaloSlot.get( context );
722 {
723 std::scoped_lock lock{cache->mutex};
724 TileCellCollection* mbts = cache->tileContainer->MBTS_collection();
725 loadedCells.reserve(mbts->size());
726 for (size_t i=0; i<mbts->size(); ++i) {
727 loadedCells.push_back(mbts->at(i));
728 }
729 }
730 return StatusCode::SUCCESS;
731
732}
#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
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
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
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