00001
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"
00024 #include "CalibDataSvc/ICalibMetaCnvSvc.h"
00025
00026
00027
00028
00029
00030 #include "CalibData/CalibModel.h"
00031 using namespace CalibData;
00032
00033
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
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;
00066 std::vector<CalibData::ETofSimBase> tmpeTof;
00067 std::vector<CalibData::TofSimConstBase> tofbaseCol;
00068
00069 int cnt;
00070
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
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
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
00141 StatusCode sc = openWrite(fname);
00142 if(!sc)
00143 { log<<MSG::ERROR<<"unable to open files"<<endreq;
00144 }
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 return sc;
00252
00253 }