CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
ROBFragment.h
Go to the documentation of this file.
1//Dear emacs, this is -*- c++ -*-
2
3/**
4 * @file eformat/ROBFragment.h
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 * @brief Defines the ROB fragment entity as described in the Event Format
11 * note.
12 */
13
14#ifndef EFORMAT_ROBFRAGMENT_H
15#define EFORMAT_ROBFRAGMENT_H
16
17#include "eformat/Header.h"
22
23namespace eformat {
24
25 /**
26 * Describes how to access the contents of a subdetector fragment, as
27 * prescribed by the event format note.
28 */
29 template <class TPointer>
30 class ROBFragment : public eformat::Header<TPointer> {
31
32 public: //interface
33
34 /**
35 * To build a fragment given the containing buffer. I need to know
36 * where the fragment starts in order to do that.
37 *
38 * @param it The exact position where this fragment should start.
39 */
40 ROBFragment (const TPointer& it);
41
42 /**
43 * Copy constructor
44 *
45 * @param other The fragment to be copied
46 */
47 ROBFragment (const ROBFragment& other)
48 : Header<TPointer>(other), m_start(other.m_start) {}
49
50 /**
51 * Builds an empty, otherwise useless ROBFragment
52 */
53 ROBFragment () : Header<TPointer>(), m_start() {}
54
55 /**
56 * Destructor virtualisation
57 */
58 virtual ~ROBFragment() {}
59
60 /**
61 * Assignment
62 *
63 * @param other The fragment to be copied
64 */
66 { Header<TPointer>::operator=(other); m_start=other.m_start; return *this; }
67
68 /**
69 * Manual re-assignment
70 *
71 * @param it The position pointing the first word of this fragment
72 */
73 ROBFragment& assign (const TPointer& it);
74
75 /**
76 * Says if the the fragment is valid. This may throw exceptions.
77 */
78 virtual bool check () const;
79
80 /**
81 * Says if the the fragment is valid. This may throw exceptions.
82 */
83 inline bool check_tree () const { check(); return true; }
84
85 /**
86 * Returns the fragment type.
87 */
88 inline uint32_t rod_marker() const { return m_start[0]; }
89
90 /**
91 * Returns the total fragment size
92 */
93 inline uint32_t rod_fragment_size_word() const
94 { return this->payload_size_word(); }
95
96 /**
97 * Returns the size, in words, of the current header. That does @b
98 * not include the trailer.
99 */
100 inline uint32_t rod_header_size_word() const { return m_start[1]; }
101
102 /**
103 * Returns the size, in words, of the trailer
104 */
105 inline uint32_t rod_trailer_size_word() const { return 3; }
106
107 /**
108 * Returns the formatting version.
109 */
110 inline uint32_t rod_version() const { return m_start[2]; }
111
112 /**
113 * Returns the full source identifier.
114 */
115 inline uint32_t rod_source_id() const { return m_start[3]; }
116
117 /**
118 * Returns the current run number.
119 */
120 inline uint32_t rod_run_no() const { return m_start[4]; }
121
122 /**
123 * Returns the lvl1 identifier
124 */
125 inline uint32_t rod_lvl1_id() const { return m_start[5]; }
126
127 /**
128 * Returns the bunch crossing identifier
129 */
130 inline uint32_t rod_bc_id() const { return m_start[6]; }
131
132 /**
133 * Returns the lvl1 trigger type
134 */
135 inline uint32_t rod_lvl1_trigger_type() const { return m_start[7]; }
136
137 /**
138 * Returns the detector event type
139 */
140 inline uint32_t rod_detev_type() const { return m_start[8]; }
141
142 /**
143 * Returns the number of status words available
144 */
145 inline uint32_t rod_nstatus () const
146 { return m_start[this->payload_size_word()-3]; }
147
148 /**
149 * Returns the status words, as an iterator to the status words
150 * available.
151 *
152 * @param it An <em>updateable</em> iterator you should provide.
153 */
154 void rod_status (TPointer& it) const;
155
156 /**
157 * Returns the number of data words available
158 */
159 inline uint32_t rod_ndata () const
160 { return m_start[this->payload_size_word()-2]; }
161
162 /**
163 * Returns a pointer to the first data word
164 *
165 * @param it An <em>updateable</em> iterator you should provide.
166 */
167 void rod_data (TPointer& it) const;
168
169 /**
170 * Returns the status block position. A value of <tt>zero</tt> indicates
171 * that the status block preceeds the data block. A value of <tt>one</tt>
172 * means the contrary.
173 */
174 inline uint32_t rod_status_position () const
175 { return m_start[this->payload_size_word()-1]; }
176
177 private: //static stuff
178
179 static const uint32_t NSPECIFIC;
180
181 private: //representation
182
183 TPointer m_start; ///< my last word
184
185 };
186
187}
188
189template <class TPointer>
191
192template <class TPointer>
194 : eformat::Header<TPointer>(it, eformat::ROB),
195 m_start()
196{
197 ERS_DEBUG_3("Building ROBFragment from pointer");
198 specific_header(m_start);
199 ERS_DEBUG_1("Initialized header with source identifier = %s",
201 ERS_DEBUG_3("Building underlying RODFragment");
202 if (rod_marker() != eformat::ROD)
204 ERS_DEBUG_1("Initialized ROD header with source identifier = %s",
206}
207
208template <class TPointer> eformat::ROBFragment<TPointer>&
210{
211 ERS_DEBUG_3("Re-building ROBFragment from pointer");
213 specific_header(m_start);
214 ERS_DEBUG_1("Initialized header with source identifier = %s",
215 eformat::helper::SourceIdentifier(source_id()).human().c_str());
216 ERS_DEBUG_3("Re-building underlying RODFragment");
217 if (rod_marker() != eformat::ROD)
218 throw EFORMAT_WRONG_MARKER(rod_marker(), eformat::ROD);
219 ERS_DEBUG_1("Reinitialized header with source identifier = %s",
220 eformat::helper::SourceIdentifier(rod_source_id()).human().c_str());
221 return *this;
222}
223
224template <class TPointer>
226{
227 //ROB checking
228 ERS_DEBUG_2("Checking for consistency of ROBFragment [%s]",
229 eformat::helper::SourceIdentifier(source_id()).human().c_str());
230 eformat::Header<TPointer>::check(); //< first do a generic check
231 if (eformat::Header<TPointer>::nspecific() != NSPECIFIC)
232 throw EFORMAT_SIZE_CHECK(NSPECIFIC, this->nspecific());
233
234 //ROD checking
235 ERS_DEBUG_2("Checking for consistency of RODFragment [%s]",
236 eformat::helper::SourceIdentifier(rod_source_id()).human().c_str());
237 if ( rod_version() >> 16 != eformat::MAJOR_DEFAULT_VERSION )
238 throw EFORMAT_BAD_VERSION(rod_version() >> 16,
240 if ( rod_header_size_word() != 9 )
241 throw EFORMAT_SIZE_CHECK(9, rod_header_size_word());
242 if ( rod_fragment_size_word() != 12 + rod_nstatus() + rod_ndata() )
243 throw EFORMAT_SIZE_CHECK(rod_fragment_size_word(),
244 (12 + rod_nstatus() + rod_ndata()));
245 return true;
246}
247
248template <class TPointer>
250{
251 it = m_start;
252 it += 9;
253 if (rod_status_position()) it += rod_ndata();
254}
255
256template <class TPointer>
258{
259 it = m_start;
260 it += 9;
261 if (!rod_status_position()) it += rod_nstatus();
262}
263
264#endif /* EFORMAT_ROBFRAGMENT_H */
Exception thrown when versions do not match.
#define EFORMAT_BAD_VERSION(current, supported)
Defines the constants used by Event Fragments.
Defines the Header entity. The definition is based on the update of ATL-DAQ-98-129,...
When size checks do not match, this exception must be thrown.
#define EFORMAT_SIZE_CHECK(actual, informed)
#define ERS_DEBUG_1(...)
#define ERS_DEBUG_3(...)
#define ERS_DEBUG_2(...)
Defines the wrong-marker exception, to be used when the wrong marker is found on the event stream.
#define EFORMAT_WRONG_MARKER(current, expected)
uint32_t source_id() const
Definition Header.h:116
uint32_t payload_size_word(void) const
Definition Header.h:149
Header & operator=(const Header &other)
Definition Header.h:75
Header & assign(const TPointer &it, uint32_t match)
Definition Header.h:236
void specific_header(TPointer &it) const
Definition Header.h:172
virtual bool check() const
Definition Header.h:249
void rod_data(TPointer &it) const
uint32_t rod_nstatus() const
uint32_t rod_status_position() const
uint32_t rod_trailer_size_word() const
ROBFragment(const ROBFragment &other)
Definition ROBFragment.h:47
uint32_t rod_version() const
uint32_t rod_marker() const
Definition ROBFragment.h:88
uint32_t rod_bc_id() const
uint32_t rod_lvl1_id() const
bool check_tree() const
Definition ROBFragment.h:83
ROBFragment & operator=(const ROBFragment &other)
Definition ROBFragment.h:65
ROBFragment & assign(const TPointer &it)
void rod_status(TPointer &it) const
uint32_t rod_fragment_size_word() const
Definition ROBFragment.h:93
uint32_t rod_lvl1_trigger_type() const
uint32_t rod_source_id() const
uint32_t rod_header_size_word() const
uint32_t rod_run_no() const
uint32_t rod_ndata() const
virtual bool check() const
uint32_t rod_detev_type() const
@ ROB
The ROB marker.
@ ROD
The ROD marker.
const uint16_t MAJOR_DEFAULT_VERSION
Definition Version.h:29