10#include "GaudiKernel/IInterface.h"
11#include "GaudiKernel/MsgStream.h"
12#include "GaudiKernel/StatusCode.h"
45 const std::string& name,
46 const IInterface* parent)
49 m_errorTool(
"LVL1BS::L1CaloErrorByteStreamTool/L1CaloErrorByteStreamTool"),
53 declareInterface<JepRoiByteStreamV2Tool>(
this);
56 "Tool to collect errors for monitoring");
58 "Offset of JEP crate numbers in bytestream");
60 "Offset of JEP crate numbers in RDOs");
64 "ROB fragment source identifiers");
66 "ROB fragment source identifiers");
70 "Format version number in sub-block header");
72 "Format identifier (0-1) in sub-block header");
74 "The number of S-Links per crate");
76 "Minimum crate number, allows partial output");
78 "Maximum crate number, allows partial output");
98 return StatusCode::SUCCESS;
105 return StatusCode::SUCCESS;
111 const EventContext& ctx,
112 const std::string& sgKey,
115 const std::vector<uint32_t>& vID(
sourceIDs(sgKey));
119 ATH_MSG_DEBUG(
"Number of ROB fragments:" << robFrags.size());
120 return convert(robFrags, collection);
127 return convertBs(robFrags, jeCollection,
nullptr);
133 const EventContext& ctx,
134 const std::string& sgKey,
137 const std::vector<uint32_t>& vID(
sourceIDs(sgKey));
141 ATH_MSG_DEBUG(
"Number of ROB fragments:" << robFrags.size());
142 return convert(robFrags, cmCollection);
149 return convertBs(robFrags,
nullptr, cmCollection);
163 "JepRoiByteStreamV2") );
164 const uint16_t minorVersion =
m_srcIdMap.minorVersion();
181 JemRoiMap::const_iterator mapIter = roiMap.begin();
182 JemRoiMap::const_iterator mapIterEnd = roiMap.end();
196 for (
int module = 0;
module < m_modules; ++module) {
200 if (module % modulesPerSlink == 0) {
201 const int daqOrRoi = 1;
202 const int slink =
module / modulesPerSlink;
204 msg() <<
"Treating crate " << hwCrate
205 <<
" slink " << slink <<
endmsg
209 const uint32_t rodIdJem =
m_srcIdMap.getRodID(hwCrate, slink, daqOrRoi,
214 theROD->push_back(userHeader.
header());
217 if (
debug)
msg() <<
"JEM Module " <<
module << endmsg;
229 for (; mapIter != mapIterEnd; ++mapIter) {
231 if (roi->
crate() < crate)
continue;
232 if (roi->
crate() > crate)
break;
233 if (roi->
jem() < module)
continue;
234 if (roi->
jem() > module)
break;
236 if (neutralFormat) subBlock.
fillRoi(*roi);
237 else theROD->push_back(roi->
roiWord());
244 if ( !subBlock.
pack()) {
245 msg(MSG::ERROR) <<
"JEM RoI sub-block packing failed" <<
endmsg;
246 return StatusCode::FAILURE;
249 msg() <<
"JEM RoI sub-block data words: "
252 subBlock.
write(theROD);
259 if (crate !=
m_crates - 1)
continue;
264 const int timeslices = 1;
270 const int cmxEnergyVersion = 3;
275 for (
int source = 0; source < maxSource; ++source) {
278 const unsigned int ex = sums->
Ex();
279 const unsigned int ey = sums->
Ey();
280 const unsigned int et = sums->
Et();
281 const int exErr = sums->
ExError();
282 const int eyErr = sums->
EyError();
283 const int etErr = sums->
EtError();
285 subBlock.
setSubsums(slice, source, ex, ey,
et, exErr, eyErr, etErr);
292 subBlock.
setSubsums(slice, srcType, sumType, ex, ey,
et,
293 exErr, eyErr, etErr);
300 if ( !subBlock.
pack()) {
301 msg(MSG::ERROR) <<
"CMX-Energy sub-block packing failed" <<
endmsg;
302 return StatusCode::FAILURE;
305 msg() <<
"CMX-Energy sub-block data words: "
308 subBlock.
write(theROD);
318 theROD->push_back(roi->
roiWord(word));
324 return StatusCode::SUCCESS;
345 for (
int slink = 0; slink < maxSlinks; ++slink)
347 const int daqOrRoi = 1;
348 const uint32_t rodId =
m_srcIdMap.getRodID(hwCrate, slink, daqOrRoi,
350 const uint32_t robId =
m_srcIdMap.getRobID(rodId);
353 if (slink < 2)
sourceIDs.push_back(robId);
355 else if (slink >= 2)
sourceIDs.push_back(robId);
364 const std::string& sgKey)
const
366 const std::string flag(
"RoIB");
367 const std::string::size_type pos = sgKey.find(flag);
369 (pos == std::string::npos || pos != sgKey.length() - flag.length());
376 static const std::vector<uint32_t> sourceIDsRoIB =
makeSourceIDs(roiDaq);
377 return sourceIDsRoIB;
394 std::set<uint32_t> dupCheck;
395 std::set<uint32_t> dupRoiCheck;
398 for (; rob != robEnd; ++rob) {
402 msg() <<
"Treating ROB fragment " << robCount <<
endmsg;
407 uint32_t robid = (*rob)->source_id();
408 if ((*rob)->nstatus() > 0) {
410 (*rob)->status(robData);
413 if (
debug)
msg() <<
"ROB status error - skipping fragment" <<
endmsg;
420 if (!dupCheck.insert(robid).second) {
431 (*rob)->rod_data(payloadBeg);
432 payloadEnd = payloadBeg + (*rob)->rod_ndata();
433 payload = payloadBeg;
434 if (payload == payloadEnd) {
440 const uint32_t sourceID = (*rob)->rod_source_id();
449 msg() <<
"Wrong source identifier in data: "
450 << MSG::hex << sourceID << MSG::dec <<
endmsg;
456 const int minorVersion = (*rob)->rod_version() & 0xffff;
457 if (minorVersion <=
m_srcIdMap.minorVersionPreLS1()) {
461 const int rodCrate =
m_srcIdMap.crate(sourceID);
463 msg() <<
"Treating crate " << rodCrate
471 const int headerWords = userHeader.
words();
472 if (headerWords != 1) {
474 if (
debug)
msg() <<
"Unexpected number of user header words: "
478 for (
int i = 0; i < headerWords; ++i) ++payload;
484 while (payload != payloadEnd) {
492 payload = subBlock.
read(payload, payloadEnd);
493 if (cmCollection !=
nullptr) {
497 msg() <<
"CMX-Energy sub-block unpacking failed: "
558 payload = subBlock.
read(payload, payloadEnd);
559 if (jeCollection !=
nullptr) {
563 msg() <<
"JEM RoI sub-block unpacking failed: "
569 for (
int frame = 0; frame <
m_frames; ++frame) {
582 if (jeCollection !=
nullptr) {
584 if (
debug)
msg() <<
"Inconsistent RoI crate number: "
589 const uint32_t location = (*payload) & 0xfff80000;
590 if (dupRoiCheck.insert(location).second) {
595 if (
debug)
msg() <<
"Duplicate RoI word "
596 << MSG::hex << *payload << MSG::dec <<
endmsg;
602 if (cmCollection !=
nullptr) {
603 const uint32_t roiType = (*payload) & 0xfc000000;
605 if (dupRoiCheck.insert(roiType).second) {
608 if (
debug)
msg() <<
"Duplicate RoI word "
609 << MSG::hex << *payload << MSG::dec <<
endmsg;
615 if (
debug)
msg() <<
"Invalid RoI word "
616 << MSG::hex << *payload << MSG::dec <<
endmsg;
627 return StatusCode::SUCCESS;
637 CmxSumsMap::const_iterator mapIter;
638 mapIter = cmxEtMap.find(crate * 100 + source);
639 if (mapIter != cmxEtMap.end()) sums = mapIter->second;
653 for (; pos != pose; ++pos) {
655 const uint32_t key = roi->
roiWord();
656 roiMap.insert(std::make_pair(key, roi));
671 for (; pos != pose; ++pos) {
674 const int key = crate * 100 + sums->
source();
675 cmxEtMap.insert(std::make_pair(key, sums));
#define ATH_CHECK
Evaluate an expression and check for errors.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
bool msgLvl(const MSG::Level lvl) const
DataModel_detail::const_iterator< DataVector > const_iterator
value_type push_back(value_type pElem)
Add an element to the end of the collection.
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.
Template class for assembling a full atlas raw event from subfragments.
void setRodMinorVersion(uint16_t m)
change the ROD minor version
std::vector< uint32_t > RODDATA
ROD data as a vector of unsigned int.
RODDATA * getRodData(uint32_t id)
get a block of ROD data
std::vector< const ROBF * > VROBFRAG
Sub-Block class for CMX-Energy data post LS1.
unsigned int hits(int slice, HitsType hType, SumType sType) const
Return hits map for given hits type and sum type.
void setSubsums(int slice, int jem, unsigned int ex, unsigned int ey, unsigned int et, int exError, int eyError, int etError)
Store energy subsums and errors for given JEM.
void setEtHits(int slice, HitsType hType, SumType sType, unsigned int map)
Store hits map for given hits type and sum type.
bool unpack()
Unpack data.
unsigned int energy(int slice, int jem, EnergyType eType) const
Return energy subsum for given JEM and energy type.
int error(int slice, int jem, EnergyType eType) const
Return energy subsum error for given JEM and energy type.
static bool cmxBlock(uint32_t word)
Determine if header word corresponds to CMX.
void setCmxHeader(int version, int format, int slice, int crate, int summing, int firmware, int position, int timeslices)
Store CMX header.
static CmxFirmwareCode cmxType(uint32_t word)
CMX differentiation (CMX_CP, CMX_JET, or CMX_ENERGY).
Sub-Block class for JEM RoI data (neutral format) post-LS1.
bool unpack()
Unpack data.
void clear()
Clear all data.
LVL1::JEMTobRoI roi(int frame) const
Return RoI for given frame.
void fillRoi(LVL1::JEMTobRoI roi)
Store RoI.
void setRoiHeader(int version, int crate, int module)
Store header.
int unpackErrorCode() const
Return the unpacking error code.
int dataWords() const
Return number of data words.
static SubBlockWordType wordType(uint32_t word)
Word identification.
void write(FullEventAssembler< L1CaloSrcIdMap >::RODDATA *theROD) const
Output complete packed sub-block to ROD vector.
std::string unpackErrorMsg() const
Return the unpacking error message for printing.
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.
CMXEtSums object stores Et sums from the Energy CMXs.
unsigned int Ey() const
returns module Ey sum for peak sample
unsigned int Ex() const
returns module Ex sum for peak sample
int source() const
returns data source
unsigned int Et() const
For triggered time slice.
int ExError() const
returns module Ex sum error for peak sample
int crate() const
Data accessors.
int EyError() const
returns module Ey sum error for peak sample
int EtError() const
returns module ET sum error for peak sample
@ MISSING_ET_SIG_STANDARD
bool setRoiWord(uint32_t roiWord)
Set RoI word with ID check.
uint32_t roiWord(int word) const
Return packed Energy RoI word (0-5).
bool setRoiWord(uint32_t roiWord)
Set RoI word with ID check.
uint32_t roiWord() const
Return packed RoI word.
int jem() const
Return JEM number (0-15).
int energyLarge() const
Return energy large window size.
int energySmall() const
Return energy small window size.
int crate() const
Return crate number (0-1).
Jet/Energy Processor RoI container for writing bytestream post-LS1.
const CMXRoI * CmxRoi() const
Return pointer to CMX RoIs.
const DataVector< CMXEtSums > * CmxSums() const
Return pointer to CMX energy sums collection.
const DataVector< JEMTobRoI > * JemRoi() const
Return pointer to JEM RoI collection.
static const InterfaceID IID_IJepRoiByteStreamV2Tool("JepRoiByteStreamV2Tool", 1, 1)
Extra patterns decribing particle interation process.