ATLAS Offline Software
TgcCoinDataContainerCnv_p2.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /* Takashi Kubota - June 30, 2008 */
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 helper from the detector store
37  CHECK( detStore->retrieve(m_TgcId) );
38 
39  CHECK( detStore->retrieve(m_muonDetMgr) );
40 
41  log << MSG::DEBUG << "Converter initialized." << endmsg;
42  return StatusCode::SUCCESS;
43 }
44 
46 {
47 
48  // The transient model has a container holding collections and the
49  // collections hold channels.
50  //
51  // The persistent model flattens this so that the persistent
52  // container has two vectors:
53  // 1) all collections, and
54  // 2) all RDO
55  //
56  // The persistent collections, then only maintain indexes into the
57  // container's vector of all channels.
58  //
59  // So here we loop over all collection and add their channels
60  // to the container's vector, saving the indexes in the
61  // collection.
62 
65 
66  TgcCoinDataCnv_p2 chanCnv;
67  TRANS::const_iterator it_Coll = transCont->begin();
68  TRANS::const_iterator it_CollEnd = transCont->end();
69  unsigned int collIndex;
70  unsigned int chanBegin = 0;
71  unsigned int chanEnd = 0;
72  int numColl = transCont->numberOfCollections();
73  // if(numColl == transCont->hashFunc().max() ) { // let's count how many collections we have:
74  // numColl = 0;
75  // for ( ; it_Coll != it_CollEnd; it_Coll++)
76  // numColl++;
77  // it_Coll = transCont->begin(); // reset the iterator, we used it!
78  // }
79  persCont->m_collections.resize(numColl); 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  log << MSG::DEBUG << " New collection" << endmsg;
84  const Muon::TgcCoinDataCollection& collection = (**it_Coll);
85  chanBegin = chanEnd;
86  chanEnd += collection.size();
87  Muon::MuonCoinDataCollection_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_CoinData.resize(chanEnd);
94  for (unsigned int i = 0; i < collection.size(); ++i) {
95  const Muon::TgcCoinData* chan = collection[i];
96  persCont->m_CoinData[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
97  }
98  }
99  log << MSG::DEBUG << " *** Writing TgcCoinDataContainer ***" << 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::TgcCoinDataCollection* coll = nullptr;
121 
122  TgcCoinDataCnv_p2 chanCnv;
124 
125  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 TgcCoinData (SG::VIEW_ELEMENTS)
129  // IDet collection don't have the Ownership policy c'tor
130  const Muon::MuonCoinDataCollection_p1& pcoll = persCont->m_collections[icoll];
131  Identifier collID(Identifier(pcoll.m_id));
132  IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
133  coll = new Muon::TgcCoinDataCollection(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_CoinData[ichan + pcoll.m_begin];
141  Muon::TgcCoinData* chan = dynamic_cast<Muon::TgcCoinData*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
143  const MuonGM::TgcReadoutElement * deOut = m_muonDetMgr->getTgcReadoutElement(Identifier(chan->channelIdOut()));
144  chan->m_detElOut = deOut;
145  }
148  const MuonGM::TgcReadoutElement * deIn = m_muonDetMgr->getTgcReadoutElement(Identifier(chan->channelIdIn()));
149  chan->m_detElIn = deIn;
150  }
151  else {
152  chan->m_detElIn = nullptr;
153  }
154  (*coll)[ichan] = chan;
155  }
156 
157  // register the rdo collection in IDC with hash - faster addCollection
158  StatusCode sc = transCont->addCollection(coll, collIDHash);
159  if (sc.isFailure()) {
160  throw std::runtime_error("Failed to add collection to ID Container");
161  }
162  if (log.level() <= MSG::DEBUG) {
163  log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
164  collID.get_compact() << ", added to Identifiable container." << endmsg;
165  }
166  }
167 
168  log << MSG::DEBUG << " *** Reading TgcCoinDataContainer" << endmsg;
169 }
170 
171 
172 
173 //================================================================
175 {
176  if(!m_isInitialized) {
177  if (this->initialize(log) != StatusCode::SUCCESS) {
178  log << MSG::FATAL << "Could not initialize TgcCoinDataContainerCnv_p2 " << endmsg;
179  return nullptr;
180  }
181  }
182  std::unique_ptr<Muon::TgcCoinDataContainer> trans(new Muon::TgcCoinDataContainer(m_TgcId->module_hash_max()));
183  persToTrans(persObj, trans.get(), log);
184  return(trans.release());
185 }
186 
187 
Muon::TgcCoinDataContainerCnv_p2::m_muonDetMgr
const MuonGM::MuonDetectorManager * m_muonDetMgr
Definition: TgcCoinDataContainerCnv_p2.h:39
ITPConverterFor
Definition: TPConverter.h:37
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
initialize
void initialize()
Definition: run_EoverP.cxx:894
Muon::MuonCoinDataCollection
Definition: MuonCoinDataCollection.h:25
Muon::TgcCoinDataContainerCnv_p2::initialize
StatusCode initialize(MsgStream &log)
Definition: TgcCoinDataContainerCnv_p2.cxx:28
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
Identifier::get_compact
value_type get_compact() const
Get the compact id.
Muon::TgcCoinData::TYPE_TRACKLET
@ TYPE_TRACKLET
Definition: TgcCoinData.h:50
Muon::MuonCoinDataCollection::identify
Identifier identify() const
Muon::TgcCoinDataCollection
MuonCoinDataCollection< TgcCoinData > TgcCoinDataCollection
Definition: MuonCoinDataContainer.h:84
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition: Identifier32.h:44
Muon::MuonCoinDataContainer_p1::m_collections
std::vector< Muon::MuonCoinDataCollection_p1 > m_collections
Definition: MuonCoinDataContainer_p1.h:21
TPObjRef
Definition: TPObjRef.h:20
Muon::TgcCoinData
Definition: TgcCoinData.h:37
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
TgcCoinDataCnv_p2.h
Muon::TgcCoinDataContainerCnv_p2::persToTrans
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
Definition: TgcCoinDataContainerCnv_p2.cxx:102
TgcCoinData_p2.h
IdentifiableContainerMT::numberOfCollections
virtual size_t numberOfCollections() const override final
return number of collections
Definition: IdentifiableContainerMT.h:213
Muon::TgcCoinData::TYPE_HIPT
@ TYPE_HIPT
Definition: TgcCoinData.h:51
Muon::MuonCoinDataContainer_p1
Definition: MuonCoinDataContainer_p1.h:16
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::TgcCoinDataContainerCnv_p2::transToPers
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
Definition: TgcCoinDataContainerCnv_p2.cxx:45
MuonCoinDataContainer_p1.h
TgcCoinDataContainerCnv_p2.h
MuonGM::TgcReadoutElement
A TgcReadoutElement corresponds to a single TGC chamber; therefore typically a TGC station contains s...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/TgcReadoutElement.h:42
Muon::MuonCoinDataContainer_p1::m_CoinData
std::vector< TPObjRef > m_CoinData
Definition: MuonCoinDataContainer_p1.h:22
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::TgcCoinDataContainerCnv_p2::m_isInitialized
bool m_isInitialized
Definition: TgcCoinDataContainerCnv_p2.h:40
Muon::MuonCoinDataCollection_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: MuonCoinDataCollection_p1.h:35
DataPool.h
TgcCoinDataContainer.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::MuonCoinDataCollection_p1::m_end
unsigned int m_end
End index into master collection.
Definition: MuonCoinDataCollection_p1.h:41
Muon::MuonCoinDataContainer
Definition: MuonCoinDataContainer.h:32
errorcheck.h
Helpers for checking error return status codes and reporting errors.
MuonDetectorManager.h
Muon::MuonCoinDataCollection::identifyHash
IdentifierHash identifyHash() const
Muon::MuonCoinDataCollection_p1
Definition: MuonCoinDataCollection_p1.h:12
Muon::TgcCoinDataContainerCnv_p2::m_TgcId
const TgcIdHelper * m_TgcId
Definition: TgcCoinDataContainerCnv_p2.h:38
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
Muon::TgcCoinData::TYPE_TRACKLET_EIFI
@ TYPE_TRACKLET_EIFI
Definition: TgcCoinData.h:54
Muon::MuonCoinDataCollection_p1::m_begin
unsigned int m_begin
Begin index into master collection.
Definition: MuonCoinDataCollection_p1.h:38
Muon::MuonCoinDataCollection::setIdentifier
void setIdentifier(Identifier id)
TgcIdHelper.h
TgcCoinData.h
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
TgcCoinDataCnv_p2
Definition: TgcCoinDataCnv_p2.h:27
StoreGateSvc.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
Muon::TgcCoinDataContainerCnv_p2::createTransient
virtual Muon::TgcCoinDataContainer * createTransient(const Muon::MuonCoinDataContainer_p1 *persObj, MsgStream &log)
Definition: TgcCoinDataContainerCnv_p2.cxx:174
Muon::MuonCoinDataCollection_p1::m_id
unsigned int m_id
Identifier of this collection.
Definition: MuonCoinDataCollection_p1.h:31
Identifier
Definition: IdentifierFieldParser.cxx:14