BOSS 8.0.0
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:Andre.dos.Anjos@cern.ch">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/BadVersionIssue.h"
14#include "eformat/HeaderMarker.h"
15#include "eformat/SourceIdentifier.h"
16#include "eformat/Version.h"
17#include "eformat/WrongMarkerIssue.h"
18#include "eformat/old/FullEventFragment.h"
19#include "eformat/old/ROBFragment.h"
20#include "eformat/old/RODFragment.h"
21#include "eformat/old/ROSFragment.h"
22#include "eformat/old/SubDetectorFragment.h"
23#include "eformat/old/UnboundSourceIdentifierIssue.h"
24#include "eformat/old/util.h"
25#include "eformat/write/FullEventFragment.h"
26#include "ers/StreamFactory.h"
27
28uint32_t eformat::old::convert_source( uint32_t old_id ) {
29 using namespace eformat;
30
31 uint16_t id = old_id & 0x00ff;
32 uint8_t sd = ( old_id >> 8 ) & 0xff;
33 uint8_t md = ( old_id >> 16 ) & 0xff;
34 uint32_t retval = 0;
35
36 switch ( (SubDetector)sd )
37 {
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: retval = sd; break;
80 case TDAQ_CALO_CLUSTER_PROC_ROI: // old TDAQ_CALO_JET
81 retval = 0x74;
82 break;
83 case TDAQ_CALO_JET_PROC_DAQ: // old TDAQ_CTP
84 retval = 0x77;
85 break;
86 case TDAQ_CALO_JET_PROC_ROI: // old TDAQ_MUON_INTERFACE
87 retval = 0x76;
88 break;
89 case TDAQ_MUON_CTP_INTERFACE: // old TDAQ_DATAFLOW
90 switch ( md )
91 {
92 case 0x02: // LVL1 ROSes
93 case 0x04: // old SUPERVISOR
94 retval = 0x78; // new L2SV
95 break;
96 case 0x06: // old SFI
97 retval = 0x79; // new SFI
98 break;
99 case 0x07: // old SFO
100 retval = 0x7a; // new SFO
101 break;
102 case 0x0a: // old OTHER_MODULE
103 retval = OTHER; // new OTHER
104 break;
105 default:
106 ERS_WARN( "%s%x%s%s", "Propose an equivalent of the source identifier 0x", old_id,
107 " [v2.4], for the 3.0 format, to eformat developers.",
108 "The subdetector identifier field will be zero'd for now." );
109 }
110 break;
111 case TDAQ_CTP: // old TDAQ_LVL2
112 switch ( md )
113 {
114 case 0x01: // old L2PU->PROS
115 case 0x02: // old L2PU->PROS
116 case 0x05: // old HLT_PROCESSOR
117 retval = 0x7b; // new LVL2
118 break;
119 case 0x04: // old SUPERVISOR
120 retval = 0x78; // new L2SV
121 break;
122 case 0x06: // old SFI marker for PROS data
123 retval = 0x79; // new SFI
124 break;
125 default:
126 ERS_WARN( "%s%x%s%s", "Propose an equivalent of the source identifier 0x", old_id,
127 " [v2.4], for the 3.0 format, to eformat developers.",
128 "The subdetector identifier field will be zero'd for now." );
129 }
130 break;
131 case TDAQ_L2SV: // old TDAQ_EVENT_FILTER
132 switch ( md )
133 {
134 case 0x05: // old HLT_PROCESSOR
135 retval = 0x7b; // new LVL2
136 default:
137 ERS_WARN( "%s%x%s%s", "Propose an equivalent of the source identifier 0x", old_id,
138 " [v2.4], for the 3.0 format, to eformat developers.",
139 "The subdetector identifier field will be zero'd for now." );
140 }
141 break;
142 case TDAQ_SFI:
143 case TDAQ_SFO:
144 case TDAQ_LVL2:
146 default:
147 ERS_WARN( "%s%x%s%s", "Propose an equivalent of the source identifier 0x", old_id,
148 " [v2.4], for the 3.0 format, to eformat developers.",
149 "The subdetector identifier field will be zero'd for now." );
150 break;
151 }
152 retval <<= 16;
153 retval |= id;
154 ERS_DEBUG_3( "Source identifier 0x%x [v2.4] was converted to 0x%x [v3.0]", old_id, retval );
155 return retval;
156}
157
158/**
159 * Converts a ROS fragment, from the old to new format, using the space of
160 * contiguous memory storage area given. If the event given is already on v3.0
161 * format, no conversion takes place.
162 *
163 * @param src A pointer to the first word of the fragment, lying in a @b
164 * contiguous area of memory.
165 * @param dest The destination area of memory, preallocated
166 * @param max The maximum number of words that fit in the preallocated
167 * memory area "dest".
168 *
169 * @return A counter, for the number of words copied from the source to the
170 * destination. If that number is zero, something wrong happened.
171 */
172uint32_t convert_ros( const uint32_t* src, uint32_t* dest, uint32_t max ) {
173 using namespace eformat;
174
175 if ( src[0] != ROS ) { throw EFORMAT_WRONG_MARKER( src[0], ROS ); }
176
177 // check version
178 helper::Version version( src[3] );
179 if ( version.major2() == MAJOR_DEFAULT_VERSION )
180 {
181 memcpy( dest, src, sizeof( uint32_t ) * src[1] );
182 return src[1];
183 }
184 if ( version.major2() != MAJOR_OLD_VERSION )
186
187 // this is from the old major version of eformat, proceed with conversion
188 old::ROSFragment ros( src );
189 ros.check_tree(); // this may throw
190 /**********renzy edit***/
191 // write::ROSFragment nros(old::convert_source(ros.source_id()),
193 /**********renzy edit***/
194 ros.run_no(), ros.lvl1_id(), ros.bc_id() );
195 nros.status( ros.nstatus(), ros.status() );
196 helper::Version ros_version( ros.version() );
197 nros.minor_version( ros_version.minor2() );
198
199 /**********renzy edit***/
200 // std::vector<write::ROBFragment*> acc_rob;
201 std::vector<eformat::write::ROBFragment*> acc_rob;
202 /**********renzy edit***/
203 for ( size_t k = 0; k < ros.noffset(); ++k )
204 {
205 old::ROBFragment rob( ros.child( k ) );
206 uint32_t source_id = rob.source_id();
207
208 for ( size_t l = 0; l < rob.noffset(); ++l )
209 {
210 old::RODFragment rod( rob.rod( l ) );
211 if ( rob.noffset() != 1 ) source_id = rod.source_id();
212 /**********renzy edit***/
213 // write::ROBFragment* nrob = new write::ROBFragment
215 /**********renzy edit***/
216 ( old::convert_source( source_id ), rod.run_no(), rod.lvl1_id(), rod.bc_id(),
217 rod.lvl1_trigger_type(), rod.detev_type(), rod.ndata(), rod.data(),
218 rod.status_position() );
219 nrob->status( rob.nstatus(), rob.status() );
220 nrob->rod_status( rod.nstatus(), rod.status() );
221 helper::Version rob_version( rob.version() );
222 nrob->minor_version( rob_version.minor2() );
223 helper::Version rod_version( rod.version() );
224 nrob->rod_minor_version( rod_version.minor2() );
225
226 // make this new ROB part of the new ROS
227 nros.append( nrob );
228 // make sure we don't forget to delete this guy
229 acc_rob.push_back( nrob );
230 }
231 }
232
233 // now the ROS is in `nros', bind
234 const eformat::write::node_t* top = nros.bind();
235 // memcpy the list of pages into contiguous memory
236 uint32_t retval = eformat::write::copy( *top, dest, max );
237
238 // delete the dynamically allocated stuff
239 for ( size_t i = 0; i < acc_rob.size(); ++i ) delete acc_rob[i];
240
241 return retval;
242}
243
244uint32_t eformat::old::convert( const uint32_t* src, uint32_t* dest, uint32_t max ) {
245 using namespace eformat;
246
247 if ( src[0] != FULL_EVENT )
248 {
249 if ( src[0] != ROS ) { throw EFORMAT_WRONG_MARKER( src[0], FULL_EVENT ); }
250 return convert_ros( src, dest, max );
251 }
252
253 // check version
254 helper::Version version( src[3] );
255 if ( version.major2() == MAJOR_DEFAULT_VERSION )
256 {
257 memcpy( dest, src, sizeof( uint32_t ) * src[1] );
258 return src[1];
259 }
260 if ( version.major2() != MAJOR_OLD_VERSION )
262
263 // this is from the old major version of eformat, proceed with conversion
264 old::FullEventFragment fe( src );
265 fe.check_tree(); // this may throw
266
267 // create the base FullEvent
268 /**********renzy edit***/
269 // write::FullEventFragment nfe(convert_source(fe.source_id()),
271 /**********renzy edit***/
272 fe.date(), fe.global_id(), fe.run_no(), fe.lvl1_id(),
274 fe.event_filter_info() );
275 nfe.status( fe.nstatus(), fe.status() );
276 nfe.minor_version( version.minor2() );
277
278 /**********renzy edit***/
279 /*std::vector<write::SubDetectorFragment*> acc_sd;
280 std::vector<write::ROSFragment*> acc_ros;
281 std::vector<write::ROBFragment*> acc_rob;*/
282 std::vector<eformat::write::SubDetectorFragment*> acc_sd;
283 std::vector<eformat::write::ROSFragment*> acc_ros;
284 std::vector<eformat::write::ROBFragment*> acc_rob;
285 /**********renzy edit***/
286 for ( size_t i = 0; i < fe.noffset(); ++i )
287 {
288 old::SubDetectorFragment sd( fe.child( i ) );
289 // create the new subdetector and set _all_ relevant stuff
290 /**********renzy edit***/
291 /*write::SubDetectorFragment* nsd =
292 new write::SubDetectorFragment(convert_source(sd.source_id()));*/
295 /**********renzy edit***/
296 nsd->status( sd.nstatus(), sd.status() );
297 helper::Version sd_version( sd.version() );
298 nsd->minor_version( sd_version.minor2() );
299
300 for ( size_t j = 0; j < sd.noffset(); ++j )
301 {
302 old::ROSFragment ros( sd.child( j ) );
303 /**********renzy edit***/
304 /*write::ROSFragment* nros =
305 new write::ROSFragment(convert_source(ros.source_id()),
306 ros.run_no(), ros.lvl1_id(), ros.bc_id());*/
308 convert_source( ros.source_id() ), ros.run_no(), ros.lvl1_id(), ros.bc_id() );
309 /**********renzy edit***/
310 nros->status( ros.nstatus(), ros.status() );
311 helper::Version ros_version( ros.version() );
312 nros->minor_version( ros_version.minor2() );
313
314 for ( size_t k = 0; k < ros.noffset(); ++k )
315 {
316 old::ROBFragment rob( ros.child( k ) );
317 uint32_t source_id = rob.source_id();
318
319 for ( size_t l = 0; l < rob.noffset(); ++l )
320 {
321 old::RODFragment rod( rob.rod( l ) );
322 if ( rob.noffset() != 1 ) source_id = rod.source_id();
323 /**********renzy edit***/
324 // write::ROBFragment* nrob = new write::ROBFragment
326 /**********renzy edit***/
327 ( convert_source( source_id ), rod.run_no(), rod.lvl1_id(), rod.bc_id(),
328 rod.lvl1_trigger_type(), rod.detev_type(), rod.ndata(), rod.data(),
329 rod.status_position() );
330 nrob->status( rob.nstatus(), rob.status() );
331 nrob->rod_status( rod.nstatus(), rod.status() );
332 helper::Version rob_version( rob.version() );
333 nrob->minor_version( rob_version.minor2() );
334 helper::Version rod_version( rod.version() );
335 nrob->rod_minor_version( rod_version.minor2() );
336
337 // make this new ROB part of the new ROS
338 nros->append( nrob );
339 // make sure we don't forget to delete this guy
340 acc_rob.push_back( nrob );
341 }
342 }
343 // maks this new ROS part of the new SD
344 nsd->append( nros );
345 // make sure we don't forget to delete this guy
346 acc_ros.push_back( nros );
347 }
348 // make this new SD part of the new FE
349 nfe.append( nsd );
350 // make sure we don't forget to delete this guy
351 acc_sd.push_back( nsd );
352 }
353
354 // now the FullEvent is in `nfe', bind
355 const eformat::write::node_t* top = nfe.bind();
356 // memcpy the list of pages into contiguous memory
357 uint32_t retval = eformat::write::copy( *top, dest, max );
358
359 // delete the allocated stuff
360 for ( size_t i = 0; i < acc_rob.size(); ++i ) delete acc_rob[i];
361 for ( size_t i = 0; i < acc_ros.size(); ++i ) delete acc_ros[i];
362 for ( size_t i = 0; i < acc_sd.size(); ++i ) delete acc_sd[i];
363
364 return retval;
365}
#define max(a, b)
#define EFORMAT_BAD_VERSION(current, supported)
#define EFORMAT_WRONG_MARKER(current, expected)
#define ERS_DEBUG_3(...)
const uint32_t * child(size_t n) const
Definition Header24.cxx:36
eformat::old::RODFragment rod(size_t n) const
const uint32_t * status(void) const
const uint32_t * data(void) 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 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:244
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:60
uint32_t convert_ros(const uint32_t *src, uint32_t *dest, uint32_t max)
Definition util24.cxx:172