ATLAS Offline Software
Loading...
Searching...
No Matches
eformat_utils.cxx File Reference
#include "eformat_utils.h"
#include <vector>
#include <set>
#include "eformat/eformat.h"
#include "eformat/index.h"
#include "eformat/write/eformat.h"
#include "eformat/SourceIdentifier.h"
#include "eformat/FullEventFragmentNoTemplates.h"
#include "eformat/compression.h"
Include dependency graph for eformat_utils.cxx:

Go to the source code of this file.

Functions

 ERS_DECLARE_ISSUE (HLTMPPUIssue, EformatIssue, "Eformat Issue: \""<< type<< "\".",((const char *) type)) std

Function Documentation

◆ ERS_DECLARE_ISSUE()

ERS_DECLARE_ISSUE ( HLTMPPUIssue ,
EformatIssue ,
"Eformat Issue: \""<< type<< "\"." ,
((const char *) type)  )

Definition at line 16 of file eformat_utils.cxx.

18 : \"" << type << "\".", // message
19 ((const char *)type ) // first attribute
20 )
21
22std::vector<uint32_t>
23 DFEF::merge_hltresult_with_input_event(const uint32_t* hltresult,
24 const uint32_t* input,
25 eformat::Compression comp,
26 unsigned int comp_level) {
27 ERS_DEBUG(5, "Create read fullevent");
28 eformat::read::FullEventFragment fullevent(input); // Input full event
29 ERS_DEBUG(5, "Create write hltresult");
30 eformat::write::FullEventFragment newEvent(hltresult); // HLT result robs and event header
31
32 // Get stream tag from event passed by HLT
33 auto nstream_tag = newEvent.nstream_tag();
34 auto stream_tag = newEvent.stream_tag();
35 ERS_DEBUG(4, nstream_tag << " stream tag words, stream_tag[0]= " << stream_tag[0]);
36 std::vector<eformat::helper::StreamTag> vstream_tag;
37 eformat::helper::decode(nstream_tag, stream_tag, vstream_tag);
38
39 // set compression type
40 newEvent.compression_type(comp);
41 newEvent.compression_level(comp_level);
42 newEvent.lvl2_trigger_info(0, nullptr);
43
44 std::vector<eformat::read::ROBFragment> currRobs;
45 fullevent.robs(currRobs);
46 ERS_DEBUG(4, currRobs.size() << " robs in input event");
47
48 // Create a set of all ROB IDs in the HLT Result event
49 eformat::read::FullEventFragment tempEvent(hltresult);
50 std::vector<eformat::read::ROBFragment> tempRobs;
51 tempEvent.robs(tempRobs);
52 std::set<uint32_t> hltResultRobIds;
53 for (auto & r : tempRobs) {
54 hltResultRobIds.emplace(r.rob_source_id());
55 }
56
57 std::set<uint32_t> robset;
58 std::set<eformat::SubDetector> detset;
59 for (const auto &t : vstream_tag) {
60 if (t.robs.empty()&& t.dets.empty()) { // At least one stream_tag require full event building
61 robset.clear();
62 detset.clear();
63 break;
64 } else { // Only add the ROBs requested by stream tags
65 std::copy(std::begin(t.robs), std::end(t.robs),
66 std::inserter(robset, std::begin(robset)));
67 std::copy(std::begin(t.dets), std::end(t.dets),
68 std::inserter(detset, std::begin(detset)));
69 }
70 }
71
72 std::vector<eformat::write::ROBFragment> robs2write;
73 robs2write.reserve(currRobs.size());
74
75 // Function that decides which ROBs to add to new event
76 auto toCopy = [&](const auto & rob){
77 auto sId = rob.rob_source_id();
78 auto subId = eformat::helper::SourceIdentifier{sId}.subdetector_id();
79
80 bool build_full_event = robset.empty() && detset.empty();
81 bool HLT_rob = (subId == eformat::TDAQ_HLT);
82 bool already_in_HLTResult = (hltResultRobIds.find(sId) != hltResultRobIds.end());
83 bool suitable_for_copy = (!HLT_rob && !already_in_HLTResult);
84
85 if (build_full_event && suitable_for_copy) { // 1. Full event building
86 return true;
87 } else { // Partial event building with only some robs
88 bool requested_by_streamtag = (robset.find(sId) != robset.end()|| detset.find(subId) != detset.end());
89 if (requested_by_streamtag && suitable_for_copy) {
90 return true;
91 }
92 }
93 return false;
94 };
95
96 for (const auto& r : currRobs) {
97 if (toCopy(r)) {
98 robs2write.push_back(r.start());
99 }
100 }
101
102 ERS_DEBUG(4, robs2write.size() << " ROBs will be written to write event");
103 // do I need to do that?
104 for (size_t t = 0; t < robs2write.size(); t++) {
105 newEvent.append(&robs2write[t]);
106 }
107 // compression happens here
108 const eformat::write::node_t* top = newEvent.bind();
109 auto finalSize = newEvent.size_word();
110 auto finalEvent = std::make_unique<uint32_t[]>(finalSize);
111 ERS_DEBUG(4, finalSize << " words will be copied to final event");
112 auto res = eformat::write::copy(*top, finalEvent.get(), finalSize);
113 if (res != finalSize) {
114 std::string errMsg("ERROR, event serialization failed - ");
115 errMsg += std::string("Serialized event size: ") + std::to_string(finalSize);
116 errMsg += std::string(", Written size: ") + std::to_string(res);
117 auto issue = HLTMPPUIssue::EformatIssue(ERS_HERE,errMsg.c_str());
118 ers::warning(issue);
119 throw issue;
120 }
121 std::vector<uint32_t> result;
122 result.assign(finalEvent.get(), finalEvent.get() + finalSize);
123 return result;
124}
std::pair< std::vector< unsigned int >, bool > res
@ top
int r
Definition globals.cxx:22
std::vector< uint32_t > merge_hltresult_with_input_event(const uint32_t *hltresult, const uint32_t *input, eformat::Compression comp, unsigned int comp_level)
Merge two events: Take header and robs from hltresult event, add all res of the ROBS from input event...