ATLAS Offline Software
TgcPrepDataContainerCnv_p1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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
22 #include "StoreGate/StoreGateSvc.h"
23 
24 
25 
26 #include "AthAllocators/DataPool.h"
27 
29  // Do not initialize again:
30  m_isInitialized=true;
31 
32  // Get Storegate, ID helpers, and so on
33  ISvcLocator* svcLocator = Gaudi::svcLocator();
34  // get StoreGate service
35  StatusCode sc = svcLocator->service("StoreGateSvc", m_storeGate);
36  if (sc.isFailure()) {
37  log << MSG::FATAL << "StoreGate service not found !" << endmsg;
38  return StatusCode::FAILURE;
39  }
40 
41  // get DetectorStore service
43  sc = svcLocator->service("DetectorStore", detStore);
44  if (sc.isFailure()) {
45  log << MSG::FATAL << "DetectorStore service not found !" << endmsg;
46  return StatusCode::FAILURE;
47  } else {
48  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Found DetectorStore." << endmsg;
49  }
50 
51  // Get the pixel helper from the detector store
52  sc = detStore->retrieve(m_TgcId);
53  if (sc.isFailure()) {
54  log << MSG::FATAL << "Could not get Tgc ID helper !" << endmsg;
55  return StatusCode::FAILURE;
56  } else {
57  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Found the Tgc ID helper." << endmsg;
58  }
59 
60  if (m_eventCnvTool.retrieve().isFailure()) {
61  log << MSG::FATAL << "Could not get DetectorDescription manager" << endmsg;
62  return StatusCode::FAILURE;
63  }
64 
65  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Converter initialized." << endmsg;
66  return StatusCode::SUCCESS;
67 }
69  const Trk::ITrkEventCnvTool* cnv_tool = m_eventCnvTool->getCnvTool(id);
70  if (!cnv_tool) return nullptr;
71  return dynamic_cast<const MuonGM::TgcReadoutElement*>(cnv_tool->getDetectorElement(id));
72 }
74 {
75 
76  // The transient model has a container holding collections and the
77  // collections hold channels.
78  //
79  // The persistent model flattens this so that the persistent
80  // container has two vectors:
81  // 1) all collections, and
82  // 2) all RDO
83  //
84  // The persistent collections, then only maintain indexes into the
85  // container's vector of all channels.
86  //
87  // So here we loop over all collection and add their channels
88  // to the container's vector, saving the indexes in the
89  // collection.
90 
93 
94  TgcPrepDataCnv_p1 chanCnv;
95  TRANS::const_iterator it_Coll = transCont->begin();
96  TRANS::const_iterator it_CollEnd = transCont->end();
97  unsigned int collIndex = 0;
98  unsigned int chanBegin = 0;
99  unsigned int chanEnd = 0;
100  int numColl = transCont->numberOfCollections();
101 
102  persCont->m_collections.resize(numColl);
103  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
104 
105  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
106  // Add in new collection
107  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " New collection" << endmsg;
108  const Muon::TgcPrepDataCollection& collection = (**it_Coll);
109  chanBegin = chanEnd;
110  chanEnd += collection.size();
111  Muon::MuonPRD_Collection_p1& pcollection = persCont->m_collections[collIndex];
112  pcollection.m_id = collection.identify().get_identifier32().get_compact();
113  pcollection.m_hashId = (unsigned int) collection.identifyHash();
114  pcollection.m_begin = chanBegin;
115  pcollection.m_end = chanEnd;
116  // Add in channels
117  persCont->m_PRD.resize(chanEnd);
118  for (unsigned int i = 0; i < collection.size(); ++i) {
119  const Muon::TgcPrepData* chan = collection[i];
120  persCont->m_PRD[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
121  }
122  }
123  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing TgcPrepDataContainer ***" << endmsg;
124 }
125 
127 {
128 
129  // The transient model has a container holding collections and the
130  // collections hold channels.
131  //
132  // The persistent model flattens this so that the persistent
133  // container has two vectors:
134  // 1) all collections, and
135  // 2) all channels
136  //
137  // The persistent collections, then only maintain indexes into the
138  // container's vector of all channels.
139  //
140  // So here we loop over all collection and extract their channels
141  // from the vector.
142 
143 
144  Muon::TgcPrepDataCollection* coll = nullptr;
145 
146  TgcPrepDataCnv_p1 chanCnv;
148 
149  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
150  for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
151 
152  // Create trans collection - is NOT owner of TgcPrepData (SG::VIEW_ELEMENTS)
153  // IDet collection don't have the Ownership policy c'tor
154  const Muon::MuonPRD_Collection_p1& pcoll = persCont->m_collections[icoll];
155  Identifier collID(Identifier(pcoll.m_id));
156  IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
157  coll = new Muon::TgcPrepDataCollection(collIDHash);
158  coll->setIdentifier(Identifier(pcoll.m_id));
159  unsigned int nchans = pcoll.m_end - pcoll.m_begin;
160  coll->resize(nchans);
161 // No hash based lookup for Tgcs?
162  const MuonGM::TgcReadoutElement * de = getReadOutElement(collID);
163  // Fill with channels
164  for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
165  const TPObjRef pchan = persCont->m_PRD[ichan + pcoll.m_begin];
166  Muon::TgcPrepData* chan = dynamic_cast<Muon::TgcPrepData*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
167  if(chan) {
168  chan->m_detEl = de;
169  (*coll)[ichan] = chan;
170  }
171  }
172 
173  // register the rdo collection in IDC with hash - faster addCollection
174  StatusCode sc = transCont->addCollection(coll, collIDHash);
175  if (sc.isFailure()) {
176  throw std::runtime_error("Failed to add collection to ID Container");
177  }
178  if (log.level() <= MSG::DEBUG) {
179  log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
180  collID.get_compact() << ", added to Identifiable container." << endmsg;
181  }
182  }
183 
184  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading TgcPrepDataContainer" << endmsg;
185 }
186 
187 
188 
189 //================================================================
191 {
192  if(!m_isInitialized) {
193  if (this->initialize(log) != StatusCode::SUCCESS) {
194  log << MSG::FATAL << "Could not initialize TgcPrepDataContainerCnv_p1 " << endmsg;
195  return nullptr;
196  }
197  }
198  std::unique_ptr<Muon::TgcPrepDataContainer> trans(new Muon::TgcPrepDataContainer(m_TgcId->module_hash_max()));
199  persToTrans(persObj, trans.get(), log);
200  return(trans.release());
201 }
202 
203 
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:73
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:300
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
Muon::TgcPrepDataContainerCnv_p1::m_TgcId
const TgcIdHelper * m_TgcId
Definition: TgcPrepDataContainerCnv_p1.h:40
Muon::MuonPrepDataCollection::setIdentifier
virtual void setIdentifier(Identifier id)
TgcPrepData.h
TPObjRef
Definition: TPObjRef.h:20
Muon::TgcPrepDataContainerCnv_p1::m_storeGate
StoreGateSvc * m_storeGate
Definition: TgcPrepDataContainerCnv_p1.h:41
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
MuonPRD_Container_p1.h
ITrkEventCnvTool.h
TgcPrepDataCnv_p1
Definition: TgcPrepDataCnv_p1.h:23
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
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:68
IdentifiableContainerMT::numberOfCollections
virtual size_t numberOfCollections() const override final
return number of collections
Definition: IdentifiableContainerMT.h:216
Identifier32::get_compact
value_type get_compact(void) const
Get the compact id.
Definition: Identifier32.h:171
lumiFormat.i
int i
Definition: lumiFormat.py:92
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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:242
IdentifiableContainerMT::const_iterator
Definition: IdentifiableContainerMT.h:82
IdentifiableContainerMT::begin
const_iterator begin() const
return const_iterator for first entry
Definition: IdentifiableContainerMT.h:236
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::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:190
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
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:126
TgcPrepDataContainerCnv_p1.h
DEBUG
#define DEBUG
Definition: page_access.h:11
Muon::TgcPrepDataContainerCnv_p1::m_isInitialized
bool m_isInitialized
Definition: TgcPrepDataContainerCnv_p1.h:43
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:28
TgcIdHelper.h
Muon::TgcPrepDataCollection
MuonPrepDataCollection< TgcPrepData > TgcPrepDataCollection
Definition: MuonPrepDataCollection.h:108
Muon::MuonPRD_Container_p1
Definition: MuonPRD_Container_p1.h:14
IdentifierHash
Definition: IdentifierHash.h:38
Identifier::get_identifier32
Identifier32 get_identifier32(void) const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
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:42