7#include "GaudiKernel/TypeNameString.h"
8#include "GaudiKernel/MsgStream.h"
9#include "GaudiKernel/Bootstrap.h"
10#include "GaudiKernel/ISvcLocator.h"
11#include "GaudiKernel/IToolSvc.h"
38 (
"LArRodDecoder", 1, 0);
46 declareInterface< LArRodDecoder >(
this );
78 m_StatusNMask = !m_StatusMask;
81 StatusCode
sc = detStore()->retrieve(m_onlineHelper,
"LArOnlineID");
83 msg(MSG::ERROR) <<
"Could not get LArOnlineID helper !" <<
endmsg;
89 std::vector<std::string>::const_iterator it = m_LArCellCorrNames.begin();
90 std::vector<std::string>::const_iterator it_end = m_LArCellCorrNames.end();
91 for(; it!=it_end;++it)
94 Gaudi::Utils::TypeNameString li(*it);
95 if((toolSvc()->retrieveTool(li.type(), li.name(), tool)).isFailure() )
96 {
msg(MSG::ERROR) <<
" Can't get AlgTool for CaloCellCorrection " <<
endmsg;
97 return StatusCode::FAILURE;
102 {
msg(MSG::ERROR) <<
" Can't d-cast to CaloCellCorrection* " <<
endmsg;
103 return StatusCode::FAILURE;
105 m_LArCellCorrTools.push_back(corr);
109 if (m_vBEPreselection.size() && m_vPosNegPreselection.size() && m_vFTPreselection.size()) {
111 for (
const unsigned BE : m_vBEPreselection) {
112 for (
const unsigned PN : m_vPosNegPreselection) {
113 for (
const unsigned FT : m_vFTPreselection) {
114 HWIdentifier finalFTId=m_onlineHelper->feedthrough_Id(BE,PN,FT);
116 ATH_MSG_INFO(
"Adding feedthrough Barrel/Endcap=" << BE <<
" pos/neg=" << PN <<
" FT=" << FT
117 <<
" (0x" << std::hex << finalFTId32 << std::dec <<
")");
118 m_vFinalPreselection.push_back(finalFTId32);
122 std::sort(m_vFinalPreselection.begin(),m_vFinalPreselection.end());
125 if (m_vBEPreselection.size() || m_vPosNegPreselection.size() || m_vFTPreselection.size()) {
126 msg(MSG::ERROR) <<
"Feedthrough preselection: jobOption inconsistency! "<<
endmsg;
127 msg(MSG::ERROR) <<
"Need to set all three jobOptions BEPreselection PNPreselecton and FTPreselection" <<
endmsg;
128 return StatusCode::FAILURE;
144 std::vector<short> samples;
146 if (!BlStruct)
return;
152 msg(MSG::WARNING) <<
"Invalid FEB identifer 0x" << std::hex << fId32 << std::dec <<
". Skipping" <<
endmsg;
170 ATH_MSG_DEBUG(
"No Raw Data for this FEB - NULL event for FEBID 0x"<< std::hex << BlStruct->
getFEBID() << std::dec);
178 for(; it_feb!=it_feb_end;++it_feb)
186 msg(MSG::WARNING) <<
"RodStatus&0x" << std::hex <<
m_StatusNMask <<
" indicates corrupt data for FEB "<< std::hex << fId32 << std::dec <<
". Ignored." <<
endmsg;
195 msg(MSG::WARNING) <<
"Checksum error for FEB: " << MSG::hex << fId32 <<
endmsg;
196 msg(MSG::WARNING) <<
" online checksum = " << MSG::hex << onsum <<
endmsg;
197 msg(MSG::WARNING) <<
" offline checksum = " << MSG::hex << offsum << MSG::dec <<
endmsg;
203 const unsigned int ftId=
m_onlineHelper->feedthrough_Id(fId).get_identifier32().get_compact();
205 ATH_MSG_DEBUG(
"Feedthrough with id 0x" << MSG::hex << ftId << MSG::dec <<
" not in preselection. Ignored.");
211 {
if (fcNb>=NthisFebChannel)
213 if (samples.size()==0)
continue;
216 dg =
new LArDigit(cId, calogain, std::move(samples));
238 if (!BlStruct)
return;
244 msg(MSG::WARNING) <<
"Invalid FEB identifer " << std::hex << fId32 << std::dec <<
". Skipping" <<
endmsg;
260 ATH_MSG_DEBUG(
"No Physics Data for this FEB - NULL event for FEBID 0x" << std::hex << BlStruct->
getFEBID() << std::dec);
268 for(; it_feb!=it_feb_end;++it_feb)
276 msg(MSG::WARNING) <<
"RodStatus&0x" << std::hex <<
m_StatusNMask <<
" indicates corrupt data for FEB "<< std::hex << fId32 << std::dec <<
". Ignored." <<
endmsg;
286 msg(MSG::WARNING) <<
"Checksum error:" <<
endmsg;
287 msg(MSG::WARNING) <<
" online checksum = " << MSG::hex << onsum <<
endmsg;
288 msg(MSG::WARNING) <<
" offline checksum = " << MSG::hex << offsum <<
endmsg;
294 int ftId=
m_onlineHelper->feedthrough_Id(fId).get_identifier32().get_compact();
296 ATH_MSG_DEBUG(
"Feedthrough with id " << std::hex << ftId << std::dec <<
" not in preselection. Ignored.");
301 while (BlStruct->
getNextEnergy(fcNb,energy,time,quality,gain)) {
302 if (fcNb>=NthisFebChannel)
305 uint16_t iquality = 0;
306 uint16_t iprovenance = 0x1000;
308 iprovenance |= 0x2000;
309 iquality = (quality & 0xFFFF);
312 coll.push_back(chan);
334 std::vector<short> samples;
336 ATH_MSG_VERBOSE(
"FillCollection for LArCalibDigitContainer is called.");
338 if (!BlStruct)
return;
347 ATH_MSG_DEBUG(
"No Raw Data for this FEB - NULL event for FEBID " << std::hex << BlStruct->
getFEBID());
354 ATH_MSG_DEBUG(
"Bad FebID=0x"<< std::hex << BlStruct->
getFEBID() <<
" found for this FEB, skipping it!");
361 for(; it_feb!=it_feb_end;++it_feb)
369 msg(MSG::WARNING) <<
"RodStatus&0x" << std::hex <<
m_StatusNMask <<
" indicates corrupt data for FEB "<< std::hex << fId32 << std::dec <<
". Ignored." <<
endmsg;
378 msg(MSG::WARNING) <<
"Checksum error:" <<
endmsg;
379 msg(MSG::WARNING) <<
" online checksum = " << MSG::hex << onsum <<
endmsg;
380 msg(MSG::WARNING) <<
" offline checksum = " << MSG::hex << offsum <<
endmsg;
396 unsigned int ftId=
m_onlineHelper->feedthrough_Id(fId).get_identifier32().get_compact();
398 ATH_MSG_DEBUG(
"Feedthrough with id 0x" << std::hex << ftId << std::dec <<
" not in preselection. Ignored.");
404 {
if (fcNb>=NthisFebChannel)
406 if (samples.size()==0)
continue;
419 ATH_MSG_VERBOSE(
"Not LArCalibDigit data block found. Building it using DB values");
422 StatusCode
sc=
detStore()->retrieve(calibParams);
424 {
msg(MSG::ERROR) <<
"Cannot load LArCalibParams from DetStore!" <<
endmsg;
429 if (!evt.isValid()) {
433 const unsigned eventNb=evt->eventNumber();
434 const std::vector<HWIdentifier>* calibChannelIDs;
439 ATH_MSG_DEBUG(
"No Raw Data for this FEB - NULL event for FEBID 0x" << std::hex << BlStruct->
getFEBID() << std::dec);
446 ATH_MSG_DEBUG(
"Bad FebID=0x" << std::hex << BlStruct->
getFEBID() <<
" found for this FEB, skipping it!" << std::dec);
466 while ( (!onOffIdMapping.
isOnlineConnected(cId) || calibChannelIDs->size()==0) && fcNb<128);
468 if ( calibChannelIDs->size()==0 ) {
469 msg(MSG::ERROR) <<
"Cannot get calibration Channel ID for FEB " << std::hex << fId32 << std::dec <<
endmsg;
476 std::vector<HWIdentifier>::const_iterator csl_it=calibChannelIDs->begin();
478 dac=calibParams->
DAC(eventNb,*csl_it);
490 if (fcNb>=NthisFebChannel)
continue;
491 if (samples.size()==0)
continue;
498 if (calibChannelIDs->size()!=0) {
499 csl_it=calibChannelIDs->begin();
500 ispulsed=calibParams->
isPulsed(eventNb,*csl_it);
526 uint32_t gain, ntrigger;
527 int dac,
delay, NStep=-1, StepIndex=-1;
529 uint16_t ispulsed_int;
531 uint32_t FirstGoodFEB=1;
533 std::vector< uint64_t > samplesSum;
534 std::vector< uint64_t > samples2Sum;
540 if (!BlStruct)
return;
557 ATH_MSG_DEBUG(
"Bad FebID=0x" << std::hex << BlStruct->
getFEBID() <<
" found for this FEB, skipping it!" << std::dec);
564 for(; it_feb!=it_feb_end;++it_feb)
572 msg(MSG::WARNING) <<
"RodStatus&0x" << std::hex <<
m_StatusNMask <<
" indicates corrupt data for FEB "<< std::hex << fId32 << std::dec <<
". Ignored." <<
endmsg;
581 msg(MSG::WARNING) <<
"Checksum error:" <<
endmsg;
582 msg(MSG::WARNING) <<
" online checksum = " << MSG::hex << onsum <<
endmsg;
583 msg(MSG::WARNING) <<
" offline checksum = " << MSG::hex << offsum <<
endmsg;
599 unsigned int ftId=
m_onlineHelper->feedthrough_Id(fId).get_identifier32().get_compact();
601 ATH_MSG_DEBUG(
"Feedthrough with id " << std::hex << ftId << std::dec <<
" not in preselection. Ignored.");
611 if (fcNb>=NthisFebChannel)
continue;
612 if (samplesSum.size()==0)
continue;
622 const std::vector<HWIdentifier>& calibChannelIDs = calibLineMapping.
calibSlotLine(cId);
623 if (calibChannelIDs.size()==0) {
629 for(std::vector<HWIdentifier>::const_iterator csl_it=calibChannelIDs.begin(); csl_it!=calibChannelIDs.end();++csl_it){
632 ispulsed_int=( ispulsed_int | ((uint16_t)ispulsed<<bitShift) );
637 (uint16_t)ispulsed_int, NStep, StepIndex);
652 uint32_t gain, ntrigger;
655 std::vector<uint64_t> sampleSum;
656 std::vector< uint64_t > sampleSquare;
662 if (!BlStruct)
return;
674 ATH_MSG_DEBUG(
"Bad FebID=0x" << std::hex << BlStruct->
getFEBID() <<
" found for this FEB, skipping it!" << std::dec);
681 for(; it_feb!=it_feb_end;++it_feb)
689 msg(MSG::WARNING) <<
"RodStatus&0x" << std::hex <<
m_StatusNMask <<
" indicates corrupt data for FEB "<< std::hex << fId32 << std::dec <<
". Ignored." <<
endmsg;
698 msg(MSG::WARNING) <<
"Checksum error:" <<
endmsg;
699 msg(MSG::WARNING) <<
" online checksum = " << MSG::hex << onsum <<
endmsg;
700 msg(MSG::WARNING) <<
" offline checksum = " << MSG::hex << offsum <<
endmsg;
716 unsigned int ftId=
m_onlineHelper->feedthrough_Id(fId).get_identifier32().get_compact();
718 ATH_MSG_DEBUG(
"Feedthrough with id " << std::hex << ftId << std::dec <<
" not in preselection. Ignored.");
728 if (fcNb>=NthisFebChannel)
continue;
729 if (sampleSquare.size()==0)
continue;
752 if (!BlStruct)
return;
762 msg(MSG::WARNING) <<
"Invalid FEB identifer " << std:: hex << FEBID32 << std::dec <<
". Skipping" <<
endmsg;
778 const unsigned int ftId=
m_onlineHelper->feedthrough_Id(FEBID).get_identifier32().get_compact();
780 ATH_MSG_DEBUG(
"Feedthrough with id 0x" << std::hex << ftId << std::dec <<
" not in preselection. Ignored.");
791 larFebHeader->
SetSourceId(robFrag.rod_source_id());
793 larFebHeader->
SetELVL1Id(robFrag.rod_lvl1_id());
794 larFebHeader->
SetBCId(robFrag.rod_bc_id());
800 const uint32_t status= BlStruct->
getStatus();
814 larFebHeader->
SetFebBCId(robFrag.rod_bc_id());
816 const uint16_t evtid = BlStruct->
getCtrl1(0) & 0x1f;
817 const uint16_t bcid = BlStruct->
getCtrl2(0) & 0x1fff;
821 for(
int iadc=0;iadc<16;iadc++) {
826 for(
unsigned int i = 0; i<nsample; i++ ) {
840 const unsigned MAXMINOR = 12;
841 const unsigned MAXTYPE = 10;
843 if (rodMinorVersion > MAXMINOR || robBlockType > MAXTYPE) {
844 msg(MSG::ERROR) <<
"Bad Rod block type " << robBlockType
845 <<
" / " << rodMinorVersion <<
endmsg;
848 std::vector<std::unique_ptr<LArRodBlockStructure> >& blstructs =
850 unsigned int index = robBlockType * (MAXMINOR+1) + rodMinorVersion;
851 if (blstructs.empty()) {
852 blstructs.resize ((MAXMINOR+1)*(MAXTYPE+1));
854 if (!blstructs[
index]) {
857 if (!blstructs[
index]) {
858 msg(MSG::ERROR) <<
"Bad Rod block type " << robBlockType
859 <<
" / " << rodMinorVersion <<
endmsg;
864 ATH_MSG_DEBUG(
"Found version " << rodMinorVersion <<
" of Rod block type " << robBlockType);
867 return blstructs[
index].get();
876 ATH_MSG_DEBUG(
"Prepare LArRodBlockStructure. Got a fragement of size " << n);
880 eformat::helper::Version ver(robFrag.rod_version());
881 const uint16_t rodMinorVersion=ver.minor_version();
882 const uint32_t rodBlockType=robFrag.rod_detev_type()&0xff;
890 constexpr int maxMess = 100;
891 static std::atomic<int> nMess = 1;
892 int thismess = nMess++;
893 if (thismess <= maxMess) {
894 msg(MSG::ERROR) <<
"Could not set fragment (wrong number of samples in data ?) - container will not be filled" <<
endmsg;
895 if (thismess == maxMess)
896 msg(MSG::ERROR) <<
"This message will not be repeated" <<
endmsg;
904 BlStruct->
setGain(RequestedGain);
913std::unique_ptr<LArRodBlockStructure>
915 unsigned int rodMinorVersion)
const
917 switch (rodBlockType) {
920 switch (rodMinorVersion) {
926 return std::make_unique<LArRodBlockTransparentV0<LArRodBlockHeaderTransparentV0> >();
928 return std::make_unique<LArRodBlockCalibrationV1>();
936 return std::make_unique<LArRodBlockCalibrationV3>();
944 return std::make_unique<LArRodBlockTransparentV0<LArRodBlockHeaderTransparentV0> >();
948 switch (rodMinorVersion) {
950 return std::make_unique<LArRodBlockPhysicsV0>();
952 return std::make_unique<LArRodBlockPhysicsV1>();
960 return std::make_unique<LArRodBlockPhysicsV2>();
962 return std::make_unique<LArRodBlockPhysicsV4>();
966 auto bl = std::make_unique<LArRodBlockPhysicsV5>();
974 auto bl = std::make_unique<LArRodBlockPhysicsV6>();
988 return std::make_unique<LArRodBlockPhysicsV3>();
992 switch (rodMinorVersion) {
994 return std::make_unique<LArRodBlockPhysicsV0>();
997 return std::make_unique<LArRodBlockPhysicsV2>();
1005 switch (rodMinorVersion) {
1007 return std::make_unique<LArRodBlockCalibrationV0<LArRodBlockHeaderCalibrationV0> >();
1012 return std::make_unique<LArRodBlockCalibrationV1>();
1014 return std::make_unique<LArRodBlockCalibrationV2>();
1022 return std::make_unique<LArRodBlockCalibrationV3>();
1031 return std::make_unique<LArRodBlockAccumulatedV3>();
1037 return std::unique_ptr<LArRodBlockStructure>();
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
double delay(std::size_t d)
StatusCode LArRodDecoder::initialize ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
static const InterfaceID IID_ILArRodDecoder("LArRodDecoder", 1, 0)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
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.
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.
void setDelayScale(const double scale)
set delay scale
Base class for LArDigits taken during calibration runs.
const std::vector< HWIdentifier > & calibSlotLine(const HWIdentifier id) const
unsigned Delay(const unsigned event, const HWIdentifier calibLineID) const
bool isPulsed(const unsigned event, const HWIdentifier calibLineID) const
unsigned DAC(const unsigned event, const HWIdentifier calibLineID) const
Container class for LArDigit.
Liquid Argon digit base class.
bool isOnlineConnected(const HWIdentifier &sid) const
Test whether a HWIdentifier is connected of not (inline)
Container for LArRawChannel (IDC using LArRawChannelCollection)
Liquid Argon ROD output object base class.
virtual uint16_t getCtrl1(uint32_t adc) const
bool setFragment(const uint32_t *p, uint32_t n)
virtual uint32_t hasPhysicsBlock() const
virtual uint16_t getNStep() const
virtual uint32_t hasCalibBlock() const
virtual uint16_t getDelay() const
virtual uint16_t getCtrl3(uint32_t adc) const
virtual uint16_t getResults1Size() const
virtual bool getPulsed(unsigned channelNumber) const
virtual uint16_t getDAC() const
virtual int getNextEnergy(int &channelNumber, int32_t &energy, int32_t &time, int32_t &quality, uint32_t &gain)
virtual uint16_t getRawDataSize() const
virtual uint32_t hasAccumBlock() const
virtual int getNextAccumulatedCalibDigit(int &channelNumber, std::vector< uint64_t > &SamplesSum, std::vector< uint64_t > &Samples2Sum, uint32_t &nStepTriggers, uint32_t &gain)
virtual uint32_t hasRawDataBlock() const
virtual bool canSetCalibration()
virtual uint32_t getDspCodeVersion() const
virtual uint16_t getCtrl2(uint32_t adc) const
virtual uint32_t getRadd(uint32_t adc, uint32_t sample) const
uint32_t getFEBID() const
virtual uint16_t getStepIndex() const
virtual uint16_t getNTrigger() const
virtual int setGain(const int GainValue)
virtual uint32_t offlineCheckSum() const
void setFirstSample(const int rearrangeFirstSample)
virtual uint16_t getNbSweetCells2() const
virtual uint32_t getNumberOfSamples() const
virtual uint32_t hasControlWords() const
virtual int getNextRawData(int &channelNumber, std::vector< short > &samples, uint32_t &gain)
virtual uint32_t getStatus() const
virtual uint16_t getResults2Size() const
virtual uint16_t getNbSweetCells1() const
virtual int32_t getDspEventCounter() const
virtual uint32_t onlineCheckSum() const
virtual int getNextAccumulatedDigit(int &channelNumber, std::vector< uint64_t > &SamplesSum, std::vector< uint64_t > &corr2Sum, uint32_t &gain)
std::vector< unsigned int > m_vFinalPreselection
virtual ~LArRodDecoder()
Destructor.
std::vector< std::string > m_LArCellCorrNames
LArRodBlockStructure * prepareBlockStructure1(const uint16_t rodMinorVersion, const uint32_t robBlockType) const
std::vector< int > m_vFTPreselection
const LArOnlineID * m_onlineHelper
std::vector< unsigned int > m_IgnoreCheckFEBs
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
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
LArRodBlockStructure * prepareBlockStructure(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment &robFrag, const uint32_t *p, uint32_t n, const CaloGain::CaloGain RequestedGain) const
std::vector< int > m_vPosNegPreselection
LArRodDecoder(const std::string &type, const std::string &name, const IInterface *parent)
Constructor Standard AlgTool constructor.
eformat::ROBFragment< PointerType > ROBFragment
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.