15 #include "GaudiKernel/ITHistSvc.h"
18 #include "eformat/FullEventFragmentNoTemplates.h"
19 #include "eformat/ROBFragmentNoTemplates.h"
20 #include "eformat/StreamTag.h"
21 #include "hltinterface/DataCollector.h"
30 constexpr
float wordsToKiloBytes = 0.001*
sizeof(
uint32_t);
31 template<
typename T>
inline bool contains(
const std::vector<T>&
vec,
const T&
val) {
34 template<
typename T>
inline int index(
const std::vector<T>&
vec,
const T&
val) {
38 template<
typename T>
struct printWordHex {
39 printWordHex(
const T w) : word(
w) {}
42 template<
typename T> std::ostream&
operator<<(std::ostream&
str,
const printWordHex<T>& pw) {
43 str <<
"0x" << std::hex << std::setfill(
'0') << std::setw(2*
sizeof(
T));
46 str << static_cast<int>(pw.word);
52 template<
typename T>
struct printNWordsHex {
53 printNWordsHex(
const size_t n,
const T*
w,
const std::string&
s=
" ") : nwords(
n),
words(
w),
sep(
s) {}
58 template<
typename T> std::ostream&
operator<<(std::ostream&
str,
const printNWordsHex<T>& pnw) {
59 for (
size_t i=0;
i<pnw.nwords; ++
i) {
60 str << printWordHex<T>(pnw.words[
i]);
61 if (
i!=pnw.nwords-1)
str << pnw.sep;
66 inline const std::string mon_streamTypeName(
const eformat::helper::StreamTag& st){
67 return st.type+
"_"+st.name;
69 inline const std::string& mon_streamType(
const eformat::helper::StreamTag& st){
72 inline bool mon_streamIsPeb(
const eformat::helper::StreamTag& st){
73 return st.robs.size()>0 || st.dets.size()>0;
75 inline size_t mon_streamPebRobsNum(
const eformat::helper::StreamTag& st){
76 return st.robs.size();
78 inline size_t mon_streamPebSubDetsNum(
const eformat::helper::StreamTag& st){
79 return st.dets.size();
87 : base_class(
name, svcLoc) {}
104 return StatusCode::SUCCESS;
118 return StatusCode::SUCCESS;
125 ATH_MSG_ERROR(
"Bytestream creation is not supported by TrigByteStreamCnvSvc");
130 const std::string& ) {
131 ATH_MSG_ERROR(
"Bytestream creation is not supported by TrigByteStreamCnvSvc");
132 return StatusCode::FAILURE;
141 if (eventContext ==
nullptr)
return StatusCode::FAILURE;
148 ATH_MSG_DEBUG(
"Creating new RawEventWrite for EventContext = " << eventContext);
152 if (!inputRawEvent) {
153 ATH_MSG_ERROR(
"Input RawEvent is nullptr, cannot create output");
154 return StatusCode::FAILURE;
156 re->copy_header(inputRawEvent);
161 return StatusCode::SUCCESS;
179 if (eventContext ==
nullptr)
return StatusCode::FAILURE;
191 std::unique_ptr<uint32_t[]> rawEventPtr;
193 const eformat::write::node_t*
top =
re->bind();
195 rawEventPtr = std::make_unique<uint32_t[]>(rawEventSize);
197 if(copiedSize!=rawEventSize) {
199 return StatusCode::FAILURE;
203 ATH_MSG_ERROR(
"FullEventFragment serialisation failed, caught an unexpected std::exception " <<
e.what());
205 return StatusCode::FAILURE;
208 ATH_MSG_ERROR(
"FullEventFragment serialisation failed, caught an unexpected exception");
210 return StatusCode::FAILURE;
225 ATH_MSG_DEBUG(
"Serialised FullEventFragment with HLT result was returned to DataCollector successfully, "
226 <<
"the eventDone call took " << (
double)t_eventDone <<
" milliseconds");
229 ATH_MSG_ERROR(
"Sending output to DataCollector failed, caught an unexpected std::exception " <<
e.what());
230 result = StatusCode::FAILURE;
233 ATH_MSG_ERROR(
"Sending output to DataCollector failed, caught an unexpected exception");
234 result = StatusCode::FAILURE;
249 const EventContext* eventContext =
nullptr;
250 if (
m_evtStore->retrieve(eventContext).isFailure()) {
251 ATH_MSG_ERROR(
"Failed to retrieve EventContext from the event store");
259 if (eventContext ==
nullptr)
return nullptr;
285 if (rawEvent.nstatus() > 1) {
287 std::ostringstream
ss;
294 std::vector<eformat::helper::StreamTag> streamTags;
299 ATH_MSG_ERROR(
"StreamTag decoding failed, caught an unexpected std::exception " << ex.what());
303 ATH_MSG_ERROR(
"StreamTag decoding failed, caught an unexpected exception");
308 std::vector<eformat::read::ROBFragment>
robs;
310 std::vector<uint16_t> resultSizeMap_moduleID;
311 std::vector<uint32_t> resultSizeMap_size;
315 eformat::helper::SourceIdentifier sid(rob.rob_source_id());
316 if (sid.subdetector_id() != eformat::SubDetector::TDAQ_HLT)
318 const uint16_t module_id = sid.module_id();
320 totalSizeWords +=
size;
321 if (!
contains(resultSizeMap_moduleID, module_id)) {
322 resultSizeMap_moduleID.push_back(module_id);
323 resultSizeMap_size.push_back(
size);
326 ATH_MSG_ERROR(
"HLT result ROB monitoring found multiple HLT ROBs with the same module ID " << module_id);
331 ATH_MSG_ERROR(
"HLT result ROB monitoring failed, caught an unexpected std::exception " << ex.what());
335 ATH_MSG_ERROR(
"HLT result ROB monitoring failed, caught an unexpected exception");
340 std::vector<std::string> sdFromRobList;
341 std::vector<std::string> sdFromSubDetList;
342 std::vector<std::string> streamTagCorrA;
343 std::vector<std::string> streamTagCorrB;
344 std::vector<float> streamResultSize;
345 streamTagCorrA.reserve(streamTags.size() * streamTags.size());
346 streamTagCorrB.reserve(streamTags.size() * streamTags.size());
347 streamResultSize.reserve(streamTags.size());
348 for (
const eformat::helper::StreamTag& st : streamTags) {
349 bool hasHLTSubDet = st.dets.find(eformat::SubDetector::TDAQ_HLT) != st.dets.end();
350 bool includeAll = st.robs.empty() && (st.dets.empty() || hasHLTSubDet);
352 uint32_t sizeWords = includeAll ? totalSizeWords : 0;
353 for (
const eformat::SubDetector
sd : st.dets) {
354 const std::string&
detName = eformat::helper::SubDetectorDictionary.string(
sd);
357 for (
const uint32_t robid : st.robs) {
358 eformat::helper::SourceIdentifier sid(robid);
359 const std::string&
detName = sid.human_detector();
361 if (!includeAll && sid.subdetector_id() == eformat::SubDetector::TDAQ_HLT) {
362 if (
const int ix =
index(resultSizeMap_moduleID, sid.module_id()); ix >= 0) {
363 sizeWords += resultSizeMap_size[ix];
366 ATH_MSG_WARNING(
"Stream tag " << st.type <<
"_" << st.name <<
" declares " << sid.human()
367 <<
" in ROB list, but the ROBFragment is missing");
371 streamResultSize.push_back(sizeWords*wordsToKiloBytes);
372 for (
const eformat::helper::StreamTag& st2 : streamTags) {
373 streamTagCorrA.push_back(mon_streamTypeName(st));
374 streamTagCorrB.push_back(mon_streamTypeName(st2));
386 auto monPebRobsNum =
Monitored::Collection(
"StreamTagsPebRobsNum", streamTags, mon_streamPebRobsNum);
387 auto monPebSubDetsNum =
Monitored::Collection(
"StreamTagsPebSubDetsNum", streamTags, mon_streamPebSubDetsNum);
388 auto monSubDetsFromRobList =
Monitored::Collection(
"StreamTagsPebSubDetsFromRobList", sdFromRobList);
389 auto monSubDetsFromSubDetList =
Monitored::Collection(
"StreamTagsPebSubDetsFromSubDetList", sdFromSubDetList);
392 auto monResultSizeFullEvFrag =
Monitored::Scalar<float>(
"ResultSizeFullEvFrag", rawEvent.fragment_size_word()*wordsToKiloBytes);
398 monStreamTagCorrB, monStreamIsPeb, monPebRobsNum, monPebSubDetsNum, monSubDetsFromRobList,
399 monSubDetsFromSubDetList, monResultSizeTotal, monResultSizeFullEvFrag, monResultCollModuleID,
400 monResultCollModuleSize, monResultSizeByStream);
411 std::ostringstream
ss;
412 ss <<
"Dumping header of the FullEventFragment with HLT result:" << std::endl;
413 ss <<
"--> status = "
414 << printNWordsHex<uint32_t>(
re->nstatus(),
re->status())
416 ss <<
"--> source_id = " << printWordHex<uint32_t>(
re->source_id()) << std::endl;
417 ss <<
"--> checksum_type = " << printWordHex<uint32_t>(
re->checksum_type()) << std::endl;
418 ss <<
"--> compression_type = " << printWordHex<uint32_t>(
re->compression_type()) << std::endl;
419 ss <<
"--> compression_level = " <<
re->compression_level() << std::endl;
420 ss <<
"--> bc_time_seconds = " <<
re->bc_time_seconds() << std::endl;
421 ss <<
"--> bc_time_nanoseconds = " <<
re->bc_time_nanoseconds() << std::endl;
422 ss <<
"--> global_id = " <<
re->global_id() << std::endl;
423 ss <<
"--> run_type = " <<
re->run_type() << std::endl;
424 ss <<
"--> run_no = " <<
re->run_no() << std::endl;
425 ss <<
"--> lumi_block = " <<
re->lumi_block() << std::endl;
426 ss <<
"--> lvl1_id = " <<
re->lvl1_id() << std::endl;
427 ss <<
"--> bc_id = " <<
re->bc_id() << std::endl;
428 ss <<
"--> lvl1_trigger_type = " << printWordHex<uint8_t>(
re->lvl1_trigger_type()) << std::endl;
429 ss <<
"--> lvl1_trigger_info = "
430 << printNWordsHex<uint32_t>(
re->nlvl1_trigger_info(),
re->lvl1_trigger_info())
432 ss <<
"--> lvl2_trigger_info = "
433 << printNWordsHex<uint32_t>(
re->nlvl2_trigger_info(),
re->lvl2_trigger_info())
435 ss <<
"--> event_filter_info = "
436 << printNWordsHex<uint32_t>(
re->nevent_filter_info(),
re->event_filter_info())
438 ss <<
"--> hlt_info = "
439 << printNWordsHex<uint32_t>(
re->nhlt_info(),
re->hlt_info())
442 std::vector<eformat::helper::StreamTag>
stream_tags;
447 ATH_MSG_ERROR(
"StreamTag decoding failed, caught an unexpected std::exception " << ex.what());
451 ATH_MSG_ERROR(
"StreamTag decoding failed, caught an unexpected exception");
454 ss <<
"--> stream_tags = ";
459 ss <<
"{" << st.name <<
", " << st.type <<
", obeysLB=" << st.obeys_lumiblock <<
", robs=[";
460 for (
const auto& robid : st.robs) ss << printWordHex<uint32_t>(robid) <<
", ";
462 for (
const auto& detid : st.dets) ss << printWordHex<uint8_t>(detid) <<
", ";
463 ss <<
"]}" << std::endl;