/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/eformat/eformat-00-00-04/src/old/util24.cxx

Go to the documentation of this file.
00001 //Dear emacs, this is -*- c++ -*-
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: //old TDAQ_CALO_JET
00083     retval = 0x74;
00084     break;
00085   case TDAQ_CALO_JET_PROC_DAQ: //old TDAQ_CTP
00086     retval = 0x77;
00087     break;
00088   case TDAQ_CALO_JET_PROC_ROI: //old TDAQ_MUON_INTERFACE
00089     retval = 0x76;
00090     break;
00091   case TDAQ_MUON_CTP_INTERFACE: //old TDAQ_DATAFLOW
00092     switch (md) {
00093     case 0x02: //LVL1 ROSes
00094     case 0x04: //old SUPERVISOR
00095       retval = 0x78; //new L2SV
00096       break;
00097     case 0x06: //old SFI
00098       retval = 0x79; //new SFI
00099       break;
00100     case 0x07: //old SFO
00101       retval = 0x7a; //new SFO
00102       break;
00103     case 0x0a: //old OTHER_MODULE
00104       retval = OTHER; //new 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: //old TDAQ_LVL2
00114     switch (md) {
00115     case 0x01: //old L2PU->PROS
00116     case 0x02: //old L2PU->PROS
00117     case 0x05: //old HLT_PROCESSOR
00118       retval = 0x7b; //new LVL2
00119       break;
00120     case 0x04: //old SUPERVISOR
00121       retval = 0x78; //new L2SV
00122       break;
00123     case 0x06: //old SFI marker for PROS data
00124       retval = 0x79; //new SFI
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: //old TDAQ_EVENT_FILTER
00134     switch (md) {
00135     case 0x05: //old HLT_PROCESSOR
00136       retval = 0x7b; //new LVL2
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   //check version
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   //this is from the old major version of eformat, proceed with conversion
00194   old::ROSFragment ros(src);
00195   ros.check_tree(); //this may throw
00196 /**********renzy edit***/
00197 //  write::ROSFragment nros(old::convert_source(ros.source_id()),
00198   eformat::write::ROSFragment nros(old::convert_source(ros.source_id()),
00199 /**********renzy edit***/
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 /**********renzy edit***/
00206   //std::vector<write::ROBFragment*> acc_rob;
00207   std::vector<eformat::write::ROBFragment*> acc_rob;
00208 /**********renzy edit***/
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 /**********renzy edit***/
00217       //write::ROBFragment* nrob = new write::ROBFragment
00218       eformat::write::ROBFragment* nrob = new eformat::write::ROBFragment
00219 /**********renzy edit***/
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       //make this new ROB part of the new ROS
00231       nros.append(nrob);
00232       //make sure we don't forget to delete this guy
00233       acc_rob.push_back(nrob);
00234     }
00235   }
00236 
00237   //now the ROS is in `nros', bind
00238   const eformat::write::node_t* top = nros.bind();
00239   //memcpy the list of pages into contiguous memory
00240   uint32_t retval = eformat::write::copy(*top, dest, max);
00241 
00242   //delete the dynamically allocated stuff
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   //check version
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   //this is from the old major version of eformat, proceed with conversion
00270   old::FullEventFragment fe(src);
00271   fe.check_tree(); //this may throw
00272 
00273   //create the base FullEvent
00274 /**********renzy edit***/
00275   //write::FullEventFragment nfe(convert_source(fe.source_id()), 
00276   eformat::write::FullEventFragment nfe(convert_source(fe.source_id()), 
00277 /**********renzy edit***/
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 /**********renzy edit***/
00285   /*std::vector<write::SubDetectorFragment*> acc_sd;
00286   std::vector<write::ROSFragment*> acc_ros;
00287   std::vector<write::ROBFragment*> acc_rob;*/
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 /**********renzy edit***/
00292   for (size_t i=0; i<fe.noffset(); ++i) {
00293     old::SubDetectorFragment sd(fe.child(i));
00294     //create the new subdetector and set _all_ relevant stuff
00295 /**********renzy edit***/
00296     /*write::SubDetectorFragment* nsd = 
00297       new write::SubDetectorFragment(convert_source(sd.source_id()));*/
00298     eformat::write::SubDetectorFragment* nsd = 
00299       new eformat::write::SubDetectorFragment(convert_source(sd.source_id()));
00300 /**********renzy edit***/
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 /**********renzy edit***/
00308       /*write::ROSFragment* nros = 
00309         new write::ROSFragment(convert_source(ros.source_id()),
00310                                ros.run_no(), ros.lvl1_id(), ros.bc_id());*/
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 /**********renzy edit***/
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 /**********renzy edit***/
00327           //write::ROBFragment* nrob = new write::ROBFragment
00328           eformat::write::ROBFragment* nrob = new eformat::write::ROBFragment
00329 /**********renzy edit***/
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           //make this new ROB part of the new ROS
00341           nros->append(nrob);
00342           //make sure we don't forget to delete this guy
00343           acc_rob.push_back(nrob);
00344         }
00345       }
00346       //maks this new ROS part of the new SD
00347       nsd->append(nros);
00348       //make sure we don't forget to delete this guy
00349       acc_ros.push_back(nros);
00350     }
00351     //make this new SD part of the new FE
00352     nfe.append(nsd);
00353     //make sure we don't forget to delete this guy
00354     acc_sd.push_back(nsd);
00355   }
00356 
00357   //now the FullEvent is in `nfe', bind
00358   const eformat::write::node_t* top = nfe.bind();
00359   //memcpy the list of pages into contiguous memory
00360   uint32_t retval = eformat::write::copy(*top, dest, max);
00361 
00362   //delete the allocated stuff
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 

Generated on Tue Nov 29 22:58:25 2016 for BOSS_7.0.2 by  doxygen 1.4.7