ATLAS Offline Software
Loading...
Searching...
No Matches
PhaseIIStripRawDataContainerCnv.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
5
9
10#include <memory>
11#include <stdexcept>
12
15 ATH_CHECK( detStore()->retrieve(m_idHelper, "SCT_ID") );
16 return StatusCode::SUCCESS;
17}
18
20 assert( transCont);
21 std::unique_ptr< SCT_RawDataContainer_p4 > persObj( std::make_unique<SCT_RawDataContainer_p4>() );
22 persObj->m_collections.reserve( transCont->size() );
23 unsigned int n_rdos=0;
24 auto rdo_container_collection_proxy = PhaseII::makeRawDataCollectionProxy(*transCont);
27 // convert element index and count total number of elements in all containers.
28 for (StripRawDataContainerProxy module_rdo_container_proxy : rdo_container_collection_proxy) {
29 if (!module_rdo_container_proxy.empty()) {
30 IdentifierHash id_hash(module_rdo_container_proxy.identifyHash());
31 assert( n_rdos + module_rdo_container_proxy.size() < std::numeric_limits<unsigned int>::max());
32 persObj->m_collections.emplace_back();
33 persObj->m_collections.back().m_id = m_idHelper->wafer_id(id_hash ).get_identifier32().get_compact();
34 persObj->m_collections.back().m_hashId = id_hash.value();
35 persObj->m_collections.back().m_begin = n_rdos;
36 persObj->m_collections.back().m_end = static_cast<unsigned int>(n_rdos+module_rdo_container_proxy.size());
37 n_rdos += module_rdo_container_proxy.size();
38 }
39 }
40
41 // determine the raw data type, which must be the same for the entire collection.
43 bool is_empty=true;
44 for (StripRawDataContainerProxy module_rdo_container_proxy : rdo_container_collection_proxy) {
45 if (!module_rdo_container_proxy.empty()) {
46 StripRawDataProxy rdo_proxy = module_rdo_container_proxy[0];
47 type=rdo_proxy.dataType();
48 is_empty=false;
49 break;
50 }
51 }
52
53 if (!is_empty) {
55 persObj->m_rawdata.reserve( n_rdos );
56 for (StripRawDataContainerProxy module_rdo_container_proxy : rdo_container_collection_proxy) {
57 if (!module_rdo_container_proxy.empty()) {
58 IdentifierHash id_hash(module_rdo_container_proxy.identifyHash());
59 Identifier wafer_id = m_idHelper->wafer_id(id_hash);
60 assert( module_rdo_container_proxy.identifyHash() < persObj->m_collections.size());
61 assert( persObj->m_rawdata.size() == persObj->m_collections[ module_rdo_container_proxy.identifyHash() ].m_begin );
62 for (StripRawDataProxy rdo_proxy : module_rdo_container_proxy) {
63 persObj->m_rawdata.emplace_back();
64 persObj->m_rawdata.back().m_rdoId = m_idHelper->strip_id(wafer_id,
65 rdo_proxy.coordinates()[0],
66 rdo_proxy.coordinates()[1]).get_identifier32().get_compact();
67 persObj->m_rawdata.back().m_word = rdo_proxy.dataWord();
68 }
69 assert( persObj->m_rawdata.size() == persObj->m_collections[ module_rdo_container_proxy.identifyHash() ].m_end);
70 }
71 }
72 }
74 // @TODO support persistification of SCT3 Raw data ? For which data was that used ?
75 throw std::runtime_error("Strip data type 3 not implemented in PhaseIIStripRawDataContainer");
76 }
77 else {
78 throw std::runtime_error("Strip data type unhandled by the PhaseIIStripRawDataContainer");
79 }
80 }
81 return persObj.release();
82}
83
85 // @TODO support p0_guid 7F2C09B6-0B47-4957-8BBA-EDC665A290AC i.e. initial container
86 // @TOOD support TP1_guid DA76970C-E019-43D2-B2F9-25660DCECD9D i.e. t/p separated version with InDetRawDataContainer_p1
87 static const pool::Guid SCT_TP4_guid("6C7540BE-E85C-4777-BC1C-A9FF11460F54"); // for t/p separated version with SCT_RawDataContainer_p4
88
89 if( compareClassGuid(SCT_TP4_guid) ) {
90 std::unique_ptr< SCT_RawDataContainer_p4 > persCont( poolReadObject< SCT_RawDataContainer_p4 >() );
91 std::unique_ptr<PhaseIIStripRawDataContainer> transCont(std::make_unique<PhaseIIStripRawDataContainer>(m_idHelper->wafer_hash_max(),
92 1 /* one container only */ ));
93
95 if (persCont->m_sct3data.size() != 0){
97 }
98 else if (persCont->m_rawdata.size() != 0){
100 }
101 else {
102 throw std::runtime_error("Unhandled persistent SCT raw data container.");
103 }
104
105 unsigned int n_rdos_total=0u;
106 for ( const InDetRawDataCollection_p1 &a_collection : persCont->m_collections) {
107 assert( a_collection.m_hashId < transCont->size() );
108 assert( a_collection.m_hashId == m_idHelper->wafer_hash(Identifier(a_collection.m_id)));
109 unsigned int n_rdos = a_collection.m_end - a_collection.m_begin;
110
111 assert( n_rdos_total == a_collection.m_begin);
112 assert( n_rdos_total+n_rdos == a_collection.m_end);
113 n_rdos_total += n_rdos;
114 }
115
116 using RangeBeginIndex_t = PhaseII::DataRange::RangeBeginIndex_t;
117 using RangeSize_t = PhaseII::DataRange::RangeSize_t;
118 using ContainerIndex_t = PhaseII::DataRange::ContainerIndex_t;
119 constexpr ContainerIndex_t container_i=0u;
120
121 PhaseII::StripRawDataContainer &rdo_container_dest = transCont->data(container_i);
122 rdo_container_dest.reserve(n_rdos_total);
123 assert(persCont->m_rawdata.size() == n_rdos_total);
124
125 [[maybe_unused]] unsigned int n_rejected_ranges=0u;
127 assert(persCont->m_rawdata.size() == n_rdos_total);
128 // type 1
129 for ( const InDetRawDataCollection_p1 &a_collection : persCont->m_collections) {
130 // @TODO should use the ContainerRangeGuard, and the convenience method addDataForModule
131 PhaseII::DataRange new_range( static_cast<RangeBeginIndex_t>(rdo_container_dest.size()),
132 static_cast<RangeSize_t>(0u) ,
133 container_i);
134 for (unsigned int rdo_i = a_collection.m_begin; rdo_i < a_collection.m_end; ++rdo_i) {
135 assert( rdo_i < persCont->m_rawdata.size() );
136 Identifier strip_id(persCont->m_rawdata[rdo_i].m_rdoId);
137 int strip = m_idHelper->strip( strip_id);
138 assert( strip <= std::numeric_limits<short>::max() && strip >= std::numeric_limits<short>::min());
139 assert( rdo_i == rdo_container_dest.size());
140 rdo_container_dest.emplace_back( std::array<std::int16_t,1>{static_cast<short>(strip)},
141 persCont->m_rawdata[rdo_i].m_word
142 );
143 }
144
145 // @TODO remove :
146 assert( new_range.beginIndex() == a_collection.m_begin);
147 assert( rdo_container_dest.size() == a_collection.m_end);
148
149 assert( static_cast<std::size_t>(rdo_container_dest.size() - new_range.beginIndex()) < std::numeric_limits<RangeSize_t>::max() );
150 // update the number of elements in this range.
151 new_range.setSize(static_cast<RangeSize_t>( rdo_container_dest.size() - new_range.beginIndex()));
152 // register the new hit range
153 n_rejected_ranges += !(transCont->registerOrEraseNewData( a_collection.m_hashId, new_range));
154 // since only this converter registers ranges in this container, the just added range of elements should never be erased:
155 assert( n_rejected_ranges == 0u);
156 }
157 assert( transCont->data(0).size() == n_rdos_total);
158 rdo_container_dest.setDataType( type );
159 }
160 else {
161 //type3
162 assert(persCont->m_sct3data.size() == n_rdos_total);
163 for ( const InDetRawDataCollection_p1 &a_collection : persCont->m_collections) {
164 // @TODO should use the ContainerRangeGuard, and the convenience method addDataForModule
165 PhaseII::DataRange new_range( static_cast<RangeBeginIndex_t>(rdo_container_dest.size()),
166 static_cast<RangeSize_t>(0u) ,
167 container_i);
168 for (unsigned int rdo_i = a_collection.m_begin; rdo_i < a_collection.m_end; ++rdo_i) {
169 assert( rdo_i < persCont->m_sct3data.size() );
170 const SCT3_RawData_p4 &persObj=persCont->m_sct3data[rdo_i];
171 int strip = persObj.getStrip();
172 assert( strip <= std::numeric_limits<short>::max() && strip >= std::numeric_limits<short>::min());
173
174 // P: Bits 0-10 for group size, Bits 11-13 for time bin
175 // T: Bits 0-10 for group size, Bits 22-24 for time bin
176 unsigned int word = static_cast<unsigned int>(persObj.m_word);
177 unsigned int group_size = word & 0x7FF;
178 unsigned int time_bin = (word>>11) & 0x7;
179 constexpr unsigned int errors =0u;
180 assert( rdo_i == rdo_container_dest.size());
181 rdo_container_dest.emplace_back( std::array<std::int16_t,1>{static_cast<short>(strip)},
182 PhaseII::StripRawDataContainer::makeWord(group_size, time_bin,errors)
183 );
184 }
185 // @TODO remove :
186 assert( new_range.beginIndex() == a_collection.m_begin);
187 assert( rdo_container_dest.size() == a_collection.m_end);
188
189 assert( static_cast<std::size_t>(rdo_container_dest.size() - new_range.beginIndex()) < std::numeric_limits<RangeSize_t>::max() );
190 // update the number of elements in this range.
191 std::size_t capped_size = rdo_container_dest.size() - new_range.beginIndex();
192 if (capped_size >= std::numeric_limits<PhaseII::DataRange::RangeSize_t>::max()) {
193 ATH_MSG_WARNING( "Too many RDOs registered for module hash " << a_collection.m_hashId
194 << " : " << capped_size << " !< " << std::numeric_limits<PhaseII::DataRange::RangeSize_t>::max()
195 << ". Elements above maximum possible size will not be accessible.");
196 capped_size =std::numeric_limits<PhaseII::DataRange::RangeSize_t>::max();
197 }
198 new_range.setSize( static_cast<RangeSize_t>( capped_size) );
199 // register the new hit range
200 n_rejected_ranges += !(transCont->registerOrEraseNewData( a_collection.m_hashId, new_range));
201 // since only this converter registers ranges in this container, the just added range of elements should never be erased:
202 assert( n_rejected_ranges == 0u);
203 }
204 assert( transCont->data(0).size() == n_rdos_total);
205 rdo_container_dest.setDataType( type );
206 }
207 return transCont.release();
208 }
209 throw std::runtime_error("Unsupported persistent version in PhaseIIStripRawDataContainerCnv");
210}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
SCT_RawDataContainer_p4 StripRDO_Container_PERS
PhaseII::StripRawDataContainerCollectionTypes<>::ContainerCollection PhaseIIStripRawDataContainer
This is an Identifier helper class for the SCT subdetector.
This is a "hash" representation of an Identifier.
value_type value() const
IdentifierHash::value_type m_hashId
virtual StripRDO_Container_PERS * createPersistent(PhaseIIStripRawDataContainer *transCont) override
virtual StatusCode initialize() override
Gaudi Service Interface method implementations:
virtual PhaseIIStripRawDataContainer * createTransient() override
void emplace_back(std::array< std::int16_t, NDim > &&coordinates, std::uint32_t data_word)
Add a new RDO to the end of this container.
std::size_t size() const
total number of RDOs which are in this container.
void reserve(std::size_t new_capacity)
reserve space for a certain number of RDOs.
std::size_t size() const
return the total number of element ranges.
The container for strip RDOs The base class is the InDetRawDataContainer with a coordinate dimension ...
static std::uint32_t makeWord(unsigned int group_size, unsigned int time_bin, unsigned int errors)
Create a bit-packed data word.
ERawDataType
The data format of the RAW data.
void setDataType(ERawDataType type)
Set the RAW data type of this container.
S.Oda, Oct 2018 replace unsigned int by unsigned short for for the presampling samples for Overlay MC...
int getStrip() const
unsigned short m_word
auto makeRawDataCollectionProxy(const T_RawDataContainerCollection &collection)
Create the top level container proxy for an RDO container collection (read only).
Type describing a range of elements living in a one of N containers.
unsigned int beginIndex() const
void setSize(RangeSize_t new_size)
PhaseII::RawDataContainerProxy< StripRawDataContainer, RawDataProxy, accessPolicy > RawDataContainerProxy
typename RawData::details::traits< StripRawDataContainer >::template RawDataProxy< accessPolicy > RawDataProxy