ATLAS Offline Software
ITkStripRawDataProvider.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 
12 #include <memory>
13 
15 
16 
17 // Initialize
18 
20 {
21  // Get ROBDataProviderSvc
22  ATH_CHECK(m_robDataProvider.retrieve());
23 
24  // Get the SCT ID helper
25  ATH_CHECK(detStore()->retrieve(m_sctID, "SCT_ID"));
26  if (m_roiSeeded.value()) {
27  // Don't need SCT cabling if running in RoI-seeded mode
29  ATH_CHECK(m_regionSelector.retrieve());
30  m_cabling.disable();
31  }
32  else {
33  //Disable Roi requirement
35  // Retrieve Cabling tool
36  ATH_CHECK(m_cabling.retrieve());
37  m_regionSelector.disable();
38  }
39 
40  //Initialize
45  ATH_CHECK(m_rdoContainerCacheKey.initialize(!m_rdoContainerCacheKey.key().empty()));
47 
48  ATH_CHECK( m_rawDataTool.retrieve() );
49 
50  return StatusCode::SUCCESS;
51 }
52 
53 // Execute
54 
55 StatusCode ITkStripRawDataProvider::execute(const EventContext& ctx) const
56 {
58  bool externalCacheRDO = !m_rdoContainerCacheKey.key().empty();
59  if (not externalCacheRDO) {
60  ATH_CHECK(rdoContainer.record (std::make_unique<SCT_RDO_Container>(m_sctID->wafer_hash_max(), EventContainers::Mode::OfflineFast)));
61  ATH_MSG_DEBUG("Created container for " << m_sctID->wafer_hash_max());
62  }
63  else {
65  ATH_CHECK(rdoCache.isValid());
66  ATH_CHECK(rdoContainer.record (std::make_unique<SCT_RDO_Container>(rdoCache.ptr())));
67  ATH_MSG_DEBUG("Created container using cache for " << m_rdoContainerCacheKey.key());
68  }
69 
71  if ( m_bsErrContainerCacheKey.key().empty() ) {
72  ATH_CHECK(bsIDCErrContainer.record( std::make_unique<IDCInDetBSErrContainer>(m_sctID->wafer_hash_max(), std::numeric_limits<IDCInDetBSErrContainer::ErrorCode>::min() )));
73  ATH_MSG_DEBUG("Created IDCInDetBSErrContainer w/o using external cache");
74  } else { // use cache
76  ATH_CHECK( cacheHandle.isValid() );
77  ATH_CHECK(bsIDCErrContainer.record( std::make_unique<IDCInDetBSErrContainer>(cacheHandle.ptr())) );
78  ATH_MSG_DEBUG("Created SCT IDCInDetBSErrContainer using external cache");
79  }
80 
81  // Ask ROBDataProviderSvc for the vector of ROBFragment for all SCT ROBIDs
82  std::vector<const ROBFragment*> vecROBFrags;
83  std::vector<IdentifierHash> hashIDs;
84  if (not m_roiSeeded.value()) {
85  std::vector<uint32_t> rodList;
86  m_cabling->getAllRods(rodList, ctx);
87  ATH_MSG_DEBUG("Size of rodList: " << rodList.size());
88  m_robDataProvider->getROBData(ctx, rodList, vecROBFrags);
89  }
90  else {
91  // Only load ROBs from RoI
92  std::vector<uint32_t> listOfROBs;
94  ATH_CHECK(roiCollection.isValid());
95  TrigRoiDescriptor superRoI; // Add all RoIs to a super-RoI
96  superRoI.reserve(roiCollection->size());
97  superRoI.setComposite(true);
98  superRoI.manageConstituents(false);
99  for (const TrigRoiDescriptor* roi : *roiCollection) {
100  superRoI.push_back(roi);
101  }
102 
103  m_regionSelector->lookup(ctx)->ROBIDList(superRoI, listOfROBs );
104  m_regionSelector->lookup(ctx)->HashIDList(superRoI, hashIDs );
105 
106  m_robDataProvider->getROBData(ctx, listOfROBs, vecROBFrags);
107  }
108 
109 
110  ATH_MSG_DEBUG("Number of ROB fragments " << vecROBFrags.size());
111 
112  if (m_storeInDetTimeColls) {
115  lvl1Collection = SG::makeHandle(m_lvl1CollectionKey,ctx);
116  bcIDCollection = SG::makeHandle(m_bcIDCollectionKey,ctx);
117 
118  ATH_CHECK(lvl1Collection.record(std::make_unique<InDetTimeCollection>()));
119  ATH_CHECK(bcIDCollection.record(std::make_unique<InDetTimeCollection>()));
120 
121  lvl1Collection->reserve(vecROBFrags.size());
122  bcIDCollection->reserve(vecROBFrags.size());
123 
124  for (const ROBFragment* robFrag : vecROBFrags) {
125  // Store LVL1ID and BCID information in InDetTimeCollection
126  // to be stored in StoreGate at the end of the loop.
127  // We want to store a pair<ROBID, LVL1ID> for each ROD, once per event.
128  uint32_t robID{(robFrag)->rod_source_id()};
129 
130  unsigned int lvl1ID{(robFrag)->rod_lvl1_id()};
131  lvl1Collection->emplace_back(robID, lvl1ID);
132 
133  unsigned int bcID{(robFrag)->rod_bc_id()};
134  bcIDCollection->emplace_back(robID, bcID);
135 
136  ATH_MSG_DEBUG("Stored LVL1ID " << lvl1ID << " and BCID " << bcID << " in InDetTimeCollections");
137  }
138  }
139 
140  if ( not hashIDs.empty() ) {
141  int missingCount{};
142  for ( IdentifierHash hash: hashIDs ) {
143  if ( not rdoContainer->tryAddFromCache( hash ) ) missingCount++;
144  bsIDCErrContainer->tryAddFromCache( hash );
145  }
146  ATH_MSG_DEBUG("Out of: " << hashIDs.size() << "Hash IDs missing: " << missingCount );
147  if ( missingCount == 0 ) {
148  return StatusCode::SUCCESS;
149  }
150  }
151 
152  std::unique_ptr<DataPool<SCT3_RawData>> dataItemsPool = nullptr;
153  if(!externalCacheRDO){
154  dataItemsPool = std::make_unique<DataPool<SCT3_RawData>>(ctx);
155  dataItemsPool->reserve(10000); // Some large default size
156  } else if (m_useDataPoolWithCache) {
157  dataItemsPool = std::make_unique<DataPool<SCT3_RawData>>(ctx);
158  // for now a default size 1024.
159  }
160 
161  // Ask SCTRawDataProviderTool to decode it and to fill the IDC
162  StatusCode statConv = m_rawDataTool->convert(vecROBFrags,
163  *(rdoContainer.ptr()),
164  *bsIDCErrContainer,
165  dataItemsPool.get(),
166  ctx);
167 
168  if (statConv.isFailure() && statConv != StatusCode::RECOVERABLE) {
169  ATH_MSG_WARNING("BS conversion into RDOs failed");
170  return statConv;
171  } else {
172  return StatusCode::SUCCESS;
173  }
174 
175 }
ITkStripRawDataProvider::m_rdoContainerCacheKey
SG::UpdateHandleKey< SCT_RDO_Cache > m_rdoContainerCacheKey
Update handle for SCT RDO and Erorrs Cache.
Definition: ITkStripRawDataProvider.h:117
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
ITkStripRawDataProvider::m_bsErrContainerCacheKey
SG::UpdateHandleKey< IDCInDetBSErrContainer_Cache > m_bsErrContainerCacheKey
Definition: ITkStripRawDataProvider.h:118
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
SG::UpdateHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
ITkStripRawDataProvider::m_roiCollectionKey
SG::ReadHandleKey< TrigRoiDescriptorCollection > m_roiCollectionKey
Read handle for Trigger ROI descriptor collection.
Definition: ITkStripRawDataProvider.h:86
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
ITkStripRawDataProvider::m_rdoContainerKey
SG::WriteHandleKey< SCT_RDO_Container > m_rdoContainerKey
Write handle for SCT RDO container.
Definition: ITkStripRawDataProvider.h:92
ITkStripRawDataProvider::m_lvl1CollectionKey
SG::WriteHandleKey< InDetTimeCollection > m_lvl1CollectionKey
Write handle for LVL 1 Inner Detector time collection.
Definition: ITkStripRawDataProvider.h:98
ITkStripRawDataProvider::m_useDataPoolWithCache
Gaudi::Property< bool > m_useDataPoolWithCache
Boolean to Use DataPool with IDC online Cache.
Definition: ITkStripRawDataProvider.h:82
SG::UpdateHandle::ptr
pointer_type ptr()
Dereference the pointer.
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
ITkStripRawDataProvider::m_rawDataTool
ToolHandle< IITkStripRawDataProviderTool > m_rawDataTool
Tool to fill Collections of SCT RDO Containers.
Definition: ITkStripRawDataProvider.h:63
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
RoiDescriptor::push_back
void push_back(const IRoiDescriptor *roi)
add a RoiDescriptor
Definition: RoiDescriptor.h:157
SCT_ID::wafer_hash_max
size_type wafer_hash_max() const
Definition: SCT_ID.cxx:646
RoiDescriptor::reserve
void reserve(size_t s)
reserve elements in vector
Definition: RoiDescriptor.h:154
eformat::ROBFragment
Definition: L1CaloBsDecoderUtil.h:12
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
IITkStripRawDataProviderTool.h
IdentifiableContainerMT::tryAddFromCache
virtual bool tryAddFromCache(IdentifierHash hashId) override final
Looks in the cache to see if item already exists if not it returns false, If it does exist it incorpo...
Definition: IdentifiableContainerMT.h:331
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
ITkStripRawDataProvider::m_robDataProvider
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
ROB Data Provider for accessing ROB data.
Definition: ITkStripRawDataProvider.h:53
IITkStripCablingTool.h
ITkStripRawDataProvider::m_cabling
ToolHandle< IITkStripCablingTool > m_cabling
Providing mappings of online and offline identifiers and also serial numbers.
Definition: ITkStripRawDataProvider.h:69
ITkStripRawDataProvider::m_storeInDetTimeColls
Gaudi::Property< bool > m_storeInDetTimeColls
Definition: ITkStripRawDataProvider.h:120
SG::UpdateHandle
Definition: UpdateHandle.h:91
EventContainers::Mode::OfflineFast
@ OfflineFast
ITkStripRawDataProvider::m_sctID
const SCT_ID * m_sctID
Identifier helper class for the SCT subdetector that creates compact Identifier objects and Identifie...
Definition: ITkStripRawDataProvider.h:76
OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment
eformat::ROBFragment< PointerType > ROBFragment
Definition: RawEvent.h:27
ITkStripRawDataProvider::m_bsIDCErrContainerKey
SG::WriteHandleKey< IDCInDetBSErrContainer > m_bsIDCErrContainerKey
Write handle for Inner Detector ByteStream error container.
Definition: ITkStripRawDataProvider.h:110
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:108
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ITkStripRawDataProvider.h
IdentifiableContTemp.h
ITkStripRawDataProvider::initialize
virtual StatusCode initialize() override
Initialize.
Definition: ITkStripRawDataProvider.cxx:19
IdentifiableValueContainer::tryAddFromCache
bool tryAddFromCache(size_t i)
Returns true if the value is also in the external cache, sets mask to true if it is.
Definition: IdentifiableValueContainer.h:114
ITkStripRawDataProvider::execute
virtual StatusCode execute(const EventContext &ctx) const override
Execute.
Definition: ITkStripRawDataProvider.cxx:55
RoiDescriptor::setComposite
void setComposite(bool b=true)
Definition: RoiDescriptor.h:138
RoiDescriptor::manageConstituents
bool manageConstituents() const
always manage constituents ???
Definition: RoiDescriptor.h:141
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
ITkStripRawDataProvider::m_bcIDCollectionKey
SG::WriteHandleKey< InDetTimeCollection > m_bcIDCollectionKey
Write handle for BC ID Inner Detector time collection.
Definition: ITkStripRawDataProvider.h:104
IdentifiableContainerBase.h
ITkStripRawDataProvider::m_roiSeeded
BooleanProperty m_roiSeeded
Boolean to determine if SCT Raw Data Provider should be run in RoI seeded mode.
Definition: ITkStripRawDataProvider.h:79
ITkStripRawDataProvider::m_regionSelector
ToolHandle< IRegSelTool > m_regionSelector
Region Selector tool for Athena.
Definition: ITkStripRawDataProvider.h:58