ATLAS Offline Software
Loading...
Searching...
No Matches
LArRodDecoder.h
Go to the documentation of this file.
1//Dear emacs, this is -*- c++ -*-
2
3/*
4 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
5*/
6
7
8#ifndef LARBYTESTREAM_LARRODDECODER_H
9#define LARBYTESTREAM_LARRODDECODER_H
10
11#include <stdint.h>
12
13//#include "GaudiKernel/AlgTool.h"
14//#include "GaudiKernel/MsgStream.h"
15
17#include "GaudiKernel/ToolHandle.h"
18
29
30
33
37
42
43#include "eformat/Version.h"
44#include "eformat/Issue.h"
45#include <vector>
46#include <string>
47
50
123
124
125//using namespace OFFLINE_FRAGMENTS_NAMESPACE ;
126
128{
129
130public:
131// typedef EventFormat::RODHeader RODHEADER; //Give default template explicitly to work around apparent compiler bug
132// typedef eformat::Header<const uint32_t *> RODHeader ;
133
137 LArRodDecoder(const std::string& type, const std::string& name,
138 const IInterface* parent ) ;
139
140 static const InterfaceID& interfaceID( ) ;
143 virtual ~LArRodDecoder();
144
145 virtual StatusCode initialize ATLAS_NOT_THREAD_SAFE () override;
146
147 // Simple method to associate the second feb
149
150 // fast decoding for trigger
151 inline uint32_t fillCollectionHLT (const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment& robFrag,
152 const uint32_t* p, uint32_t n, LArCellCollection& coll,
153 LArRodBlockStructure*& providedRodBlockStructure,
154 uint16_t& rodMinorVersion, uint32_t& robBlockType) const;
155
157 const uint32_t* p, uint32_t n, LArRawChannelContainer& coll, const CaloGain::CaloGain gain) const;
158
159 //Specialized method to convert ROD Data words into LArDigit
161 const uint32_t* p, uint32_t n, LArDigitContainer& coll, const CaloGain::CaloGain gain) const;
162
163 //Specialized method to convert ROD Accumulated Calib Digit words into LArAccumulatedCalibDigit
165 const uint32_t* p,
166 uint32_t n,
168 const CaloGain::CaloGain gain,
169 const LArCalibLineMapping& calibLineMapping) const;
170
171 //Specialized method to convert ROD Accumulated Digit words into LArAccumulatedDigit
173 const uint32_t* p, uint32_t n, LArAccumulatedDigitContainer& coll, const CaloGain::CaloGain gain) const;
174
175 //Specialized method to convert ROD Data words into LArCalibDigit
177 const uint32_t* p,
178 uint32_t n,
180 const CaloGain::CaloGain gain,
181 const LArCalibLineMapping& calibLineMapping,
182 const LArOnOffIdMapping& onOffIdMapping) const;
183
184 //Specialized method to convert ROD Data words to read the headers of the Feb
186 const uint32_t* p, uint32_t n, LArFebHeaderContainer& coll, const CaloGain::CaloGain) const;
187
188 //Send an error reported by the eformat package to a MsgStream.
189 //inline void report_error (const ers::Issue& error, MsgStream& log);
190 //Inputs: error: The eformat exception
191 // log: The Gaudi MsgStream.
192
193 //Check an eformat fragment for validity. Report an error if it's not valid.
194 template <class T>
195 inline bool check_valid (const T* frag, MsgStream& log) const;
196 //Inputs: frag: The fragment to check
197 // log: The Gaudi MsgStream.
198
199
200
201private:
202 LArRodBlockStructure* prepareBlockStructure1(const uint16_t rodMinorVersion, const uint32_t robBlockType) const;
204 const uint32_t* p, uint32_t n, const CaloGain::CaloGain RequestedGain) const;
205
206 std::unique_ptr<LArRodBlockStructure>
207 makeBlockStructure (unsigned int rodBlockType,
208 unsigned int rodMinorVersion) const;
209
210 inline void setCellEnergy(
211 LArCell* element, int energy, int time,
212 int quality, CaloGain::CaloGain gain) const ;
213
214 inline void writeFebInfo(
215 LArCellCollection& m_coll, LArFebEnergy& febene) const;
216
217 // inline void writeFebInfo(LArRawChannelContainer& m_coll, LArFebEnergy& febene);
218
219
220 SG::ReadHandleKey<xAOD::EventInfo> m_evt {this, "EvtInfo", "EventInfo", "EventInfo name"};
222 bool m_readtdc; // set to True if the tdc phase is read from the upper byte of the nsamples word.
223 bool m_febExchange; //HW cause, can not be fixed otherwise: Ugly hack for swapped FEB
224 unsigned int m_febId1, m_febId2, m_febIdHLT = 0U;
225
226 int m_firstSample; // FIXED but kept for backward compatibility
227 // In Auto-Gain mode, the FEB does not send the samples in the right order, but the one first that
228 // was used for the gain selection. Unfortunatly, there is no way to extract the index if this sample
229 // form the raw data, one has to know it in advance (from the FEB configuration).
230 // For the time beeing, the jobOption ToolSvc.LArRodDecoder.FirstSample tells the LArRodDecoder what
231 // sample to put in front.
232
233
234 std::vector<int> m_vFTPreselection;
235 std::vector<int> m_vBEPreselection;
236 std::vector<int> m_vPosNegPreselection;
237 std::vector<unsigned int> m_vFinalPreselection;
240 std::vector<std::string> m_LArCellCorrNames;
241 std::vector<unsigned int> m_IgnoreCheckFEBs;
242 std::vector<const CaloCellCorrection*> m_LArCellCorrTools;
243
246 m_blstructs ATLAS_THREAD_SAFE;
247
251} ;
252
253template <class T>
254inline bool LArRodDecoder::check_valid (const T* frag, MsgStream& /*log*/) const
255{
256
257
258/* FIXME, exception?
259 EventFormat::Error error;
260 if (!frag->is_valid (&error)) {
261 report_error (error, log);
262 return false;
263 }
264 return true;
265*/
266
267 bool ret=false;
268 try {
269 ret=frag->check();
270 }
271 //catch ( .... ) {
272 catch (eformat::Issue& ex) {
273 msg(MSG::WARNING) << "Exception while checking eformat fragment validity: " << ex.what() << endmsg;
274 ret=false;
275 }
276 return ret;
277
278}
279
280/*
281inline void LArRodDecoder::report_error (const ers::Issue& error, MsgStream& log)
282{ log << MSG::FATAL << "Error reading bytestream event: " << error.what() << endmsg;
283}
284*/
285
286// fillCollection for HLT without automatic BS Cnv
287// default values
288static uint16_t rMV=99;
289static uint32_t rBT=99;
291 const uint32_t* p, uint32_t n,
292 LArCellCollection& coll,
293 LArRodBlockStructure*& providedRodBlockStructure, uint16_t& rodMinorVersion = rMV , uint32_t& robBlockType = rBT ) const
294{
295 LArCell *collElem=0; //Pointer to a new element to be added to the collection
296 uint32_t error = 0;
297
298#ifndef NDEBUG
299 ATH_MSG_VERBOSE("Prepare LArRodBlockStructure. Got a fragment of size " << n);
300#endif
301/* if (n<2) //Avoid segmentation fault
302 {(*m_log) << MSG::WARNING << "Got empty Rod Fragment!" << endmsg;
303 return;
304 }
305*/
306 const uint32_t blocksize=p[0]; //First word contains block size
307 if (blocksize>n) {
308 msg(MSG::ERROR) << "Got truncated ROD Fragment!" << endmsg;
309 // First Bit is truncated (see also below)
310 error|= 0x1;
311 return error;
312 }
313
314 //Get version and blocktype form header
315 eformat::helper::Version ver(robFrag.rod_version());
316 const uint16_t rMV_present=ver.minor_version();
317 const uint32_t rBT_present=robFrag.rod_detev_type()&0xff;
318
319 LArRodBlockStructure* BlStruct(nullptr);
320 if ( !providedRodBlockStructure || (rodMinorVersion!=rMV_present) || (robBlockType!=rBT_present) ){
321 BlStruct = prepareBlockStructure1 (rMV_present, rBT_present);
322 if (!BlStruct) {
323 // Second Bit is block empty or unknown
324 error|= 0x2;
325 return error;
326 }
327 providedRodBlockStructure = BlStruct;
328 rodMinorVersion = rMV_present;
329 robBlockType = rBT_present;
330 } else BlStruct = providedRodBlockStructure;
331
332 BlStruct->setFragment(p,n);
333 for(LArCellCollection::iterator ii=coll.begin();ii!=coll.end();++ii)
334 (*ii)->setEnergyFast(0.0);
335
336 int32_t energy(0);
337 int32_t time;
338 int32_t quality;
339 uint32_t gain;
340 CaloGain::CaloGain calogain;
341 int fcNb;
342 int nfeb;
343 calogain=CaloGain::LARNGAIN;
344 if(!BlStruct->setGain(calogain)){
345 ATH_MSG_DEBUG("Setting the Gain Problem");
346 }
347
348 int feb_number=0;
349 do //Loop over FEB's
350 {
351 HWIdentifier fId(BlStruct->getFEBID());
352 if (!(fId.get_identifier32().get_compact())) {
353#ifndef NDEBUG
354 ATH_MSG_DEBUG("Bad FebID=0x"<< std::hex << BlStruct->getFEBID() << std::dec << " found for this FEB, skipping it!");
355#endif
356 // Third Bit is FEB ID issue (disabled - use 0x20 instead)
357 //error|= 0x4;
358 continue;
359 }
360 // RL 05.11.2007 checksum
361 if(m_CheckSum) {
362 uint32_t onsum = BlStruct->onlineCheckSum();
363 uint32_t offsum = BlStruct->offlineCheckSum();
364 if(onsum!=offsum) {
365 msg(MSG::WARNING) << "Checksum error:" << endmsg;
366 msg(MSG::WARNING) << " online checksum = 0x" << MSG::hex << onsum << endmsg;
367 msg(MSG::WARNING) << " offline checksum = 0x" << MSG::hex << offsum << MSG::dec << endmsg;
368 // Fourth Bit CheckSum issue (maybe disabled!)
369 error|= 0x8;
370 continue;
371 }
372 }
373 feb_number++;
374
375 if ( BlStruct->hasPhysicsBlock() ) {
376 if ( fId == m_febIdHLT ) nfeb = 128; // This is the second feb
377 else nfeb = 0;
378 int NthisFebChannel=128 ; // m_onlineHelper->channelInSlotMax(fId);
379 uint16_t iquality;
380 uint16_t iprovenance;
381 while (BlStruct->getNextEnergy(fcNb,energy,time,quality,gain)) {
382 if (fcNb>=NthisFebChannel) continue;
383 collElem = coll[fcNb+nfeb];
384 iprovenance=0x1000; // data comes from DSP computation
385 iquality=0;
386 if ( quality>=0 ) { iprovenance|= 0x2000; iquality=(quality& 0xffff);}
387 // time converted to ns
388 collElem->set(energy, time*1e-3, iquality, iprovenance, (CaloGain::CaloGain)gain);
389 //setCellEnergy(collElem,energy, time, quality, (CaloGain::CaloGain)gain);
390 }
391 continue;
392 }
393 }
394 while (BlStruct->nextFEB()); //Get NextFeb
395 // Error meaning data corruption. Maybe in any FEB
396 if ( BlStruct->report_error() ) error |= 0x1;
397 // error of uncompatible number of cells is bit 5
398 unsigned int collection_size = coll.size();
399 if ( feb_number== 0 && collection_size>0 ) error |= 0x20;
400 if ( feb_number== 1 && collection_size !=128 ) error |= 0x20;
401 if ( feb_number== 2 && collection_size !=256 ) error |= 0x20;
402 return error;
403}
404
406 LArCell* element, int energy, int time,
407 int quality, CaloGain::CaloGain gain) const
408{
409 // Set energy, time, quality and hardware gain
410 element->set((float)energy, (float)time, (double)quality, gain);
411}
412
414 LArCellCollection& coll, LArFebEnergy& febene) const
415 {
416 coll.addfebenergy(febene);
417 }
418
419#endif
420
#define endmsg
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Maintain a set of objects, one per slot.
Property holding a SG store/key/clid from which a ReadHandle is made.
Define macros for attributes used to control the static checker.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
MsgStream & msg() const
void set(const CaloDetDescrElement *caloDDE, const Identifier &ID)
Fast method to change the identity of a cell.
Definition CaloCell.h:511
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in 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.
Container class for LArAccumulatedDigit.
Container class for LArCalibDigit.
Container Class for LArCell in a ROB used by EF.
void addfebenergy(LArFebEnergy &larfebenergy)
set the feb energy
Data object for LAr calorimeter readout cell.
Definition LArCell.h:53
Container class for LArDigit.
Holds partial energy sums Ex,Ey,Ez for each Feb.
Container class for LArFebHeader.
Container for LArRawChannel (IDC using LArRawChannelCollection)
bool setFragment(const uint32_t *p, uint32_t n)
virtual uint32_t hasPhysicsBlock() const
virtual int getNextEnergy(int &channelNumber, int32_t &energy, int32_t &time, int32_t &quality, uint32_t &gain)
bool report_error(void) const
virtual int setGain(const int GainValue)
virtual uint32_t offlineCheckSum() const
virtual uint32_t onlineCheckSum() const
std::vector< unsigned int > m_vFinalPreselection
uint32_t m_StatusNMask
virtual ~LArRodDecoder()
Destructor.
unsigned int m_febIdHLT
std::vector< std::string > m_LArCellCorrNames
LArRodBlockStructure * prepareBlockStructure1(const uint16_t rodMinorVersion, const uint32_t robBlockType) const
SG::SlotSpecificObj< std::vector< std::unique_ptr< LArRodBlockStructure > > > m_blstructs ATLAS_THREAD_SAFE
std::vector< int > m_vFTPreselection
const LArOnlineID * m_onlineHelper
std::vector< unsigned int > m_IgnoreCheckFEBs
unsigned int m_febId1
std::unique_ptr< LArRodBlockStructure > makeBlockStructure(unsigned int rodBlockType, unsigned int rodMinorVersion) const
SG::ReadHandleKey< xAOD::EventInfo > m_evt
static const InterfaceID & interfaceID()
float m_LArCellEthreshold
virtual StatusCode initialize ATLAS_NOT_THREAD_SAFE() override
void setCellEnergy(LArCell *element, int energy, int time, int quality, CaloGain::CaloGain gain) const
std::vector< const CaloCellCorrection * > m_LArCellCorrTools
unsigned short m_requiredPhysicsNSamples
std::vector< int > m_vBEPreselection
void fillCollection(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment &robFrag, const uint32_t *p, uint32_t n, LArRawChannelContainer &coll, const CaloGain::CaloGain gain) const
unsigned int m_febId2
LArRodBlockStructure * prepareBlockStructure(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment &robFrag, const uint32_t *p, uint32_t n, const CaloGain::CaloGain RequestedGain) const
void setsecfeb(HWIdentifier feb)
uint32_t m_StatusMask
uint32_t fillCollectionHLT(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment &robFrag, const uint32_t *p, uint32_t n, LArCellCollection &coll, LArRodBlockStructure *&providedRodBlockStructure, uint16_t &rodMinorVersion, uint32_t &robBlockType) const
std::vector< int > m_vPosNegPreselection
LArRodDecoder(const std::string &type, const std::string &name, const IInterface *parent)
Constructor Standard AlgTool constructor.
void writeFebInfo(LArCellCollection &m_coll, LArFebEnergy &febene) const
bool check_valid(const T *frag, MsgStream &log) const
Property holding a SG store/key/clid from which a ReadHandle is made.
Maintain a set of objects, one per slot.
@ LARNGAIN
Definition CaloGain.h:19
eformat::ROBFragment< PointerType > ROBFragment
Definition RawEvent.h:27
void initialize()