ATLAS Offline Software
TgcPrepDataContainerCnv_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 // Gaudi
15 #include "GaudiKernel/ISvcLocator.h"
16 #include "GaudiKernel/Bootstrap.h"
17 #include "GaudiKernel/StatusCode.h"
18 #include "GaudiKernel/Service.h"
19 #include "GaudiKernel/MsgStream.h"
20 
21 // Athena
23 #include "StoreGate/StoreGateSvc.h"
24 #include "AthAllocators/DataPool.h"
25 
26 
28  // Do not initialize again:
29  m_isInitialized=true;
30 
31  // get DetectorStore service
32  SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
33  CHECK( detStore.isValid() );
34 
35  // Get the helper from the detector store
36  CHECK( detStore->retrieve(m_TgcId) );
37 
38  CHECK( m_eventCnvTool.retrieve() );
39 
40  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Converter initialized." << endmsg;
41  return StatusCode::SUCCESS;
42 }
44  const Trk::ITrkEventCnvTool* cnv_tool = m_eventCnvTool->getCnvTool(id);
45  if (!cnv_tool) return nullptr;
46  return dynamic_cast<const MuonGM::TgcReadoutElement*>(cnv_tool->getDetectorElement(id));
47 }
49 {
50 
51  // The transient model has a container holding collections and the
52  // collections hold channels.
53  //
54  // The persistent model flattens this so that the persistent
55  // container has two vectors:
56  // 1) all collections, and
57  // 2) all RDO
58  //
59  // The persistent collections, then only maintain indexes into the
60  // container's vector of all channels.
61  //
62  // So here we loop over all collection and add their channels
63  // to the container's vector, saving the indexes in the
64  // collection.
65 
68 
69  TgcPrepDataCnv_p1 chanCnv;
70  TRANS::const_iterator it_Coll = transCont->begin();
71  TRANS::const_iterator it_CollEnd = transCont->end();
72  unsigned int collIndex = 0;
73  unsigned int chanBegin = 0;
74  unsigned int chanEnd = 0;
75  int numColl = transCont->numberOfCollections();
76 
77  persCont->m_collections.resize(numColl);
78  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
79 
80  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
81  // Add in new collection
82  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " New collection" << endmsg;
83  const Muon::TgcPrepDataCollection& collection = (**it_Coll);
84  chanBegin = chanEnd;
85  chanEnd += collection.size();
86  Muon::MuonPRD_Collection_p1& pcollection = persCont->m_collections[collIndex];
87  pcollection.m_id = collection.identify().get_identifier32().get_compact();
88  pcollection.m_hashId = (unsigned int) collection.identifyHash();
89  pcollection.m_begin = chanBegin;
90  pcollection.m_end = chanEnd;
91  // Add in channels
92  persCont->m_PRD.resize(chanEnd);
93  for (unsigned int i = 0; i < collection.size(); ++i) {
94  const Muon::TgcPrepData* chan = collection[i];
95  persCont->m_PRD[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
96  }
97  }
98  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing TgcPrepDataContainer ***" << endmsg;
99 }
100 
102 {
103 
104  // The transient model has a container holding collections and the
105  // collections hold channels.
106  //
107  // The persistent model flattens this so that the persistent
108  // container has two vectors:
109  // 1) all collections, and
110  // 2) all channels
111  //
112  // The persistent collections, then only maintain indexes into the
113  // container's vector of all channels.
114  //
115  // So here we loop over all collection and extract their channels
116  // from the vector.
117 
118 
119  Muon::TgcPrepDataCollection* coll = nullptr;
120 
121  TgcPrepDataCnv_p1 chanCnv;
123 
124  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
125  for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
126 
127  // Create trans collection - is NOT owner of TgcPrepData (SG::VIEW_ELEMENTS)
128  // IDet collection don't have the Ownership policy c'tor
129  const Muon::MuonPRD_Collection_p1& pcoll = persCont->m_collections[icoll];
130  Identifier collID(Identifier(pcoll.m_id));
131  IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
132  coll = new Muon::TgcPrepDataCollection(collIDHash);
133  coll->setIdentifier(Identifier(pcoll.m_id));
134  unsigned int nchans = pcoll.m_end - pcoll.m_begin;
135  coll->resize(nchans);
136 // No hash based lookup for Tgcs?
137  const MuonGM::TgcReadoutElement * de = getReadOutElement(collID);
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::TgcPrepData* chan = dynamic_cast<Muon::TgcPrepData*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
142  if(chan) {
143  chan->m_detEl = de;
144  (*coll)[ichan] = chan;
145  }
146  }
147 
148  // register the rdo collection in IDC with hash - faster addCollection
149  StatusCode sc = transCont->addCollection(coll, collIDHash);
150  if (sc.isFailure()) {
151  throw std::runtime_error("Failed to add collection to ID Container");
152  }
153  if (log.level() <= MSG::DEBUG) {
154  log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
155  collID.get_compact() << ", added to Identifiable container." << endmsg;
156  }
157  }
158 
159  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading TgcPrepDataContainer" << endmsg;
160 }
161 
162 
163 
164 //================================================================
166 {
167  if(!m_isInitialized) {
168  if (this->initialize(log) != StatusCode::SUCCESS) {
169  log << MSG::FATAL << "Could not initialize TgcPrepDataContainerCnv_p1 " << endmsg;
170  return nullptr;
171  }
172  }
173  std::unique_ptr<Muon::TgcPrepDataContainer> trans(new Muon::TgcPrepDataContainer(m_TgcId->module_hash_max()));
174  persToTrans(persObj, trans.get(), log);
175  return(trans.release());
176 }
177 
178 
Muon::MuonPrepDataContainer
Template for Muon PRD containers (which are basically collections of MuonPrepDataCollections).
Definition: MuonPrepDataContainer.h:42
Muon::MuonPRD_Container_p1::m_collections
std::vector< Muon::MuonPRD_Collection_p1 > m_collections
Definition: MuonPRD_Container_p1.h:19
ITPConverterFor< Trk::PrepRawData >
Muon::TgcPrepDataContainerCnv_p1::transToPers
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
Definition: TgcPrepDataContainerCnv_p1.cxx:48
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::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
TgcPrepData_p1.h
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
Muon::TgcPrepDataContainerCnv_p1::m_TgcId
const TgcIdHelper * m_TgcId
Definition: TgcPrepDataContainerCnv_p1.h:39
Identifier::get_compact
value_type get_compact() const
Get the compact id.
Muon::MuonPrepDataCollection::setIdentifier
virtual void setIdentifier(Identifier id)
TgcPrepData.h
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
TgcPrepDataCnv_p1
Definition: TgcPrepDataCnv_p1.h:23
Muon::MuonPrepDataCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
Muon::TgcPrepDataContainerCnv_p1::getReadOutElement
const MuonGM::TgcReadoutElement * getReadOutElement(const Identifier &id) const
Definition: TgcPrepDataContainerCnv_p1.cxx:43
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
TgcPrepDataContainer.h
Muon::MuonPrepDataCollection::identify
virtual Identifier identify() const override final
MuonGM::TgcReadoutElement
A TgcReadoutElement corresponds to a single TGC chamber; therefore typically a TGC station contains s...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/TgcReadoutElement.h:42
TgcPrepDataCnv_p1.h
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
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
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
Muon::TgcPrepDataContainerCnv_p1::createTransient
virtual Muon::TgcPrepDataContainer * createTransient(const Muon::MuonPRD_Container_p1 *persObj, MsgStream &log)
Definition: TgcPrepDataContainerCnv_p1.cxx:165
Trk::ITrkEventCnvTool::getDetectorElement
virtual const Trk::TrkDetElementBase * getDetectorElement(const Identifier &id, const IdentifierHash &idHash) const =0
Returns the detectorElement associated with this Identifier & Hash.
Muon::TgcPrepDataContainerCnv_p1::persToTrans
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
Definition: TgcPrepDataContainerCnv_p1.cxx:101
TgcPrepDataContainerCnv_p1.h
DEBUG
#define DEBUG
Definition: page_access.h:11
Muon::TgcPrepDataContainerCnv_p1::m_isInitialized
bool m_isInitialized
Definition: TgcPrepDataContainerCnv_p1.h:41
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
Muon::TgcPrepData
Class to represent TGC measurements.
Definition: TgcPrepData.h:32
Muon::TgcPrepDataContainerCnv_p1::initialize
StatusCode initialize(MsgStream &log)
Definition: TgcPrepDataContainerCnv_p1.cxx:27
TgcIdHelper.h
Muon::TgcPrepDataCollection
MuonPrepDataCollection< TgcPrepData > TgcPrepDataCollection
Definition: MuonPrepDataCollection.h:108
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
StoreGateSvc.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
Muon::TgcPrepDataContainerCnv_p1::m_eventCnvTool
ToolHandle< Trk::IEventCnvSuperTool > m_eventCnvTool
Definition: TgcPrepDataContainerCnv_p1.h:40
Identifier
Definition: IdentifierFieldParser.cxx:14