12#include "GaudiKernel/IInterface.h"
13#include "GaudiKernel/MsgStream.h"
14#include "GaudiKernel/StatusCode.h"
39 const std::string& name,
40 const IInterface* parent)
42 m_errorTool(
"LVL1BS::L1CaloErrorByteStreamTool/L1CaloErrorByteStreamTool"),
46 declareInterface<CpmRoiByteStreamTool>(
this);
49 "Offset of CP crate numbers in bytestream");
51 "Offset of CP crate numbers in RDOs");
55 "ROB fragment source identifiers");
57 "ROB fragment source identifiers for RoIBs");
61 "Format version number in sub-block header");
63 "Format identifier (0-1) in sub-block header");
65 "The number of S-Links per crate");
85 return StatusCode::SUCCESS;
103 std::set<uint32_t> dupCheck;
104 std::set<uint32_t> dupRoiCheck;
107 for (; rob != robEnd; ++rob) {
111 msg() <<
"Treating ROB fragment " << robCount <<
endmsg;
116 uint32_t robid = (*rob)->source_id();
117 if ((*rob)->nstatus() > 0) {
119 (*rob)->status(robData);
122 if (
debug)
msg() <<
"ROB status error - skipping fragment" <<
endmsg;
129 if (!dupCheck.insert(robid).second) {
140 (*rob)->rod_data(payloadBeg);
141 payloadEnd = payloadBeg + (*rob)->rod_ndata();
142 payload = payloadBeg;
143 if (payload == payloadEnd) {
149 const uint32_t sourceID = (*rob)->rod_source_id();
158 msg() <<
"Wrong source identifier in data: "
159 << MSG::hex << sourceID << MSG::dec <<
endmsg;
163 const int rodCrate =
m_srcIdMap.crate(sourceID);
165 msg() <<
"Treating crate " << rodCrate
172 const int minorVersion = (*rob)->rod_version() & 0xffff;
174 const int headerWords = userHeader.
words();
175 if (headerWords != 1 ) {
177 if (
debug)
msg() <<
"Unexpected number of user header words: "
181 for (
int i = 0; i < headerWords; ++i) ++payload;
187 while (payload != payloadEnd) {
191 payload = subBlock.
read(payload, payloadEnd);
193 msg() <<
"CPM RoI sub-block: Crate " << subBlock.
crate()
200 msg() <<
"CPM RoI sub-block unpacking failed: " << errMsg <<
endmsg;
205 const int numChips = 8;
206 const int numLocs = 2;
207 for (
int chip = 0; chip < numChips; ++chip) {
208 for (
int loc = 0; loc < numLocs; ++loc) {
220 if (
debug)
msg() <<
"Inconsistent RoI crate number: "
226 if (
debug)
msg() <<
"Invalid CPM number: "
231 const uint32_t location = (*payload) & 0xfffc0000;
232 if (dupRoiCheck.insert(location).second) {
237 if (
debug)
msg() <<
"Duplicate RoI word "
238 << MSG::hex << *payload << MSG::dec <<
endmsg;
243 if (
debug)
msg() <<
"Invalid RoI word "
244 << MSG::hex << *payload << MSG::dec <<
endmsg;
255 return StatusCode::SUCCESS;
270 "CpmRoiByteStream") );
271 const uint16_t minorVersion =
m_srcIdMap.minorVersion();
286 CpmRoiMap::const_iterator mapIter = roiMap.begin();
287 CpmRoiMap::const_iterator mapIterEnd = roiMap.end();
293 for (
int crate=0; crate <
m_crates; ++crate) {
297 for (
int module=1;
module <= m_modules; ++module) {
298 const int mod =
module - 1;
302 if (mod%modulesPerSlink == 0) {
303 const int daqOrRoi = 1;
304 const int slink = (
m_slinks == 2) ? 2*(mod/modulesPerSlink)
305 : mod/modulesPerSlink;
307 msg() <<
"Treating crate " << hwCrate
308 <<
" slink " << slink <<
endmsg
312 const uint32_t rodIdCpm =
m_srcIdMap.getRodID(hwCrate, slink, daqOrRoi,
317 theROD->push_back(userHeader.
header());
320 if (
debug)
msg() <<
"Module " <<
module << endmsg;
331 for (; mapIter != mapIterEnd; ++mapIter) {
333 if (roi->
crate() < crate)
continue;
334 if (roi->
crate() > crate)
break;
335 if (roi->
cpm() < module)
continue;
336 if (roi->
cpm() > module)
break;
338 if (neutralFormat) subBlock.
fillRoi(*roi);
339 else theROD->push_back(roi->
roiWord());
346 if ( !subBlock.
pack()) {
347 msg(MSG::ERROR) <<
"CPMRoI sub-block packing failed" <<
endmsg;
348 return StatusCode::FAILURE;
351 msg() <<
"CPMRoI sub-block data words: "
354 subBlock.
write(theROD);
359 return StatusCode::SUCCESS;
380 for (
int slink = 0; slink < maxSlinks; ++slink)
382 const int daqOrRoi = 1;
383 const uint32_t rodId =
m_srcIdMap.getRodID(hwCrate, slink, daqOrRoi,
385 const uint32_t robId =
m_srcIdMap.getRobID(rodId);
388 if (slink < 2)
sourceIDs.push_back(robId);
390 else if (slink >= 2)
sourceIDs.push_back(robId);
399 const std::string& sgKey)
const
401 const std::string flag(
"RoIB");
402 const std::string::size_type pos = sgKey.find(flag);
404 (pos == std::string::npos || pos != sgKey.length() - flag.length());
411 static const std::vector<uint32_t> sourceIDsRoIB =
makeSourceIDs(roiDaq);
412 return sourceIDsRoIB;
426 for (; pos != pose; ++pos) {
428 const uint32_t key = roi->
roiWord();
429 roiMap.insert(std::make_pair(key, roi));
#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 CPM RoI data (neutral format).
void clear()
Clear all data.
bool unpack()
Unpack data.
void fillRoi(LVL1::CPMRoI roi)
Store RoI.
void setRoiHeader(int version, int crate, int module)
Store header.
LVL1::CPMRoI roi(int chip, int loc) const
Return RoI for given chip and location (left/right)
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.
uint32_t roiWord() const
Return packed RoI word.
int crate() const
Return crate number (0-1)
int hits() const
Return hit thresholds map.
int cpm() const
Return CPM number (1-14)
bool setRoiWord(uint32_t roiWord)
Set RoI word with ID check.
int error() const
Return error flags (bit 0 Saturation, bit 1 Parity)
static const InterfaceID IID_ICpmRoiByteStreamTool("CpmRoiByteStreamTool", 1, 1)