ATLAS Offline Software
SCT_RawDataContainerCnv_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 
6 
7 
8 #include "MsgUtil.h"
9 #include "SCT1_RawDataCnv_p1.h"
10 #include "SCT3_RawDataCnv_p1.h"
11 
14 #include "InDetIdentifier/SCT_ID.h"
18 
19 #include <memory>
20 
22 {
23 
24  // The transient model has a container holding collections and the
25  // collections hold channels.
26  //
27  // The persistent model flattens this so that the persistent
28  // container has two vectors:
29  // 1) all collections, and
30  // 2) all RDO
31  //
32  // The persistent collections, then only maintain indexes into the
33  // container's vector of all channels.
34  //
35  // So here we loop over all collection and add their channels
36  // to the container's vector, saving the indexes in the
37  // collection.
38 
39  using TRANS = SCT_RDO_Container;
40 
41  SCT1_RawDataCnv_p1 chan1Cnv;
42  SCT3_RawDataCnv_p1 chan3Cnv;
43  TRANS::const_iterator it_Coll = transCont->begin();
44  TRANS::const_iterator it_CollEnd = transCont->end();
45  unsigned int collIndex;
46  unsigned int chanBegin = 0;
47  unsigned int chanEnd = 0;
48  int numColl = transCont->numberOfCollections();
49  persCont->m_collections.resize(numColl);
50 
51  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
52  // Add in new collection
53  const SCT_RDO_Collection& collection = (**it_Coll);
54  chanBegin = chanEnd;
55  chanEnd += collection.size();
56  InDetRawDataCollection_p1& pcollection = persCont->m_collections[collIndex];
57  pcollection.m_id = collection.identify().get_compact();
58  pcollection.m_hashId = static_cast<unsigned int>(collection.identifyHash());
59  pcollection.m_begin = chanBegin;
60  pcollection.m_end = chanEnd;
61  // Add in channels
62  if (m_type == 1) {
63  persCont->m_rawdata.resize(chanEnd);
64  for (unsigned int i = 0; i < collection.size(); ++i) {
65  InDetRawData_p1* pchan = &(persCont->m_rawdata[i + chanBegin]);
66  const SCT1_RawData* chan = dynamic_cast<const SCT1_RawData*>(collection[i]);
67  if (chan) {
68  chan1Cnv.transToPers(chan, pchan, log);
69  }
70  }
71  } else if (m_type == 3) {
72  persCont->m_sct3data.resize(chanEnd);
73  for (unsigned int i = 0; i < collection.size(); ++i) {
74  SCT3_RawData_p1* pchan = &(persCont->m_sct3data[i + chanBegin]);
75  const SCT3_RawData* chan = dynamic_cast<const SCT3_RawData*>(collection[i]);
76  if (chan) {
77  chan3Cnv.transToPers(chan, pchan, log);
78  }
79  }
80  }
81  }
82 }
83 
85 {
86 
87  // The transient model has a container holding collections and the
88  // collections hold channels.
89  //
90  // The persistent model flattens this so that the persistent
91  // container has two vectors:
92  // 1) all collections, and
93  // 2) all channels
94  //
95  // The persistent collections, then only maintain indexes into the
96  // container's vector of all channels.
97  //
98  // So here we loop over all collection and extract their channels
99  // from the vector.
100 
101  SCT1_RawDataCnv_p1 chan1Cnv;
102  SCT3_RawDataCnv_p1 chan3Cnv;
103  // check for the type of the contained objects:
104  //
105  if (persCont->m_rawdata.size() !=0 && persCont->m_sct3data.size() != 0) {
106  log << MSG::FATAL << "The collection has mixed SCT1 and SCT3 elements, this is not allowed " << endmsg;
107  }
108  if (persCont->m_rawdata.size() != 0 ) m_type = 1;
109  if (persCont->m_sct3data.size() != 0 ) m_type = 3;
110 
111  for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
112  // Create trans collection - in NOT owner of SCT_RDO_RawData (SG::VIEW_ELEMENTS)
113  // IDet collection don't have the Ownership policy c'tor
114  const InDetRawDataCollection_p1& pcoll = persCont->m_collections[icoll];
115  Identifier collID(pcoll.m_id);
116  IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
117  std::unique_ptr<SCT_RDO_Collection> coll = std::make_unique<SCT_RDO_Collection>(collIDHash);
118  coll->setIdentifier(collID);
119  unsigned int nchans = pcoll.m_end - pcoll.m_begin;
120  coll->resize(nchans);
121  // Fill with channels
122  for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
123  if (m_type == 1) {
124  const InDetRawData_p1* pchan = &(persCont->m_rawdata[ichan + pcoll.m_begin]);
125  std::unique_ptr<SCT1_RawData> chan = std::make_unique<SCT1_RawData>();
126  chan1Cnv.persToTrans(pchan, chan.get(), log);
127  (*coll)[ichan] = chan.release();
128  } else if (m_type == 3) {
129  const SCT3_RawData_p1* pchan = &(persCont->m_sct3data[ichan + pcoll.m_begin]);
130  std::unique_ptr<SCT3_RawData> chan = std::make_unique<SCT3_RawData>();
131  chan3Cnv.persToTrans(pchan, chan.get(), log);
132  (*coll)[ichan] = chan.release();
133  }
134  }
135 
136  // register the rdo collection in IDC with hash - faster addCollection
137  StatusCode sc = transCont->addCollection(coll.release(), collIDHash);
138  if (sc.isFailure()) {
139  throw std::runtime_error("Failed to add collection to ID Container");
140  }
141  MSG_VERBOSE(log,"AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = "
142  << collIDHash.value() << " / " << collID.get_compact() << ", added to Identifiable container.");
143  }
144 }
145 
146 //================================================================
148  std::unique_ptr<SCT_RDO_Container> trans(std::make_unique<SCT_RDO_Container>(m_sctId->wafer_hash_max()));
149  persToTrans(persObj, trans.get(), log);
150  return trans.release();
151 }
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
InDetRawDataCollection::setIdentifier
void setIdentifier(Identifier id)
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
SCT1_RawDataCnv_p1
Definition: SCT1_RawDataCnv_p1.h:22
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
SCT3_RawDataCnv_p1::transToPers
virtual void transToPers(const SCT3_RawData *transObj, SCT3_RawData_p1 *persObj, MsgStream &log)
Definition: SCT3_RawDataCnv_p1.cxx:34
SCT_RawDataContainer_p1::m_collections
std::vector< InDetRawDataCollection_p1 > m_collections
Definition: SCT_RawDataContainer_p1.h:32
InDetRawDataCollection::identify
virtual Identifier identify() const override final
InDetRawDataContainer
Definition: InDetRawDataContainer.h:27
InDetRawDataCollection_p1::m_hashId
IdentifierHash::value_type m_hashId
Definition: InDetRawDataCollection_p1.h:36
InDetRawDataCollection_p1::m_end
unsigned int m_end
Definition: InDetRawDataCollection_p1.h:42
InDetRawDataCollection_p1::m_id
Identifier32::value_type m_id
Definition: InDetRawDataCollection_p1.h:32
InDetRawDataCollection_p1
Definition: InDetRawDataCollection_p1.h:13
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
SCT3_RawDataCnv_p1::persToTrans
virtual void persToTrans(const SCT3_RawData_p1 *persObj, SCT3_RawData *transObj, MsgStream &log)
Definition: SCT3_RawDataCnv_p1.cxx:16
InDetRawDataCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
SCT_RawDataContainerCnv_p1::persToTrans
virtual void persToTrans(const SCT_RawDataContainer_p1 *persCont, SCT_RDO_Container *transCont, MsgStream &log)
Definition: SCT_RawDataContainerCnv_p1.cxx:84
SCT_RDO_Container.h
IdentifiableContainerMT::numberOfCollections
virtual size_t numberOfCollections() const override final
return number of collections
Definition: IdentifiableContainerMT.h:216
SCT3_RawData.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
SCT3_RawData
Definition: SCT3_RawData.h:24
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
InDetRawDataCollection
Definition: InDetRawDataCollection.h:31
IdentifiableContainerMT::end
const_iterator end() const
return const_iterator for end of container
Definition: IdentifiableContainerMT.h:242
SCT1_RawDataCnv_p1::persToTrans
virtual void persToTrans(const InDetRawData_p1 *persObj, SCT1_RawData *transObj, MsgStream &log)
Definition: SCT1_RawDataCnv_p1.cxx:18
SCT_RawDataContainerCnv_p1::m_type
int m_type
Definition: SCT_RawDataContainerCnv_p1.h:29
IdentifiableContainerMT::begin
const_iterator begin() const
return const_iterator for first entry
Definition: IdentifiableContainerMT.h:236
SCT_RawDataContainerCnv_p1::createTransient
virtual SCT_RDO_Container * createTransient(const SCT_RawDataContainer_p1 *persObj, MsgStream &log)
Definition: SCT_RawDataContainerCnv_p1.cxx:147
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
SCT_ID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: SCT_ID.cxx:639
InDetRawDataCollection_p1::m_begin
unsigned int m_begin
Definition: InDetRawDataCollection_p1.h:39
SCT_RawDataContainer_p1::m_rawdata
std::vector< InDetRawData_p1 > m_rawdata
Definition: SCT_RawDataContainer_p1.h:33
SCT_RawDataContainer_p1::m_sct3data
std::vector< SCT3_RawData_p1 > m_sct3data
Definition: SCT_RawDataContainer_p1.h:34
SCT_RDO_Collection.h
SCT_RDO_Container
InDetRawDataContainer< InDetRawDataCollection< SCT_RDORawData > > SCT_RDO_Container
Definition: SCT_RDO_Container.h:23
SCT_RawDataContainerCnv_p1::transToPers
virtual void transToPers(const SCT_RDO_Container *transCont, SCT_RawDataContainer_p1 *persCont, MsgStream &log)
Definition: SCT_RawDataContainerCnv_p1.cxx:21
SCT_RawDataContainerCnv_p1::m_sctId
const SCT_ID * m_sctId
Definition: SCT_RawDataContainerCnv_p1.h:28
MSG_VERBOSE
#define MSG_VERBOSE(log, x)
Definition: MsgUtil.h:17
SCT3_RawData_p1.h
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
IdentifierHash::value
unsigned int value(void) const
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
SCT1_RawData
Definition: SCT1_RawData.h:27
SCT_RawDataContainerCnv_p1.h
SCT3_RawDataCnv_p1
Definition: SCT3_RawDataCnv_p1.h:22
SCT3_RawData_p1
Definition: SCT3_RawData_p1.h:14
SCT3_RawDataCnv_p1.h
InDetRawData_p1
Definition: InDetRawData_p1.h:10
IdentifierHash
Definition: IdentifierHash.h:38
SCT1_RawDataCnv_p1::transToPers
virtual void transToPers(const SCT1_RawData *transObj, InDetRawData_p1 *persObj, MsgStream &log)
Definition: SCT1_RawDataCnv_p1.cxx:26
SCT_RawDataContainer_p1
Definition: SCT_RawDataContainer_p1.h:26
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
InDetRawDataCollection_p1.h
SCT1_RawDataCnv_p1.h
MsgUtil.h