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();
104 return StatusCode::SUCCESS;
118 return StatusCode::SUCCESS;
127 if (eventContext ==
nullptr)
return StatusCode::FAILURE;
134 ATH_MSG_DEBUG(
"Creating new RawEventWrite for EventContext = " << eventContext);
138 if (!inputRawEvent) {
139 ATH_MSG_ERROR(
"Input RawEvent is nullptr, cannot create output");
140 return StatusCode::FAILURE;
142 re->copy_header(inputRawEvent);
147 return StatusCode::SUCCESS;
165 if (eventContext ==
nullptr)
return StatusCode::FAILURE;
177 std::unique_ptr<uint32_t[]> rawEventPtr;
179 const eformat::write::node_t*
top =
re->bind();
181 rawEventPtr = std::make_unique<uint32_t[]>(rawEventSize);
183 if(copiedSize!=rawEventSize) {
185 return StatusCode::FAILURE;
189 ATH_MSG_ERROR(
"FullEventFragment serialisation failed, caught an unexpected std::exception " <<
e.what());
191 return StatusCode::FAILURE;
194 ATH_MSG_ERROR(
"FullEventFragment serialisation failed, caught an unexpected exception");
196 return StatusCode::FAILURE;
211 ATH_MSG_DEBUG(
"Serialised FullEventFragment with HLT result was returned to DataCollector successfully, "
212 <<
"the eventDone call took " << (
double)t_eventDone <<
" milliseconds");
215 ATH_MSG_ERROR(
"Sending output to DataCollector failed, caught an unexpected std::exception " <<
e.what());
216 result = StatusCode::FAILURE;
219 ATH_MSG_ERROR(
"Sending output to DataCollector failed, caught an unexpected exception");
220 result = StatusCode::FAILURE;
235 const EventContext* eventContext =
nullptr;
236 if (
m_evtStore->retrieve(eventContext).isFailure()) {
237 ATH_MSG_ERROR(
"Failed to retrieve EventContext from the event store");
245 if (eventContext ==
nullptr)
return nullptr;
271 if (rawEvent.nstatus() > 1) {
273 std::ostringstream
ss;
280 std::vector<eformat::helper::StreamTag> streamTags;
285 ATH_MSG_ERROR(
"StreamTag decoding failed, caught an unexpected std::exception " << ex.what());
289 ATH_MSG_ERROR(
"StreamTag decoding failed, caught an unexpected exception");
294 std::vector<eformat::read::ROBFragment>
robs;
296 std::vector<uint16_t> resultSizeMap_moduleID;
297 std::vector<uint32_t> resultSizeMap_size;
301 eformat::helper::SourceIdentifier sid(rob.rob_source_id());
302 if (sid.subdetector_id() != eformat::SubDetector::TDAQ_HLT)
304 const uint16_t module_id = sid.module_id();
306 totalSizeWords +=
size;
307 if (!
contains(resultSizeMap_moduleID, module_id)) {
308 resultSizeMap_moduleID.push_back(module_id);
309 resultSizeMap_size.push_back(
size);
312 ATH_MSG_ERROR(
"HLT result ROB monitoring found multiple HLT ROBs with the same module ID " << module_id);
317 ATH_MSG_ERROR(
"HLT result ROB monitoring failed, caught an unexpected std::exception " << ex.what());
321 ATH_MSG_ERROR(
"HLT result ROB monitoring failed, caught an unexpected exception");
326 std::vector<std::string> sdFromRobList;
327 std::vector<std::string> sdFromSubDetList;
328 std::vector<std::string> streamTagCorrA;
329 std::vector<std::string> streamTagCorrB;
330 std::vector<float> streamResultSize;
331 streamTagCorrA.reserve(streamTags.size() * streamTags.size());
332 streamTagCorrB.reserve(streamTags.size() * streamTags.size());
333 streamResultSize.reserve(streamTags.size());
334 for (
const eformat::helper::StreamTag& st : streamTags) {
335 bool hasHLTSubDet = st.dets.find(eformat::SubDetector::TDAQ_HLT) != st.dets.end();
336 bool includeAll = st.robs.empty() && (st.dets.empty() || hasHLTSubDet);
338 uint32_t sizeWords = includeAll ? totalSizeWords : 0;
339 for (
const eformat::SubDetector
sd : st.dets) {
340 const std::string&
detName = eformat::helper::SubDetectorDictionary.string(
sd);
343 for (
const uint32_t robid : st.robs) {
344 eformat::helper::SourceIdentifier sid(robid);
345 const std::string&
detName = sid.human_detector();
347 if (!includeAll && sid.subdetector_id() == eformat::SubDetector::TDAQ_HLT) {
348 if (
const int ix =
index(resultSizeMap_moduleID, sid.module_id()); ix >= 0) {
349 sizeWords += resultSizeMap_size[ix];
352 ATH_MSG_WARNING(
"Stream tag " << st.type <<
"_" << st.name <<
" declares " << sid.human()
353 <<
" in ROB list, but the ROBFragment is missing");
357 streamResultSize.push_back(sizeWords*wordsToKiloBytes);
358 for (
const eformat::helper::StreamTag& st2 : streamTags) {
359 streamTagCorrA.push_back(mon_streamTypeName(st));
360 streamTagCorrB.push_back(mon_streamTypeName(st2));
372 auto monPebRobsNum =
Monitored::Collection(
"StreamTagsPebRobsNum", streamTags, mon_streamPebRobsNum);
373 auto monPebSubDetsNum =
Monitored::Collection(
"StreamTagsPebSubDetsNum", streamTags, mon_streamPebSubDetsNum);
374 auto monSubDetsFromRobList =
Monitored::Collection(
"StreamTagsPebSubDetsFromRobList", sdFromRobList);
375 auto monSubDetsFromSubDetList =
Monitored::Collection(
"StreamTagsPebSubDetsFromSubDetList", sdFromSubDetList);
378 auto monResultSizeFullEvFrag =
Monitored::Scalar<float>(
"ResultSizeFullEvFrag", rawEvent.fragment_size_word()*wordsToKiloBytes);
384 monStreamTagCorrB, monStreamIsPeb, monPebRobsNum, monPebSubDetsNum, monSubDetsFromRobList,
385 monSubDetsFromSubDetList, monResultSizeTotal, monResultSizeFullEvFrag, monResultCollModuleID,
386 monResultCollModuleSize, monResultSizeByStream);
397 std::ostringstream
ss;
398 ss <<
"Dumping header of the FullEventFragment with HLT result:" << std::endl;
399 ss <<
"--> status = "
400 << printNWordsHex<uint32_t>(
re->nstatus(),
re->status())
402 ss <<
"--> source_id = " << printWordHex<uint32_t>(
re->source_id()) << std::endl;
403 ss <<
"--> checksum_type = " << printWordHex<uint32_t>(
re->checksum_type()) << std::endl;
404 ss <<
"--> compression_type = " << printWordHex<uint32_t>(
re->compression_type()) << std::endl;
405 ss <<
"--> compression_level = " <<
re->compression_level() << std::endl;
406 ss <<
"--> bc_time_seconds = " <<
re->bc_time_seconds() << std::endl;
407 ss <<
"--> bc_time_nanoseconds = " <<
re->bc_time_nanoseconds() << std::endl;
408 ss <<
"--> global_id = " <<
re->global_id() << std::endl;
409 ss <<
"--> run_type = " <<
re->run_type() << std::endl;
410 ss <<
"--> run_no = " <<
re->run_no() << std::endl;
411 ss <<
"--> lumi_block = " <<
re->lumi_block() << std::endl;
412 ss <<
"--> lvl1_id = " <<
re->lvl1_id() << std::endl;
413 ss <<
"--> bc_id = " <<
re->bc_id() << std::endl;
414 ss <<
"--> lvl1_trigger_type = " << printWordHex<uint8_t>(
re->lvl1_trigger_type()) << std::endl;
415 ss <<
"--> lvl1_trigger_info = "
416 << printNWordsHex<uint32_t>(
re->nlvl1_trigger_info(),
re->lvl1_trigger_info())
418 ss <<
"--> lvl2_trigger_info = "
419 << printNWordsHex<uint32_t>(
re->nlvl2_trigger_info(),
re->lvl2_trigger_info())
421 ss <<
"--> event_filter_info = "
422 << printNWordsHex<uint32_t>(
re->nevent_filter_info(),
re->event_filter_info())
424 ss <<
"--> hlt_info = "
425 << printNWordsHex<uint32_t>(
re->nhlt_info(),
re->hlt_info())
428 std::vector<eformat::helper::StreamTag>
stream_tags;
433 ATH_MSG_ERROR(
"StreamTag decoding failed, caught an unexpected std::exception " << ex.what());
437 ATH_MSG_ERROR(
"StreamTag decoding failed, caught an unexpected exception");
440 ss <<
"--> stream_tags = ";
445 ss <<
"{" << st.name <<
", " << st.type <<
", obeysLB=" << st.obeys_lumiblock <<
", robs=[";
446 for (
const auto& robid : st.robs) ss << printWordHex<uint32_t>(robid) <<
", ";
448 for (
const auto& detid : st.dets) ss << printWordHex<uint8_t>(detid) <<
", ";
449 ss <<
"]}" << std::endl;