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

Go to the documentation of this file.
00001 // $Header: /bes/bes/BossCvs/Calibration/CalibSvc/CalibROOTCnv/src/cnv/RootDedxSimDataCnv.cxx,v 1.6 2016/09/14 05:32:44 zhaog Exp $
00002 #include "GaudiKernel/MsgStream.h"
00003 #include "RootDedxSimDataCnv.h"
00004 #include "CalibData/Dedx/DedxSimData.h"
00005 #include "CalibDataSvc/IInstrumentName.h"
00006 
00007 #include "TFile.h"
00008 #include "TTree.h"
00009 #include "TDirectory.h"
00010 #include "TObject.h"
00011 #include "TROOT.h"
00012 
00013 #include "GaudiKernel/CnvFactory.h"
00014 #include "GaudiKernel/IOpaqueAddress.h"
00015 #include "GaudiKernel/DataObject.h"
00016 #include "GaudiKernel/IAddressCreator.h"
00017 #include "GaudiKernel/IDataProviderSvc.h"
00018 #include "GaudiKernel/IConversionSvc.h"
00019 #include "GaudiKernel/GenericAddress.h"
00020 
00021 #include "CalibDataSvc/ICalibRootSvc.h"    //maybe
00022 #include "CalibDataSvc/ICalibMetaCnvSvc.h"
00023 //#include "CalibData/CalibTime.h"
00024 //#include "commonRootData/idents/CalXtalId.h"
00025 //#include "idents/CalXtalId.h"
00026 
00027 // Temporary.  Hope to find a better way to do this
00028 #include "CalibData/CalibModel.h"
00029 using namespace CalibData;
00030 //static CnvFactory<RootDedxSimDataCnv> TofCalib_factory;
00031 //const  ICnvFactory& RootDedxSimDataCnvFactory = TofCalib_factory;
00032 
00033 
00034 
00035 RootDedxSimDataCnv::RootDedxSimDataCnv( ISvcLocator* svc) :
00036   RootCalBaseCnv(svc, CLID_Dedx_Sim) { 
00037  }
00038 
00039 
00040 const CLID& RootDedxSimDataCnv::objType() const {
00041   return CLID_Dedx_Sim;
00042 }
00043 
00044 const CLID& RootDedxSimDataCnv::classID() {
00045   return CLID_Dedx_Sim;
00046 }
00047 
00048 StatusCode RootDedxSimDataCnv::i_createObj(const std::string& fname,
00049                                            DataObject*& refpObject) {
00050 
00051     MsgStream log(msgSvc(), "RootDedxSimDataCnv");
00052     log<<MSG::DEBUG<<"SetProperty"<<endreq;
00053  
00054     CalibData::DedxSimData *tmpObject = new CalibData::DedxSimData ;
00055 
00056     TH1F *h1=new TH1F();
00057     // open the file
00058     StatusCode sc = openRead(fname);
00059     if(!sc)
00060     {
00061         log<<MSG::ERROR<<"unable to open files"<<endreq;
00062     }
00063  
00064     std::vector<TH1F> hist;
00065     std::vector<double> hRange;
00066     // Read in the object
00067     int cnt;
00068     TTree *tree=(TTree*)m_inFile->Get("TH1F_Col");
00069     tree->SetBranchAddress("TH1F_Col", &h1);
00070     int entries=tree->GetEntries();
00071     for (cnt = 0; cnt < entries; cnt++) {
00072         tree -> GetEntry(cnt);
00073         gROOT->cd();
00074         TH1F *h2=new TH1F();
00075         h2=(TH1F*)h1->Clone();
00076             hist.push_back(*h2);
00077         }
00078 //      tmpObject->setHist(&hist);
00079     int ver;
00080     double betagamma[5000];
00081     int totalNum;
00082     int bgNum;
00083     int thetaNum;
00084     TTree* bin = (TTree*)m_inFile->Get("bin");
00085     if (bin->FindBranch("version")) bin->SetBranchAddress("version", &ver);
00086     else ver = 0;
00087     if (bin->FindBranch("thetaNum")) bin->SetBranchAddress("thetaNum", &thetaNum);
00088     else thetaNum = 16;
00089     bin->SetBranchAddress("totalNum", &totalNum);
00090     bin->SetBranchAddress("betagamma",  betagamma);
00091     bin->SetBranchAddress("betagammaBounds", &bgNum);
00092     bin->GetEntry(0);
00093     
00094     //int tot=totalNum*2;
00095     for (cnt = 0; cnt < bgNum; cnt++) {
00096         hRange.push_back(betagamma[cnt]);
00097     }
00098     
00099     tmpObject->setVersion(ver);
00100     tmpObject->setRangeNo(bgNum);
00101     tmpObject->setRange(&hRange);
00102     tmpObject->setThetaNo(thetaNum);
00103     tmpObject->setHistNo(totalNum);
00104     tmpObject->setHist(&hist);
00105     refpObject = tmpObject;
00106 
00107     return StatusCode::SUCCESS;
00108 }
00109 
00110 StatusCode RootDedxSimDataCnv::createRoot(const std::string& fname, 
00111                                         CalibData::CalibBase1* pTDSObj) {
00112    MsgStream log(msgSvc(), "RootDedxSimDataCnv");
00113 
00114  // Open the file, create the branch
00115    StatusCode sc = openWrite(fname);
00116   if(!sc)
00117     { log<<MSG::ERROR<<"unable to open files"<<endreq;
00118     }
00119   // write the Data in the TCDS to RootFile
00120  /*    int i;
00121      int j;
00122      CalibData::TofCalibData* btof = dynamic_cast<CalibData::TofCalibData*>(pTDSObj);
00123 
00124   // write  btoftree----------------------------------------------------------------
00125      double cnvP1[10];
00126      double cnvP2[10];
00127      double cnvW[4];
00128      double cnvAtten[8];
00129      double cnvQ;
00130      double cnvSpeed[2];
00131      TTree *btoftree = new TTree("BarTofPar", "BarTofPar");
00132       btoftree -> Branch("Atten0",&cnvAtten[0], "Atten0/D");
00133       btoftree -> Branch("Atten1",&cnvAtten[1], "Atten1/D");
00134       btoftree -> Branch("Atten2",&cnvAtten[2], "Atten2/D");
00135       btoftree -> Branch("Atten3",&cnvAtten[3], "Atten3/D");
00136       btoftree -> Branch("Atten4",&cnvAtten[4], "Atten4/D");
00137       btoftree -> Branch("Atten5",&cnvAtten[5], "Atten5/D");
00138       btoftree -> Branch("Atten6",&cnvAtten[6], "Atten6/D");
00139       btoftree -> Branch("Atten7",&cnvAtten[7], "Atten7/D");
00140       btoftree -> Branch("Q0",&cnvQ, "Q0/D");
00141       btoftree -> Branch("Speed0",&cnvSpeed[0], "Speed0/D");
00142       btoftree -> Branch("Speed1",&cnvSpeed[1], "Speed1/D");
00143       btoftree -> Branch("P0",&cnvP1[0], "P0/D");
00144       btoftree -> Branch("P1",&cnvP1[1], "P1/D");
00145       btoftree -> Branch("P2",&cnvP1[2], "P2/D");
00146       btoftree -> Branch("P3",&cnvP1[3], "P3/D");
00147       btoftree -> Branch("P4",&cnvP1[4], "P4/D");
00148       btoftree -> Branch("P5",&cnvP1[5], "P5/D");
00149       btoftree -> Branch("P6",&cnvP1[6], "P6/D");
00150       btoftree -> Branch("P7",&cnvP1[7], "P7/D");
00151       btoftree -> Branch("P8",&cnvP1[8], "P8/D");
00152       btoftree -> Branch("P9",&cnvP1[9], "P9/D");
00153       btoftree -> Branch("P10",&cnvP2[0], "P10/D");
00154       btoftree -> Branch("P11",&cnvP2[1], "P11/D");
00155       btoftree -> Branch("P12",&cnvP2[2], "P12/D");
00156       btoftree -> Branch("P13",&cnvP2[3], "P13/D");
00157       btoftree -> Branch("P14",&cnvP2[4], "P14/D");
00158       btoftree -> Branch("P15",&cnvP2[5], "P15/D");
00159       btoftree -> Branch("P16",&cnvP2[6], "P16/D");
00160       btoftree -> Branch("P17",&cnvP2[7], "P17/D");
00161       btoftree -> Branch("P18",&cnvP2[8], "P17/D");
00162       btoftree -> Branch("P19",&cnvP2[9], "P17/D");
00163       btoftree -> Branch("W0",&cnvW[0], "W0/D");
00164       btoftree -> Branch("W1",&cnvW[1], "W1/D");
00165       btoftree -> Branch("W2",&cnvW[2], "W2/D");
00166       btoftree -> Branch("W3",&cnvW[3], "W3/D");
00167 
00168        for(i=0; i<176; i++){
00169          cnvAtten[0] = btof->getBTofAtten(i,0);
00170          cnvAtten[1] = btof->getBTofAtten(i,1);
00171          cnvAtten[2] = btof->getBTofAtten(i,2);
00172          cnvQ = btof->getBTofQ(i);
00173          cnvSpeed[0] = btof->getBTofSpeed(i,0);
00174          cnvSpeed[1] = btof->getBTofSpeed(i,1);
00175          for(j=0;j<10;j++){
00176            cnvP1[j] = btof->getBTofPleft(i,j);
00177            cnvP2[j] = btof->getBTofPright(i,j);
00178          }
00179          for(j=0;j<4;j++){
00180            cnvW[j]=btof->getBTofW(i,j);
00181          }
00182          btoftree -> Fill();
00183        }
00184      
00185  //write  etoftree----------------------------------------------------------------
00186      double ecnvP[8];
00187      double ecnvAtten[5];
00188      double ecnvSpeed[3];
00189      TTree *etoftree = new TTree("EndTofPar", "EndTofPar");
00190       etoftree -> Branch("Atten0",&ecnvAtten[0], "Atten0/D");
00191       etoftree -> Branch("Atten1",&ecnvAtten[1], "Atten1/D");
00192       etoftree -> Branch("Atten2",&ecnvAtten[2], "Atten2/D");
00193       etoftree -> Branch("Atten3",&ecnvAtten[3], "Atten3/D");
00194       etoftree -> Branch("Atten4",&ecnvAtten[4], "Atten4/D");
00195       etoftree -> Branch("Speed0",&ecnvSpeed[0], "Speed0/D");
00196       etoftree -> Branch("Speed1",&ecnvSpeed[1], "Speed1/D");
00197       etoftree -> Branch("P0",&ecnvP[0], "P0/D");
00198       etoftree -> Branch("P1",&ecnvP[1], "P1/D");
00199       etoftree -> Branch("P2",&ecnvP[2], "P2/D");
00200       etoftree -> Branch("P3",&ecnvP[3], "P3/D");
00201       etoftree -> Branch("P4",&ecnvP[4], "P4/D");
00202       etoftree -> Branch("P5",&ecnvP[5], "P5/D");
00203       etoftree -> Branch("P6",&ecnvP[6], "P6/D");
00204       etoftree -> Branch("P7",&ecnvP[7], "P7/D");
00205     
00206        for(i=0; i<96; i++){
00207          ecnvAtten[0] = btof->getETofAtten(i,0);
00208          ecnvAtten[1] = btof->getETofAtten(i,1);
00209          ecnvAtten[2] = btof->getETofAtten(i,2);
00210          ecnvSpeed[0] = btof->getETofSpeed(i,0);
00211          ecnvSpeed[1] = btof->getETofSpeed(i,1);
00212          for(j=0;j<8;j++){
00213            ecnvP[j] = btof->getETofP(i,j);
00214          }
00215          etoftree -> Fill();
00216        }
00217 //  write all the trees
00218      btoftree -> Write();
00219      etoftree -> Write();
00220      delete btoftree;
00221      delete etoftree;
00222      closeWrite();
00223      log<<MSG::INFO<<"successfully create RootFile"<<endreq;
00224 */  
00225      return sc;
00226 
00227 }

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