00001
00002
00013 #include "eformat/old/util.h"
00014 #include "eformat/old/UnboundSourceIdentifierIssue.h"
00015 #include "eformat/old/FullEventFragment.h"
00016 #include "eformat/old/SubDetectorFragment.h"
00017 #include "eformat/old/ROSFragment.h"
00018 #include "eformat/old/ROBFragment.h"
00019 #include "eformat/old/RODFragment.h"
00020 #include "eformat/SourceIdentifier.h"
00021 #include "eformat/HeaderMarker.h"
00022 #include "eformat/WrongMarkerIssue.h"
00023 #include "eformat/Version.h"
00024 #include "eformat/BadVersionIssue.h"
00025 #include "ers/StreamFactory.h"
00026 #include "eformat/write/FullEventFragment.h"
00027
00028 uint32_t eformat::old::convert_source (uint32_t old_id)
00029 {
00030 using namespace eformat;
00031
00032 uint16_t id = old_id & 0x00ff;
00033 uint8_t sd = ( old_id >> 8 ) & 0xff;
00034 uint8_t md = ( old_id >> 16 ) & 0xff;
00035 uint32_t retval = 0;
00036
00037 switch ((SubDetector)sd) {
00038 case FULL_SD_EVENT:
00039 case PIXEL_BARREL:
00040 case PIXEL_FORWARD_A_SIDE:
00041 case PIXEL_FORWARD_C_SIDE:
00042 case PIXEL_B_LAYER:
00043 case SCT_BARREL_A_SIDE:
00044 case SCT_BARREL_C_SIDE:
00045 case SCT_ENDCAP_A_SIDE:
00046 case SCT_ENDCAP_C_SIDE:
00047 case TRT_ANCILLARY_CRATE:
00048 case TRT_BARREL_A_SIDE:
00049 case TRT_BARREL_C_SIDE:
00050 case TRT_ENDCAP_A_SIDE:
00051 case TRT_ENDCAP_C_SIDE:
00052 case LAR_EM_BARREL_A_SIDE:
00053 case LAR_EM_BARREL_C_SIDE:
00054 case LAR_EM_ENDCAP_A_SIDE:
00055 case LAR_EM_ENDCAP_C_SIDE:
00056 case LAR_HAD_ENDCAP_A_SIDE:
00057 case LAR_HAD_ENDCAP_C_SIDE:
00058 case LAR_FCAL_A_SIDE:
00059 case LAR_FCAL_C_SIDE:
00060 case TILECAL_LASER_CRATE:
00061 case TILECAL_BARREL_A_SIDE:
00062 case TILECAL_BARREL_C_SIDE:
00063 case TILECAL_EXT_A_SIDE:
00064 case TILECAL_EXT_C_SIDE:
00065 case MUON_ANCILLARY_CRATE:
00066 case MUON_MDT_BARREL_A_SIDE:
00067 case MUON_MDT_BARREL_C_SIDE:
00068 case MUON_MDT_ENDCAP_A_SIDE:
00069 case MUON_MDT_ENDCAP_C_SIDE:
00070 case MUON_RPC_BARREL_A_SIDE:
00071 case MUON_RPC_BARREL_C_SIDE:
00072 case MUON_TGC_ENDCAP_A_SIDE:
00073 case MUON_TGC_ENDCAP_C_SIDE:
00074 case MUON_CSC_ENDCAP_A_SIDE:
00075 case MUON_CSC_ENDCAP_C_SIDE:
00076 case TDAQ_BEAM_CRATE:
00077 case TDAQ_CALO_PREPROC:
00078 case TDAQ_CALO_CLUSTER_PROC_DAQ:
00079 case OTHER:
00080 retval = sd;
00081 break;
00082 case TDAQ_CALO_CLUSTER_PROC_ROI:
00083 retval = 0x74;
00084 break;
00085 case TDAQ_CALO_JET_PROC_DAQ:
00086 retval = 0x77;
00087 break;
00088 case TDAQ_CALO_JET_PROC_ROI:
00089 retval = 0x76;
00090 break;
00091 case TDAQ_MUON_CTP_INTERFACE:
00092 switch (md) {
00093 case 0x02:
00094 case 0x04:
00095 retval = 0x78;
00096 break;
00097 case 0x06:
00098 retval = 0x79;
00099 break;
00100 case 0x07:
00101 retval = 0x7a;
00102 break;
00103 case 0x0a:
00104 retval = OTHER;
00105 break;
00106 default:
00107 ERS_WARN("%s%x%s%s",
00108 "Propose an equivalent of the source identifier 0x", old_id,
00109 " [v2.4], for the 3.0 format, to eformat developers.",
00110 "The subdetector identifier field will be zero'd for now.");
00111 }
00112 break;
00113 case TDAQ_CTP:
00114 switch (md) {
00115 case 0x01:
00116 case 0x02:
00117 case 0x05:
00118 retval = 0x7b;
00119 break;
00120 case 0x04:
00121 retval = 0x78;
00122 break;
00123 case 0x06:
00124 retval = 0x79;
00125 break;
00126 default:
00127 ERS_WARN("%s%x%s%s",
00128 "Propose an equivalent of the source identifier 0x", old_id,
00129 " [v2.4], for the 3.0 format, to eformat developers.",
00130 "The subdetector identifier field will be zero'd for now.");
00131 }
00132 break;
00133 case TDAQ_L2SV:
00134 switch (md) {
00135 case 0x05:
00136 retval = 0x7b;
00137 default:
00138 ERS_WARN("%s%x%s%s",
00139 "Propose an equivalent of the source identifier 0x", old_id,
00140 " [v2.4], for the 3.0 format, to eformat developers.",
00141 "The subdetector identifier field will be zero'd for now.");
00142 }
00143 break;
00144 case TDAQ_SFI:
00145 case TDAQ_SFO:
00146 case TDAQ_LVL2:
00147 case TDAQ_EVENT_FILTER:
00148 default:
00149 ERS_WARN("%s%x%s%s",
00150 "Propose an equivalent of the source identifier 0x", old_id,
00151 " [v2.4], for the 3.0 format, to eformat developers.",
00152 "The subdetector identifier field will be zero'd for now.");
00153 break;
00154 }
00155 retval <<= 16;
00156 retval |= id;
00157 ERS_DEBUG_3("Source identifier 0x%x [v2.4] was converted to 0x%x [v3.0]",
00158 old_id, retval);
00159 return retval;
00160 }
00161
00176 uint32_t convert_ros(const uint32_t* src, uint32_t* dest, uint32_t max)
00177 {
00178 using namespace eformat;
00179
00180 if (src[0] != ROS) {
00181 throw EFORMAT_WRONG_MARKER(src[0], ROS);
00182 }
00183
00184
00185 helper::Version version(src[3]);
00186 if (version.major2() == MAJOR_DEFAULT_VERSION) {
00187 memcpy(dest, src, sizeof(uint32_t)*src[1]);
00188 return src[1];
00189 }
00190 if (version.major2() != MAJOR_OLD_VERSION)
00191 throw EFORMAT_BAD_VERSION(version.major2(), MAJOR_DEFAULT_VERSION);
00192
00193
00194 old::ROSFragment ros(src);
00195 ros.check_tree();
00196
00197
00198 eformat::write::ROSFragment nros(old::convert_source(ros.source_id()),
00199
00200 ros.run_no(), ros.lvl1_id(), ros.bc_id());
00201 nros.status(ros.nstatus(), ros.status());
00202 helper::Version ros_version(ros.version());
00203 nros.minor_version(ros_version.minor2());
00204
00205
00206
00207 std::vector<eformat::write::ROBFragment*> acc_rob;
00208
00209 for (size_t k=0; k<ros.noffset(); ++k) {
00210 old::ROBFragment rob(ros.child(k));
00211 uint32_t source_id = rob.source_id();
00212
00213 for (size_t l=0; l<rob.noffset(); ++l) {
00214 old::RODFragment rod(rob.rod(l));
00215 if (rob.noffset() != 1) source_id = rod.source_id();
00216
00217
00218 eformat::write::ROBFragment* nrob = new eformat::write::ROBFragment
00219
00220 (old::convert_source(source_id), rod.run_no(), rod.lvl1_id(),
00221 rod.bc_id(), rod.lvl1_trigger_type(), rod.detev_type(),
00222 rod.ndata(), rod.data(), rod.status_position());
00223 nrob->status(rob.nstatus(), rob.status());
00224 nrob->rod_status(rod.nstatus(), rod.status());
00225 helper::Version rob_version(rob.version());
00226 nrob->minor_version(rob_version.minor2());
00227 helper::Version rod_version(rod.version());
00228 nrob->rod_minor_version(rod_version.minor2());
00229
00230
00231 nros.append(nrob);
00232
00233 acc_rob.push_back(nrob);
00234 }
00235 }
00236
00237
00238 const eformat::write::node_t* top = nros.bind();
00239
00240 uint32_t retval = eformat::write::copy(*top, dest, max);
00241
00242
00243 for (size_t i=0; i<acc_rob.size(); ++i) delete acc_rob[i];
00244
00245 return retval;
00246 }
00247
00248 uint32_t eformat::old::convert(const uint32_t* src, uint32_t* dest,
00249 uint32_t max)
00250 {
00251 using namespace eformat;
00252
00253 if (src[0] != FULL_EVENT) {
00254 if (src[0] != ROS) {
00255 throw EFORMAT_WRONG_MARKER(src[0], FULL_EVENT);
00256 }
00257 return convert_ros(src, dest, max);
00258 }
00259
00260
00261 helper::Version version(src[3]);
00262 if (version.major2() == MAJOR_DEFAULT_VERSION) {
00263 memcpy(dest, src, sizeof(uint32_t)*src[1]);
00264 return src[1];
00265 }
00266 if (version.major2() != MAJOR_OLD_VERSION)
00267 throw EFORMAT_BAD_VERSION(version.major2(), MAJOR_DEFAULT_VERSION);
00268
00269
00270 old::FullEventFragment fe(src);
00271 fe.check_tree();
00272
00273
00274
00275
00276 eformat::write::FullEventFragment nfe(convert_source(fe.source_id()),
00277
00278 fe.date(), fe.global_id(), fe.run_no(),
00279 fe.lvl1_id(), fe.lvl1_trigger_type(),
00280 fe.lvl2_trigger_info(), fe.event_filter_info());
00281 nfe.status(fe.nstatus(), fe.status());
00282 nfe.minor_version(version.minor2());
00283
00284
00285
00286
00287
00288 std::vector<eformat::write::SubDetectorFragment*> acc_sd;
00289 std::vector<eformat::write::ROSFragment*> acc_ros;
00290 std::vector<eformat::write::ROBFragment*> acc_rob;
00291
00292 for (size_t i=0; i<fe.noffset(); ++i) {
00293 old::SubDetectorFragment sd(fe.child(i));
00294
00295
00296
00297
00298 eformat::write::SubDetectorFragment* nsd =
00299 new eformat::write::SubDetectorFragment(convert_source(sd.source_id()));
00300
00301 nsd->status(sd.nstatus(), sd.status());
00302 helper::Version sd_version(sd.version());
00303 nsd->minor_version(sd_version.minor2());
00304
00305 for (size_t j=0; j<sd.noffset(); ++j) {
00306 old::ROSFragment ros(sd.child(j));
00307
00308
00309
00310
00311 eformat::write::ROSFragment* nros =
00312 new eformat::write::ROSFragment(convert_source(ros.source_id()),
00313 ros.run_no(), ros.lvl1_id(), ros.bc_id());
00314
00315 nros->status(ros.nstatus(), ros.status());
00316 helper::Version ros_version(ros.version());
00317 nros->minor_version(ros_version.minor2());
00318
00319 for (size_t k=0; k<ros.noffset(); ++k) {
00320 old::ROBFragment rob(ros.child(k));
00321 uint32_t source_id = rob.source_id();
00322
00323 for (size_t l=0; l<rob.noffset(); ++l) {
00324 old::RODFragment rod(rob.rod(l));
00325 if (rob.noffset() != 1) source_id = rod.source_id();
00326
00327
00328 eformat::write::ROBFragment* nrob = new eformat::write::ROBFragment
00329
00330 (convert_source(source_id), rod.run_no(), rod.lvl1_id(),
00331 rod.bc_id(), rod.lvl1_trigger_type(), rod.detev_type(),
00332 rod.ndata(), rod.data(), rod.status_position());
00333 nrob->status(rob.nstatus(), rob.status());
00334 nrob->rod_status(rod.nstatus(), rod.status());
00335 helper::Version rob_version(rob.version());
00336 nrob->minor_version(rob_version.minor2());
00337 helper::Version rod_version(rod.version());
00338 nrob->rod_minor_version(rod_version.minor2());
00339
00340
00341 nros->append(nrob);
00342
00343 acc_rob.push_back(nrob);
00344 }
00345 }
00346
00347 nsd->append(nros);
00348
00349 acc_ros.push_back(nros);
00350 }
00351
00352 nfe.append(nsd);
00353
00354 acc_sd.push_back(nsd);
00355 }
00356
00357
00358 const eformat::write::node_t* top = nfe.bind();
00359
00360 uint32_t retval = eformat::write::copy(*top, dest, max);
00361
00362
00363 for (size_t i=0; i<acc_rob.size(); ++i) delete acc_rob[i];
00364 for (size_t i=0; i<acc_ros.size(); ++i) delete acc_ros[i];
00365 for (size_t i=0; i<acc_sd.size(); ++i) delete acc_sd[i];
00366
00367 return retval;
00368 }
00369
00370
00371