CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
RootTofSimDataCnv.cxx
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/CalibSvc/CalibROOTCnv/src/cnv/RootTofSimDataCnv.cxx,v 1.2 2010/02/03 01:18:23 huangb Exp $
2#include "GaudiKernel/MsgStream.h"
3#include "RootTofSimDataCnv.h"
9
10#include "TFile.h"
11#include "TTree.h"
12#include "TDirectory.h"
13#include "TObject.h"
14
15#include "GaudiKernel/CnvFactory.h"
16#include "GaudiKernel/IOpaqueAddress.h"
17#include "GaudiKernel/DataObject.h"
18#include "GaudiKernel/IAddressCreator.h"
19#include "GaudiKernel/IDataProviderSvc.h"
20#include "GaudiKernel/IConversionSvc.h"
21#include "GaudiKernel/GenericAddress.h"
22
23#include "CalibDataSvc/ICalibRootSvc.h" //maybe
25//#include "CalibData/CalibTime.h"
26//#include "commonRootData/idents/CalXtalId.h"
27//#include "idents/CalXtalId.h"
28
29// Temporary. Hope to find a better way to do this
31using namespace CalibData;
32//static CnvFactory<RootTofSimDataCnv> TofCalib_factory;
33//const ICnvFactory& RootTofSimDataCnvFactory = TofCalib_factory;
34
35
36
40
41
42const CLID& RootTofSimDataCnv::objType() const {
43 return CLID_Calib_TofSim;
44}
45
47 return CLID_Calib_TofSim;
48}
49
50StatusCode RootTofSimDataCnv::i_createObj(const std::string& fname,
51 DataObject*& refpObject) {
52
53 MsgStream log(msgSvc(), "RootTofSimDataCnv");
54 log<<MSG::DEBUG<<"SetProperty"<<endreq;
55
56 // open the file
57 StatusCode sc = openRead(fname);
58 if(!sc)
59 { log<<MSG::ERROR<<"unable to open files"<<endreq;
60 }
61
65 std::vector<CalibData::BTofSimBase> tmpbTof;//; = new vector<CalibData::bTofCalibBase>;
66 std::vector<CalibData::ETofSimBase> tmpeTof;
67 std::vector<CalibData::TofSimConstBase> tofbaseCol;
68 // Read in the object
69 int cnt;
70 // read btoftree ------------------------------------------------------------
71 double AttenLength;
72 double Gain;
73 double Ratio;
74 double NoiseSmear;
75 TTree *btoftree = (TTree*)m_inFile -> Get("BTofSim");
76 btoftree -> SetBranchAddress("AttenLength", &AttenLength);
77 btoftree -> SetBranchAddress("Gain", &Gain);
78 btoftree -> SetBranchAddress("Ratio", &Ratio);
79 int entries=btoftree->GetEntries();
80 for(cnt=0; cnt<entries; cnt++){
81 btoftree -> GetEntry(cnt);
82 bTof.setGain(Gain);
83 bTof.setRatio(Ratio);
84 bTof.setAttenLength(AttenLength);
85 tmpbTof.push_back(bTof);
86 }
87 //read etoftree
88 TTree *etoftree = (TTree*)m_inFile -> Get("ETofSim");
89 etoftree -> SetBranchAddress("Gain", &Gain);
90 etoftree -> SetBranchAddress("AttenLength", &AttenLength);
91 etoftree -> SetBranchAddress("NoiseSmear", &NoiseSmear );
92 entries=etoftree->GetEntries();
93 for(cnt=0; cnt<entries; cnt++){
94 etoftree->GetEntry(cnt);
95 eTof.setGain(Gain);
96 eTof.setAttenLength(AttenLength);
97 eTof.setNoiseSmear(NoiseSmear);
98 tmpeTof.push_back(eTof);
99 }
100
101 //read SimConstants
102 double BarConstant,BarPMTGain,BarHighThres,BarLowThres,EndConstant,EndPMTGain,EndHighThres,EndLowThres,EndNoiseSwitch;
103 TTree *btofcommontree = (TTree*)m_inFile -> Get("SimConstants");
104 btofcommontree-> SetBranchAddress("BarConstant", &BarConstant);
105 btofcommontree-> SetBranchAddress("BarPMTGain", &BarPMTGain);
106 btofcommontree-> SetBranchAddress("BarHighThres", &BarHighThres);
107 btofcommontree-> SetBranchAddress("BarLowThres", &BarLowThres);
108 btofcommontree-> SetBranchAddress("EndConstant", &EndConstant);
109 btofcommontree-> SetBranchAddress("EndPMTGain", &EndPMTGain);
110 btofcommontree-> SetBranchAddress("EndHighThres", &EndHighThres);
111 btofcommontree-> SetBranchAddress("EndLowThres", &EndLowThres);
112 btofcommontree-> SetBranchAddress("EndNoiseSwitch", &EndNoiseSwitch);
113 entries = btofcommontree->GetEntries();
114 for(cnt=0;cnt<entries;cnt++){
115 btofcommontree->GetEntry(cnt);
116 tofbase.setBarLowThres(BarLowThres);
117 tofbase.setBarHighThres(BarHighThres);
118 tofbase.setEndLowThres(EndLowThres);
119 tofbase.setEndHighThres(EndHighThres);
120 tofbase.setBarPMTGain(BarPMTGain);
121 tofbase.setEndPMTGain(EndPMTGain);
122 tofbase.setBarConstant(BarConstant);
123 tofbase.setEndConstant(EndConstant);
124 tofbase.setEndNoiseSwitch(EndNoiseSwitch);
125 tofbaseCol.push_back(tofbase);
126 }
127
128 CalibData::TofSimData *tmpObject = new CalibData::TofSimData(&tofbaseCol,&tmpbTof,&tmpeTof);
129
130
131 refpObject=tmpObject;
132
133 return StatusCode::SUCCESS;
134}
135
136StatusCode RootTofSimDataCnv::createRoot(const std::string& fname,
137 CalibData::CalibBase1* pTDSObj) {
138 MsgStream log(msgSvc(), "RootTofSimDataCnv");
139
140 // Open the file, create the branch
141 StatusCode sc = openWrite(fname);
142 if(!sc)
143 { log<<MSG::ERROR<<"unable to open files"<<endreq;
144 }
145 // write the Data in the TCDS to RootFile
146 /* int i;
147 int j;
148 CalibData::TofCalibData* btof = dynamic_cast<CalibData::TofCalibData*>(pTDSObj);
149
150 // write btoftree----------------------------------------------------------------
151 double cnvP1[10];
152 double cnvP2[10];
153 double cnvW[4];
154 double cnvAtten[8];
155 double cnvQ;
156 double cnvSpeed[2];
157 TTree *btoftree = new TTree("BarTofPar", "BarTofPar");
158 btoftree -> Branch("Atten0",&cnvAtten[0], "Atten0/D");
159 btoftree -> Branch("Atten1",&cnvAtten[1], "Atten1/D");
160 btoftree -> Branch("Atten2",&cnvAtten[2], "Atten2/D");
161 btoftree -> Branch("Atten3",&cnvAtten[3], "Atten3/D");
162 btoftree -> Branch("Atten4",&cnvAtten[4], "Atten4/D");
163 btoftree -> Branch("Atten5",&cnvAtten[5], "Atten5/D");
164 btoftree -> Branch("Atten6",&cnvAtten[6], "Atten6/D");
165 btoftree -> Branch("Atten7",&cnvAtten[7], "Atten7/D");
166 btoftree -> Branch("Q0",&cnvQ, "Q0/D");
167 btoftree -> Branch("Speed0",&cnvSpeed[0], "Speed0/D");
168 btoftree -> Branch("Speed1",&cnvSpeed[1], "Speed1/D");
169 btoftree -> Branch("P0",&cnvP1[0], "P0/D");
170 btoftree -> Branch("P1",&cnvP1[1], "P1/D");
171 btoftree -> Branch("P2",&cnvP1[2], "P2/D");
172 btoftree -> Branch("P3",&cnvP1[3], "P3/D");
173 btoftree -> Branch("P4",&cnvP1[4], "P4/D");
174 btoftree -> Branch("P5",&cnvP1[5], "P5/D");
175 btoftree -> Branch("P6",&cnvP1[6], "P6/D");
176 btoftree -> Branch("P7",&cnvP1[7], "P7/D");
177 btoftree -> Branch("P8",&cnvP1[8], "P8/D");
178 btoftree -> Branch("P9",&cnvP1[9], "P9/D");
179 btoftree -> Branch("P10",&cnvP2[0], "P10/D");
180 btoftree -> Branch("P11",&cnvP2[1], "P11/D");
181 btoftree -> Branch("P12",&cnvP2[2], "P12/D");
182 btoftree -> Branch("P13",&cnvP2[3], "P13/D");
183 btoftree -> Branch("P14",&cnvP2[4], "P14/D");
184 btoftree -> Branch("P15",&cnvP2[5], "P15/D");
185 btoftree -> Branch("P16",&cnvP2[6], "P16/D");
186 btoftree -> Branch("P17",&cnvP2[7], "P17/D");
187 btoftree -> Branch("P18",&cnvP2[8], "P17/D");
188 btoftree -> Branch("P19",&cnvP2[9], "P17/D");
189 btoftree -> Branch("W0",&cnvW[0], "W0/D");
190 btoftree -> Branch("W1",&cnvW[1], "W1/D");
191 btoftree -> Branch("W2",&cnvW[2], "W2/D");
192 btoftree -> Branch("W3",&cnvW[3], "W3/D");
193
194 for(i=0; i<176; i++){
195 cnvAtten[0] = btof->getBTofAtten(i,0);
196 cnvAtten[1] = btof->getBTofAtten(i,1);
197 cnvAtten[2] = btof->getBTofAtten(i,2);
198 cnvQ = btof->getBTofQ(i);
199 cnvSpeed[0] = btof->getBTofSpeed(i,0);
200 cnvSpeed[1] = btof->getBTofSpeed(i,1);
201 for(j=0;j<10;j++){
202 cnvP1[j] = btof->getBTofPleft(i,j);
203 cnvP2[j] = btof->getBTofPright(i,j);
204 }
205 for(j=0;j<4;j++){
206 cnvW[j]=btof->getBTofW(i,j);
207 }
208 btoftree -> Fill();
209 }
210
211 //write etoftree----------------------------------------------------------------
212 double ecnvP[8];
213 double ecnvAtten[5];
214 double ecnvSpeed[3];
215 TTree *etoftree = new TTree("EndTofPar", "EndTofPar");
216 etoftree -> Branch("Atten0",&ecnvAtten[0], "Atten0/D");
217 etoftree -> Branch("Atten1",&ecnvAtten[1], "Atten1/D");
218 etoftree -> Branch("Atten2",&ecnvAtten[2], "Atten2/D");
219 etoftree -> Branch("Atten3",&ecnvAtten[3], "Atten3/D");
220 etoftree -> Branch("Atten4",&ecnvAtten[4], "Atten4/D");
221 etoftree -> Branch("Speed0",&ecnvSpeed[0], "Speed0/D");
222 etoftree -> Branch("Speed1",&ecnvSpeed[1], "Speed1/D");
223 etoftree -> Branch("P0",&ecnvP[0], "P0/D");
224 etoftree -> Branch("P1",&ecnvP[1], "P1/D");
225 etoftree -> Branch("P2",&ecnvP[2], "P2/D");
226 etoftree -> Branch("P3",&ecnvP[3], "P3/D");
227 etoftree -> Branch("P4",&ecnvP[4], "P4/D");
228 etoftree -> Branch("P5",&ecnvP[5], "P5/D");
229 etoftree -> Branch("P6",&ecnvP[6], "P6/D");
230 etoftree -> Branch("P7",&ecnvP[7], "P7/D");
231
232 for(i=0; i<96; i++){
233 ecnvAtten[0] = btof->getETofAtten(i,0);
234 ecnvAtten[1] = btof->getETofAtten(i,1);
235 ecnvAtten[2] = btof->getETofAtten(i,2);
236 ecnvSpeed[0] = btof->getETofSpeed(i,0);
237 ecnvSpeed[1] = btof->getETofSpeed(i,1);
238 for(j=0;j<8;j++){
239 ecnvP[j] = btof->getETofP(i,j);
240 }
241 etoftree -> Fill();
242 }
243// write all the trees
244 btoftree -> Write();
245 etoftree -> Write();
246 delete btoftree;
247 delete etoftree;
248 closeWrite();
249 log<<MSG::INFO<<"successfully create RootFile"<<endreq;
250*/
251 return sc;
252
253}
const CLID CLID_Calib_TofSim
Definition CalibModel.h:59
data SetBranchAddress("time",&time)
data GetEntry(0)
IMessageSvc * msgSvc()
void setRatio(double ratio)
Definition BTofSimBase.h:16
void setGain(double gain)
Definition BTofSimBase.h:15
void setAttenLength(double length)
Definition BTofSimBase.h:17
void setGain(double gain)
Definition ETofSimBase.h:14
void setAttenLength(double length)
Definition ETofSimBase.h:15
void setNoiseSmear(double noisesmear)
Definition ETofSimBase.h:16
void setBarConstant(const double bc)
void setBarHighThres(const double bhth)
void setEndNoiseSwitch(const double eswitch)
void setEndHighThres(const double ehth)
void setEndConstant(const double ec)
void setBarPMTGain(const double bg)
void setEndPMTGain(const double eg)
void setEndLowThres(const double elth)
void setBarLowThres(const double blth)
StatusCode openRead(const std::string &fname)
virtual StatusCode openWrite(const std::string &fname)
static const CLID & classID()
RootTofSimDataCnv(ISvcLocator *svc)
const CLID & objType() const
virtual StatusCode createRoot(const std::string &fname, CalibData::CalibBase1 *pTDSObj)
virtual StatusCode i_createObj(const std::string &fname, DataObject *&refpObject)