BOSS 7.0.8
BESIII Offline Software System
Loading...
Searching...
No Matches
util24.cxx
Go to the documentation of this file.
1//Dear emacs, this is -*- c++ -*-
2
3/**
4 * @file util.cxx
5 * @author <a href="mailto:[email protected]">Andre DOS ANJOS</a>
6 * $Author: zhangy $
7 * $Revision: 1.1.1.1 $
8 * $Date: 2009/06/19 07:35:41 $
9 *
10 * Implements the utilities described in the equivalent header.
11 */
12
13#include "eformat/old/util.h"
23#include "eformat/Version.h"
25#include "ers/StreamFactory.h"
27
28uint32_t eformat::old::convert_source (uint32_t old_id)
29{
30 using namespace eformat;
31
32 uint16_t id = old_id & 0x00ff;
33 uint8_t sd = ( old_id >> 8 ) & 0xff;
34 uint8_t md = ( old_id >> 16 ) & 0xff;
35 uint32_t retval = 0;
36
37 switch ((SubDetector)sd) {
38 case FULL_SD_EVENT:
39 case PIXEL_BARREL:
42 case PIXEL_B_LAYER:
58 case LAR_FCAL_A_SIDE:
59 case LAR_FCAL_C_SIDE:
76 case TDAQ_BEAM_CRATE:
79 case OTHER:
80 retval = sd;
81 break;
82 case TDAQ_CALO_CLUSTER_PROC_ROI: //old TDAQ_CALO_JET
83 retval = 0x74;
84 break;
85 case TDAQ_CALO_JET_PROC_DAQ: //old TDAQ_CTP
86 retval = 0x77;
87 break;
88 case TDAQ_CALO_JET_PROC_ROI: //old TDAQ_MUON_INTERFACE
89 retval = 0x76;
90 break;
91 case TDAQ_MUON_CTP_INTERFACE: //old TDAQ_DATAFLOW
92 switch (md) {
93 case 0x02: //LVL1 ROSes
94 case 0x04: //old SUPERVISOR
95 retval = 0x78; //new L2SV
96 break;
97 case 0x06: //old SFI
98 retval = 0x79; //new SFI
99 break;
100 case 0x07: //old SFO
101 retval = 0x7a; //new SFO
102 break;
103 case 0x0a: //old OTHER_MODULE
104 retval = OTHER; //new OTHER
105 break;
106 default:
107 ERS_WARN("%s%x%s%s",
108 "Propose an equivalent of the source identifier 0x", old_id,
109 " [v2.4], for the 3.0 format, to eformat developers.",
110 "The subdetector identifier field will be zero'd for now.");
111 }
112 break;
113 case TDAQ_CTP: //old TDAQ_LVL2
114 switch (md) {
115 case 0x01: //old L2PU->PROS
116 case 0x02: //old L2PU->PROS
117 case 0x05: //old HLT_PROCESSOR
118 retval = 0x7b; //new LVL2
119 break;
120 case 0x04: //old SUPERVISOR
121 retval = 0x78; //new L2SV
122 break;
123 case 0x06: //old SFI marker for PROS data
124 retval = 0x79; //new SFI
125 break;
126 default:
127 ERS_WARN("%s%x%s%s",
128 "Propose an equivalent of the source identifier 0x", old_id,
129 " [v2.4], for the 3.0 format, to eformat developers.",
130 "The subdetector identifier field will be zero'd for now.");
131 }
132 break;
133 case TDAQ_L2SV: //old TDAQ_EVENT_FILTER
134 switch (md) {
135 case 0x05: //old HLT_PROCESSOR
136 retval = 0x7b; //new LVL2
137 default:
138 ERS_WARN("%s%x%s%s",
139 "Propose an equivalent of the source identifier 0x", old_id,
140 " [v2.4], for the 3.0 format, to eformat developers.",
141 "The subdetector identifier field will be zero'd for now.");
142 }
143 break;
144 case TDAQ_SFI:
145 case TDAQ_SFO:
146 case TDAQ_LVL2:
148 default:
149 ERS_WARN("%s%x%s%s",
150 "Propose an equivalent of the source identifier 0x", old_id,
151 " [v2.4], for the 3.0 format, to eformat developers.",
152 "The subdetector identifier field will be zero'd for now.");
153 break;
154 }
155 retval <<= 16;
156 retval |= id;
157 ERS_DEBUG_3("Source identifier 0x%x [v2.4] was converted to 0x%x [v3.0]",
158 old_id, retval);
159 return retval;
160}
161
162/**
163 * Converts a ROS fragment, from the old to new format, using the space of
164 * contiguous memory storage area given. If the event given is already on v3.0
165 * format, no conversion takes place.
166 *
167 * @param src A pointer to the first word of the fragment, lying in a @b
168 * contiguous area of memory.
169 * @param dest The destination area of memory, preallocated
170 * @param max The maximum number of words that fit in the preallocated
171 * memory area "dest".
172 *
173 * @return A counter, for the number of words copied from the source to the
174 * destination. If that number is zero, something wrong happened.
175 */
176uint32_t convert_ros(const uint32_t* src, uint32_t* dest, uint32_t max)
177{
178 using namespace eformat;
179
180 if (src[0] != ROS) {
181 throw EFORMAT_WRONG_MARKER(src[0], ROS);
182 }
183
184 //check version
185 helper::Version version(src[3]);
186 if (version.major2() == MAJOR_DEFAULT_VERSION) {
187 memcpy(dest, src, sizeof(uint32_t)*src[1]);
188 return src[1];
189 }
190 if (version.major2() != MAJOR_OLD_VERSION)
191 throw EFORMAT_BAD_VERSION(version.major2(), MAJOR_DEFAULT_VERSION);
192
193 //this is from the old major version of eformat, proceed with conversion
194 old::ROSFragment ros(src);
195 ros.check_tree(); //this may throw
196/**********renzy edit***/
197// write::ROSFragment nros(old::convert_source(ros.source_id()),
198 eformat::write::ROSFragment nros(old::convert_source(ros.source_id()),
199/**********renzy edit***/
200 ros.run_no(), ros.lvl1_id(), ros.bc_id());
201 nros.status(ros.nstatus(), ros.status());
202 helper::Version ros_version(ros.version());
203 nros.minor_version(ros_version.minor2());
204
205/**********renzy edit***/
206 //std::vector<write::ROBFragment*> acc_rob;
207 std::vector<eformat::write::ROBFragment*> acc_rob;
208/**********renzy edit***/
209 for (size_t k=0; k<ros.noffset(); ++k) {
210 old::ROBFragment rob(ros.child(k));
211 uint32_t source_id = rob.source_id();
212
213 for (size_t l=0; l<rob.noffset(); ++l) {
214 old::RODFragment rod(rob.rod(l));
215 if (rob.noffset() != 1) source_id = rod.source_id();
216/**********renzy edit***/
217 //write::ROBFragment* nrob = new write::ROBFragment
219/**********renzy edit***/
220 (old::convert_source(source_id), rod.run_no(), rod.lvl1_id(),
221 rod.bc_id(), rod.lvl1_trigger_type(), rod.detev_type(),
222 rod.ndata(), rod.data(), rod.status_position());
223 nrob->status(rob.nstatus(), rob.status());
224 nrob->rod_status(rod.nstatus(), rod.status());
225 helper::Version rob_version(rob.version());
226 nrob->minor_version(rob_version.minor2());
227 helper::Version rod_version(rod.version());
228 nrob->rod_minor_version(rod_version.minor2());
229
230 //make this new ROB part of the new ROS
231 nros.append(nrob);
232 //make sure we don't forget to delete this guy
233 acc_rob.push_back(nrob);
234 }
235 }
236
237 //now the ROS is in `nros', bind
238 const eformat::write::node_t* top = nros.bind();
239 //memcpy the list of pages into contiguous memory
240 uint32_t retval = eformat::write::copy(*top, dest, max);
241
242 //delete the dynamically allocated stuff
243 for (size_t i=0; i<acc_rob.size(); ++i) delete acc_rob[i];
244
245 return retval;
246}
247
248uint32_t eformat::old::convert(const uint32_t* src, uint32_t* dest,
249 uint32_t max)
250{
251 using namespace eformat;
252
253 if (src[0] != FULL_EVENT) {
254 if (src[0] != ROS) {
255 throw EFORMAT_WRONG_MARKER(src[0], FULL_EVENT);
256 }
257 return convert_ros(src, dest, max);
258 }
259
260 //check version
261 helper::Version version(src[3]);
262 if (version.major2() == MAJOR_DEFAULT_VERSION) {
263 memcpy(dest, src, sizeof(uint32_t)*src[1]);
264 return src[1];
265 }
266 if (version.major2() != MAJOR_OLD_VERSION)
268
269 //this is from the old major version of eformat, proceed with conversion
271 fe.check_tree(); //this may throw
272
273 //create the base FullEvent
274/**********renzy edit***/
275 //write::FullEventFragment nfe(convert_source(fe.source_id()),
277/**********renzy edit***/
278 fe.date(), fe.global_id(), fe.run_no(),
279 fe.lvl1_id(), fe.lvl1_trigger_type(),
281 nfe.status(fe.nstatus(), fe.status());
282 nfe.minor_version(version.minor2());
283
284/**********renzy edit***/
285 /*std::vector<write::SubDetectorFragment*> acc_sd;
286 std::vector<write::ROSFragment*> acc_ros;
287 std::vector<write::ROBFragment*> acc_rob;*/
288 std::vector<eformat::write::SubDetectorFragment*> acc_sd;
289 std::vector<eformat::write::ROSFragment*> acc_ros;
290 std::vector<eformat::write::ROBFragment*> acc_rob;
291/**********renzy edit***/
292 for (size_t i=0; i<fe.noffset(); ++i) {
294 //create the new subdetector and set _all_ relevant stuff
295/**********renzy edit***/
296 /*write::SubDetectorFragment* nsd =
297 new write::SubDetectorFragment(convert_source(sd.source_id()));*/
300/**********renzy edit***/
301 nsd->status(sd.nstatus(), sd.status());
302 helper::Version sd_version(sd.version());
303 nsd->minor_version(sd_version.minor2());
304
305 for (size_t j=0; j<sd.noffset(); ++j) {
306 old::ROSFragment ros(sd.child(j));
307/**********renzy edit***/
308 /*write::ROSFragment* nros =
309 new write::ROSFragment(convert_source(ros.source_id()),
310 ros.run_no(), ros.lvl1_id(), ros.bc_id());*/
313 ros.run_no(), ros.lvl1_id(), ros.bc_id());
314/**********renzy edit***/
315 nros->status(ros.nstatus(), ros.status());
316 helper::Version ros_version(ros.version());
317 nros->minor_version(ros_version.minor2());
318
319 for (size_t k=0; k<ros.noffset(); ++k) {
320 old::ROBFragment rob(ros.child(k));
321 uint32_t source_id = rob.source_id();
322
323 for (size_t l=0; l<rob.noffset(); ++l) {
324 old::RODFragment rod(rob.rod(l));
325 if (rob.noffset() != 1) source_id = rod.source_id();
326/**********renzy edit***/
327 //write::ROBFragment* nrob = new write::ROBFragment
329/**********renzy edit***/
330 (convert_source(source_id), rod.run_no(), rod.lvl1_id(),
331 rod.bc_id(), rod.lvl1_trigger_type(), rod.detev_type(),
332 rod.ndata(), rod.data(), rod.status_position());
333 nrob->status(rob.nstatus(), rob.status());
334 nrob->rod_status(rod.nstatus(), rod.status());
335 helper::Version rob_version(rob.version());
336 nrob->minor_version(rob_version.minor2());
337 helper::Version rod_version(rod.version());
338 nrob->rod_minor_version(rod_version.minor2());
339
340 //make this new ROB part of the new ROS
341 nros->append(nrob);
342 //make sure we don't forget to delete this guy
343 acc_rob.push_back(nrob);
344 }
345 }
346 //maks this new ROS part of the new SD
347 nsd->append(nros);
348 //make sure we don't forget to delete this guy
349 acc_ros.push_back(nros);
350 }
351 //make this new SD part of the new FE
352 nfe.append(nsd);
353 //make sure we don't forget to delete this guy
354 acc_sd.push_back(nsd);
355 }
356
357 //now the FullEvent is in `nfe', bind
358 const eformat::write::node_t* top = nfe.bind();
359 //memcpy the list of pages into contiguous memory
360 uint32_t retval = eformat::write::copy(*top, dest, max);
361
362 //delete the allocated stuff
363 for (size_t i=0; i<acc_rob.size(); ++i) delete acc_rob[i];
364 for (size_t i=0; i<acc_ros.size(); ++i) delete acc_ros[i];
365 for (size_t i=0; i<acc_sd.size(); ++i) delete acc_sd[i];
366
367 return retval;
368}
369
370
371
Exception thrown when versions do not match.
#define EFORMAT_BAD_VERSION(current, supported)
Defines the constants used by Event Fragments.
Definition of the ROD header entity, following the description of the Event Format note,...
Declares a type that can perform the conversion between source identifier components and the its 32-b...
#define ERS_DEBUG_3(...)
#define ERS_WARN(...)
Defines a helper class to encode and decode version numbers.
Defines the wrong-marker exception, to be used when the wrong marker is found on the event stream.
#define EFORMAT_WRONG_MARKER(current, expected)
uint16_t minor2(void) const
Definition: Version.h:70
uint16_t major2(void) const
Definition: Version.h:65
const uint32_t * event_filter_info(void) const
uint32_t version() const
Definition: old/Header.h:83
const uint32_t * status() const
Definition: old/Header.h:104
uint32_t nstatus() const
Definition: old/Header.h:98
uint32_t run_no() const
Definition: old/Header.h:93
uint32_t source_id() const
Definition: old/Header.h:88
const uint32_t * child(size_t n) const
Definition: Header24.cxx:39
uint32_t noffset() const
Definition: old/Header.h:110
eformat::old::RODFragment rod(size_t n) const
uint32_t source_id() const
Definition: RODFragment.h:84
uint32_t status_position() const
Definition: RODFragment.h:137
uint32_t run_no() const
Definition: RODFragment.h:89
const uint32_t * status(void) const
uint32_t bc_id() const
Definition: RODFragment.h:99
uint32_t nstatus() const
Definition: RODFragment.h:114
uint32_t lvl1_id() const
Definition: RODFragment.h:94
uint32_t detev_type() const
Definition: RODFragment.h:109
uint32_t version() const
Definition: RODFragment.h:79
uint32_t ndata() const
Definition: RODFragment.h:125
const uint32_t * data(void) const
uint32_t lvl1_trigger_type() const
Definition: RODFragment.h:104
uint32_t lvl1_id() const
void append(eformat::write::SubDetectorFragment *sd)
const eformat::write::node_t * bind(void)
void status(uint32_t n, const uint32_t *status)
void status(uint32_t n, const uint32_t *status)
void rod_status(uint32_t n, const uint32_t *status)
void rod_minor_version(uint16_t v)
void status(uint32_t n, const uint32_t *status)
const eformat::write::node_t * bind(void)
void append(eformat::write::ROBFragment *rob)
void status(uint32_t n, const uint32_t *status)
void append(eformat::write::ROSFragment *ros)
uint32_t convert(const uint32_t *src, uint32_t *dest, uint32_t max)
Definition: util24.cxx:248
uint32_t convert_source(uint32_t old_id)
Definition: util24.cxx:28
uint32_t copy(const node_t &list, uint32_t *dest, size_t max)
Definition: node.cxx:64
@ TILECAL_BARREL_C_SIDE
@ TILECAL_EXT_C_SIDE
@ MUON_CSC_ENDCAP_C_SIDE
@ TILECAL_LASER_CRATE
@ MUON_TGC_ENDCAP_C_SIDE
@ MUON_CSC_ENDCAP_A_SIDE
@ LAR_EM_ENDCAP_A_SIDE
@ TDAQ_MUON_CTP_INTERFACE
@ MUON_MDT_BARREL_A_SIDE
@ MUON_MDT_ENDCAP_C_SIDE
@ LAR_HAD_ENDCAP_C_SIDE
@ MUON_TGC_ENDCAP_A_SIDE
@ LAR_EM_BARREL_A_SIDE
@ LAR_EM_BARREL_C_SIDE
@ MUON_MDT_ENDCAP_A_SIDE
@ TDAQ_CALO_JET_PROC_ROI
@ LAR_HAD_ENDCAP_A_SIDE
@ TDAQ_CALO_CLUSTER_PROC_ROI
@ TILECAL_EXT_A_SIDE
@ TDAQ_CALO_CLUSTER_PROC_DAQ
@ TDAQ_CALO_JET_PROC_DAQ
@ TRT_ANCILLARY_CRATE
@ PIXEL_FORWARD_C_SIDE
@ PIXEL_FORWARD_A_SIDE
@ MUON_RPC_BARREL_C_SIDE
@ TILECAL_BARREL_A_SIDE
@ MUON_ANCILLARY_CRATE
@ LAR_EM_ENDCAP_C_SIDE
@ MUON_RPC_BARREL_A_SIDE
@ MUON_MDT_BARREL_C_SIDE
@ FULL_EVENT
Definition: HeaderMarker.h:30
@ ROS
The ROS marker.
Definition: HeaderMarker.h:28
const uint16_t MAJOR_OLD_VERSION
Definition: Version.h:34
const uint16_t MAJOR_DEFAULT_VERSION
Definition: Version.h:29
Defines the Event Fragment entity. The definition is based on the update of ATL-DAQ-98-129,...
Defines the ROB fragment entity as described in the Event Format note.
Describes the ROS fragment as defined in the Event Format note, version 2.4.
Defines the subdetector fragment entity. The definition is based on the update of ATL-DAQ-98-129,...
A set of utilities to convert old eformat (v2.4) tags into new (v3) ones.
uint32_t convert_ros(const uint32_t *src, uint32_t *dest, uint32_t max)
Definition: util24.cxx:176
Helps the user to define and build a FullEvent fragment.