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