ATLAS Offline Software
Loading...
Searching...
No Matches
LArRawDataReadingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
11#include "eformat/Version.h"
12#include "eformat/index.h"
13
19
20#include "LArFebHeaderReader.h"
22
23
27
28 m_doDigits = !m_digitKey.empty();
29 ATH_CHECK(m_digitKey.initialize(m_doDigits));
30
33
34 ATH_CHECK(m_eventInfoKey.initialize() );
35
37 ATH_CHECK(detStore()->retrieve(m_onlineId,"LArOnlineID"));
38 //
39 //Fill FT list if only Barrel/EC and side is given:
40 if (m_vBEPreselection.size() && m_vPosNegPreselection.size() && m_vFTPreselection.size()==0) {
41 std::set<unsigned> fts;
42 if (std::find(m_vBEPreselection.begin(),m_vBEPreselection.end(),0)!=m_vBEPreselection.end()) { //Barrel selected
43 fts.insert({0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31});
44 }
45 if (std::find(m_vBEPreselection.begin(),m_vBEPreselection.end(),1)!=m_vBEPreselection.end()) { //Endcap selected
46 fts.insert({0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24});
47 }
48 m_vFTPreselection.value().insert(m_vFTPreselection.begin(),fts.begin(),fts.end());
49 }
50
51 //Build list of preselected Feedthroughs
52 if (m_vBEPreselection.size() && m_vPosNegPreselection.size() && m_vFTPreselection.size()) {
53 ATH_MSG_INFO("Building list of selected feedthroughs");
54 for (const unsigned iBE : m_vBEPreselection) {
55 for (const unsigned iPN: m_vPosNegPreselection) {
56 for (const unsigned iFT: m_vFTPreselection) {
57 HWIdentifier finalFTId=m_onlineId->feedthrough_Id(iBE,iPN,iFT);
58 //unsigned int finalFTId32 = finalFTId.get_identifier32().get_compact();
59 ATH_MSG_INFO("Adding feedthrough Barrel/Endcap=" << iBE << " pos/neg=" << iPN << " FT=" << iFT
60 //<< " (0x" << std::hex << finalFTId.get_identifier32().get_compact() << std::dec << ")");
61 << " " << std::hex << finalFTId << std::dec << ")");
62 m_vFinalPreselection.insert(finalFTId);
63 }
64 }
65 }
66 }//end if something set
67
68 if (!m_subCaloPreselection.value().empty()) {
69 ATH_MSG_INFO("Adding list of selected subcalo"<<m_subCaloPreselection.value());
70 std::set<HWIdentifier> subcaloFTs;
71 if (m_subCaloPreselection.value().compare("EM")==0) {
72 for (auto febid : m_onlineId->feb_range()) {
73 if (m_onlineId->isEMBchannel(febid) || m_onlineId->isEMECchannel(febid)) {
74 subcaloFTs.insert(m_onlineId->feedthrough_Id(febid));
75 }
76 }
77 }
78 else if (m_subCaloPreselection.value().find("HEC")!=std::string::npos || m_subCaloPreselection.value().find("FCAL")!=std::string::npos) {
79 if (m_subCaloPreselection.value().find("HEC")!=std::string::npos) {
80 for (auto febid : m_onlineId->feb_range()) {
81 if (m_onlineId->isHECchannel(febid)) {
82 subcaloFTs.insert(m_onlineId->feedthrough_Id(febid));
83 }
84 }
85 }
86 if (m_subCaloPreselection.value().find("FCAL")!=std::string::npos) {
87 for (auto febid : m_onlineId->feb_range()) {
88 if (m_onlineId->isFCALchannel(febid)) {
89 subcaloFTs.insert(m_onlineId->feedthrough_Id(febid));
90 }
91 }
92 }
93 } else {
94 ATH_MSG_ERROR("Configuration problem, property 'SubCaloPreselection' set to " << m_subCaloPreselection.value() << ", expect 'EM', 'HEC' or 'FCAL'");
95 return StatusCode::FAILURE;
96 }
97 ATH_MSG_INFO("set sizes:" << subcaloFTs.size() << ", " << m_vFinalPreselection.size());
98 if (m_vFinalPreselection.size()>0) {
99 //Form the intersection of the preselection give as subdet and side/FT/slot
100 for(auto it = m_vFinalPreselection.begin(); it != m_vFinalPreselection.end(); ) {
101 if (subcaloFTs.find(*it)==subcaloFTs.end())
102 it=m_vFinalPreselection.erase(it);
103 else
104 ++it;
105 }
106 if (m_vFinalPreselection.empty()) {
107 ATH_MSG_WARNING("Apparently inconistent configuration of FT preselections. No preselection left after intersecting 'SubCaloPreselection' with 'PosNeg/BE/FT' preselection");
108 }
109 }
110 else {
111 m_vFinalPreselection.swap(subcaloFTs);
112 }
113 }//end if subCaloPreselection set
114
115 if (!m_vFinalPreselection.empty()) {
116 ATH_MSG_INFO("Give pre-selection covers " << m_vFinalPreselection.size() << " feedthroughts. first is: "<< MSG::hex << *(m_vFinalPreselection.begin()) << MSG::dec <<" Will ignore bytestream data from other feedthroughs.");
117 }
118
119 return StatusCode::SUCCESS;
120}
121
122StatusCode LArRawDataReadingAlg::execute(const EventContext& ctx) const {
123 LArRawChannelContainer* rawChannels=nullptr;
124 LArDigitContainer* digits=nullptr;
125 LArFebHeaderContainer* febHeaders=nullptr;
126
127 if (m_doRawChannels) {
129 ATH_CHECK(rawChannelsHdl.record(std::make_unique<LArRawChannelContainer>()));
130 rawChannels=rawChannelsHdl.ptr();
131 rawChannels->reserve(182468); //Total number of LAr readout channels
132 }
133
134 if (m_doDigits) {
136 ATH_CHECK(digitsHdl.record(std::make_unique<LArDigitContainer>()));
137 digits=digitsHdl.ptr();
138 digits->reserve(1000); //Approximate number of Digits above threshold
139 }
140
141 if (m_doFebHeaders) {
143 ATH_CHECK(febHeadersHdl.record(std::make_unique<LArFebHeaderContainer>()));
144 febHeaders=febHeadersHdl.ptr();
145 febHeaders->reserve(1524); //Total number of LAr Front End Boards
146 }
147
148 //Get full events and filter out LAr ROBs
149 const RawEvent* fullEvent=m_robDataProviderSvc->getEvent(ctx);
150 std::map<eformat::SubDetectorGroup, std::vector<const uint32_t*> > rawEventTOC;
151 eformat::helper::build_toc(*fullEvent, rawEventTOC);
152 auto larRobs=rawEventTOC.find(eformat::LAR);
153 if (larRobs==rawEventTOC.end()) {
154 ATH_MSG_DEBUG("No LAr data found in this event. Recording empty LArRawChannelContainer");
155 return StatusCode::SUCCESS;
156 }
157
158
159 std::unique_ptr<LArRodBlockStructure> rodBlock;
160 uint16_t rodMinorVersion=0x0;
161 uint32_t rodBlockType=0x0;
162
163
164 for (const uint32_t* robPtr : larRobs->second) {
166 ATH_MSG_VERBOSE("Decoding ROB fragment 0x" << std::hex << rob.rob_source_id () << " with " << std::dec << rob.rod_fragment_size_word() << " ROB words");
167
168 if (rob.rod_fragment_size_word() <3) {
169 if (m_failOnCorruption) {
170 ATH_MSG_ERROR("Encountered corrupt ROD fragment, less than 3 words!");
171 return StatusCode::FAILURE;
172 }else {
173 continue;
174 }
175 } else if(rob.rob_source_id()& 0x1000 ){
176 //ATH_MSG_DEBUG(" skip Latome fragment with source ID "<< std::hex << rob.rob_source_id()
177 rodBlock=nullptr;
178 continue;
179 } else if(!(rob.rod_source_id()>>12& 0x0F) //0xnn0nnn must be
180 && !((rob.rod_source_id()>>20) == 4) ){ //0x4nnnnn must be
181
182 ATH_MSG_WARNING("Found not LAr fragment " << " event: "<<ctx.eventID().event_number());
184 ATH_MSG_WARNING("Rob source id.: 0x"<< std::hex << rob.rob_source_id () <<std::dec <<" ROD Source id: 0x"<<std::hex<<rob.rod_source_id()<<std::dec<<" Lvl1ID: "<<eventInfo->extendedLevel1ID());
185 continue;
186 }
187
188
189 eformat::helper::Version ver(rob.rod_version());
190 //(re-)init rodBlock only once per event or if (very unlikly or even impossible) some FEBs have a different firmware
191 if (rodBlock==nullptr || rodMinorVersion !=ver.minor_version() || rodBlockType!=(rob.rod_detev_type()&0xff)) {
192 rodMinorVersion=ver.minor_version();
193 rodBlockType=rob.rod_detev_type()&0xff;
194 ATH_MSG_VERBOSE("Found version " << rodMinorVersion << " of Rod Block Type " << rodBlockType);
195 if (rodBlockType==4) { //Physics mode
196 switch(rodMinorVersion) {
197 case 12: //Physics mode v6 09.03.2011 for LHC
198 rodBlock.reset(new LArRodBlockPhysicsV6 (this->msgSvc().get()));
199 break;
200 case 11: //Physics mode v5 16.06.2008 for LHC
201 case 10: //Physics mode v5 16.06.2008 for LHC
202 rodBlock.reset(new LArRodBlockPhysicsV5 (this->msgSvc().get()));
203 break;
204 default: // Unknown version of rod block type 4 (Physics mode)
205 if (m_failOnCorruption) {
206 ATH_MSG_ERROR("Found unsupported ROD Block version " << rodMinorVersion
207 << " of ROD block type " << rodBlockType << ". ROD Source id: 0x" <<std::hex<<rob.rod_source_id());
208 return StatusCode::FAILURE;
209 }
210 else {
211 ATH_MSG_WARNING("Found unsupported ROD Block version " << rodMinorVersion
212 << " of ROD block type " << rodBlockType << ". ROD Source id: 0x" <<std::hex<<rob.rod_source_id());
213 continue;
214 }
215 }// end switch(rodMinorVersion)
216 }//end rodBlockType==4 (physics mode)
217 else if (rodBlockType==2) { //Transparent mode
218 switch(rodMinorVersion) {
219 case 4:
220 rodBlock.reset(new LArRodBlockTransparentV0<LArRodBlockHeaderTransparentV0> (this->msgSvc().get()));
221 break;
222 case 12:
223 rodBlock.reset(new LArRodBlockCalibrationV3 (this->msgSvc().get()));
224 break;
225 default:
226 ATH_MSG_WARNING("Found unsupported ROD Block version " << rodMinorVersion
227 << " of ROD block type " << rodBlockType);
228 return m_failOnCorruption ? StatusCode::FAILURE : StatusCode::SUCCESS;
229 }
230 }
231 }//End if need to re-init RodBlock
232
233 const uint32_t* pData=rob.rod_data();
234 const uint32_t nData=rob.rod_ndata();
235 if (nData==0) {
236 if (m_failOnCorruption) {
237 ATH_MSG_ERROR("ROD 0x"<<std::hex<<rob.rod_source_id() << std::dec << " reports data block size 0");
238 return StatusCode::FAILURE;
239 }
240 else {
241 ATH_MSG_WARNING("ROD 0x"<<std::hex<<rob.rod_source_id() << std::dec << " reports data block size 0");
242 continue; //Jump to next ROD
243 }
244 }
245
246 if (!rodBlock || !rodBlock->setFragment(pData,nData)) {
247 if (m_failOnCorruption) {
248 ATH_MSG_ERROR("Failed to assign fragment pointer to LArRodBlockStructure");
249 return StatusCode::FAILURE;
250 }
251 else {
252 ATH_MSG_WARNING("Failed to assign fragment pointer to LArRodBlockStructure");
253 continue; // Jump to next ROD
254 }
255 }
256
257 if(m_verifyChecksum) {
258 const uint32_t onsum = rodBlock->onlineCheckSum();
259 const uint32_t offsum = rodBlock->offlineCheckSum();
260 if(onsum!=offsum) {
261 if (m_failOnCorruption) {
262 ATH_MSG_ERROR("Checksum error:");
263 ATH_MSG_ERROR("online checksum = 0x" << MSG::hex << onsum);
264 ATH_MSG_ERROR("offline checksum = 0x" << MSG::hex << offsum << MSG::dec);
265 return StatusCode::FAILURE;
266 } else {
267 continue; //Jump to the next ROD-block
268 }
269 }
270 }
271
272 //Loop over FEBs in ROD:
273 do {
274 HWIdentifier fId(Identifier32(rodBlock->getFEBID()));
275 if (!m_onlineId->isValidId(fId)) {
276 if (m_failOnCorruption){
277 ATH_MSG_ERROR("Invalid FEB identifer 0x" << std::hex << fId.get_identifier32().get_compact());
278 return StatusCode::FAILURE;
279 } else {
280 ATH_MSG_WARNING("Invalid FEB identifer 0x" << std::hex << fId.get_identifier32().get_compact());
281 continue; //Jump to next FEB
282 }
283 }
284
285 if (m_vFinalPreselection.size()) {
286 const auto ftId=m_onlineId->feedthrough_Id(fId);
287 if (m_vFinalPreselection.find(ftId)==m_vFinalPreselection.end()) {
288 ATH_MSG_DEBUG("Feedthrough with id " << MSG::hex << ftId << MSG::dec <<" not in preselection. Ignored.");
289 continue;
290 } else {
291 ATH_MSG_DEBUG("Feedthrough with id " << MSG::hex << ftId << MSG::dec <<" is preselected.");
292 }
293 }
294
295 const int NthisFebChannel=m_onlineId->channelInSlotMax(fId);
296
297 //Decode RawChanels (if requested)
298 if (m_doRawChannels) {
299 int32_t energy;
300 int32_t time;
301 int32_t quality;
302 uint32_t gain;
303 int fcNb;
304 while (rodBlock->getNextEnergy(fcNb,energy,time,quality,gain)) {
305 if (fcNb>=NthisFebChannel)
306 continue;
307
308 HWIdentifier cId = m_onlineId->channel_Id(fId,fcNb);
309 uint16_t iquality = 0;
310 uint16_t iprovenance = LArProv::DSPCALC; //0x1000
311 if (quality>0) {
312 iprovenance |= LArProv::QTPRESENT; //0x2000
313 iquality = (quality & 0xFFFF);
314 }
315 rawChannels->emplace_back(cId, energy, time, iquality, iprovenance, (CaloGain::CaloGain)gain);
316 }//end getNextEnergyLoop
317 }//end if m_doRawChannels
318
319 //Decode LArDigits (if requested)
320 if (m_doDigits) {
321 uint32_t gain;
322 int fcNb;
323 std::vector<short> samples;
324 while (rodBlock->getNextRawData(fcNb,samples,gain)) {
325 if (fcNb>=NthisFebChannel)
326 continue;
327 if (samples.size()==0) continue; // Ignore missing cells
328 HWIdentifier cId = m_onlineId->channel_Id(fId,fcNb);
329 digits->emplace_back(new LArDigit(cId, (CaloGain::CaloGain)gain, std::move(samples)));
330 samples.clear();
331 }//end getNextRawData loop
332 }//end if m_doDigits
333
334 //Decode FebHeaders (if requested)
335 if (m_doFebHeaders) {
336 std::unique_ptr<LArFebHeader> larFebHeader(new LArFebHeader(fId));
337 LArFebHeaderReader::fillFebHeader(larFebHeader.get(),rodBlock.get(),rob);
338 febHeaders->push_back(std::move(larFebHeader));
339 }//end if m_doFebHeaders
340
341 }while (rodBlock->nextFEB()); //Get NextFeb
342 } //end loop over ROBs
343 return StatusCode::SUCCESS;
344}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
OFFLINE_FRAGMENTS_NAMESPACE::FullEventFragment RawEvent
data type for reading raw event
Definition RawEvent.h:37
const ServiceHandle< StoreGateSvc > & detStore() const
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
value_type emplace_back(value_type pElem)
Add an element to the end of the collection.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
Container class for LArDigit.
Liquid Argon digit base class.
Definition LArDigit.h:25
Container class for LArFebHeader.
Holds information from the FEB Header.
Container for LArRawChannel (IDC using LArRawChannelCollection).
Gaudi::Property< std::vector< unsigned > > m_vPosNegPreselection
Gaudi::Property< std::vector< unsigned > > m_vBEPreselection
std::set< HWIdentifier > m_vFinalPreselection
BooleanProperty m_failOnCorruption
SG::WriteHandleKey< LArRawChannelContainer > m_rawChannelKey
const LArOnlineID * m_onlineId
ServiceHandle< IROBDataProviderSvc > m_robDataProviderSvc
StatusCode initialize() override
SG::WriteHandleKey< LArFebHeaderContainer > m_febHeaderKey
BooleanProperty m_verifyChecksum
Gaudi::Property< std::string > m_subCaloPreselection
SG::WriteHandleKey< LArDigitContainer > m_digitKey
Gaudi::Property< std::vector< unsigned > > m_vFTPreselection
StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
This class provides decoding/encoding from/to ROD format.
This class provides decoding/encoding from/to ROD format.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:132
void fillFebHeader(LArFebHeader *lfh, const LArRodBlockStructure *bl, const ROBFragment &robFrag)
Fill info for one FEB Header.
eformat::ROBFragment< PointerType > ROBFragment
Definition RawEvent.h:27