ATLAS Offline Software
SCTRawDataProvider.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "SCTRawDataProvider.h"
6 
12 
13 #include <memory>
14 
16 
17 // Constructor
18 
19 SCTRawDataProvider::SCTRawDataProvider(const std::string& name, ISvcLocator* pSvcLocator) :
20  AthReentrantAlgorithm(name, pSvcLocator)
21 {
22  declareProperty("RDOCacheKey", m_rdoContainerCacheKey="");
23  declareProperty("BSErrCacheKey", m_bsErrContainerCacheKey="");
24 }
25 
26 // Initialize
27 
29 {
30  // Get ROBDataProviderSvc
31  ATH_CHECK(m_robDataProvider.retrieve());
32 
33  // Get the SCT ID helper
34  ATH_CHECK(detStore()->retrieve(m_sctID, "SCT_ID"));
35  if (m_roiSeeded.value()) {
36  // Don't need SCT cabling if running in RoI-seeded mode
38  ATH_CHECK(m_regionSelector.retrieve());
39  m_cabling.disable();
40  }
41  else {
42  //Disable Roi requirement
44  // Retrieve Cabling tool
45  ATH_CHECK(m_cabling.retrieve());
46  m_regionSelector.disable();
47  }
48 
49  //Initialize
50  ATH_CHECK(m_rdoContainerKey.initialize());
54  ATH_CHECK(m_rdoContainerCacheKey.initialize(!m_rdoContainerCacheKey.key().empty()));
56 
57  ATH_CHECK( m_rawDataTool.retrieve() );
58 
59  return StatusCode::SUCCESS;
60 }
61 
62 // Execute
63 
64 StatusCode SCTRawDataProvider::execute(const EventContext& ctx) const
65 {
67  bool externalCacheRDO = !m_rdoContainerCacheKey.key().empty();
68  if (not externalCacheRDO) {
69  ATH_CHECK(rdoContainer.record (std::make_unique<SCT_RDO_Container>(m_sctID->wafer_hash_max(), EventContainers::Mode::OfflineFast)));
70  ATH_MSG_DEBUG("Created container for " << m_sctID->wafer_hash_max());
71  }
72  else {
74  ATH_CHECK(rdoCache.isValid());
75  ATH_CHECK(rdoContainer.record (std::make_unique<SCT_RDO_Container>(rdoCache.ptr())));
76  ATH_MSG_DEBUG("Created container using cache for " << m_rdoContainerCacheKey.key());
77  }
78 
80  if ( m_bsErrContainerCacheKey.key().empty() ) {
81  ATH_CHECK(bsIDCErrContainer.record( std::make_unique<IDCInDetBSErrContainer>(m_sctID->wafer_hash_max(), std::numeric_limits<IDCInDetBSErrContainer::ErrorCode>::min() )));
82  ATH_MSG_DEBUG("Created IDCInDetBSErrContainer w/o using external cache");
83  } else { // use cache
85  ATH_CHECK( cacheHandle.isValid() );
86  ATH_CHECK(bsIDCErrContainer.record( std::make_unique<IDCInDetBSErrContainer>(cacheHandle.ptr())) );
87  ATH_MSG_DEBUG("Created SCT IDCInDetBSErrContainer using external cache");
88  }
89 
90  // Ask ROBDataProviderSvc for the vector of ROBFragment for all SCT ROBIDs
91  std::vector<const ROBFragment*> vecROBFrags;
92  std::vector<IdentifierHash> hashIDs;
93  if (not m_roiSeeded.value()) {
94  std::vector<uint32_t> rodList;
95  m_cabling->getAllRods(rodList, ctx);
96  m_robDataProvider->getROBData(ctx, rodList, vecROBFrags);
97  }
98  else {
99  // Only load ROBs from RoI
100  std::vector<uint32_t> listOfROBs;
102  ATH_CHECK(roiCollection.isValid());
103  TrigRoiDescriptor superRoI; // Add all RoIs to a super-RoI
104  superRoI.reserve(roiCollection->size());
105  superRoI.setComposite(true);
106  superRoI.manageConstituents(false);
107  for (const TrigRoiDescriptor* roi : *roiCollection) {
108  superRoI.push_back(roi);
109  }
110  m_regionSelector->ROBIDList(superRoI, listOfROBs);
111  m_regionSelector->HashIDList(superRoI, hashIDs);
112  m_robDataProvider->getROBData(ctx, listOfROBs, vecROBFrags);
113  }
114 
115 
116  ATH_MSG_DEBUG("Number of ROB fragments " << vecROBFrags.size());
117 
118  if (m_storeInDetTimeColls) {
121  lvl1Collection = SG::makeHandle(m_lvl1CollectionKey,ctx);
122  bcIDCollection = SG::makeHandle(m_bcIDCollectionKey,ctx);
123 
124  ATH_CHECK(lvl1Collection.record(std::make_unique<InDetTimeCollection>()));
125  ATH_CHECK(bcIDCollection.record(std::make_unique<InDetTimeCollection>()));
126 
127  lvl1Collection->reserve(vecROBFrags.size());
128  bcIDCollection->reserve(vecROBFrags.size());
129 
130  for (const ROBFragment* robFrag : vecROBFrags) {
131  // Store LVL1ID and BCID information in InDetTimeCollection
132  // to be stored in StoreGate at the end of the loop.
133  // We want to store a pair<ROBID, LVL1ID> for each ROD, once per event.
134  uint32_t robID{(robFrag)->rod_source_id()};
135 
136  unsigned int lvl1ID{(robFrag)->rod_lvl1_id()};
137  lvl1Collection->emplace_back(robID, lvl1ID);
138 
139  unsigned int bcID{(robFrag)->rod_bc_id()};
140  bcIDCollection->emplace_back(robID, bcID);
141 
142  ATH_MSG_DEBUG("Stored LVL1ID " << lvl1ID << " and BCID " << bcID << " in InDetTimeCollections");
143  }
144  }
145 
146  if ( not hashIDs.empty() ) {
147  int missingCount{};
148  for ( IdentifierHash hash: hashIDs ) {
149  if ( not rdoContainer->tryAddFromCache( hash ) ) missingCount++;
150  bsIDCErrContainer->tryAddFromCache( hash );
151  }
152  ATH_MSG_DEBUG("Out of: " << hashIDs.size() << "Hash IDs missing: " << missingCount );
153  if ( missingCount == 0 ) {
154  return StatusCode::SUCCESS;
155  }
156  }
157 
158  std::unique_ptr<DataPool<SCT3_RawData>> dataItemsPool = nullptr;
159  if(!externalCacheRDO){
160  dataItemsPool = std::make_unique<DataPool<SCT3_RawData>>(ctx);
161  dataItemsPool->reserve(10000); // Some large default size
162  } else if (m_useDataPoolWithCache) {
163  dataItemsPool = std::make_unique<DataPool<SCT3_RawData>>(ctx);
164  // for now a default size 1024.
165  }
166 
167  // Ask SCTRawDataProviderTool to decode it and to fill the IDC
168  StatusCode statConv = m_rawDataTool->convert(vecROBFrags,
169  *(rdoContainer.ptr()),
170  *bsIDCErrContainer,
171  dataItemsPool.get(),
172  ctx);
173 
174  if (statConv.isFailure() && statConv != StatusCode::RECOVERABLE) {
175  ATH_MSG_WARNING("BS conversion into RDOs failed");
176  return statConv;
177  } else {
178  return StatusCode::SUCCESS;
179  }
180 
181 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
SCTRawDataProvider::m_bsErrContainerCacheKey
SG::UpdateHandleKey< IDCInDetBSErrContainer_Cache > m_bsErrContainerCacheKey
Definition: SCTRawDataProvider.h:131
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
ISCTRawDataProviderTool.h
SCTRawDataProvider::m_useDataPoolWithCache
Gaudi::Property< bool > m_useDataPoolWithCache
Boolean to Use DataPool with IDC online Cache.
Definition: SCTRawDataProvider.h:95
SCTRawDataProvider::m_robDataProvider
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
ROB Data Provider for accessing ROB data.
Definition: SCTRawDataProvider.h:66
SCTRawDataProvider::m_bcIDCollectionKey
SG::WriteHandleKey< InDetTimeCollection > m_bcIDCollectionKey
Write handle for BC ID Inner Detector time collection.
Definition: SCTRawDataProvider.h:117
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
SG::UpdateHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SCTRawDataProvider::SCTRawDataProvider
SCTRawDataProvider(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: SCTRawDataProvider.cxx:19
SCTRawDataProvider::m_storeInDetTimeColls
Gaudi::Property< bool > m_storeInDetTimeColls
Definition: SCTRawDataProvider.h:133
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
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
SCTRawDataProvider::initialize
virtual StatusCode initialize() override
Initialize.
Definition: SCTRawDataProvider.cxx:28
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
RoiDescriptor::push_back
void push_back(const IRoiDescriptor *roi)
add a RoiDescriptor
Definition: RoiDescriptor.h:157
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.
SCTRawDataProvider::m_rdoContainerCacheKey
SG::UpdateHandleKey< SCT_RDO_Cache > m_rdoContainerCacheKey
Update handle for SCT RDO and Erorrs Cache.
Definition: SCTRawDataProvider.h:130
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
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:334
SCTRawDataProvider::m_cabling
ToolHandle< ISCT_CablingTool > m_cabling
Providing mappings of online and offline identifiers and also serial numbers.
Definition: SCTRawDataProvider.h:82
SCTRawDataProvider::m_roiCollectionKey
SG::ReadHandleKey< TrigRoiDescriptorCollection > m_roiCollectionKey
Read handle for Trigger ROI descriptor collection.
Definition: SCTRawDataProvider.h:99
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SCTRawDataProvider.h
SCTRawDataProvider::m_bsIDCErrContainerKey
SG::WriteHandleKey< IDCInDetBSErrContainer > m_bsIDCErrContainerKey
Write handle for Inner Detector ByteStream error container.
Definition: SCTRawDataProvider.h:123
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
SCTRawDataProvider::m_roiSeeded
BooleanProperty m_roiSeeded
Boolean to determine if SCT Raw Data Provider should be run in RoI seeded mode.
Definition: SCTRawDataProvider.h:92
min
#define min(a, b)
Definition: cfImp.cxx:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SCT_ID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: SCT_ID.cxx:636
SG::UpdateHandle
Definition: UpdateHandle.h:94
EventContainers::Mode::OfflineFast
@ OfflineFast
OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment
eformat::ROBFragment< PointerType > ROBFragment
Definition: RawEvent.h:27
SCTRawDataProvider::m_lvl1CollectionKey
SG::WriteHandleKey< InDetTimeCollection > m_lvl1CollectionKey
Write handle for LVL 1 Inner Detector time collection.
Definition: SCTRawDataProvider.h:111
SCTRawDataProvider::m_rdoContainerKey
SG::WriteHandleKey< SCT_RDO_Container > m_rdoContainerKey
Write handle for SCT RDO container.
Definition: SCTRawDataProvider.h:105
SCTRawDataProvider::execute
virtual StatusCode execute(const EventContext &ctx) const override
Execute.
Definition: SCTRawDataProvider.cxx:64
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
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:109
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
IdentifiableContTemp.h
SCTRawDataProvider::m_rawDataTool
ToolHandle< ISCTRawDataProviderTool > m_rawDataTool
Tool to fill Collections of SCT RDO Containers.
Definition: SCTRawDataProvider.h:76
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
RoiDescriptor::setComposite
void setComposite(bool b=true)
Definition: RoiDescriptor.h:138
ISCT_CablingTool.h
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
IdentifiableContainerBase.h
SCTRawDataProvider::m_regionSelector
ToolHandle< IRegSelTool > m_regionSelector
Region Selector tool for Athena.
Definition: SCTRawDataProvider.h:71
SCTRawDataProvider::m_sctID
const SCT_ID * m_sctID
Identifier helper class for the SCT subdetector that creates compact Identifier objects and Identifie...
Definition: SCTRawDataProvider.h:89