ATLAS Offline Software
Loading...
Searching...
No Matches
LArRawCalibDataReadingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
13#include "eformat/Version.h"
14#include "eformat/index.h"
15
20
21#include "LArFebHeaderReader.h"
22
23LArRawCalibDataReadingAlg::LArRawCalibDataReadingAlg(const std::string& name, ISvcLocator* pSvcLocator) :
24 AthReentrantAlgorithm(name, pSvcLocator) {}
25
27
28 if (m_DigitKey.key().size()>0) {
29 ATH_CHECK(m_DigitKey.initialize());
30 m_doDigits=true;
31 }
32 else {
33 m_doDigits=false;
34 }
35
36 if (m_calibDigitKey.key().size()>0) {
37 ATH_CHECK(m_calibDigitKey.initialize());
38 m_doCalibDigits=true;
39 }
40 else {
41 m_doCalibDigits=false;
42 }
43
44 if (m_accDigitKey.key().size()>0) {
45 ATH_CHECK(m_accDigitKey.initialize());
46 m_doAccDigits=true;
47 }
48 else {
49 m_doAccDigits=false;
50 }
51
52 if (m_accCalibDigitKey.key().size()>0) {
53 ATH_CHECK(m_accCalibDigitKey.initialize());
55 }
56 else {
58 }
59
60 if (m_febHeaderKey.key().size()>0) {
61 ATH_CHECK(m_febHeaderKey.initialize());
62 m_doFebHeaders=true;
63 }
64 else {
65 m_doFebHeaders=false;
66 }
67
69 ATH_MSG_FATAL("Needs ether Digits or CalibDigits or AccDigits or AccCalibDigit Key");
70 return StatusCode::FAILURE;
71 }
72
74 ATH_MSG_FATAL("Could not have both CalibDigits, AccCalibDigits Key");
75 return StatusCode::FAILURE;
76 }
77
79 ATH_MSG_FATAL("Could not have AccDigits with Calib Key");
80 return StatusCode::FAILURE;
81 }
82
84 ATH_CHECK(detStore()->retrieve(m_onlineId,"LArOnlineID"));
85
86 ATH_CHECK(m_CLKey.initialize());
87
88
89 //Fill FT list if only Barrel/EC and side is given:
90 if (m_vBEPreselection.size() && m_vPosNegPreselection.size() && m_vFTPreselection.size()==0) {
91 std::set<unsigned> fts;
92 if (std::find(m_vBEPreselection.begin(),m_vBEPreselection.end(),0)!=m_vBEPreselection.end()) { //Barrel selected
93 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});
94 }
95 if (std::find(m_vBEPreselection.begin(),m_vBEPreselection.end(),1)!=m_vBEPreselection.end()) { //Endcap selected
96 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});
97 }
98 m_vFTPreselection.value().insert(m_vFTPreselection.begin(),fts.begin(),fts.end());
99 }
100
101 //Build list of preselected Feedthroughs
102 if (m_vBEPreselection.size() && m_vPosNegPreselection.size() && m_vFTPreselection.size()) {
103 ATH_MSG_INFO("Building list of selected feedthroughs");
104 for (const unsigned iBE : m_vBEPreselection) {
105 for (const unsigned iPN: m_vPosNegPreselection) {
106 for (const unsigned iFT: m_vFTPreselection) {
107 HWIdentifier finalFTId=m_onlineId->feedthrough_Id(iBE,iPN,iFT);
108 ATH_MSG_INFO("Adding feedthrough Barrel/Endcap=" << iBE << " pos/neg=" << iPN << " FT=" << iFT
109 << " (0x" << std::hex << finalFTId.get_identifier32().get_compact() << std::dec << ")");
110 m_vFinalPreselection.insert(finalFTId);
111 }
112 }
113 }
114 }//end if something set
115
116 if (!m_subCaloPreselection.value().empty()) {
117 ATH_MSG_INFO("Adding list of selected subcalo"<<m_subCaloPreselection.value());
118 std::set<HWIdentifier> subcaloFTs;
119 if (m_subCaloPreselection.value().compare("EM")==0) {
120 for (auto febid : m_onlineId->feb_range()) {
121 if (m_onlineId->isEMBchannel(febid) || m_onlineId->isEMECchannel(febid)) {
122 subcaloFTs.insert(m_onlineId->feedthrough_Id(febid));
123 }
124 }
125 }
126 else if (m_subCaloPreselection.value().find("HEC")!=std::string::npos || m_subCaloPreselection.value().find("FCAL")!=std::string::npos) {
127 if (m_subCaloPreselection.value().find("HEC")!=std::string::npos) {
128 for (auto febid : m_onlineId->feb_range()) {
129 if (m_onlineId->isHECchannel(febid)) {
130 subcaloFTs.insert(m_onlineId->feedthrough_Id(febid));
131 }
132 }
133 }
134 if (m_subCaloPreselection.value().find("FCAL")!=std::string::npos) {
135 for (auto febid : m_onlineId->feb_range()) {
136 if (m_onlineId->isFCALchannel(febid)) {
137 subcaloFTs.insert(m_onlineId->feedthrough_Id(febid));
138 }
139 }
140 }
141 } else {
142 ATH_MSG_ERROR("Configuration problem, property 'SubCaloPreselection' set to " << m_subCaloPreselection.value() << ", expect 'EM', 'HEC' or 'FCAL'");
143 return StatusCode::FAILURE;
144 }
145 if (m_vFinalPreselection.size()>0) {
146 //Form the intersection of the preselection give as subdet and side/FT/slot
147 for(auto it = m_vFinalPreselection.begin(); it != m_vFinalPreselection.end(); ) {
148 if (subcaloFTs.find(*it)==subcaloFTs.end())
149 it=m_vFinalPreselection.erase(it);
150 else
151 ++it;
152 }
153 if (m_vFinalPreselection.empty()) {
154 ATH_MSG_WARNING("Apparently inconistent configuration of FT preselections. No preselection left after intersecting 'SubCaloPreselection' with 'PosNeg/BE/FT' preselection");
155 }
156 }
157 else {
158 m_vFinalPreselection.swap(subcaloFTs);
159 }
160 }//end if subCaloPreselection set
161
162 if (!m_vFinalPreselection.empty()) {
163 ATH_MSG_INFO("Give pre-selection covers " << m_vFinalPreselection.size() << " feedthroughts. Will ignore bytestream data from other feedthroughs.");
164 }
165
166 return StatusCode::SUCCESS;
167}
168
169StatusCode LArRawCalibDataReadingAlg::execute(const EventContext& ctx) const {
170 LArDigitContainer* digits=nullptr;
171 LArCalibDigitContainer* cdigits=nullptr;
172 LArAccumulatedDigitContainer* accdigits=nullptr;
173 LArAccumulatedCalibDigitContainer* caccdigits=nullptr;
174 LArFebHeaderContainer* febHeaders=nullptr;
175
176 if (m_doDigits) {
178 ATH_CHECK(digitsHdl.record(std::make_unique<LArDigitContainer>()));
179 digits=digitsHdl.ptr();
180 digits->reserve(200000); //Enough space for the full calo
181 }
182
183 if (m_doCalibDigits) {
185 ATH_CHECK(cdigitsHdl.record(std::make_unique<LArCalibDigitContainer>()));
186 cdigits=cdigitsHdl.ptr();
187 cdigits->reserve(200000); //Enough space for the full calo
188 }
189
190 if (m_doAccDigits) {
192 ATH_CHECK(accdigitsHdl.record(std::make_unique<LArAccumulatedDigitContainer>()));
193 accdigits=accdigitsHdl.ptr();
194 accdigits->reserve(200000); //Enough space for the full calo
195 }
196
197 if (m_doAccCalibDigits) {
199 ATH_CHECK(caccdigitsHdl.record(std::make_unique<LArAccumulatedCalibDigitContainer>()));
200 caccdigits=caccdigitsHdl.ptr();
201 caccdigits->reserve(200000); //Enough space for the full calo
202 }
203
204 if (m_doFebHeaders) {
206 ATH_CHECK(febHeadersHdl.record(std::make_unique<LArFebHeaderContainer>()));
207 febHeaders=febHeadersHdl.ptr();
208 febHeaders->reserve(1524); //Total number of LAr Front End Boards
209 }
210
211 //Get full events and filter out LAr ROBs
212 const RawEvent* fullEvent=m_robDataProviderSvc->getEvent(ctx);
213 std::map<eformat::SubDetectorGroup, std::vector<const uint32_t*> > rawEventTOC;
214 eformat::helper::build_toc(*fullEvent, rawEventTOC);
215 auto larRobs=rawEventTOC.find(eformat::LAR);
216 if (larRobs==rawEventTOC.end()) {
217 ATH_MSG_DEBUG("No LAr data found in this event.");
218 return StatusCode::SUCCESS;
219 }
220
221
222 std::unique_ptr<LArRodBlockStructure> rodBlock;
223 uint16_t rodMinorVersion=0x0;
224 uint32_t rodBlockType=0x0;
225
226 const LArCalibLineMapping *calibMap=nullptr;
227 if (m_doAccCalibDigits) {
229 calibMap = *clHdl;
230 if(!calibMap) {
231 ATH_MSG_ERROR( "Do not have calib line mapping !!!" );
232 return StatusCode::FAILURE;
233 }
234 }
235
236 for (const uint32_t* robPtr : larRobs->second) {
238 ATH_MSG_VERBOSE("Decoding ROB fragment 0x" << std::hex << rob.rob_source_id () << " with " << std::dec << rob.rod_fragment_size_word() << "ROB words");
239
240 if (rob.rod_fragment_size_word() <3) {
241 ATH_MSG_ERROR("Encountered corrupt ROD fragment, less than 3 words!");
242 if (m_failOnCorruption) {
243 return StatusCode::FAILURE;
244 }else
245 continue; //Jump to next ROD block
246 }else if(rob.rob_source_id()& 0x1000 ){
247 ATH_MSG_VERBOSE(" skip Latome fragment with source ID "<< std::hex << rob.rob_source_id());
248 rodBlock=nullptr;
249 continue;
250 }
251
252 eformat::helper::Version ver(rob.rod_version());
253 //(re-)init rodBlock only once per event or if (very unlikly or even impossible) some FEBs have a differnt firmware
254 if (rodBlock==nullptr || rodMinorVersion !=ver.minor_version() || rodBlockType!=(rob.rod_detev_type()&0xff)) {
255 rodMinorVersion=ver.minor_version();
256 rodBlockType=rob.rod_detev_type()&0xff;
257 ATH_MSG_VERBOSE("Found version " << rodMinorVersion << " of Rod Block Type " << rodBlockType);
258 if (rodBlockType==10) { // Accumulated digits
259 rodBlock.reset(new LArRodBlockAccumulatedV3 (this->msgSvc().get()));
260 }//end of rodBlockType ==10
261 else if (rodBlockType==7 || rodBlockType==2) { // Calib. digits
262 if(rodMinorVersion>=6) { // Accumulated calib. digits
263 rodBlock.reset(new LArRodBlockCalibrationV3 (this->msgSvc().get()));
264 } else {
265 ATH_MSG_ERROR("Found unsupported ROD Block version " << rodMinorVersion
266 << " of ROD block type " << rodBlockType);
267 return m_failOnCorruption ? StatusCode::FAILURE : StatusCode::SUCCESS;
268 }
269 } else {
270 ATH_MSG_ERROR("Found unsupported Rod block type " << rodBlockType << " in ROB sourceId: 0x" << std::hex << rob.rob_source_id () << std::dec
271 << ", ROD source ID: 0x" << rob.rod_source_id() << std::dec);
273 return StatusCode::FAILURE;
274 else
275 continue; //Jump to next ROD block
276 }
277 }//End if need to re-init RodBlock
278
279 const uint32_t* pData=rob.rod_data();
280 const uint32_t nData=rob.rod_ndata();
281 if (!rodBlock->setFragment(pData,nData)) {
282 ATH_MSG_ERROR("Failed to assign fragment pointer to LArRodBlockStructure");
283 return StatusCode::FAILURE;
284 }
285
286 if(m_verifyChecksum) {
287 const uint32_t onsum = rodBlock->onlineCheckSum();
288 const uint32_t offsum = rodBlock->offlineCheckSum();
289 if(onsum!=offsum) {
290 ATH_MSG_ERROR("Checksum error:");
291 ATH_MSG_ERROR("online checksum = 0x" << MSG::hex << onsum);
292 ATH_MSG_ERROR("offline checksum = 0x" << MSG::hex << offsum << MSG::dec);
294 return StatusCode::FAILURE;
295 else
296 continue; //Jump to the next ROD-block
297 }
298 }
299
300 //Loop over FEBs in ROD:
301 do {
302 HWIdentifier fId(Identifier32(rodBlock->getFEBID()));
303 if (!m_onlineId->isValidId(fId)) {
304 ATH_MSG_ERROR("Invalid FEB identifer 0x" << std::hex << fId.get_identifier32().get_compact());
306 return StatusCode::FAILURE;
307 else
308 continue;
309 }
310
311 if (m_vFinalPreselection.size()) {
312 const auto ftId=m_onlineId->feedthrough_Id(fId);
313 if (m_vFinalPreselection.find(ftId)==m_vFinalPreselection.end()) {
314 ATH_MSG_DEBUG("Feedthrough with id 0x" << MSG::hex << ftId << MSG::dec <<" not in preselection. Ignored.");
315 continue;
316 }
317 }
318
319
320 const int NthisFebChannel=m_onlineId->channelInSlotMax(fId);
321
322 //Decode LArDigits (if requested)
323 if (m_doDigits) {
324 uint32_t gain;
325 int fcNb;
326 std::vector<short> samples;
327 while (rodBlock->getNextRawData(fcNb,samples,gain)) {
328 if (fcNb>=NthisFebChannel)
329 continue;
330 if (samples.size()==0) continue; // Ignore missing cells
331 HWIdentifier cId = m_onlineId->channel_Id(fId,fcNb);
332 digits->emplace_back(new LArDigit(cId, (CaloGain::CaloGain)gain, std::move(samples)));
333 samples.clear();
334 }//end getNextRawData loop
335 }//end if m_doDigits
336
337 //Decode LArCalibDigits (if requested)
338 if (m_doCalibDigits) {
339 uint32_t gain;
340 uint16_t dac;
341 uint16_t delay;
342 bool ispulsed;
343 int fcNb;
344 std::vector<short> samples;
345 while (rodBlock->getNextRawData(fcNb,samples,gain)) {
346 if (fcNb>=NthisFebChannel)
347 continue;
348 if (samples.size()==0) continue; // Ignore missing cells
349 dac = rodBlock->getDAC();
350 delay = rodBlock->getDelay();
351 ispulsed = rodBlock->getPulsed(fcNb);
352 HWIdentifier cId = m_onlineId->channel_Id(fId,fcNb);
353 cdigits->emplace_back(new LArCalibDigit(cId, (CaloGain::CaloGain)gain, std::move(samples), dac, delay, ispulsed));
354 samples.clear();
355 }//end getNextRawData loop
356 }//end if m_doCalibDigits
357
358 //Decode LArAccumulatedDigits (if requested)
359 if (m_doAccDigits && rodBlockType==10) {
360 uint32_t gain;
361 int fcNb;
362 std::vector<uint64_t> samplesSum;
363 std::vector<uint64_t> samples2Sum;
364 uint32_t nTrigger;
365 while (rodBlock->getNextAccumulatedDigit(fcNb,samplesSum,samples2Sum,gain)) {
366 if (fcNb>=NthisFebChannel)
367 continue;
368 if (samplesSum.size()==0 || samples2Sum.size()==0) continue; // Ignore missing cells
369 nTrigger = rodBlock->getNTrigger();
370 HWIdentifier cId = m_onlineId->channel_Id(fId,fcNb);
371 accdigits->emplace_back(new LArAccumulatedDigit(cId, (CaloGain::CaloGain)gain, std::move(samplesSum), std::move(samples2Sum), nTrigger));
372 samplesSum.clear();
373 samples2Sum.clear();
374 }//end getNext loop
375 }//end if m_doAccDigits
376
377 //Decode LArAccumulatedCalibDigits (if requested)
378 if (m_doAccCalibDigits) {
379 uint32_t gain;
380 uint32_t itmp;
381 uint16_t dac;
382 uint16_t delay;
383 uint16_t nstep;
384 uint16_t istep;
385 bool ispulsed=false;
386 uint16_t ispulsed_int;
387 unsigned bitShift;
388 int fcNb;
389 std::vector<uint64_t> samplesSum;
390 std::vector<uint64_t> samples2Sum;
391 uint32_t nTrigger;
392 while (rodBlock->getNextAccumulatedCalibDigit(fcNb,samplesSum,samples2Sum,itmp,gain)) {
393 if (fcNb>=NthisFebChannel)
394 continue;
395 if (samplesSum.size()==0 || samples2Sum.size()==0) continue; // Ignore missing cells
396 ispulsed_int=0;
397 bitShift=0;
398 dac = rodBlock->getDAC();
399 delay = rodBlock->getDelay();
400 nTrigger = rodBlock->getNTrigger();
401 nstep = rodBlock->getNStep();
402 istep = rodBlock->getStepIndex();
403 HWIdentifier cId = m_onlineId->channel_Id(fId,fcNb);
404 const std::vector<HWIdentifier>& calibChannelIDs = calibMap->calibSlotLine(cId);
405 for(std::vector<HWIdentifier>::const_iterator csl_it=calibChannelIDs.begin(); csl_it!=calibChannelIDs.end();++csl_it){
406 uint32_t calibLine = m_onlineId->channel(*csl_it);
407 ispulsed=rodBlock->getPulsed(calibLine);
408 ispulsed_int=( ispulsed_int | ((uint16_t)ispulsed<<bitShift) );
409 bitShift++;
410 }
411 caccdigits->emplace_back(new LArAccumulatedCalibDigit(cId, (CaloGain::CaloGain)gain, std::move(samplesSum), std::move(samples2Sum), nTrigger, dac, delay, ispulsed_int, nstep, istep));
412 }//end getNext loop
413 caccdigits->setDelayScale(m_delayScale);
414 }//end if m_doAccDigits
415
416 //Decode FebHeaders (if requested)
417 if (m_doFebHeaders) {
418 std::unique_ptr<LArFebHeader> larFebHeader(new LArFebHeader(fId));
419 LArFebHeaderReader::fillFebHeader(larFebHeader.get(),rodBlock.get(),rob);
420 febHeaders->push_back(std::move(larFebHeader));
421 }//end if m_doFebHeaders
422
423 }while (rodBlock->nextFEB()); //Get NextFeb
424 } //end loop over ROBs
425 return StatusCode::SUCCESS;
426}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
double delay(std::size_t d)
OFFLINE_FRAGMENTS_NAMESPACE::FullEventFragment RawEvent
data type for reading raw event
Definition RawEvent.h:37
const ServiceHandle< StoreGateSvc > & detStore() const
An algorithm that can be simultaneously executed in multiple threads.
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 LArAccumulatedCalibDigit.
void setDelayScale(const double scale)
set the delay Scale
Data class for calibration ADC samples preprocessed by the DSP.
Container class for LArAccumulatedDigit.
Data class for ADC samples and autocorr preprocessed by the DSP.
Container class for LArCalibDigit.
Base class for LArDigits taken during calibration runs.
const std::vector< HWIdentifier > & calibSlotLine(const HWIdentifier id) const
Container class for LArDigit.
Liquid Argon digit base class.
Definition LArDigit.h:25
Container class for LArFebHeader.
Holds information from the FEB Header.
SG::WriteHandleKey< LArAccumulatedCalibDigitContainer > m_accCalibDigitKey
SG::WriteHandleKey< LArDigitContainer > m_DigitKey
ServiceHandle< IROBDataProviderSvc > m_robDataProviderSvc
StatusCode execute(const EventContext &ctx) const override
SG::ReadCondHandleKey< LArCalibLineMapping > m_CLKey
Gaudi::Property< std::vector< unsigned > > m_vFTPreselection
SG::WriteHandleKey< LArAccumulatedDigitContainer > m_accDigitKey
LArRawCalibDataReadingAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteHandleKey< LArFebHeaderContainer > m_febHeaderKey
Gaudi::Property< std::vector< unsigned > > m_vPosNegPreselection
Gaudi::Property< std::string > m_subCaloPreselection
Gaudi::Property< std::vector< unsigned > > m_vBEPreselection
std::set< HWIdentifier > m_vFinalPreselection
SG::WriteHandleKey< LArCalibDigitContainer > m_calibDigitKey
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