ATLAS Offline Software
TRT_LoLumRawDataContainerCnv_p1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #include "TRT_LoLumRawDataCnv_p1.h"
12 #include "MsgUtil.h"
13 
14 #include "AthAllocators/DataPool.h"
15 
17 {
18 
19  // The transient model has a container holding collections and the
20  // collections hold channels.
21  //
22  // The persistent model flattens this so that the persistent
23  // container has two vectors:
24  // 1) all collections, and
25  // 2) all RDO
26  //
27  // The persistent collections, then only maintain indexes into the
28  // container's vector of all channels.
29  //
30  // So here we loop over all collection and add their channels
31  // to the container's vector, saving the indexes in the
32  // collection.
33 
34  using TRANS = TRT_RDO_Container;
35 
36  TRT_LoLumRawDataCnv_p1 chanCnv;
37  TRANS::const_iterator it_Coll = transCont->begin();
38  TRANS::const_iterator it_CollEnd = transCont->end();
39  unsigned int collIndex;
40  unsigned int chanBegin = 0;
41  unsigned int chanEnd = 0;
42  int numColl = transCont->numberOfCollections();
43  //if(numColl == transCont->fullSize() ) { // let's count how many collections we have:
44  // numColl = 0;
45  // for ( ; it_Coll != it_CollEnd; it_Coll++)
46  // numColl++;
47  // it_Coll = transCont->begin(); // reset the iterator, we used it!
48  // }
49  persCont->m_collections.resize(numColl);
50  MSG_DEBUG(log," Preparing " << persCont->m_collections.size() << "Collections");
51 
52  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
53  // Add in new collection
54  const TRT_RDO_Collection& collection = (**it_Coll);
55  chanBegin = chanEnd;
56  chanEnd += collection.size();
57  InDetRawDataCollection_p1& pcollection = persCont->m_collections[collIndex];
58  pcollection.m_id = collection.identify().get_identifier32().get_compact();
59  pcollection.m_hashId = (unsigned int) collection.identifyHash();
60  pcollection.m_begin = chanBegin;
61  pcollection.m_end = chanEnd;
62  MSG_VERBOSE(log,"Writing collection number " << collIndex << " with hash" << pcollection.m_hashId);
63  // Add in channels
64  persCont->m_rawdata.resize(chanEnd);
65  for (unsigned int i = 0; i < collection.size(); ++i) {
66  InDetRawData_p1* pchan = &(persCont->m_rawdata[i + chanBegin]);
67  const TRT_LoLumRawData* chan = static_cast<const TRT_LoLumRawData*>(collection[i]);
68  chanCnv.transToPers(chan, pchan, log);
69  }
70  }
71  MSG_DEBUG(log," *** Writing TRT_RDO_Container (TRT_LoLumRawData concrete type)");
72 }
73 
75 {
76 
77  // The transient model has a container holding collections and the
78  // collections hold channels.
79  //
80  // The persistent model flattens this so that the persistent
81  // container has two vectors:
82  // 1) all collections, and
83  // 2) all channels
84  //
85  // The persistent collections, then only maintain indexes into the
86  // container's vector of all channels.
87  //
88  // So here we loop over all collection and extract their channels
89  // from the vector.
90 
91  // create Data Pool
93  // It resizes as needed .
94  // The max number of straws is 350847 but assume
95  // that we do not have 100% occupancy
96  dataItems.reserve(180000);
97 
98  TRT_RDO_Collection* coll = nullptr;
99  TRT_LoLumRawDataCnv_p1 chanCnv;
100  MSG_DEBUG(log," Reading " << persCont->m_collections.size() << "Collections");
101  for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
102 
103  // Create trans collection - in NOT owner of TRT_RDO_RawData (SG::VIEW_ELEMENTS)
104  // IDet collection don't have the Ownership policy c'tor
105  const InDetRawDataCollection_p1& pcoll = persCont->m_collections[icoll];
106  Identifier collID(pcoll.m_id);
107  IdentifierHash collIDHash(pcoll.m_hashId);
108  coll = new TRT_RDO_Collection(collIDHash);
109  coll->setIdentifier(collID);
110  coll->clear (SG::VIEW_ELEMENTS);
111  unsigned int nchans = pcoll.m_end - pcoll.m_begin;
112  coll->resize(nchans);
113  // Fill with channels
114  for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
115  const InDetRawData_p1* pchan = &(persCont->m_rawdata[ichan + pcoll.m_begin]);
116  //ask the pool for the next pointer
117  TRT_LoLumRawData* chan = dataItems.nextElementPtr();
118  //set the payload
119  *chan = TRT_LoLumRawData();
120  chanCnv.persToTrans(pchan, chan, log);
121  (*coll)[ichan] = chan;
122  }
123 
124  // register the rdo collection in IDC with hash - faster addCollection
125  StatusCode sc = transCont->addCollection(coll, collIDHash);
126  if (sc.isFailure()) {
127  throw std::runtime_error("Failed to add collection to ID Container");
128  }
129  MSG_VERBOSE(log,"AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = "
130  << (int) collIDHash << " / " << collID.get_compact() << ", added to Identifiable container.");
131  }
132 
133  MSG_DEBUG(log," *** Reading TRT_RDO_Container (TRT_LoLumRawData concrete type)");
134 }
135 
136 //================================================================
138  std::unique_ptr<TRT_RDO_Container> trans(std::make_unique<TRT_RDO_Container>(m_trtId->straw_layer_hash_max()));
139  persToTrans(persObj, trans.get(), log);
140  return(trans.release());
141 }
142 
TRT_RDO_Container.h
InDetRawDataCollection::setIdentifier
void setIdentifier(Identifier id)
DataPool::reserve
void reserve(unsigned int size)
Set the desired capacity.
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
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
TRT_LoLumRawDataContainerCnv_p1::transToPers
virtual void transToPers(const TRT_RDO_Container *transCont, InDetRawDataContainer_p1 *persCont, MsgStream &log)
Definition: TRT_LoLumRawDataContainerCnv_p1.cxx:16
TRT_LoLumRawData
Definition: TRT_LoLumRawData.h:25
TRT_ID::straw_layer_hash_max
size_type straw_layer_hash_max(void) const
Definition: TRT_ID.h:920
InDetRawDataCollection::identify
virtual Identifier identify() const override final
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
InDetRawDataContainer
Definition: InDetRawDataContainer.h:27
InDetRawDataCollection_p1::m_hashId
IdentifierHash::value_type m_hashId
Definition: InDetRawDataCollection_p1.h:36
InDetRawData_p1.h
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
TRT_LoLumRawDataCnv_p1
Definition: TRT_LoLumRawDataCnv_p1.h:22
InDetRawDataCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
TRT_RDO_Collection
InDetRawDataCollection< TRT_RDORawData > TRT_RDO_Collection
Definition: TRT_RDO_Collection.h:20
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
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TRT_LoLumRawDataContainerCnv_p1::createTransient
virtual TRT_RDO_Container * createTransient(const InDetRawDataContainer_p1 *persObj, MsgStream &log)
Definition: TRT_LoLumRawDataContainerCnv_p1.cxx:137
InDetRawDataCollection
Definition: InDetRawDataCollection.h:31
InDetRawDataContainer_p1::m_collections
std::vector< InDetRawDataCollection_p1 > m_collections
Definition: InDetRawDataContainer_p1.h:39
TRT_LoLumRawDataContainerCnv_p1.h
IdentifiableContainerMT::end
const_iterator end() const
return const_iterator for end of container
Definition: IdentifiableContainerMT.h:242
IdentifiableContainerMT::begin
const_iterator begin() const
return const_iterator for first entry
Definition: IdentifiableContainerMT.h:236
DataPool::nextElementPtr
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
InDetRawDataContainer_p1::m_rawdata
std::vector< InDetRawData_p1 > m_rawdata
Definition: InDetRawDataContainer_p1.h:40
DataVector::clear
void clear()
Erase all the elements in the collection.
DataPool.h
TRT_LoLumRawDataCnv_p1::transToPers
virtual void transToPers(const TRT_LoLumRawData *transObj, InDetRawData_p1 *persObj, MsgStream &log)
Definition: TRT_LoLumRawDataCnv_p1.cxx:26
TRT_RDO_Container
InDetRawDataContainer< InDetRawDataCollection< TRT_RDORawData > > TRT_RDO_Container
Definition: TRT_RDO_Container.h:26
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
InDetRawDataCollection_p1::m_begin
unsigned int m_begin
Definition: InDetRawDataCollection_p1.h:39
TRT_LoLumRawDataCnv_p1.h
MSG_VERBOSE
#define MSG_VERBOSE(log, x)
Definition: MsgUtil.h:17
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
TRT_LoLumRawDataContainerCnv_p1::m_trtId
const TRT_ID * m_trtId
Definition: TRT_LoLumRawDataContainerCnv_p1.h:28
TRT_LoLumRawDataContainerCnv_p1::persToTrans
virtual void persToTrans(const InDetRawDataContainer_p1 *persCont, TRT_RDO_Container *transCont, MsgStream &log)
Definition: TRT_LoLumRawDataContainerCnv_p1.cxx:74
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MSG_DEBUG
#define MSG_DEBUG(log, x)
Definition: MsgUtil.h:15
DataPool
a typed memory pool that saves time spent allocation small object. This is typically used by containe...
Definition: DataPool.h:47
InDetRawData_p1
Definition: InDetRawData_p1.h:10
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.
TRT_LoLumRawDataCnv_p1::persToTrans
virtual void persToTrans(const InDetRawData_p1 *persObj, TRT_LoLumRawData *transObj, MsgStream &log)
Definition: TRT_LoLumRawDataCnv_p1.cxx:17
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
InDetRawDataContainer_p1
Definition: InDetRawDataContainer_p1.h:31
InDetRawDataCollection_p1.h
TRT_LoLumRawData.h
MsgUtil.h