ATLAS Offline Software
CscStripPrepDataContainerCnv_p1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 
14 
15 // Gaudi
16 #include "GaudiKernel/ISvcLocator.h"
17 #include "GaudiKernel/Bootstrap.h"
18 #include "GaudiKernel/StatusCode.h"
19 #include "GaudiKernel/Service.h"
20 #include "GaudiKernel/MsgStream.h"
21 
22 // Athena
24 #include "AthAllocators/DataPool.h"
25 #include "StoreGate/StoreGateSvc.h"
26 
27 
29  // Do not initialize again:
30  m_isInitialized=true;
31 
32  // get DetectorStore service
33  SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
34  CHECK( detStore.isValid() );
35 
36  // Get the CSC helper from the detector store
37  CHECK( detStore->retrieve(m_cscStripId) );
38 
39  CHECK( m_eventCnvTool.retrieve() );
40 
41  if (log.level() <= MSG::DEBUG)
42  log << MSG::DEBUG << "Converter initialized." << endmsg;
43  return StatusCode::SUCCESS;
44 }
46  const Trk::ITrkEventCnvTool* cnv_tool = m_eventCnvTool->getCnvTool(id);
47  if (!cnv_tool) return nullptr;
48  return dynamic_cast<const MuonGM::CscReadoutElement*>(cnv_tool->getDetectorElement(id));
49 }
50 
52 {
53 
54  // The transient model has a container holding collections and the
55  // collections hold channels.
56  //
57  // The persistent model flattens this so that the persistent
58  // container has two vectors:
59  // 1) all collections, and
60  // 2) all RDO
61  //
62  // The persistent collections, then only maintain indexes into the
63  // container's vector of all channels.
64  //
65  // So here we loop over all collection and add their channels
66  // to the container's vector, saving the indexes in the
67  // collection.
68 
71 
72  CscStripPrepDataCnv_p1 chanCnv;
73  TRANS::const_iterator it_Coll = transCont->begin();
74  TRANS::const_iterator it_CollEnd = transCont->end();
75  unsigned int collIndex;
76  unsigned int chanBegin = 0;
77  unsigned int chanEnd = 0;
78  persCont->m_collections.resize(transCont->numberOfCollections());
79  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
80 
81  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
82  // Add in new collection
83  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " New collection" << endmsg;
84  const Muon::CscStripPrepDataCollection& collection = (**it_Coll);
85  chanBegin = chanEnd;
86  chanEnd += collection.size();
87  Muon::MuonPRD_Collection_p1& pcollection = persCont->m_collections[collIndex];
88  pcollection.m_id = collection.identify().get_identifier32().get_compact();
89  pcollection.m_hashId = (unsigned int) collection.identifyHash();
90  pcollection.m_begin = chanBegin;
91  pcollection.m_end = chanEnd;
92  // Add in channels
93  persCont->m_PRD.resize(chanEnd);
94  for (unsigned int i = 0; i < collection.size(); ++i) {
95  const Muon::CscStripPrepData* chan = collection[i];
96  persCont->m_PRD[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
97  }
98  }
99  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing CscStripPrepDataContainer ***" << endmsg;
100 }
101 
103 {
104 
105  // The transient model has a container holding collections and the
106  // collections hold channels.
107  //
108  // The persistent model flattens this so that the persistent
109  // container has two vectors:
110  // 1) all collections, and
111  // 2) all channels
112  //
113  // The persistent collections, then only maintain indexes into the
114  // container's vector of all channels.
115  //
116  // So here we loop over all collection and extract their channels
117  // from the vector.
118 
119 
120  Muon::CscStripPrepDataCollection* coll = nullptr;
121 
122  CscStripPrepDataCnv_p1 chanCnv;
124 
125  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
126  for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
127 
128  // Create trans collection - is NOT owner of CscStripPrepData (SG::VIEW_ELEMENTS)
129  // IDet collection don't have the Ownership policy c'tor
130  const Muon::MuonPRD_Collection_p1& pcoll = persCont->m_collections[icoll];
131  Identifier collID(Identifier(pcoll.m_id));
132  IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
133  coll = new Muon::CscStripPrepDataCollection(collIDHash);
134  coll->setIdentifier(Identifier(pcoll.m_id));
135  unsigned int nchans = pcoll.m_end - pcoll.m_begin;
136  coll->resize(nchans);
137 
138  // Fill with channels
139  for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
140  const TPObjRef pchan = persCont->m_PRD[ichan + pcoll.m_begin];
141  Muon::CscStripPrepData* chan = dynamic_cast<Muon::CscStripPrepData*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
142  if (!chan) {
143  log << MSG::ERROR << "AthenaPoolTPCnvIDCont::persToTrans: Cannot get CscStripPrepData!" << endmsg;
144  continue;
145  }
146  const MuonGM::CscReadoutElement * de = getReadOutElement(chan->identify());
147  chan->m_detEl = de;
148  (*coll)[ichan] = chan;
149  }
150 
151  // register the rdo collection in IDC with hash - faster addCollection
152  StatusCode sc = transCont->addCollection(coll, collIDHash);
153  if (sc.isFailure()) {
154  throw std::runtime_error("Failed to add collection to ID Container");
155  }
156  if (log.level() <= MSG::DEBUG) {
157  log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
158  collID.get_compact() << ", added to Identifiable container." << endmsg;
159  }
160  }
161 
162  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading CscStripPrepDataContainer" << endmsg;
163 }
164 
165 
166 
167 //================================================================
169 {
170  if(!m_isInitialized) {
171  if (this->initialize(log) != StatusCode::SUCCESS) {
172  log << MSG::FATAL << "Could not initialize CscStripPrepDataContainerCnv_p1 " << endmsg;
173  return nullptr;
174  }
175  }
176  std::unique_ptr<Muon::CscStripPrepDataContainer> trans(new Muon::CscStripPrepDataContainer(m_cscStripId->module_hash_max()));
177  persToTrans(persObj, trans.get(), log);
178  return(trans.release());
179 }
180 
181 
CscIdHelper.h
Muon::MuonPrepDataContainer
Template for Muon PRD containers (which are basically collections of MuonPrepDataCollections).
Definition: MuonPrepDataContainer.h:42
CscStripPrepDataContainer.h
Muon::MuonPRD_Container_p1::m_collections
std::vector< Muon::MuonPRD_Collection_p1 > m_collections
Definition: MuonPRD_Container_p1.h:19
ITPConverterFor< Trk::PrepRawData >
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
IdentifiableContainerMT::addCollection
virtual StatusCode addCollection(const T *coll, IdentifierHash hashId) override final
insert collection into container with id hash if IDC should not take ownership of collection,...
Definition: IdentifiableContainerMT.h:297
Muon::MuonPRD_Collection_p1::m_id
unsigned int m_id
Identifier of this collection.
Definition: MuonPRD_Collection_p1.h:31
Muon::MuonPRD_Collection_p1::m_hashId
unsigned int m_hashId
Hash Identifier of this collection (write this one as well, so we don't rely on the IdHelper for it)
Definition: MuonPRD_Collection_p1.h:35
Muon::CscStripPrepDataCollection
MuonPrepDataCollection< CscStripPrepData > CscStripPrepDataCollection
Definition: MuonPrepDataCollection.h:111
CscStripPrepDataContainerCnv_p1.h
Muon::MuonPRD_Collection_p1::m_end
unsigned int m_end
End index into master collection.
Definition: MuonPRD_Collection_p1.h:41
initialize
void initialize()
Definition: run_EoverP.cxx:894
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
CscStripPrepData.h
Identifier::get_compact
value_type get_compact() const
Get the compact id.
Muon::CscStripPrepDataContainerCnv_p1::m_eventCnvTool
ToolHandle< Trk::IEventCnvSuperTool > m_eventCnvTool
Definition: CscStripPrepDataContainerCnv_p1.h:39
Muon::CscStripPrepDataContainerCnv_p1::transToPers
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
Definition: CscStripPrepDataContainerCnv_p1.cxx:51
MuonGM::CscReadoutElement
Definition: CscReadoutElement.h:56
CscStripPrepDataCnv_p1
Definition: CscStripPrepDataCnv_p1.h:23
Muon::MuonPrepDataCollection::setIdentifier
virtual void setIdentifier(Identifier id)
Muon::CscStripPrepDataContainerCnv_p1::persToTrans
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
Definition: CscStripPrepDataContainerCnv_p1.cxx:102
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition: Identifier32.h:44
TPObjRef
Definition: TPObjRef.h:20
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
MuonPRD_Container_p1.h
ITrkEventCnvTool.h
Muon::CscStripPrepData
Class representing the raw data of one CSC strip (for clusters look at Muon::CscPrepData).
Definition: CscStripPrepData.h:40
Muon::MuonPrepDataCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
IdentifiableContainerMT::numberOfCollections
virtual size_t numberOfCollections() const override final
return number of collections
Definition: IdentifiableContainerMT.h:213
lumiFormat.i
int i
Definition: lumiFormat.py:85
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Muon::CscStripPrepDataContainerCnv_p1::createTransient
virtual Muon::CscStripPrepDataContainer * createTransient(const Muon::MuonPRD_Container_p1 *persObj, MsgStream &log)
Definition: CscStripPrepDataContainerCnv_p1.cxx:168
Muon::MuonPrepDataCollection::identify
virtual Identifier identify() const override final
Trk::ITrkEventCnvTool
Definition: ITrkEventCnvTool.h:31
IdentifiableContainerMT::end
const_iterator end() const
return const_iterator for end of container
Definition: IdentifiableContainerMT.h:239
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
CscStripPrepData_p1.h
IdentifiableContainerMT::const_iterator
Definition: IdentifiableContainerMT.h:79
IdentifiableContainerMT::begin
const_iterator begin() const
return const_iterator for first entry
Definition: IdentifiableContainerMT.h:233
Muon::MuonPrepDataCollection
Template to hold collections of MuonPrepRawData objects.
Definition: MuonPrepDataCollection.h:46
DataPool.h
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
DataVector::resize
void resize(size_type sz)
Resizes the collection to the specified number of elements.
defineDB.ichan
int ichan
Definition: JetTagCalibration/share/defineDB.py:28
Muon::CscStripPrepDataContainerCnv_p1::m_cscStripId
const CscIdHelper * m_cscStripId
Definition: CscStripPrepDataContainerCnv_p1.h:38
errorcheck.h
Helpers for checking error return status codes and reporting errors.
Muon::MuonPRD_Collection_p1::m_begin
unsigned int m_begin
Begin index into master collection.
Definition: MuonPRD_Collection_p1.h:38
Muon::MuonPRD_Collection_p1
Definition: MuonPRD_Collection_p1.h:11
Muon::MuonPRD_Container_p1::m_PRD
std::vector< TPObjRef > m_PRD
Definition: MuonPRD_Container_p1.h:20
Trk::ITrkEventCnvTool::getDetectorElement
virtual const Trk::TrkDetElementBase * getDetectorElement(const Identifier &id, const IdentifierHash &idHash) const =0
Returns the detectorElement associated with this Identifier & Hash.
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
Muon::CscStripPrepDataContainerCnv_p1::initialize
StatusCode initialize(MsgStream &log)
Definition: CscStripPrepDataContainerCnv_p1.cxx:28
Muon::CscStripPrepDataContainerCnv_p1::m_isInitialized
bool m_isInitialized
Definition: CscStripPrepDataContainerCnv_p1.h:40
Muon::MuonPRD_Container_p1
Definition: MuonPRD_Container_p1.h:14
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
Muon::CscStripPrepDataContainerCnv_p1::getReadOutElement
const MuonGM::CscReadoutElement * getReadOutElement(const Identifier &id) const
Definition: CscStripPrepDataContainerCnv_p1.cxx:45
StoreGateSvc.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
CscStripPrepDataCnv_p1.h
Identifier
Definition: IdentifierFieldParser.cxx:14