00001 #include "GaudiKernel/MsgStream.h"
00002 #include "TreeTofSimCnv.h"
00003 #include "CalibData/Tof/TofSimData.h"
00004 #include "CalibDataSvc/IInstrumentName.h"
00005 #include "CalibMySQLCnv/TreeAddress.h"
00006 #include "TFile.h"
00007 #include "TTree.h"
00008 #include "TDirectory.h"
00009 #include "TObject.h"
00010 #include "TBuffer.h"
00011
00012 #include "GaudiKernel/CnvFactory.h"
00013 #include "GaudiKernel/IOpaqueAddress.h"
00014 #include "GaudiKernel/DataObject.h"
00015 #include "GaudiKernel/IAddressCreator.h"
00016 #include "GaudiKernel/IDataProviderSvc.h"
00017 #include "GaudiKernel/IConversionSvc.h"
00018 #include "GaudiKernel/GenericAddress.h"
00019
00020 #include "CalibDataSvc/ICalibTreeSvc.h"
00021 #include "CalibDataSvc/ICalibMetaCnvSvc.h"
00022
00023
00024 #include "CalibData/CalibModel.h"
00025 using namespace CalibData;
00026
00027
00028
00029
00030
00031 TreeTofSimDataCnv::TreeTofSimDataCnv( ISvcLocator* svc) :
00032 TreeCalBaseCnv(svc, CLID_Calib_TofSim) {
00033
00034 }
00035
00036
00037 const CLID& TreeTofSimDataCnv::objType() const {
00038 return CLID_Calib_TofSim;
00039 }
00040
00041 const CLID& TreeTofSimDataCnv::classID() {
00042 return CLID_Calib_TofSim;
00043 }
00044
00045 StatusCode TreeTofSimDataCnv::i_createObj(IOpaqueAddress* addr,
00046 DataObject*& refpObject) {
00047
00048 MsgStream log(msgSvc(), "TreeTofSimDataCnv");
00049 log<<MSG::DEBUG<<"SetProperty"<<endreq;
00050
00051 TreeAddress* add = dynamic_cast<TreeAddress*>(addr);
00052
00053 DatabaseRecord *records=add->pp();
00054
00055 TBufferFile *buf1 = new TBufferFile(TBuffer::kRead);
00056 TBufferFile *buf2 = new TBufferFile(TBuffer::kRead);
00057 TBufferFile *buf3 = new TBufferFile(TBuffer::kRead);
00058
00059 buf1->SetBuffer((*records)["BTofSim"],512000,kFALSE);
00060 buf2->SetBuffer((*records)["ETofSim"],512000,kFALSE);
00061 buf3->SetBuffer((*records)["SimConstants"],512000,kFALSE);
00062
00063
00064 std::cout<<" SftVer is "<<(*records)["SftVer"];
00065 std::cout<<" CalVerSft is "<<(*records)["TofSimParVer"];
00066 std::cout<<" File name is "<<(*records)["FileName"]<<std::endl;
00067
00068
00069
00070 TTree *btoftree= new TTree();
00071 TTree *etoftree= new TTree();
00072 TTree *btofcommontree = new TTree();
00073 btoftree->Streamer(*buf1);
00074 etoftree->Streamer(*buf2);
00075 btofcommontree->Streamer(*buf3);
00076
00077 CalibData::BTofSimBase bTof;
00078 CalibData::ETofSimBase eTof;
00079 CalibData::TofSimConstBase tofbase;
00080 std::vector<CalibData::BTofSimBase> tmpbTof;
00081 std::vector<CalibData::ETofSimBase> tmpeTof;
00082 std::vector<CalibData::TofSimConstBase> tofbaseCol;
00083
00084 int cnt;
00085
00086 double AttenLength;
00087 double Gain;
00088 double Ratio;
00089 double NoiseSmear;
00090 btoftree -> SetBranchAddress("AttenLength", &AttenLength);
00091 btoftree -> SetBranchAddress("Gain", &Gain);
00092 btoftree -> SetBranchAddress("Ratio", &Ratio);
00093 int entries=btoftree->GetEntries();
00094 for(cnt=0; cnt<entries; cnt++){
00095 btoftree -> GetEntry(cnt);
00096 bTof.setGain(Gain);
00097 bTof.setRatio(Ratio);
00098 bTof.setAttenLength(AttenLength);
00099 tmpbTof.push_back(bTof);
00100 }
00101
00102 etoftree -> SetBranchAddress("Gain", &Gain);
00103 etoftree -> SetBranchAddress("AttenLength", &AttenLength);
00104 etoftree -> SetBranchAddress("NoiseSmear", &NoiseSmear );
00105 entries=etoftree->GetEntries();
00106 for(cnt=0; cnt<entries; cnt++){
00107 etoftree->GetEntry(cnt);
00108 eTof.setGain(Gain);
00109 eTof.setAttenLength(AttenLength);
00110 eTof.setNoiseSmear(NoiseSmear);
00111 tmpeTof.push_back(eTof);
00112 }
00113
00114 double BarConstant,BarPMTGain,BarHighThres,BarLowThres,EndConstant,EndPMTGain,EndHighThres,EndLowThres,EndNoiseSwitch;
00115 btofcommontree-> SetBranchAddress("BarConstant", &BarConstant);
00116 btofcommontree-> SetBranchAddress("BarPMTGain", &BarPMTGain);
00117 btofcommontree-> SetBranchAddress("BarHighThres", &BarHighThres);
00118 btofcommontree-> SetBranchAddress("BarLowThres", &BarLowThres);
00119 btofcommontree-> SetBranchAddress("EndConstant", &EndConstant);
00120 btofcommontree-> SetBranchAddress("EndPMTGain", &EndPMTGain);
00121 btofcommontree-> SetBranchAddress("EndHighThres", &EndHighThres);
00122 btofcommontree-> SetBranchAddress("EndLowThres", &EndLowThres);
00123 btofcommontree-> SetBranchAddress("EndNoiseSwitch", &EndNoiseSwitch);
00124 entries = btofcommontree->GetEntries();
00125 for(cnt=0;cnt<entries;cnt++){
00126 btofcommontree->GetEntry(cnt);
00127 tofbase.setBarLowThres(BarLowThres);
00128 tofbase.setBarHighThres(BarHighThres);
00129 tofbase.setEndLowThres(EndLowThres);
00130 tofbase.setEndHighThres(EndHighThres);
00131 tofbase.setBarPMTGain(BarPMTGain);
00132 tofbase.setEndPMTGain(EndPMTGain);
00133 tofbase.setBarConstant(BarConstant);
00134 tofbase.setEndConstant(EndConstant);
00135 tofbase.setEndNoiseSwitch(EndNoiseSwitch);
00136 tofbaseCol.push_back(tofbase);
00137 }
00138
00139 CalibData::TofSimData *tmpObject = new CalibData::TofSimData(&tofbaseCol,&tmpbTof,&tmpeTof);
00140 refpObject=tmpObject;
00141 delete btoftree;
00142 delete etoftree;
00143 delete btofcommontree;
00144
00145 return StatusCode::SUCCESS;
00146
00147
00148 }
00149