|
ATLAS Offline Software
|
Go to the documentation of this file.
10 #include "GaudiKernel/IInterface.h"
11 #include "GaudiKernel/MsgStream.h"
12 #include "GaudiKernel/StatusCode.h"
38 static const InterfaceID IID_ICpByteStreamV1Tool(
"CpByteStreamV1Tool", 1, 1);
42 return IID_ICpByteStreamV1Tool;
48 const std::string&
name,
51 m_cpmMaps(
"LVL1::CpmMappingTool/CpmMappingTool"),
52 m_errorTool(
"LVL1BS::L1CaloErrorByteStreamTool/L1CaloErrorByteStreamTool"),
53 m_channels(80), m_crates(4), m_modules(14),
54 m_subDetector(
eformat::TDAQ_CALO_CLUSTER_PROC_DAQ)
56 declareInterface<CpByteStreamV1Tool>(
this);
59 "Crate/Module/Channel to Eta/Phi/Layer mapping tool");
61 "Tool to collect errors for monitoring");
64 "Offset of CP crate numbers in bytestream");
66 "Offset of CP crate numbers in RDOs");
70 "ROB fragment source identifiers");
74 "Format version number in sub-block header");
76 "Format identifier (0-1) in sub-block header");
78 "The number of S-Links per crate");
80 "The number of slices in the simulation");
82 "If >0, the number of slices in bytestream");
84 "Minimum crate number, allows partial output");
86 "Maximum crate number, allows partial output");
107 return StatusCode::SUCCESS;
113 const std::string& sgKey,
124 const std::string& sgKey,
135 const std::string& sgKey,
183 int timeslicesNew = 1;
194 if (
mod%modulesPerSlink == 0) {
195 const int daqOrRoi = 0;
196 const int slink = (
m_slinks == 2) ? 2*(
mod/modulesPerSlink)
197 :
mod/modulesPerSlink;
199 msg() <<
"Treating crate " << hwCrate
200 <<
" slink " << slink <<
endmsg;
210 msg(MSG::ERROR) <<
"Inconsistent number of slices or "
211 <<
"triggered slice offsets in data for crate "
212 << hwCrate <<
" slink " << slink <<
endmsg;
213 return StatusCode::FAILURE;
220 <<
"Slices/offset: " << timeslices <<
" " << trigCpm;
221 if (timeslices != timeslicesNew) {
222 msg() <<
" modified to " << timeslicesNew <<
" " << trigCpmNew;
227 userHeader.
setCpm(trigCpmNew);
231 theROD->push_back(userHeader.
header());
243 hwCrate,
module, timeslicesNew);
245 if (neutralFormat)
break;
256 const unsigned int key = towerKey.
ttKey(phi, eta);
259 std::vector<int> emData;
260 std::vector<int> hadData;
261 std::vector<int> emError;
262 std::vector<int> hadError;
276 const int index = ( neutralFormat ) ? 0 :
slice;
279 hadData[
slice], emErr, hadErr);
289 std::vector<unsigned int> vec0;
290 std::vector<unsigned int> vec1;
294 const int index = ( neutralFormat ) ? 0 :
slice;
305 if ( !subBlock->
pack()) {
306 msg(MSG::ERROR) <<
"CPM sub-block packing failed" <<
endmsg;
307 return StatusCode::FAILURE;
310 msg() <<
"CPM sub-block data words: "
313 subBlock->
write(theROD);
339 if (neutralFormat)
break;
345 for (
int dataID = 1; dataID < maxDataID; ++dataID) {
372 std::vector<unsigned int> hits0;
373 std::vector<unsigned int> hits1;
374 std::vector<int> err0;
375 std::vector<int> err1;
383 const int index = ( neutralFormat ) ? 0 :
slice;
387 subBlock = cmmHit1Blocks[
index];
394 for (;
cos != cmmHit0Blocks.
end(); ++
cos) {
396 if ( !subBlock->
pack()) {
397 msg(MSG::ERROR) <<
"CMM-Cp sub-block packing failed" <<
endmsg;
398 return StatusCode::FAILURE;
401 msg() <<
"CMM-Cp sub-block data words: "
404 subBlock->
write(theROD);
407 for (;
cos != cmmHit1Blocks.
end(); ++
cos) {
409 if ( !subBlock->
pack()) {
410 msg(MSG::ERROR) <<
"CMM-Cp sub-block packing failed" <<
endmsg;
411 return StatusCode::FAILURE;
414 msg() <<
"CMM-Cp sub-block data words: "
417 subBlock->
write(theROD);
421 return StatusCode::SUCCESS;
438 for (
int slink = 0; slink < maxSlinks; ++slink)
440 const int daqOrRoi = 0;
460 const std::string& sgKey,
466 const static std::string
flag(
"Overlap");
467 const std::string::size_type
pos = sgKey.find(
flag);
469 (
pos == std::string::npos ||
pos != sgKey.length() -
flag.length()) ? 0 : 1;
480 std::set<uint32_t> dupCheck;
483 for (; rob != robEnd; ++rob) {
487 msg() <<
"Treating ROB fragment " << robCount <<
endmsg;
492 uint32_t robid = (*rob)->source_id();
493 if ((*rob)->nstatus() > 0) {
495 (*rob)->status(robData);
498 if (
debug)
msg() <<
"ROB status error - skipping fragment" <<
endmsg;
505 if (!dupCheck.insert(robid).second) {
516 (*rob)->rod_data(payloadBeg);
517 payloadEnd = payloadBeg + (*rob)->rod_ndata();
525 const uint32_t sourceID = (*rob)->rod_source_id();
534 msg() <<
"Wrong source identifier in data: ROD "
535 << MSG::hex << sourceID <<
" ROB " << robid
542 const int minorVersion = (*rob)->rod_version() & 0xffff;
549 msg() <<
"Treating crate " << rodCrate
561 const int headerWords = userHeader.
words();
562 if (headerWords != 1) {
564 if (
debug)
msg() <<
"Unexpected number of user header words: "
568 for (
int i = 0;
i < headerWords; ++
i) ++
payload;
570 int trigCpm = userHeader.
cpm();
571 int trigCmm = userHeader.
cpCmm();
573 msg() <<
"Minor format version number: " << MSG::hex
574 << minorVersion << MSG::dec <<
endmsg
575 <<
"CPM triggered slice offset: " << trigCpm <<
endmsg
576 <<
"CMM triggered slice offset: " << trigCmm <<
endmsg;
578 if (trigCpm != trigCmm) {
579 const int newTrig = (trigCpm > trigCmm) ? trigCpm : trigCmm;
582 if (
debug)
msg() <<
"Changed both offsets to " << newTrig <<
endmsg;
588 while (
payload != payloadEnd) {
602 cmmCpSubBlock.
clear();
604 if (cmmCpSubBlock.
crate() != rodCrate) {
605 if (
debug)
msg() <<
"Inconsistent crate number in ROD source ID"
627 if (cpmSubBlock.
crate() != rodCrate) {
628 if (
debug)
msg() <<
"Inconsistent crate number in ROD source ID"
646 return StatusCode::SUCCESS;
658 const int hwCrate = subBlock->
crate();
662 const int timeslices = subBlock->
timeslices();
663 const int sliceNum = subBlock->
slice();
665 msg() <<
"CMM-CP: Crate " << hwCrate
667 <<
" Firmware " << firmware
668 <<
" Summing " << summing
669 <<
" Total slices " << timeslices
670 <<
" Slice " << sliceNum <<
endmsg;
672 if (timeslices <= trigCmm) {
673 if (
debug)
msg() <<
"Triggered CMM slice from header "
674 <<
"inconsistent with number of slices: "
675 << trigCmm <<
", " << timeslices <<
endmsg;
679 if (timeslices <= sliceNum) {
680 if (
debug)
msg() <<
"Total slices inconsistent with slice number: "
681 << timeslices <<
", " << sliceNum <<
endmsg;
689 msg() <<
"CMM-CP sub-block unpacking failed: " << errMsg <<
endmsg;
702 const int sliceBeg = ( neutralFormat ) ? 0 : sliceNum;
703 const int sliceEnd = ( neutralFormat ) ? timeslices : sliceNum + 1;
742 ld.hitsVec0.assign(timeslices, 0);
743 ld.hitsVec1.assign(timeslices, 0);
744 ld.errVec0.assign(timeslices, 0);
745 ld.errVec1.assign(timeslices, 0);
754 std::make_unique<LVL1::CMMCPHits>(swCrate, dataID,
ld.hitsVec0,
ld.hitsVec1,
755 ld.errVec0,
ld.errVec1, trigCmm);
756 const int key = crate*100 + dataID;
757 data.m_cmmHitsMap.insert(std::make_pair(
key, chp.get()));
758 data.m_cmmHitCollection->push_back(std::move(chp));
760 ld.hitsVec0 =
ch->HitsVec0();
761 ld.hitsVec1 =
ch->HitsVec1();
762 ld.errVec0 =
ch->ErrorVec0();
763 ld.errVec1 =
ch->ErrorVec1();
764 const int nsl =
ld.hitsVec0.size();
765 if (timeslices != nsl) {
766 if (
debug)
msg() <<
"Inconsistent number of slices in sub-blocks"
785 ch->addHits(
ld.hitsVec0,
ld.hitsVec1,
ld.errVec0,
ld.errVec1);
804 const int hwCrate = subBlock->
crate();
806 const int timeslices = subBlock->
timeslices();
807 const int sliceNum = subBlock->
slice();
809 msg() <<
"CPM: Crate " << hwCrate
811 <<
" Total slices " << timeslices
812 <<
" Slice " << sliceNum <<
endmsg;
819 if (timeslices <= trigCpm) {
820 if (
debug)
msg() <<
"Triggered CPM slice from header "
821 <<
"inconsistent with number of slices: "
822 << trigCpm <<
", " << timeslices <<
endmsg;
826 if (timeslices <= sliceNum) {
827 if (
debug)
msg() <<
"Total slices inconsistent with slice number: "
828 << timeslices <<
", " << sliceNum <<
endmsg;
836 msg() <<
"CPM sub-block unpacking failed: " << errMsg <<
endmsg;
847 const int ssError = dErr.
error();
850 const int sliceBeg = ( neutralFormat ) ? 0 : sliceNum;
851 const int sliceEnd = ( neutralFormat ) ? timeslices : sliceNum + 1;
865 int emErr1 = ssError;
870 emErr1 = emErrBits.
error();
872 int hadErr1 = ssError;
877 hadErr1 = hadErrBits.
error();
879 if (em || had || emErr1 || hadErr1) {
885 const unsigned int key =
ld.towerKey.ttKey(phi, eta);
888 ld.emVec.assign(timeslices, 0);
889 ld.hadVec.assign(timeslices, 0);
890 ld.emErrVec.assign(timeslices, 0);
891 ld.hadErrVec.assign(timeslices, 0);
897 std::make_unique<LVL1::CPMTower>(phi, eta,
ld.emVec,
ld.emErrVec,
898 ld.hadVec,
ld.hadErrVec, trigCpm);
899 tdata.
m_ttMap.insert(std::make_pair(
key, ttp.get()));
902 ld.emVec =
tt->emEnergyVec();
903 ld.hadVec =
tt->hadEnergyVec();
904 ld.emErrVec =
tt->emErrorVec();
905 ld.hadErrVec =
tt->hadErrorVec();
906 const int nsl =
ld.emVec.size();
907 if (timeslices != nsl) {
909 msg() <<
"Inconsistent number of slices in sub-blocks"
917 if (
debug)
msg() <<
"Duplicate data for slice "
926 tt->fill(
ld.emVec,
ld.emErrVec,
ld.hadVec,
ld.hadErrVec, trigCpm);
929 }
else if (
verbose && (em || had || emErr || hadErr)) {
930 msg(
MSG::VERBOSE) <<
"Non-zero data but no channel mapping for channel "
945 const unsigned int hits0 = subBlock->
hits0(
slice);
946 const unsigned int hits1 = subBlock->
hits1(
slice);
947 if (hits0 || hits1) {
950 ld.hitsVec0.assign(timeslices, 0);
951 ld.hitsVec1.assign(timeslices, 0);
955 std::make_unique<LVL1::CPMHits>(swCrate,
module,
ld.hitsVec0,
ld.hitsVec1, trigCpm);
959 ld.hitsVec0 =
ch->HitsVec0();
960 ld.hitsVec1 =
ch->HitsVec1();
961 const int nsl =
ld.hitsVec0.size();
962 if (timeslices != nsl) {
963 if (
debug)
msg() <<
"Inconsistent number of slices in sub-blocks"
975 ch->addHits(
ld.hitsVec0,
ld.hitsVec1);
994 ConstCpmTowerMap::const_iterator mapIter = ttMap.find(
key);
995 if (mapIter != ttMap.end())
return mapIter->second;
1000 const unsigned int key)
const
1002 CpmTowerMap::const_iterator mapIter =
data.m_ttMap.find(
key);
1003 if (mapIter !=
data.m_ttMap.end())
return mapIter->second;
1014 ConstCpmHitsMap::const_iterator mapIter =
1016 if (mapIter != hitsMap.end())
return mapIter->second;
1021 const int crate,
const int module)
const
1023 CpmHitsMap::const_iterator mapIter =
1025 if (mapIter !=
data.m_hitsMap.end())
return mapIter->second;
1036 ConstCmmCpHitsMap::const_iterator mapIter = cmmHitsMap.find(crate*100 + dataID);
1037 if (mapIter != cmmHitsMap.end())
return mapIter->second;
1043 const int dataID)
const
1045 CmmCpHitsMap::const_iterator mapIter =
data.m_cmmHitsMap.find(crate*100 + dataID);
1046 if (mapIter !=
data.m_cmmHitsMap.end())
return mapIter->second;
1060 for (;
pos != pose; ++
pos) {
1062 const unsigned int key = towerKey.
ttKey(
tt->phi(),
tt->eta());
1063 ttMap.insert(std::make_pair(
key,
tt));
1071 const hitCollection,
1075 if (hitCollection) {
1078 for (;
pos != pose; ++
pos) {
1082 hitsMap.insert(std::make_pair(
key,
hits));
1090 const hitCollection,
1094 if (hitCollection) {
1097 for (;
pos != pose; ++
pos) {
1100 const int key = crate*100 +
hits->dataID();
1101 cmmHitsMap.insert(std::make_pair(
key,
hits));
1109 const int modulesPerSlink,
1125 const unsigned int key = towerKey.
ttKey(phi, eta);
1127 if ( !
tt )
continue;
1128 const int numdat = 4;
1129 std::vector<int> sums(numdat);
1130 std::vector<int> sizes(numdat);
1132 (
tt->emEnergyVec()).end(), 0);
1134 (
tt->hadEnergyVec()).end(), 0);
1136 (
tt->emErrorVec()).end(), 0);
1138 (
tt->hadErrorVec()).end(), 0);
1139 sizes[0] = (
tt->emEnergyVec()).
size();
1140 sizes[1] = (
tt->hadEnergyVec()).
size();
1141 sizes[2] = (
tt->emErrorVec()).
size();
1142 sizes[3] = (
tt->hadErrorVec()).
size();
1143 const int peak =
tt->peak();
1144 for (
int i = 0;
i < numdat; ++
i) {
1145 if (sums[
i] == 0)
continue;
1149 }
else if (
slices != sizes[
i] || trigC != peak)
return false;
1154 const int numdat = 2;
1155 std::vector<unsigned int> sums(numdat);
1156 std::vector<int> sizes(numdat);
1158 (
hits->HitsVec0()).end(), 0);
1160 (
hits->HitsVec1()).end(), 0);
1161 sizes[0] = (
hits->HitsVec0()).
size();
1162 sizes[1] = (
hits->HitsVec1()).
size();
1163 const int peak =
hits->peak();
1164 for (
int i = 0;
i < numdat; ++
i) {
1165 if (sums[
i] == 0)
continue;
1169 }
else if (
slices != sizes[
i] || trigC != peak)
return false;
1176 for (
int dataID = 0; dataID < maxDataID; ++dataID) {
1177 const int numdat = 4;
1178 std::vector<unsigned int> sums(numdat);
1179 std::vector<int> sizes(numdat);
1183 (
hits->HitsVec0()).end(), 0);
1185 (
hits->HitsVec1()).end(), 0);
1187 (
hits->ErrorVec0()).end(), 0);
1189 (
hits->ErrorVec1()).end(), 0);
1190 sizes[0] = (
hits->HitsVec0()).
size();
1191 sizes[1] = (
hits->HitsVec1()).
size();
1192 sizes[2] = (
hits->ErrorVec0()).
size();
1193 sizes[3] = (
hits->ErrorVec1()).
size();
1194 const int peak =
hits->peak();
1195 for (
int i = 0;
i < numdat; ++
i) {
1196 if (sums[
i] == 0)
continue;
1200 }
else if (
slices != sizes[
i] || trigC != peak)
return false;
static CmmFirmwareCode cmmType(uint32_t word)
CMM differentiation (CMM_CP, CMM_JET, or CMM_ENERGY)
uint16_t minorVersionPreLS1() const
Return last ROD header minor version for pre-LS1 data.
char data[hepevt_bytes_allocation_ATLAS]
int slink(uint32_t code) const
Return slink from unpacked moduleID.
Const iterator class for DataVector/DataList.
int unpackErrorCode() const
Return the unpacking error code.
bool unpack()
Unpack data.
Template class for assembling a full atlas raw event from subfragments.
Sub-Block class for CMM-CP data.
static int peak(int oldPeak, int oldSlices, int newSlices)
Return new triggered slice offset.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
unsigned int hits(int slice, int source) const
Return hit counts for given CPM or source ID.
void setHits(int slice, int source, unsigned int hits, int error)
Store hit counts for given CPM or source ID.
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
void setCmmHeader(int version, int format, int slice, int crate, int summing, int firmware, int position, int timeslices)
Store CMM header.
static bool cmmBlock(uint32_t word)
Determine if header word corresponds to CMM.
void write(FullEventAssembler< L1CaloSrcIdMap >::RODDATA *theROD) const
Output complete packed sub-block to ROD vector.
bool msgLvl(const MSG::Level lvl) const
uint32_t getRobID(uint32_t rod_id) const
Make a ROB Source ID from a ROD source ID.
The CPMHits object contains the hit data produced by a given Cluster Processor Module,...
OFFLINE_FRAGMENTS_NAMESPACE::PointerType read(const OFFLINE_FRAGMENTS_NAMESPACE::PointerType beg, const OFFLINE_FRAGMENTS_NAMESPACE::PointerType end)
Input complete packed sub-block from ROD array.
void setCpmHeader(int version, int format, int slice, int crate, int module, int timeslices)
Store CPM header.
int hitsError(int slice, int source) const
Return hit error for given CPM or source ID.
unsigned int hits1(int slice) const
Return tau hit counts.
int emError(int slice, int channel) const
Return Em error for given channel.
void clear()
Clear all data.
The CPMTower class contains the TriggerTower information received by the Cluster Processor Modules.
bool unpack()
Unpack data.
static void data(const std::vector< int > &oldVec, std::vector< int > &newVec, int newSlices)
Return modified data vector<int>
(Non-const) Iterator class for DataVector/DataList.
::StatusCode StatusCode
StatusCode definition for legacy code.
Summary of CP (EM/tau) hits received by the merger modules.
void set(ErrorBit bit, int value=1)
Set an error bit or data.
int crate(uint32_t code) const
Return crate from unpacked moduleID.
Sub-Block class for CPM data.
void fillTowerData(int slice, int channel, int em, int had, int emErr, int hadErr)
Store trigger tower data.
std::vector< const ROBF * > VROBFRAG
int timeslices() const
Return number of timeslices.
unsigned int hits0(int slice) const
Return e/gamma hit counts.
Cluster Processor container for writing bytestream.
static SubBlockWordType wordType(uint32_t word)
Word identification.
int error() const
Return the full error word.
std::string unpackErrorMsg() const
Return the unpacking error message for printing.
int dataWords() const
Return number of data words.
uint32_t subStatus() const
Return Sub-status word.
int hadError(int slice, int channel) const
Return Had error for given channel.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
void clear()
Clear all data.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
eformat::SubDetector subDet(uint32_t code) const
Return sub-detector for given ID.
void setRodMinorVersion(uint16_t m)
change the ROD minor version
bool anyTowerData(int channel) const
Return true if there is tower data for given channel.
uint32_t getRodID(int crate, int slink, int daqOrRoi, eformat::SubDetector subdet) const
Make a ROD Source ID.
std::vector< uint32_t > RODDATA
ROD data as a vector of unsigned int.
int get(ErrorBit bit) const
Return an error bit or data.
virtual unsigned int ttKey(const TriggerTower &tower)
returns the key of the passed tower
int maxSlinks() const
Return the maximum possible number of slinks.
int hadData(int slice, int channel) const
Return Had data for given channel.
void setHits(int slice, unsigned int hit0, unsigned int hit1)
Store hit counts.
int daqOrRoi(uint32_t code) const
Return daqOrRoi from unpacked moduleID.
The TriggerTowerKey object provides the key for each trigger tower depending on its eta-phi coords.
RODDATA * getRodData(uint32_t id)
get a block of ROD data
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
int emData(int slice, int channel) const
Return Em data for given channel.