ATLAS Offline Software
TgcCoinDataContainerCnv_p3.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
13 
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 
28 
29 
31  // Do not initialize again:
32  m_isInitialized=true;
33 
34  // Get Storegate, ID helpers, and so on
35  ISvcLocator* svcLocator = Gaudi::svcLocator();
36  // get StoreGate service
37  StatusCode sc = svcLocator->service("StoreGateSvc", m_storeGate);
38  if (sc.isFailure()) {
39  log << MSG::FATAL << "StoreGate service not found !" << endmsg;
40  return StatusCode::FAILURE;
41  }
42 
43  // get DetectorStore service
45  sc = svcLocator->service("DetectorStore", detStore);
46  if (sc.isFailure()) {
47  log << MSG::FATAL << "DetectorStore service not found !" << endmsg;
48  return StatusCode::FAILURE;
49  } else {
50  log << MSG::DEBUG << "Found DetectorStore." << endmsg;
51  }
52 
53  // Get the pixel helper from the detector store
54  sc = detStore->retrieve(m_TgcId);
55  if (sc.isFailure()) {
56  log << MSG::FATAL << "Could not get Tgc ID helper !" << endmsg;
57  return StatusCode::FAILURE;
58  } else {
59  log << MSG::DEBUG << "Found the Tgc ID helper." << endmsg;
60  }
61 
62  sc = detStore->retrieve(m_muonDetMgr);
63  if (sc.isFailure()) {
64  log << MSG::FATAL << "Could not get PixelDetectorDescription" << endmsg;
65  return sc;
66  }
67 
68  log << MSG::DEBUG << "Converter initialized." << endmsg;
69  return StatusCode::SUCCESS;
70 }
71 
73 {
74 
75  // The transient model has a container holding collections and the
76  // collections hold channels.
77  //
78  // The persistent model flattens this so that the persistent
79  // container has two vectors:
80  // 1) all collections, and
81  // 2) all RDO
82  //
83  // The persistent collections, then only maintain indexes into the
84  // container's vector of all channels.
85  //
86  // So here we loop over all collection and add their channels
87  // to the container's vector, saving the indexes in the
88  // collection.
89 
92 
93  TgcCoinDataCnv_p3 chanCnv;
94  TRANS::const_iterator it_Coll = transCont->begin();
95  TRANS::const_iterator it_CollEnd = transCont->end();
96  unsigned int collIndex;
97  unsigned int chanBegin = 0;
98  unsigned int chanEnd = 0;
99  int numColl = transCont->numberOfCollections();
100  // if(numColl == transCont->hashFunc().max() ) { // let's count how many collections we have:
101  // numColl = 0;
102  // for ( ; it_Coll != it_CollEnd; it_Coll++)
103  // numColl++;
104  // it_Coll = transCont->begin(); // reset the iterator, we used it!
105  // }
106  persCont->m_collections.resize(numColl); log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
107 
108  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
109  // Add in new collection
110  log << MSG::DEBUG << " New collection" << endmsg;
111  const Muon::TgcCoinDataCollection& collection = (**it_Coll);
112  chanBegin = chanEnd;
113  chanEnd += collection.size();
114  Muon::MuonCoinDataCollection_p1& pcollection = persCont->m_collections[collIndex];
115  pcollection.m_id = collection.identify().get_identifier32().get_compact();
116  pcollection.m_hashId = (unsigned int) collection.identifyHash();
117  pcollection.m_begin = chanBegin;
118  pcollection.m_end = chanEnd;
119  // Add in channels
120  persCont->m_CoinData.resize(chanEnd);
121  for (unsigned int i = 0; i < collection.size(); ++i) {
122  const Muon::TgcCoinData* chan = collection[i];
123  persCont->m_CoinData[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
124  }
125  }
126  log << MSG::DEBUG << " *** Writing TgcCoinDataContainer ***" << endmsg;
127 }
128 
130 {
131 
132  // The transient model has a container holding collections and the
133  // collections hold channels.
134  //
135  // The persistent model flattens this so that the persistent
136  // container has two vectors:
137  // 1) all collections, and
138  // 2) all channels
139  //
140  // The persistent collections, then only maintain indexes into the
141  // container's vector of all channels.
142  //
143  // So here we loop over all collection and extract their channels
144  // from the vector.
145 
146 
147  Muon::TgcCoinDataCollection* coll = nullptr;
148 
149  TgcCoinDataCnv_p3 chanCnv;
151 
152  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 TgcCoinData (SG::VIEW_ELEMENTS)
156  // IDet collection don't have the Ownership policy c'tor
157  const Muon::MuonCoinDataCollection_p1& pcoll = persCont->m_collections[icoll];
158  Identifier collID(Identifier(pcoll.m_id));
159  IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
160  coll = new Muon::TgcCoinDataCollection(collIDHash);
161  coll->setIdentifier(Identifier(pcoll.m_id));
162  unsigned int nchans = pcoll.m_end - pcoll.m_begin;
163  coll->resize(nchans);
164 
165  // Fill with channels
166  for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
167  const TPObjRef pchan = persCont->m_CoinData[ichan + pcoll.m_begin];
168  Muon::TgcCoinData* chan = dynamic_cast<Muon::TgcCoinData*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
169  if( (chan->type()!=Muon::TgcCoinData::TYPE_TRACKLET_EIFI && (!chan->isInner() )) && (chan->type()!=Muon::TgcCoinData::TYPE_UNKNOWN) ) {
170  const MuonGM::TgcReadoutElement * deOut = m_muonDetMgr->getTgcReadoutElement(Identifier(chan->channelIdOut()));
171  chan->m_detElOut = deOut;
172  }
174  chan->type()==Muon::TgcCoinData::TYPE_TRACKLET_EIFI)&& !chan->isInner() ) {
175  const MuonGM::TgcReadoutElement * deIn = m_muonDetMgr->getTgcReadoutElement(Identifier(chan->channelIdIn()));
176  chan->m_detElIn = deIn;
177  }
178  else {
179  chan->m_detElIn = nullptr;
180  }
181  (*coll)[ichan] = chan;
182  }
183 
184  // register the rdo collection in IDC with hash - faster addCollection
185  StatusCode sc = transCont->addCollection(coll, collIDHash);
186  if (sc.isFailure()) {
187  throw std::runtime_error("Failed to add collection to ID Container");
188  }
189  if (log.level() <= MSG::DEBUG) {
190  log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
191  collID.get_compact() << ", added to Identifiable container." << endmsg;
192  }
193  }
194 
195  log << MSG::DEBUG << " *** Reading TgcCoinDataContainer" << endmsg;
196 }
197 
198 
199 
200 //================================================================
202 {
203  if(!m_isInitialized) {
204  if (this->initialize(log) != StatusCode::SUCCESS) {
205  log << MSG::FATAL << "Could not initialize TgcCoinDataContainerCnv_p3 " << endmsg;
206  return nullptr;
207  }
208  }
209  std::unique_ptr<Muon::TgcCoinDataContainer> trans(new Muon::TgcCoinDataContainer(m_TgcId->module_hash_max()));
210  persToTrans(persObj, trans.get(), log);
211  return(trans.release());
212 }
213 
214 
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:300
initialize
void initialize()
Definition: run_EoverP.cxx:894
Muon::TgcCoinDataContainerCnv_p3::createTransient
virtual Muon::TgcCoinDataContainer * createTransient(const Muon::MuonCoinDataContainer_p1 *persObj, MsgStream &log)
Definition: TgcCoinDataContainerCnv_p3.cxx:201
TgcCoinDataCnv_p3.h
Muon::MuonCoinDataCollection
Definition: MuonCoinDataCollection.h:25
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
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
Muon::TgcCoinDataContainerCnv_p3::m_muonDetMgr
const MuonGM::MuonDetectorManager * m_muonDetMgr
Definition: TgcCoinDataContainerCnv_p3.h:42
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Muon::TgcCoinDataContainerCnv_p3::transToPers
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
Definition: TgcCoinDataContainerCnv_p3.cxx:72
TgcCoinData_p3.h
TgcCoinDataCnv_p3
Definition: TgcCoinDataCnv_p3.h:26
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
IdentifiableContainerMT::numberOfCollections
virtual size_t numberOfCollections() const override final
return number of collections
Definition: IdentifiableContainerMT.h:216
Muon::TgcCoinData::TYPE_HIPT
@ TYPE_HIPT
Definition: TgcCoinData.h:51
Identifier32::get_compact
value_type get_compact(void) const
Get the compact id.
Definition: Identifier32.h:171
Muon::MuonCoinDataContainer_p1
Definition: MuonCoinDataContainer_p1.h:16
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
MuonCoinDataContainer_p1.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
Muon::TgcCoinDataContainerCnv_p3::m_isInitialized
bool m_isInitialized
Definition: TgcCoinDataContainerCnv_p3.h:43
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::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
Muon::TgcCoinData::TYPE_UNKNOWN
@ TYPE_UNKNOWN
Definition: TgcCoinData.h:53
Muon::TgcCoinDataContainerCnv_p3::persToTrans
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
Definition: TgcCoinDataContainerCnv_p3.cxx:129
DataPool.h
Muon::TgcCoinDataContainerCnv_p3::m_TgcId
const TgcIdHelper * m_TgcId
Definition: TgcCoinDataContainerCnv_p3.h:40
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
Muon::TgcCoinDataContainerCnv_p3::initialize
StatusCode initialize(MsgStream &log)
Definition: TgcCoinDataContainerCnv_p3.cxx:30
MuonDetectorManager.h
Muon::MuonCoinDataCollection::identifyHash
IdentifierHash identifyHash() const
Muon::TgcCoinDataContainerCnv_p3::m_storeGate
StoreGateSvc * m_storeGate
Definition: TgcCoinDataContainerCnv_p3.h:41
Muon::MuonCoinDataCollection_p1
Definition: MuonCoinDataCollection_p1.h:12
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
TgcCoinDataContainerCnv_p3.h
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
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::MuonCoinDataCollection_p1::m_id
unsigned int m_id
Identifier of this collection.
Definition: MuonCoinDataCollection_p1.h:31