ATLAS Offline Software
Loading...
Searching...
No Matches
v40_write_FullEventFragment.cxx
Go to the documentation of this file.
1//Dear emacs, this is -*- c++ -*-
2
3/*
4 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
5*/
6
7
17
20#include "eformat/HeaderMarker.h"
21#include "eformat/Status.h"
22#include "eformat/Issue.h"
23#include "eformat/checksum.h"
24
26{
27 m_header[0] = eformat::FULL_EVENT; //marker
28 m_header[1] = 21; //this header size + status size
29 m_header[2] = 21; //this header size + status size
30 eformat::helper::Version version(0, eformat::MAJOR_V40_VERSION);
31 m_header[3] = version.code(); //format version
32 m_header[4] = 0; //source identifier
33 m_header[5] = 1; //number of status
34 m_header[6] = eformat::NO_CHECKSUM; //check sum
35 m_header[7] = 0; //bc time seconds
36 m_header[8] = 0; //bc time nanoseconds
37 m_header[9] = 0; //global identifier
38 m_header[10] = 0; //run type
39 m_header[11] = 0; //run number
40 m_header[12] = 0; //luminosity block number
41 m_header[13] = 0; //LVL1 identifiery
42 m_header[14] = 0; //bunch crossing identifier
43 m_header[15] = 0; //LVL1 trigger type
44 m_header[16] = 0; //number of LVL1 info words
45 m_header[17] = 0; //number of LVL2 info words
46 m_header[18] = 0; //number of EF info words
47 m_header[19] = 0; //number of Stream Tag words
48
49 //now initialize pages
50 set(m_node[0], m_header, 6, &m_node[1]);
51 set(m_node[1], &eformat::DEFAULT_STATUS, 1, &m_node[2]);
52 set(m_node[2], &m_header[6], 11, &m_node[3]);
53 set(m_node[3], 0, 0, &m_node[4]); //no LVL1 info yet
54 set(m_node[4], &m_header[17], 1, &m_node[5]);
55 set(m_node[5], 0, 0, &m_node[6]); //no LVL2 info yet
56 set(m_node[6], &m_header[18], 1, &m_node[7]);
57 set(m_node[7], 0, 0, &m_node[8]); //no EF info yet
58 set(m_node[8], &m_header[19], 1, &m_node[9]);
59 set(m_node[9], 0, 0, 0); //no stream tag yet
60
61 //optional extra payload
62 set(m_node[10], 0, 0, 0);
63
64 //optional checksum stuff (trailer)
65 m_checksum = 0;
66 set(m_node[11], &m_checksum, 1, 0);
67
68 //our unchecked data
69 m_n_unchecked = 0;
70 set(m_unchecked[0], 0, 0, 0);
71
72 m_child = 0;
73 m_last = 0;
74}
75
77(uint32_t source_id, uint32_t bc_time_secs, uint32_t bc_time_nsec,
78 uint32_t global_id, uint32_t run_type,
79 uint32_t run_no, uint16_t lumi_block,
80 uint32_t lvl1_id, uint16_t bc_id, uint8_t lvl1_type)
81{
82 initialize();
83 this->source_id(source_id);
84 bc_time_seconds(bc_time_secs);
85 bc_time_nanoseconds(bc_time_nsec);
86 this->global_id(global_id);
87 this->run_type(run_type);
88 this->run_no(run_no);
89 this->lumi_block(lumi_block);
90 this->lvl1_id(lvl1_id);
91 this->bc_id(bc_id);
92 lvl1_trigger_type(lvl1_type);
93}
94
96{
97 initialize();
98 copy_header(fe);
100 if (read.payload_size_word() > 0) {
101 const uint32_t* tmp;
102 m_node[9].next = &m_node[10];
103 read.payload(tmp);
104 set(m_node[10], tmp, read.payload_size_word(), 0);
105 m_header[1] += read.payload_size_word();
106 }
107}
108
113
117
119{
121 read.check(); //this gives us a good start-up scenario
122 eformat::helper::Version fe_ver(read.version());
123 minor_version(fe_ver.minor_version());
124 source_id(read.source_id());
125 bc_time_seconds(read.bc_time_seconds());
126 bc_time_nanoseconds(read.bc_time_nanoseconds());
127 global_id(read.global_id());
128 run_type(read.run_type());
129 run_no(read.run_no());
130 lumi_block(read.lumi_block());
131 lvl1_id(read.lvl1_id());
132 bc_id(read.bc_id());
133 lvl1_trigger_type(read.lvl1_trigger_type());
134 const uint32_t* tmp;
135 read.status(tmp);
136 status(read.nstatus(), tmp);
137 read.lvl1_trigger_info(tmp);
138 lvl1_trigger_info(read.nlvl1_trigger_info(), tmp);
139 read.lvl2_trigger_info(tmp);
140 lvl2_trigger_info(read.nlvl2_trigger_info(), tmp);
141 read.event_filter_info(tmp);
142 event_filter_info(read.nevent_filter_info(), tmp);
143 read.stream_tag(tmp);
144 stream_tag(read.nstream_tag(), tmp);
145 checksum_type(read.checksum_type());
146}
147
150{
151 minor_version(other.minor_version());
152 source_id(other.source_id());
153 bc_time_seconds(other.bc_time_seconds());
154 bc_time_nanoseconds(other.bc_time_nanoseconds());
155 global_id(other.global_id());
156 run_type(other.run_type());
157 run_no(other.run_no());
158 lumi_block(other.lumi_block());
159 lvl1_id(other.lvl1_id());
160 bc_id(other.bc_id());
161 lvl1_trigger_type(other.lvl1_trigger_type());
162 status(other.nstatus(), other.status());
163 lvl1_trigger_info(other.nlvl1_trigger_info(), other.lvl1_trigger_info());
164 lvl2_trigger_info(other.nlvl2_trigger_info(), other.lvl2_trigger_info());
165 event_filter_info(other.nevent_filter_info(), other.event_filter_info());
166 stream_tag(other.nstream_tag(), other.stream_tag());
167 checksum_type(other.checksum_type());
168}
169
171(uint32_t n, const uint32_t* status)
172{
173 m_node[0].base[1] -= m_node[0].base[5]; //remove count from previous status
174 m_node[0].base[2] -= m_node[0].base[5]; //remove count from previous status
175 m_node[1].size_word = m_node[0].base[5] = n; //set new values
176 m_node[0].base[1] += n;
177 m_node[0].base[2] += n;
178 // FIXME: I'm assuming that these are ok.
179 // Probably can't avoid this as long as we're using node_t from eformat.
180 uint32_t* status_nc ATLAS_THREAD_SAFE = const_cast<uint32_t*>(status);
181 m_node[1].base = status_nc;
182}
183
185(uint32_t n, const uint32_t* data)
186{
187 m_node[0].base[1] -= nlvl1_trigger_info(); //remove previous count
188 m_node[0].base[2] -= nlvl1_trigger_info(); //remove previous count
189 m_node[3].size_word = m_node[2].base[10] = n; //set new values
190 m_node[0].base[1] += n; //fragment size
191 m_node[0].base[2] += n; //header size
192 // FIXME: I'm assuming that these are ok.
193 // Probably can't avoid this as long as we're using node_t from eformat.
194 uint32_t* data_nc ATLAS_THREAD_SAFE = const_cast<uint32_t*>(data);
195 m_node[3].base = data_nc;
196}
197
199(uint32_t n, const uint32_t* data)
200{
201 m_node[0].base[1] -= nlvl2_trigger_info(); //remove previous count
202 m_node[0].base[2] -= nlvl2_trigger_info(); //remove previous count
203 m_node[5].size_word = m_node[4].base[0] = n; //set new values
204 m_node[0].base[1] += n; //fragment size
205 m_node[0].base[2] += n; //header size
206 // FIXME: I'm assuming that these are ok.
207 // Probably can't avoid this as long as we're using node_t from eformat.
208 uint32_t* data_nc ATLAS_THREAD_SAFE = const_cast<uint32_t*>(data);
209 m_node[5].base = data_nc;
210}
211
213(uint32_t n, const uint32_t* data)
214{
215 m_node[0].base[1] -= nevent_filter_info(); //remove previous count
216 m_node[0].base[2] -= nevent_filter_info(); //remove previous count
217 m_node[7].size_word = m_node[6].base[0] = n; //set new values
218 m_node[0].base[1] += n; //fragment size
219 m_node[0].base[2] += n; //header size
220 // FIXME: I'm assuming that these are ok.
221 // Probably can't avoid this as long as we're using node_t from eformat.
222 uint32_t* data_nc ATLAS_THREAD_SAFE = const_cast<uint32_t*>(data);
223 m_node[7].base = data_nc;
224}
225
227(uint32_t n, const uint32_t* data)
228{
229 m_node[0].base[1] -= nstream_tag(); //remove previous count
230 m_node[0].base[2] -= nstream_tag(); //remove previous count
231 m_node[9].size_word = m_node[8].base[0] = n; //set new values
232 m_node[0].base[1] += n; //fragment size
233 m_node[0].base[2] += n; //header size
234 // FIXME: I'm assuming that these are ok.
235 // Probably can't avoid this as long as we're using node_t from eformat.
236 uint32_t* data_nc ATLAS_THREAD_SAFE = const_cast<uint32_t*>(data);
237 m_node[9].base = data_nc;
238}
239
242{
243 rob->parent(this);
244 rob->next(0); //reset any previous relationship
245 m_node[0].base[1] += rob->size_word();
246
247 //adjust `m_last' and `m_child' to point to the new last ROB
248 if (m_last) m_last->next(rob);
249 else m_child = rob;
250 m_last = rob;
251}
252
254{
256 throw EFORMAT_TOO_MANY_UNCHECKED(MAX_UNCHECKED_FRAGMENTS);
257 v40::ROBFragment frag(rob);
258 if (m_n_unchecked) //more fragments are available before this one
261 m_node[0].base[1] += frag.fragment_size_word();
262}
263
265{
266 uint32_t retval = 10 + (m_node[9].next?1:0) + (checksum_type()?1:0);
267 for (const v40_write::ROBFragment* curr = m_child; curr; curr = curr->next())
268 retval += curr->page_count();
269 return retval+m_n_unchecked;
270}
271
272const eformat::write::node_t*
274{
275 //the header is already concatenated by construction
276 eformat::write::node_t* last = &m_node[9];
277 eformat::write::node_t* payload = last; //buffer for an instant...
278 if (m_node[10].size_word) last = last->next; //advance one node
279 last->next = 0; //potentially remove old checksum
280
281 //iterate over the attached children
282 for (v40_write::ROBFragment* curr = m_child; curr; curr = curr->next()) {
283 last->next = curr->bind();
284 while (last->next) last = last->next; //advance until end
285 }
286
287 //make sure the last page of the last attached children points to the first
288 //unchecked page, but only if we have unchecked ROB fragments appended
289 if (m_n_unchecked) {
290 last->next = m_unchecked;
291 last = &m_unchecked[m_n_unchecked-1];
292 last->next = 0; //potentially remove old checksum
293 }
294
295 //calculate the checksum if it was requested and we have data
296 //in this part of the code "payload" points to 1 node before the begin
297 if (checksum_type() != eformat::NO_CHECKSUM) {
298 payload = payload->next; //position cursor at payload start
299 if (!payload) {
300 eformat::write::node_t null;
301 set(null, 0, 0, 0);
302 m_checksum = eformat::write::checksum(checksum_type(), &null);
303 }
304 else
305 m_checksum = eformat::write::checksum(checksum_type(), payload);
306 last->next = &m_node[11];
307 }
308
309 return m_node;
310}
311
313{
314 if (m_node[2].base[0] == eformat::NO_CHECKSUM && s != eformat::NO_CHECKSUM) {
315 //Going from no checksum to having a checksum: update sizes
316 m_node[0].base[1] += 1;
317 }
318 else if (m_node[2].base[0] != eformat::NO_CHECKSUM &&
319 s == eformat::NO_CHECKSUM) {
320 //Going from having a checksum to no checksum: update sizes
321 m_node[0].base[1] -= 1;
322 }
323 m_node[2].base[0] = s;
324}
325
327(uint32_t n) const
328{
329 return m_unchecked[n].base;
330}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
#define ATLAS_THREAD_SAFE
Describes how to access the contents of an event fragment, as prescribed by the event format note.
uint32_t fragment_size_word() const
Returns the size, in words, of the current fragment.
Describes how to access the contents of a subdetector fragment, as prescribed by the event format not...
Defines a helper class to aid the creation of FullEvent fragments.
void minor_version(uint16_t v)
Changes the minor version number of the fragment.
void stream_tag(uint32_t n, const uint32_t *data)
Changes the stream tag words from the fragment.
uint32_t page_count(void) const
Returns the total number of (raw memory) pages this fragment is composed of.
const uint32_t * stream_tag(void) const
Returns a pointer to the first stream tag word to be used by this fragment.
FullEventFragment()
Builds a new empty FullEventFragment, otherwise invalid.
const eformat::write::node_t * bind(void)
Returns the first node of a list of nodes that represent the fragment you have constructed.
eformat::write::node_t m_node[12]
Node representation.
const uint32_t * lvl2_trigger_info(void) const
Returns a pointer to the first LVL2 trigger info to be used by this fragment.
uint32_t nlvl2_trigger_info(void) const
Returns the number of status wors in this fragment.
uint32_t nstream_tag(void) const
Returns the number of stream tag words in this fragment.
void append(v40_write::ROBFragment *rob)
Appends a new ROB fragment to this FullEvent fragment.
void copy_header(const uint32_t *other)
Copies the header (meta data information) from another existing FullEvent Fragment.
void lvl1_trigger_info(uint32_t n, const uint32_t *data)
Changes the LVL1 trigger info words from the fragment.
uint32_t checksum_type(void) const
Returns the check sum type of this fragment.
void global_id(uint32_t s)
Changes the global identifier for this event.
const uint32_t * status(void) const
Returns a pointer to the first status word to be used by this fragment.
uint32_t m_n_unchecked
The number of unchecked nodes attached.
void status(uint32_t n, const uint32_t *status)
Changes the number of status words and the status words themselves from the fragment.
const uint32_t * unchecked_fragment(uint32_t n) const
Returns a particular unchecked ROB fragment.
void lvl1_id(uint32_t s)
Changes the lvl1 identifier in this fragment.
void source_id(uint32_t s)
Changes the source identifier for this fragment.
void bc_id(uint16_t s)
Changes the bunch crossing identifier in this fragment.
uint32_t m_checksum
My payload's checksum, if asked.
const uint32_t * event_filter_info(void) const
Returns a pointer to the first EF trigger info to be used by this fragment.
uint32_t nevent_filter_info(void) const
Returns the number of status wors in this fragment.
eformat::write::node_t m_unchecked[MAX_UNCHECKED_FRAGMENTS]
Unchecked nodes.
void bc_time_nanoseconds(uint32_t s)
Changes the bunch crossing time (the nanoseconds part) this fragment was produced at.
void lvl1_trigger_type(uint8_t s)
Changes the lvl1 trigger type in this fragment.
void event_filter_info(uint32_t n, const uint32_t *data)
Changes the EF trigger info words from the fragment.
void lumi_block(uint16_t s)
Changes the luminosity block number.
void lvl2_trigger_info(uint32_t n, const uint32_t *data)
Changes the LVL2 trigger info words from the fragment.
void checksum_type(uint32_t s)
Changes the check-sum type for this fragment.
void initialize(void)
Initializes the internal fields of this ROB fragment with the standard values.
uint32_t nlvl1_trigger_info(void) const
Returns the number of status wors in this fragment.
uint32_t size_word(void) const
Returns the total size for this fragment, in words.
const uint32_t * lvl1_trigger_info(void) const
Returns a pointer to the first LVL1 trigger info to be used by this fragment.
void append_unchecked(const uint32_t *rob)
Appends an unchecked (read-only) ROB fragment to the current FullEvent.
void bc_time_seconds(uint32_t s)
Changes the bunch crossing time (seconds) this fragment was produced at.
Defines a helper class to aid the creation of ROB fragments.
void parent(v40_write::FullEventFragment *ros)
This sets the parent fragment.
void next(ROBFragment *n)
Sets the next sibling.
uint32_t size_word(void) const
Returns the total size for this fragment, in words.
STL class.
std::string base
Definition hcg.cxx:81
const uint32_t MAX_UNCHECKED_FRAGMENTS
Maximum number of unchecked fragments a writeable FullEventFragment may have.
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
void initialize()