ATLAS Offline Software
TRT_LoLumRawDataContainerCnv_p3.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
8 #include "TRT_RDO_Elements.h"
9 #include "MsgUtil.h"
10 
11 #include "AthAllocators/DataPool.h"
12 
14 {
15 
16  // The transient model has a container holding collections (up to 14912 TRT detector elements/modules)
17  // and the collections hold channels (e.g. up to 24 straws in the TRT endcaps). There are a total of 350848 TRT straws.
18  // The persistent model flattens this so that the persistent container has two vectors: 1) all collections, 2) all RDO
19  // The persistent collections then only maintain indexes into the container's vector of all channels.
20  // So here we loop over all collection and add their channels to the container's vector, saving the indexes in the collection.
21 
22  // Hard-code the number of collections their ids and their sizes to generate collections and channels for the whole detector
23  const unsigned int dummy_digit=0;
24  const unsigned int trt_number_of_collections=14912;
25  const unsigned int trt_number_of_channels=350848;
26  const unsigned int trt_channel_id_increment=0x20u;
27 
28  std::vector<unsigned int> trt_collection_id; // There are 14912 elements/modules in the TRT
29  std::vector<unsigned int> trt_collection_size; // Each element has a specific number of straws
30 
32  trt_collection_size,
33  trt_number_of_collections);
34 
35  unsigned int trt_collection_index=0; // module index (0,14911), initialized first collection
36  unsigned int trt_channel_index=0; // straw index (0,350847)
37  unsigned int trt_channel_id; // straw id (32-bit), initialized to the first channel in the first collection
38  unsigned int tcoll_id; // transient collection id from transCont
39  unsigned int tchan_id; // transient channel id from transCont
40  unsigned int tchan_word; // transient channel word from transCont
41 
42  using TRANS = TRT_RDO_Container;
43  TRANS::const_iterator it_transColl = transCont->begin(); // The transient container has an incomplete list of collections
44  TRANS::const_iterator it_transCollEnd = transCont->end(); // and channels, we can access them with this iterator
45 
46  persCont->m_collections.resize(trt_number_of_collections);
47  persCont->m_rawdata.resize(trt_number_of_channels);
48 
49  // Loop over all existing transient collections, add missing collections and missing channels
50  for (; it_transColl != it_transCollEnd; ++it_transColl) {
51 
52  const TRT_RDO_Collection& collection = (**it_transColl);
53  tcoll_id = collection.identify().get_identifier32().get_compact();
54 
55  // create collections and channels until we find a match to a transient container
56  while ( trt_collection_id[trt_collection_index] != tcoll_id ) {
57  // The transient collection is missing; create the persistent collection with empty digits
58  trt_channel_id = trt_collection_id[trt_collection_index];
59  InDetRawDataCollection_p1& pcollection = persCont->m_collections[trt_collection_index];
60  pcollection.m_id = 0;
61  pcollection.m_hashId = 0; // no hashId for this empty collection
62  pcollection.m_begin = 0;
63  pcollection.m_end = 0;
64  // Fill all the channels with with empty digits.
65  for (unsigned int i=0; i<trt_collection_size[trt_collection_index]; ++i) {
66  persCont->m_rawdata[trt_channel_index] = dummy_digit;
67  trt_channel_id += trt_channel_id_increment;
68  trt_channel_index++;
69  }
70  trt_collection_index++;
71  }
72 
73  // Here we have a match to a transient collection
74  // create the persistent collection just as we did above
75  trt_channel_id = trt_collection_id[trt_collection_index];
76  InDetRawDataCollection_p1& pcollection = persCont->m_collections[trt_collection_index];
77  pcollection.m_id = 0;
78  pcollection.m_hashId = (unsigned int) collection.identifyHash(); // Required by the overlay alogrithm (not the reco algorithms)
79  pcollection.m_begin = 0;
80  pcollection.m_end = 0;
81 
82  const unsigned int collection_end = trt_channel_index+trt_collection_size[trt_collection_index];
83 
84  // Fill all the channels; some with existing digits, the others with empty digits.
85  for (unsigned int i = 0; i < collection.size(); ++i) {
86 
87  // Get the channel id and word from the digitization transient object
88  // We will use the id to determine when to insert missing straws to create a container that represents the complete detector.
89  // We will only store the digit word.
90  const TRT_LoLumRawData* tchan0 = dynamic_cast<const TRT_LoLumRawData*>(collection[i]);
91  if (not tchan0) throw std::runtime_error("TRT_LoLumRawDataContainerCnv_p3::transToPers: could not cast ptr to TRT_LoLumRawData");
92  tchan_id = tchan0->identify().get_identifier32().get_compact(); // the i'th channel id in the transient collection
93  tchan_word = tchan0->getWord(); // the i'th channel word in the transient collection
94 
95  while ( trt_channel_id != tchan_id) {
96  persCont->m_rawdata[trt_channel_index] = dummy_digit;
97  trt_channel_id += trt_channel_id_increment;
98  ++trt_channel_index;
99  }
100 
101  // Here we have a matching transient channel; write it.
102  persCont->m_rawdata[trt_channel_index]=tchan_word;
103  trt_channel_id += trt_channel_id_increment;
104  trt_channel_index++;
105 
106  } // end transient channel loop
107 
108  // write all other missing channels
109  while (trt_channel_index != collection_end) {
110  persCont->m_rawdata[trt_channel_index] = dummy_digit;
111  trt_channel_id += trt_channel_id_increment;
112  trt_channel_index++;
113  }
114 
115  // increment to the next collection
116  trt_collection_index++;
117 
118  } // end transient collection loop
119 
120  // Finally, create any remaining missing collections
121  while ( trt_collection_index < trt_number_of_collections ) {
122  // The transient collection is missing; create the persistent collection with empty digits
123  trt_channel_id = trt_collection_id[trt_collection_index];
124  InDetRawDataCollection_p1& pcollection = persCont->m_collections[trt_collection_index];
125  pcollection.m_id = 0;
126  pcollection.m_hashId = 0; // no hashId for this empty collection
127  pcollection.m_begin = 0;
128  pcollection.m_end = 0;
129 
130  // Fill all the channels with with empty digits.
131  for (unsigned int i=0; i<trt_collection_size[trt_collection_index]; ++i) {
132  persCont->m_rawdata[trt_channel_index] = dummy_digit;
133  trt_channel_id += trt_channel_id_increment;
134  trt_channel_index++;
135  }
136  trt_collection_index++;
137  }
138 
139  MSG_DEBUG(log," Prepared " << persCont->m_collections.size() << "Collections");
140  MSG_DEBUG(log," *** Writing TRT_RDO_Container (TRT_LoLumRawData concrete type)");
141 
142  trt_collection_id.clear();
143  trt_collection_size.clear();
144 
145 } // end of transToPers
146 
147 
149 {
150 
151  // The transient model has a container holding collections (up to 14912 TRT detector elements/modules)
152  // and the collections hold channels (e.g. up to 24 straws in the TRT endcaps). There are a total of 350848 TRT straws.
153  // The persistent model flattens this so that the persistent container has two vectors: 1) all collections, 2) all RDO
154  // The persistent collections then only maintain indexes into the container's vector of all channels.
155  // So here we loop over all collection and extract their channels from the vector.
156 
157  // Hard-code the number of collections, their ids and their sizes to generate collections and channels for the whole detector
158  const unsigned int dummy_digit=0;
159  const unsigned int trt_number_of_collections=14912;
160  const unsigned int trt_channel_id_increment=0x20u;
161  std::vector<unsigned int> trt_collection_id; // There are 14912 elements/modules in the TRT
162  std::vector<unsigned int> trt_collection_size; // Each element has a specific number of straws
163 
164  set_vectors_of_collection_ids_and_size(trt_collection_id,
165  trt_collection_size,
166  trt_number_of_collections);
167 
168  unsigned int trt_channel_id;
169  unsigned int trt_channel_index=0;
170  unsigned int trt_channel_index_old;
171 
172 
173  MSG_DEBUG(log," Reading " << persCont->m_collections.size() << "Collections");
174  if (persCont->m_collections.size() != trt_number_of_collections){
175  log << MSG::ERROR
176  << "TRT_LoLumRawDataContainerCnv_p3::persToTrans expected 14912 "
177  "collections but got "
178  << persCont->m_collections.size()
179  << ". We should be reading the whole detector!" << endmsg;
180  }
181  //create Data Pool
182  DataPool<TRT_LoLumRawData> dataItems;
183  // It resizes as needed .
184  // The max number of straws is 350847 but assume
185  // that we do not have 100% occupancy
186  dataItems.reserve(180000);
187 
188  TRT_RDO_Collection* tcoll=nullptr; // transient collection to be constructed
189  for (unsigned int trt_collection_index=0; trt_collection_index<trt_number_of_collections; ++trt_collection_index) {
190  // count the number of non-dummy digits and skip to the next persistent collection if there are none.
191  unsigned int nchans = trt_collection_size[trt_collection_index];
192  trt_channel_index_old = trt_channel_index; // the beginning of this collection
193  unsigned int mchans = 0;
194  for (unsigned int ichan = 0; ichan < nchans; ++ichan) {
195  const unsigned int pword = persCont->m_rawdata[trt_channel_index];
196  if ( pword != dummy_digit ) mchans++;
197  trt_channel_index++;
198  }
199  if (!mchans) {
200  continue;
201  }
202 
203  // Create the transient collection we need it to be VIEW
204  // as the ptr we will pass to it are managed by
205  // a DataPool
206  tcoll = new TRT_RDO_Collection(IdentifierHash(trt_collection_index));
207  tcoll->clear (SG::VIEW_ELEMENTS);
208  //set identifier resize
209  tcoll->setIdentifier(Identifier(trt_collection_id[trt_collection_index]));
210  tcoll->resize(mchans);
211 
212  trt_channel_id = trt_collection_id[trt_collection_index]; // the id of the first channel in this collection
213  trt_channel_index = trt_channel_index_old; // go back to the beginning of this collection and process it again
214 
215  unsigned int jchan=0; // counter for the non-dummy digits
216  for (unsigned int ichan = 0; ichan < nchans; ++ichan) {
217  const unsigned int pword = persCont->m_rawdata[trt_channel_index];
218  if ( pword == dummy_digit ) {
219  // advance to the next straw
220  trt_channel_id += trt_channel_id_increment;
221  trt_channel_index++;
222  continue; // don't write a dummy digit
223  }
224  //ask the pool for the next pointer
225  TRT_LoLumRawData* tchan = dataItems.nextElementPtr();
226  //set the payload
227  *tchan = TRT_LoLumRawData(Identifier(trt_channel_id),pword);
228  (*tcoll)[jchan] = tchan;
229  jchan++;
230  // advance to the next straw
231  trt_channel_id += trt_channel_id_increment;
232  trt_channel_index++;
233  }
234 
235  // register the rdo collection in IDC with hash - faster addCollection
236  StatusCode sc = transCont->addCollection(tcoll, IdentifierHash(trt_collection_index));
237  if (sc.isFailure()) {
238  throw std::runtime_error("Failed to add collection to ID Container");
239  }
240  MSG_VERBOSE(
241  log,
242  "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id / coll_id = "
243  << trt_collection_index << " / "
244  << trt_collection_id[trt_collection_index]
245  << ", added to Identifiable container.");
246  }
247 
248  trt_collection_id.clear();
249  trt_collection_size.clear();
250 
251  MSG_DEBUG(log," *** Reading TRT_RDO_Container (TRT_LoLumRawData concrete type)");
252 
253 } // end of persToTrans
254 
255 //================================================================
257  std::unique_ptr<TRT_RDO_Container> trans(std::make_unique<TRT_RDO_Container>(m_trtId->straw_layer_hash_max()));
258  persToTrans(persObj, trans.get(), log);
259  return(trans.release());
260 }
set_vectors_of_collection_ids_and_size
void set_vectors_of_collection_ids_and_size(std::vector< unsigned int > &element, std::vector< unsigned int > &nstraws, const unsigned int number_of_elements)
Definition: TRT_RDO_Elements.h:1
TRT_LoLumRawDataContainerCnv_p3::createTransient
virtual TRT_RDO_Container * createTransient(const InDetRawDataContainer_p3 *persObj, MsgStream &log)
Definition: TRT_LoLumRawDataContainerCnv_p3.cxx:256
TRT_RDO_Container.h
InDetRawDataCollection::setIdentifier
void setIdentifier(Identifier id)
TRT_RDO_Elements.h
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_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...
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
InDetRawDataContainer_p3
Definition: InDetRawDataContainer_p3.h:19
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
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition: Identifier32.h:44
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
InDetRawDataCollection_p1::m_id
Identifier32::value_type m_id
Definition: InDetRawDataCollection_p1.h:32
InDetRawDataCollection_p1
Definition: InDetRawDataCollection_p1.h:13
InDetRawDataContainer_p3::m_collections
std::vector< InDetRawDataCollection_p1 > m_collections
Definition: InDetRawDataContainer_p3.h:25
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
InDetRawDataCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
TRT_RDO_Collection
InDetRawDataCollection< TRT_RDORawData > TRT_RDO_Collection
Definition: TRT_RDO_Collection.h:20
TRT_LoLumRawDataContainerCnv_p3::m_trtId
const TRT_ID * m_trtId
Definition: TRT_LoLumRawDataContainerCnv_p3.h:28
TRT_LoLumRawDataContainerCnv_p3::transToPers
virtual void transToPers(const TRT_RDO_Container *transCont, InDetRawDataContainer_p3 *persCont, MsgStream &log)
Definition: TRT_LoLumRawDataContainerCnv_p3.cxx:13
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
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...
TRT_LoLumRawDataContainerCnv_p3.h
DataVector::clear
void clear()
Erase all the elements in the collection.
DataPool.h
TRT_LoLumRawDataContainerCnv_p3::persToTrans
virtual void persToTrans(const InDetRawDataContainer_p3 *persCont, TRT_RDO_Container *transCont, MsgStream &log)
Definition: TRT_LoLumRawDataContainerCnv_p3.cxx:148
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
InDetRawDataContainer_p3::m_rawdata
std::vector< unsigned int > m_rawdata
Definition: InDetRawDataContainer_p3.h:26
InDetRawDataCollection_p1::m_begin
unsigned int m_begin
Definition: InDetRawDataCollection_p1.h:39
MSG_VERBOSE
#define MSG_VERBOSE(log, x)
Definition: MsgUtil.h:17
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
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
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
InDetRawDataCollection_p1.h
Identifier
Definition: IdentifierFieldParser.cxx:14
MsgUtil.h