/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Calibration/CalibSvc/CalibROOTCnv/CalibROOTCnv-00-01-13/src/cnv/RootTofSimDataCnv.cxx

Go to the documentation of this file.
00001 // $Header: /bes/bes/BossCvs/Calibration/CalibSvc/CalibROOTCnv/src/cnv/RootTofSimDataCnv.cxx,v 1.2 2010/02/03 01:18:23 huangb Exp $
00002 #include "GaudiKernel/MsgStream.h"
00003 #include "RootTofSimDataCnv.h"
00004 #include "CalibData/Tof/TofSimData.h"
00005 #include "CalibData/Tof/BTofSimBase.h"
00006 #include "CalibData/Tof/ETofSimBase.h"
00007 #include "CalibData/Tof/TofSimConstBase.h"
00008 #include "CalibDataSvc/IInstrumentName.h"
00009 
00010 #include "TFile.h"
00011 #include "TTree.h"
00012 #include "TDirectory.h"
00013 #include "TObject.h"
00014 
00015 #include "GaudiKernel/CnvFactory.h"
00016 #include "GaudiKernel/IOpaqueAddress.h"
00017 #include "GaudiKernel/DataObject.h"
00018 #include "GaudiKernel/IAddressCreator.h"
00019 #include "GaudiKernel/IDataProviderSvc.h"
00020 #include "GaudiKernel/IConversionSvc.h"
00021 #include "GaudiKernel/GenericAddress.h"
00022 
00023 #include "CalibDataSvc/ICalibRootSvc.h"    //maybe
00024 #include "CalibDataSvc/ICalibMetaCnvSvc.h"
00025 //#include "CalibData/CalibTime.h"
00026 //#include "commonRootData/idents/CalXtalId.h"
00027 //#include "idents/CalXtalId.h"
00028 
00029 // Temporary.  Hope to find a better way to do this
00030 #include "CalibData/CalibModel.h"
00031 using namespace CalibData;
00032 //static CnvFactory<RootTofSimDataCnv> TofCalib_factory;
00033 //const  ICnvFactory& RootTofSimDataCnvFactory = TofCalib_factory;
00034 
00035 
00036 
00037 RootTofSimDataCnv::RootTofSimDataCnv( ISvcLocator* svc) :
00038   RootCalBaseCnv(svc, CLID_Calib_TofSim) { 
00039  }
00040 
00041 
00042 const CLID& RootTofSimDataCnv::objType() const {
00043   return CLID_Calib_TofSim;
00044 }
00045 
00046 const CLID& RootTofSimDataCnv::classID() {
00047   return CLID_Calib_TofSim;
00048 }
00049 
00050 StatusCode RootTofSimDataCnv::i_createObj(const std::string& fname,
00051                                        DataObject*& refpObject) {
00052 
00053   MsgStream log(msgSvc(), "RootTofSimDataCnv");
00054   log<<MSG::DEBUG<<"SetProperty"<<endreq;
00055  
00056  // open the file
00057   StatusCode sc = openRead(fname);
00058   if(!sc)
00059     { log<<MSG::ERROR<<"unable to open files"<<endreq;
00060     }
00061  
00062   CalibData::BTofSimBase bTof;
00063   CalibData::ETofSimBase eTof;
00064   CalibData::TofSimConstBase tofbase;
00065   std::vector<CalibData::BTofSimBase> tmpbTof;//; = new vector<CalibData::bTofCalibBase>;
00066   std::vector<CalibData::ETofSimBase> tmpeTof;
00067   std::vector<CalibData::TofSimConstBase> tofbaseCol;
00068    // Read in the object
00069   int cnt;
00070   // read btoftree ------------------------------------------------------------
00071      double AttenLength;
00072      double Gain;
00073      double Ratio;
00074      double NoiseSmear;
00075      TTree *btoftree = (TTree*)m_inFile -> Get("BTofSim");
00076      btoftree -> SetBranchAddress("AttenLength", &AttenLength);
00077      btoftree -> SetBranchAddress("Gain", &Gain);
00078      btoftree -> SetBranchAddress("Ratio", &Ratio);
00079      int entries=btoftree->GetEntries();
00080        for(cnt=0; cnt<entries; cnt++){
00081          btoftree -> GetEntry(cnt);
00082          bTof.setGain(Gain);
00083          bTof.setRatio(Ratio);
00084          bTof.setAttenLength(AttenLength);
00085          tmpbTof.push_back(bTof);
00086           }
00087        //read etoftree
00088      TTree *etoftree = (TTree*)m_inFile -> Get("ETofSim");
00089      etoftree -> SetBranchAddress("Gain", &Gain);
00090      etoftree -> SetBranchAddress("AttenLength", &AttenLength);
00091      etoftree -> SetBranchAddress("NoiseSmear",  &NoiseSmear );
00092        entries=etoftree->GetEntries();
00093        for(cnt=0; cnt<entries; cnt++){
00094          etoftree->GetEntry(cnt);
00095          eTof.setGain(Gain);
00096          eTof.setAttenLength(AttenLength);
00097          eTof.setNoiseSmear(NoiseSmear);
00098          tmpeTof.push_back(eTof);
00099           }
00100 
00101    //read SimConstants
00102     double BarConstant,BarPMTGain,BarHighThres,BarLowThres,EndConstant,EndPMTGain,EndHighThres,EndLowThres,EndNoiseSwitch;
00103     TTree *btofcommontree = (TTree*)m_inFile -> Get("SimConstants");
00104     btofcommontree-> SetBranchAddress("BarConstant", &BarConstant);
00105     btofcommontree-> SetBranchAddress("BarPMTGain",  &BarPMTGain);
00106     btofcommontree-> SetBranchAddress("BarHighThres", &BarHighThres);
00107     btofcommontree-> SetBranchAddress("BarLowThres", &BarLowThres);
00108     btofcommontree-> SetBranchAddress("EndConstant", &EndConstant);
00109     btofcommontree-> SetBranchAddress("EndPMTGain",  &EndPMTGain);
00110     btofcommontree-> SetBranchAddress("EndHighThres", &EndHighThres);
00111     btofcommontree-> SetBranchAddress("EndLowThres", &EndLowThres);
00112     btofcommontree-> SetBranchAddress("EndNoiseSwitch", &EndNoiseSwitch);
00113        entries = btofcommontree->GetEntries();
00114       for(cnt=0;cnt<entries;cnt++){
00115               btofcommontree->GetEntry(cnt);
00116               tofbase.setBarLowThres(BarLowThres);
00117               tofbase.setBarHighThres(BarHighThres);
00118               tofbase.setEndLowThres(EndLowThres);
00119               tofbase.setEndHighThres(EndHighThres);
00120               tofbase.setBarPMTGain(BarPMTGain);
00121               tofbase.setEndPMTGain(EndPMTGain); 
00122               tofbase.setBarConstant(BarConstant);
00123               tofbase.setEndConstant(EndConstant); 
00124               tofbase.setEndNoiseSwitch(EndNoiseSwitch); 
00125               tofbaseCol.push_back(tofbase);   
00126      }
00127 
00128      CalibData::TofSimData *tmpObject = new CalibData::TofSimData(&tofbaseCol,&tmpbTof,&tmpeTof);
00129 
00130   
00131       refpObject=tmpObject;
00132 
00133   return StatusCode::SUCCESS;
00134 }
00135 
00136 StatusCode RootTofSimDataCnv::createRoot(const std::string& fname, 
00137                                         CalibData::CalibBase1* pTDSObj) {
00138    MsgStream log(msgSvc(), "RootTofSimDataCnv");
00139 
00140  // Open the file, create the branch
00141    StatusCode sc = openWrite(fname);
00142   if(!sc)
00143     { log<<MSG::ERROR<<"unable to open files"<<endreq;
00144     }
00145   // write the Data in the TCDS to RootFile
00146  /*    int i;
00147      int j;
00148      CalibData::TofCalibData* btof = dynamic_cast<CalibData::TofCalibData*>(pTDSObj);
00149 
00150   // write  btoftree----------------------------------------------------------------
00151      double cnvP1[10];
00152      double cnvP2[10];
00153      double cnvW[4];
00154      double cnvAtten[8];
00155      double cnvQ;
00156      double cnvSpeed[2];
00157      TTree *btoftree = new TTree("BarTofPar", "BarTofPar");
00158       btoftree -> Branch("Atten0",&cnvAtten[0], "Atten0/D");
00159       btoftree -> Branch("Atten1",&cnvAtten[1], "Atten1/D");
00160       btoftree -> Branch("Atten2",&cnvAtten[2], "Atten2/D");
00161       btoftree -> Branch("Atten3",&cnvAtten[3], "Atten3/D");
00162       btoftree -> Branch("Atten4",&cnvAtten[4], "Atten4/D");
00163       btoftree -> Branch("Atten5",&cnvAtten[5], "Atten5/D");
00164       btoftree -> Branch("Atten6",&cnvAtten[6], "Atten6/D");
00165       btoftree -> Branch("Atten7",&cnvAtten[7], "Atten7/D");
00166       btoftree -> Branch("Q0",&cnvQ, "Q0/D");
00167       btoftree -> Branch("Speed0",&cnvSpeed[0], "Speed0/D");
00168       btoftree -> Branch("Speed1",&cnvSpeed[1], "Speed1/D");
00169       btoftree -> Branch("P0",&cnvP1[0], "P0/D");
00170       btoftree -> Branch("P1",&cnvP1[1], "P1/D");
00171       btoftree -> Branch("P2",&cnvP1[2], "P2/D");
00172       btoftree -> Branch("P3",&cnvP1[3], "P3/D");
00173       btoftree -> Branch("P4",&cnvP1[4], "P4/D");
00174       btoftree -> Branch("P5",&cnvP1[5], "P5/D");
00175       btoftree -> Branch("P6",&cnvP1[6], "P6/D");
00176       btoftree -> Branch("P7",&cnvP1[7], "P7/D");
00177       btoftree -> Branch("P8",&cnvP1[8], "P8/D");
00178       btoftree -> Branch("P9",&cnvP1[9], "P9/D");
00179       btoftree -> Branch("P10",&cnvP2[0], "P10/D");
00180       btoftree -> Branch("P11",&cnvP2[1], "P11/D");
00181       btoftree -> Branch("P12",&cnvP2[2], "P12/D");
00182       btoftree -> Branch("P13",&cnvP2[3], "P13/D");
00183       btoftree -> Branch("P14",&cnvP2[4], "P14/D");
00184       btoftree -> Branch("P15",&cnvP2[5], "P15/D");
00185       btoftree -> Branch("P16",&cnvP2[6], "P16/D");
00186       btoftree -> Branch("P17",&cnvP2[7], "P17/D");
00187       btoftree -> Branch("P18",&cnvP2[8], "P17/D");
00188       btoftree -> Branch("P19",&cnvP2[9], "P17/D");
00189       btoftree -> Branch("W0",&cnvW[0], "W0/D");
00190       btoftree -> Branch("W1",&cnvW[1], "W1/D");
00191       btoftree -> Branch("W2",&cnvW[2], "W2/D");
00192       btoftree -> Branch("W3",&cnvW[3], "W3/D");
00193 
00194        for(i=0; i<176; i++){
00195          cnvAtten[0] = btof->getBTofAtten(i,0);
00196          cnvAtten[1] = btof->getBTofAtten(i,1);
00197          cnvAtten[2] = btof->getBTofAtten(i,2);
00198          cnvQ = btof->getBTofQ(i);
00199          cnvSpeed[0] = btof->getBTofSpeed(i,0);
00200          cnvSpeed[1] = btof->getBTofSpeed(i,1);
00201          for(j=0;j<10;j++){
00202            cnvP1[j] = btof->getBTofPleft(i,j);
00203            cnvP2[j] = btof->getBTofPright(i,j);
00204          }
00205          for(j=0;j<4;j++){
00206            cnvW[j]=btof->getBTofW(i,j);
00207          }
00208          btoftree -> Fill();
00209        }
00210      
00211  //write  etoftree----------------------------------------------------------------
00212      double ecnvP[8];
00213      double ecnvAtten[5];
00214      double ecnvSpeed[3];
00215      TTree *etoftree = new TTree("EndTofPar", "EndTofPar");
00216       etoftree -> Branch("Atten0",&ecnvAtten[0], "Atten0/D");
00217       etoftree -> Branch("Atten1",&ecnvAtten[1], "Atten1/D");
00218       etoftree -> Branch("Atten2",&ecnvAtten[2], "Atten2/D");
00219       etoftree -> Branch("Atten3",&ecnvAtten[3], "Atten3/D");
00220       etoftree -> Branch("Atten4",&ecnvAtten[4], "Atten4/D");
00221       etoftree -> Branch("Speed0",&ecnvSpeed[0], "Speed0/D");
00222       etoftree -> Branch("Speed1",&ecnvSpeed[1], "Speed1/D");
00223       etoftree -> Branch("P0",&ecnvP[0], "P0/D");
00224       etoftree -> Branch("P1",&ecnvP[1], "P1/D");
00225       etoftree -> Branch("P2",&ecnvP[2], "P2/D");
00226       etoftree -> Branch("P3",&ecnvP[3], "P3/D");
00227       etoftree -> Branch("P4",&ecnvP[4], "P4/D");
00228       etoftree -> Branch("P5",&ecnvP[5], "P5/D");
00229       etoftree -> Branch("P6",&ecnvP[6], "P6/D");
00230       etoftree -> Branch("P7",&ecnvP[7], "P7/D");
00231     
00232        for(i=0; i<96; i++){
00233          ecnvAtten[0] = btof->getETofAtten(i,0);
00234          ecnvAtten[1] = btof->getETofAtten(i,1);
00235          ecnvAtten[2] = btof->getETofAtten(i,2);
00236          ecnvSpeed[0] = btof->getETofSpeed(i,0);
00237          ecnvSpeed[1] = btof->getETofSpeed(i,1);
00238          for(j=0;j<8;j++){
00239            ecnvP[j] = btof->getETofP(i,j);
00240          }
00241          etoftree -> Fill();
00242        }
00243 //  write all the trees
00244      btoftree -> Write();
00245      etoftree -> Write();
00246      delete btoftree;
00247      delete etoftree;
00248      closeWrite();
00249      log<<MSG::INFO<<"successfully create RootFile"<<endreq;
00250 */  
00251      return sc;
00252 
00253 }

Generated on Tue Nov 29 22:57:51 2016 for BOSS_7.0.2 by  doxygen 1.4.7