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"
37 static const InterfaceID IID_ILArRodDecoder
38 (
"LArRodDecoder", 1, 0);
42 m_LArCellEthreshold(-100.),
46 declareInterface< LArRodDecoder >(
this );
72 {
return IID_ILArRodDecoder; }
78 m_StatusNMask = !m_StatusMask;
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) {
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;
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;
296 ATH_MSG_DEBUG(
"Feedthrough with id " << std::hex << ftId << std::dec <<
" not in preselection. Ignored.");
302 if (fcNb>=NthisFebChannel)
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;
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");
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);
527 int dac,
delay, NStep=-1, StepIndex=-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;
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);
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;
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;
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());
814 larFebHeader->
SetFebBCId(robFrag.rod_bc_id());
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);
913 std::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>();