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