BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
ROSFragment.cxx
Go to the documentation of this file.
1//Dear emacs, this is -*- c++ -*-
2
3/**
4 * @file ROSFragment.cxx
5 * @author <a href="mailto:[email protected]">Andre DOS ANJOS</a>
6 * $Author: maqm $
7 * $Revision: 1.2 $
8 * $Date: 2011/02/20 23:38:21 $
9 *
10 * Implements the ROS fragment writing helper class
11 */
12
13#include "eformat/write/ROSFragment.h"
14#include "eformat/write/SubDetectorFragment.h"
15#include "eformat/HeaderMarker.h"
16#include "eformat/Status.h"
17#include "ers/StreamFactory.h"
18#include <cstring>
20(uint32_t source_id, uint32_t run_no, uint32_t lvl1_id, uint32_t bc_id)
21 : m_parent(0),
22 m_child(0),
23 m_last(0),
24 m_next(0),
25 m_extra_count(0)
26{
27 m_header[0] = eformat::ROS; //marker
28 m_header[1] = 11; //this header size + status size
29 m_header[2] = 11; //this header size + status size
30 m_header[3] = eformat::DEFAULT_VERSION; //format version
31 m_header[4] = source_id;
32 m_header[5] = 1; //number of status
33 m_header[6] = 3; //number of fragment specific
34 m_header[7] = run_no;
35 m_header[8] = lvl1_id;
36 m_header[9] = bc_id;
37
38 //now initialize pages
39 set(m_node[0], m_header, 6, &m_node[1]);
40 set(m_node[1], &eformat::DEFAULT_STATUS, 1, &m_node[2]);
41 set(m_node[2], &m_header[6], 4, 0);
42 ERS_DEBUG_3("%s Source Id. = 0x%x., LVL1 Id. = %d, Run Number = %d",
43 "Built (write) ros fragment from scratch, with",
46}
47
49 : m_parent(0),
50 m_child(0),
51 m_last(0),
52 m_next(0),
53 m_extra_count(0)
54{
55 //now initialize pages
56 set(m_node[0], ros, 6, &m_node[1]);
57 set(m_node[1], &ros[6], ros[5], &m_node[2]);
58 set(m_node[2], &ros[6+ros[5]], 4, &m_extra);
59 eformat::write::set(m_extra, &ros[10+ros[5]], ros[1]-ros[2]);
60 ++m_extra_count;
61 ERS_DEBUG_3("%s Source Id. = 0x%x., LVL1 Id. = %d, Run Number = %d",
62 "Built (write) ros fragment from contiguous memory, with",
63 source_id(), lvl1_id(), run_no());
64}
65
67 : m_parent(0),
68 m_child(0),
69 m_last(0),
70 m_next(0),
71 m_extra_count(0)
72{
73 //now initialize pages
74 set(m_node[0], ros->base, 6, &m_node[1]);
75 set(m_node[1], &ros->base[6], ros->base[5], &m_node[2]);
76 set(m_node[2], &ros->base[6+ros->base[5]], 4, &m_extra);
77 eformat::write::set(m_extra, &ros->base[10+ros->base[5]],
78 ros->size_word - ros->base[2], ros->next);
79 m_extra_count += eformat::write::count(m_extra);
80 ERS_DEBUG_3("%s Source Id. = 0x%x., LVL1 Id. = %d, Run Number = %d",
81 "Built (write) ros fragment from paged memory, with",
82 source_id(), lvl1_id(), run_no());
83}
84
86 : m_parent(0),
87 m_child(0),
88 m_last(0),
89 m_next(0),
90 m_extra_count(0)
91{
92 m_header[0] = eformat::ROS; //marker
93 m_header[1] = 11; //this header size + status size
94 m_header[2] = 11; //this header size + status size
95 m_header[3] = eformat::DEFAULT_VERSION; //format version
96 m_header[4] = 0; //source identifier
97 m_header[5] = 1; //number of status
98 m_header[6] = 3; //number of fragment specific
99 m_header[7] = 0; //run number
100 m_header[8] = 0; //LVL1 identifier
101 m_header[9] = 0; //bunch crossing identifier
102
103 //now initialize pages
104 set(m_node[0], m_header, 6, &m_node[1]);
105 set(m_node[1], &eformat::DEFAULT_STATUS, 1, &m_node[2]);
106 set(m_node[2], &m_header[6], 4, 0);
107 ERS_DEBUG_3("%s Source Id. = 0x%x., LVL1 Id. = %d, Run Number = %d",
108 "Built empty (write) ros fragment from scratch, with",
111}
112
114(const eformat::write::ROSFragment& other)
115 : m_parent(0),
116 m_child(0),
117 m_last(0),
118 m_next(0),
119 m_extra_count(0)
120{
121 *this = other;
122 ERS_DEBUG_3("%s Source Id. = 0x%x., LVL1 Id. = %d, Run Number = %d",
123 "Built (write) ros fragment from copy, with",
126}
127
128eformat::write::ROSFragment& eformat::write::ROSFragment::operator=
129 (const eformat::write::ROSFragment& other)
130{
131 memcpy(reinterpret_cast<void*>(m_header),
132 reinterpret_cast<const void*>(other.m_node[0].base),
133 6*sizeof(uint32_t));
134 memcpy(reinterpret_cast<void*>(m_header+6),
135 reinterpret_cast<const void*>(other.m_node[2].base),
136 4*sizeof(uint32_t));
137
138 //now initialize pages
139 set(m_node[0], m_header, 6, &m_node[1]);
140 set(m_node[1], other.m_node[1].base, other.m_node[1].size_word, &m_node[2]);
141 set(m_node[2], &m_header[6], 4, 0);
142 ERS_DEBUG_3("%s Source Id. = 0x%x., LVL1 Id. = %d, Run Number = %d",
143 "Copied (write) ros fragment, with",
146 return *this;
147}
148
149void eformat::write::ROSFragment::status (uint32_t n, const uint32_t* status)
150{
151 if (m_parent) m_parent->size_change(m_node[0].base[1],
152 m_node[0].base[1]-m_node[0].base[5]+n);
153 m_node[0].base[1] -= m_node[0].base[5]; //remove count from previous status
154 m_node[0].base[2] -= m_node[0].base[5]; //remove count from previous status
155 m_node[1].size_word = m_node[0].base[5] = n; //set new values
156 m_node[0].base[1] += n;
157 m_node[0].base[2] += n;
158 m_node[1].base = const_cast<uint32_t*>(status);
159}
160
162{
163 uint32_t old_size = m_node[0].base[1];
164 m_node[0].base[1] -= o;
165 m_node[0].base[1] += n;
166 if (m_parent) m_parent->size_change(old_size, m_node[0].base[1]);
167}
168
170{
171 ERS_DEBUG_3("%s Source Id. = 0x%x to ros fragment with Source Id. = 0x%x",
172 "Appending rob fragment with",
173 rob->source_id(), source_id());
174 rob->parent(this);
175 uint32_t old_size = m_node[0].base[1];
176 m_node[0].base[1] += rob->size_word();
177
178 //adjust `m_last' and `m_child' to point to the new last ROB
179 if (m_last) m_last->next(rob);
180 else m_child = rob;
181 m_last = rob;
182
183 //propagate changes to my parent
184 if (m_parent) m_parent->size_change(old_size, m_node[0].base[1]);
185}
186
188{
189 uint32_t retval = 3 + m_extra_count;
190 for (const ROBFragment* curr = m_child; curr; curr = curr->next())
191 retval += curr->page_count();
192 return retval;
193}
194
196{
197 //the header is already concatenated by construction
198 eformat::write::node_t* last = &m_node[2];
199 if (m_extra_count) {
200 last = &m_extra;
201 while (last->next) last = last->next;
202 }
203 for (const ROBFragment* curr = m_child; curr; curr = curr->next()) {
204 last->next = const_cast<eformat::write::node_t*>(curr->bind());
205 while (last->next) last = last->next; //advance until end
206 }
207 return m_node;
208}
const Int_t n
uint32_t page_count(void) const
void size_change(uint32_t o, uint32_t n)
const eformat::write::node_t * bind(void)
void append(eformat::write::ROBFragment *rob)
uint32_t count(const node_t &list)
Definition: node.cxx:42
void set(node_t &i, const uint32_t *b, size_t l, node_t *n=0)
Definition: node.cxx:16
uint32_t * base
The base address for this page.
size_t size_word
The size, in 4-byte words for this page.