17#include "GaudiKernel/IInterface.h"
18#include "GaudiKernel/MsgStream.h"
47 const std::string& name,
48 const IInterface* parent) :
62 declareInterface<ZdcByteStreamTool> (
this);
68 "Only make trigger towers with non-zero EM or Had energy");
71 "Pedestal value - needed for compressed formats 0,1 only");
76 "FADC baseline lower bound for compressed formats");
78 "FADC threshold for super-compressed format");
81 "The number of LUT slices in the simulation");
83 "The number of FADC slices in the simulation");
85 "If >0, the number of LUT slices in bytestream");
87 "If >0, the number of FADC slices in bytestream");
109 const ZdcID* zdcID =
nullptr;
110 if (
detStore()->retrieve( zdcID ).isFailure() ) {
111 msg(MSG::ERROR) <<
"execute: Could not retrieve ZdcID object from the detector store" <<
endmsg;
112 return StatusCode::FAILURE;
115 msg(MSG::DEBUG) <<
"execute: retrieved ZdcID" <<
endmsg;
119 return StatusCode::SUCCESS;
137 return StatusCode::SUCCESS;
157 typedef std::map<uint32_t,ZdcDigits*> hashmapType;
158 hashmapType digits_map;
165 for (; rob != robEnd; ++rob)
171 msg() <<
"ZDC: Treating ROB fragment " << robCount <<
endmsg;
179 (*rob)->rod_data(payloadBeg);
180 payloadEnd = payloadBeg + (*rob)->rod_ndata();
181 payload = payloadBeg;
182 if (payload == payloadEnd)
189 const uint32_t sourceID = (*rob)->rod_source_id();
195 msg() <<
"ZDC: Wrong source identifier in data: " << MSG::hex << sourceID << MSG::dec
213 const int minorVersion = (*rob)->rod_version() & 0xffff;
215 const int headerWords = userHeader.
words();
216 if (headerWords != 1 &&
debug)
218 msg() <<
"ZDC: Unexpected number of user header words: " << headerWords <<
endmsg;
221 for (
int i = 0; i < headerWords; ++i)
224 const int trigLut = userHeader.
ppmLut();
225 const int trigFadc = userHeader.
ppmFadc();
230 msg() <<
"ZDC: Minor format version number: " << MSG::hex << minorVersion << MSG::dec
231 <<
endmsg <<
"ZDC: LUT triggered slice offset: " << trigLut <<
endmsg
232 <<
"ZDC: FADC triggered slice offset: " << trigFadc <<
endmsg
235 const int runNumber = (*rob)->rod_run_no() & 0xffffff;
238 int chanPerSubBlock = 0;
239 if (payload != payloadEnd)
243 msg(MSG::ERROR) <<
"Missing Sub-block header" <<
endmsg;
244 return StatusCode::FAILURE;
249 testBlock.
read(payload, payloadEnd);
251 if (chanPerSubBlock == 0)
253 msg(MSG::ERROR) <<
"Unsupported version/data format: " << testBlock.
version()
255 return StatusCode::FAILURE;
259 msg(MSG::ERROR) <<
"Invalid channels per sub-block: " << chanPerSubBlock <<
endmsg;
260 return StatusCode::FAILURE;
262 if (
debug)
msg() <<
"Channels per sub-block: " << chanPerSubBlock <<
endmsg;
266 if (
debug)
msg() <<
"ROB fragment contains user header only" <<
endmsg;
269 const int numSubBlocks =
m_channels / chanPerSubBlock;
273 payload = payloadBeg;
274 for (
int i = 0; i < headerWords; ++i)
276 while (payload != payloadEnd)
284 for (
int block = 0; block < numSubBlocks; ++block)
289 msg(MSG::ERROR) <<
"Unexpected data sequence" <<
endmsg;
290 return StatusCode::FAILURE;
297 msg() <<
"Unexpected channel sequence number: "
299 * chanPerSubBlock <<
endmsg;
306 msg(MSG::ERROR) <<
"Unexpected channel sequence number" <<
endmsg;
308 return StatusCode::FAILURE;
313 payload = subBlock->
read(payload, payloadEnd);
316 crate = subBlock->
crate();
317 module = subBlock->module();
320 msg() <<
"Module " <<
module << endmsg;
321 if (crate != rodCrate)
323 msg() <<
"Inconsistent crate number in ROD source ID" <<
endmsg;
329 if (subBlock->
crate() != crate)
331 msg(MSG::ERROR) <<
"Inconsistent crate number in sub-blocks" <<
endmsg;
332 return StatusCode::FAILURE;
334 if (subBlock->
module() != module)
336 msg(MSG::ERROR) <<
"Inconsistent module number in sub-blocks" <<
endmsg;
337 return StatusCode::FAILURE;
340 if (payload == payloadEnd && block != numSubBlocks - 1)
352 if (payload != payloadEnd)
362 msg(MSG::ERROR) <<
"Inconsistent crate number in error block" <<
endmsg;
363 return StatusCode::FAILURE;
367 msg(MSG::ERROR) <<
"Inconsistent module number in error block" <<
endmsg;
368 return StatusCode::FAILURE;
375 msg() <<
"Unpacking error block failed: " << errMsg <<
endmsg;
385 for (
int block = 0; block < actualSubBlocks; ++block)
395 msg() <<
"Unpacking sub-block version/format/seqno: " << subBlock->
version()
403 msg() <<
"Unpacking PPM sub-block failed: " << errMsg <<
endmsg;
407 for (
int chan = 0; chan < chanPerSubBlock; ++chan)
409 const int channel = block * chanPerSubBlock + chan;
410 std::vector<int> lut;
411 std::vector<int> fadc;
412 std::vector<int> bcidLut;
413 std::vector<int> bcidFadc;
414 subBlock->
ppmData(channel, lut, fadc, bcidLut, bcidFadc);
417 if (lut.size() <
size_t(trigLut + 1))
421 msg() <<
"Triggered LUT slice from header "
422 <<
"inconsistent with number of slices: " << trigLut <<
", "
423 << lut.size() <<
", reset to 0" <<
endmsg;
427 if (fadc.size() <
size_t(trigFadc + 1))
431 msg() <<
"Triggered FADC slice from header "
432 <<
"inconsistent with number of slices: " << trigFadc <<
", "
433 << fadc.size() <<
", reset to 0" <<
endmsg;
461 const bool any = std::accumulate(lut.begin(), lut.end(), 0)
462 || std::accumulate(fadc.begin(), fadc.end(), 0)
463 || std::accumulate(bcidLut.begin(), bcidLut.end(), 0)
464 || std::accumulate(bcidFadc.begin(), bcidFadc.end(), 0);
482 msg(MSG::DEBUG) <<
"chan_hash = " << chan_hash <<
endmsg;
493 msg(MSG::DEBUG) <<
" --------------------------------------" <<
endmsg;
495 "--> ZDC: [SubDet., Crate, Mod., Slink Chn., PPM Chan.] ";
498 module <<
", " << channel <<
"," << ppmChannel <<
"]" <<
endmsg;
500 msg(MSG::DEBUG) <<
"--> ZDC: LUT: ";
504 msg(MSG::DEBUG) <<
"--> ZDC: FADC: ";
508 msg(MSG::DEBUG) <<
"--> ZDC: bcidLUT: ";
512 msg(MSG::DEBUG) <<
"--> ZDC: bcidFADC: ";
520 msg(MSG::DEBUG) <<
"--> ID channel: " <<
m_zdcID->channel(chan_id) <<
endmsg;
522 msg(MSG::DEBUG) <<
"gain=" << gain <<
" delay=" <<
delay <<
endmsg;
524 msg(MSG::DEBUG) <<
" --------------------------------------" <<
endmsg;
528 hashmapType::iterator iter = digits_map.find(chan_hash);
529 if (iter == digits_map.end())
531 digits_map.insert(std::pair<uint32_t,ZdcDigits*>(chan_hash,
new ZdcDigits(chan_id)));
532 iter = digits_map.find(chan_hash);
534 if (iter != digits_map.end())
536 if (gain==0&&
delay==0) (*iter).second->set_digits_gain0_delay0(fadc);
537 if (gain==1&&
delay==0) (*iter).second->set_digits_gain1_delay0(fadc);
538 if (gain==0&&
delay==1) (*iter).second->set_digits_gain0_delay1(fadc);
539 if (gain==1&&
delay==1) (*iter).second->set_digits_gain1_delay1(fadc);
548 hashmapType::iterator iter = digits_map.begin();
549 hashmapType::iterator iter_end = digits_map.end();
551 while (iter != iter_end)
557 msg(MSG::DEBUG) <<
"-->ZDC: Collection has " << ttCollection->
size() <<
" elements " <<
endmsg;
559 return StatusCode::SUCCESS;
570 return StatusCode::SUCCESS;
578 if (stats.empty())
return;
579 const int n = stats.size();
581 for (
int i = 0; i < n; ++i)
590 msg() <<
"Compression stats format/count: ";
592 for (
int i = 0; i < n; ++i)
606 for (
int crate = 0; crate <
m_crates; ++crate) {
607 for (
int slink = 0; slink < maxlinks; ++slink) {
608 const int daqOrRoi = 0;
624 std::vector<int>::const_iterator pos;
626 for (pos =
vec.begin(); pos !=
vec.end(); ++pos)
628 if (pos !=
vec.begin())
msg() <<
",";
std::vector< size_t > vec
double delay(std::size_t d)
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::FullEventFragment RawEventWrite
data type for writing raw event
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
std::vector< const ROBF * > VROBFRAG
value_type get_compact() const
Get the compact id.
std::string getString() const
Provide a string form of the identifier - hexadecimal.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
int hwid2gain(int crate, int channel) const
static const ZdcCablingService * getInstance()
get pointer to service instance
int hwid2delay(int crate, int channel) const
Identifier h2s_channel_id(int crate, int channel) const
Sub-Block class for PPM data.
void setPedestal(int pedval)
void setLutOffset(int offset)
void ppmData(int chan, std::vector< int > &lut, std::vector< int > &fadc, std::vector< int > &bcidLut, std::vector< int > &bcidFadc) const
Return unpacked data for given channel.
void setFadcBaseline(int baseline)
const std::vector< uint32_t > & compStats() const
Return reference to compression stats.
bool unpack()
Unpack data.
void setRunNumber(int run)
static bool errorBlock(uint32_t word)
Check if a header word is for an error block.
void setFadcOffset(int offset)
static int channelsPerSubBlock(int version, int format)
Return the number of channels per sub-block.
int getPpmChannel(const int channel) const
This class provides conversion between Lower level Source ID to higher level source ID for L1Calo Byt...
static eformat::SubDetector subDet(uint32_t code)
ID -> sub-detector.
static uint32_t getRobID(uint32_t rod_id)
ROD -> ROB.
static int crate(uint32_t code)
moduleID -> crate
static uint32_t getRodID(int crate, int slink, int daqOrRoi, eformat::SubDetector subdet)
Make a ROD Source ID.
static int maxSlinks()
Return the maximum possible number of slinks.
static int daqOrRoi(uint32_t code)
moduleID -> daqOrRoi
static int slink(uint32_t code)
moduleID -> slink
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.
int dataWords() const
Return number of data words.
std::string unpackErrorMsg() const
Return the unpacking error message for printing.
static SubBlockWordType wordType(uint32_t word)
Word identification.