BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
RootEstTofCalibDataCnv.cxx
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/CalibSvc/CalibROOTCnv/src/cnv/RootEstTofCalibDataCnv.cxx,v 1.4 2012/11/06 07:54:07 sunss Exp $
2#include "GaudiKernel/MsgStream.h"
8
9#include "TFile.h"
10#include "TTree.h"
11#include "TDirectory.h"
12#include "TObject.h"
13
14#include "GaudiKernel/CnvFactory.h"
15#include "GaudiKernel/IOpaqueAddress.h"
16#include "GaudiKernel/DataObject.h"
17#include "GaudiKernel/IAddressCreator.h"
18#include "GaudiKernel/IDataProviderSvc.h"
19#include "GaudiKernel/IConversionSvc.h"
20#include "GaudiKernel/GenericAddress.h"
21
22#include "CalibDataSvc/ICalibRootSvc.h" //maybe
24//#include "CalibData/CalibTime.h"
25//#include "commonRootData/idents/CalXtalId.h"
26//#include "idents/CalXtalId.h"
27
28// Temporary. Hope to find a better way to do this
30using namespace CalibData;
31//static CnvFactory<RootEstTofCalibDataCnv> TofCalib_factory;
32//const ICnvFactory& RootEstTofCalibDataCnvFactory = TofCalib_factory;
33
34const unsigned int nBarPar = 10;
35const unsigned int nBarParOff = 20;
36const unsigned int nEndPar = 8;
37const unsigned int nBarOffset = 2;
38
41 }
42
43
46}
47
50}
51
52StatusCode RootEstTofCalibDataCnv::i_createObj(const std::string& fname,
53 DataObject*& refpObject) {
54
55 MsgStream log(msgSvc(), "RootEstTofCalibDataCnv");
56 log<<MSG::DEBUG<<"SetProperty"<<endreq;
57
58 // open the file
59 StatusCode sc = openRead(fname);
60 if(!sc)
61 { log<<MSG::ERROR<<"unable to open files"<<endreq;
62 }
63
68
69 std::vector<CalibData::bTofCalibBase> tmpbTof;
70 std::vector<CalibData::eTofCalibBase> tmpeTof;
71 std::vector<CalibData::bTofCommonCalibBase> tmpbTofCommon;
72 std::vector<CalibData::tofCalibInfoBase> tofinfoCol;
73
74 // Read in the object
75 int cnt;
76 // read btoftree ------------------------------------------------------------
77 double cnvBarPar1[nBarPar];
78 double cnvBarPar2[nBarPar];
79 double cnvBarParOff1_bunch0[nBarParOff];
80 double cnvBarParOff2_bunch0[nBarParOff];
81 double cnvBarParOff1_bunch1[nBarParOff];
82 double cnvBarParOff2_bunch1[nBarParOff];
83 double cnvBarParOff1_bunch2[nBarParOff];
84 double cnvBarParOff2_bunch2[nBarParOff];
85 double cnvBarParOff1_bunch3[nBarParOff];
86 double cnvBarParOff2_bunch3[nBarParOff];
87
88 TTree *btoftree = (TTree*)m_inFile -> Get("BarTofPar");
89
90 char brname[10];
91 for( unsigned int i=0; i<nBarPar; i++ ) {
92 sprintf( brname, "P%i", i );
93 btoftree -> SetBranchAddress( brname, &cnvBarPar1[i] );
94 }
95 for( unsigned int i=0; i<nBarPar; i++ ) {
96 sprintf( brname, "P%i", i+nBarPar );
97 btoftree -> SetBranchAddress( brname, &cnvBarPar2[i] );
98 }
99 for( unsigned int i=0; i<nBarParOff; i++ ) {
100 sprintf( brname, "Bunch0_Poff%i", i );
101 btoftree -> SetBranchAddress( brname, &cnvBarParOff1_bunch0[i] );
102 }
103 for( unsigned int i=0; i<nBarParOff; i++ ) {
104 sprintf( brname, "Bunch0_Poff%i", i+nBarParOff );
105 btoftree -> SetBranchAddress( brname, &cnvBarParOff2_bunch0[i] );
106 }
107 for( unsigned int i=0; i<nBarParOff; i++ ) {
108 sprintf( brname, "Bunch1_Poff%i", i );
109 btoftree -> SetBranchAddress( brname, &cnvBarParOff1_bunch1[i] );
110 }
111 for( unsigned int i=0; i<nBarParOff; i++ ) {
112 sprintf( brname, "Bunch1_Poff%i", i+nBarParOff );
113 btoftree -> SetBranchAddress( brname, &cnvBarParOff2_bunch1[i] );
114 }
115 for( unsigned int i=0; i<nBarParOff; i++ ) {
116 sprintf( brname, "Bunch2_Poff%i", i );
117 btoftree -> SetBranchAddress( brname, &cnvBarParOff1_bunch2[i] );
118 }
119 for( unsigned int i=0; i<nBarParOff; i++ ) {
120 sprintf( brname, "Bunch2_Poff%i", i+nBarParOff );
121 btoftree -> SetBranchAddress( brname, &cnvBarParOff2_bunch2[i] );
122 }
123 for( unsigned int i=0; i<nBarParOff; i++ ) {
124 sprintf( brname, "Bunch3_Poff%i", i );
125 btoftree -> SetBranchAddress( brname, &cnvBarParOff1_bunch3[i] );
126 }
127 for( unsigned int i=0; i<nBarParOff; i++ ) {
128 sprintf( brname, "Bunch3_Poff%i", i+nBarParOff );
129 btoftree -> SetBranchAddress( brname, &cnvBarParOff2_bunch3[i] );
130 }
131
132 for(cnt=0; cnt<176; cnt++){
133 btoftree -> GetEntry(cnt);
134 bTof.setP1( cnvBarPar1 );
135 bTof.setP2( cnvBarPar2 );
136 bTof.setPoff1_bunch0( cnvBarParOff1_bunch0 );
137 bTof.setPoff2_bunch0( cnvBarParOff2_bunch0 );
138 bTof.setPoff1_bunch1( cnvBarParOff1_bunch1 );
139 bTof.setPoff2_bunch1( cnvBarParOff2_bunch1 );
140 bTof.setPoff1_bunch2( cnvBarParOff1_bunch2 );
141 bTof.setPoff2_bunch2( cnvBarParOff2_bunch2 );
142 bTof.setPoff1_bunch3( cnvBarParOff1_bunch3 );
143 bTof.setPoff2_bunch3( cnvBarParOff2_bunch3 );
144 tmpbTof.push_back( bTof );
145 }
146
147 //read etoftree
148 double cnvEndPar[nEndPar];
149
150 TTree *etoftree = (TTree*)m_inFile -> Get("EndTofPar");
151
152 char ecname[10];
153 for( unsigned int i=0; i<nEndPar; i++ ) {
154 sprintf( ecname, "P%i", i );
155 etoftree -> SetBranchAddress( ecname, &cnvEndPar[i] );
156 }
157
158 for(cnt=0; cnt<96; cnt++){
159 etoftree->GetEntry(cnt);
160 eTof.setP( cnvEndPar );
161 tmpeTof.push_back(eTof);
162 }
163
164 //read bTofCommonCalibBase
165 double cnvBarOffset[nBarOffset];
166 TTree *btofcommontree = (TTree*)m_inFile -> Get("BarTofParCommon");
167 for( unsigned int i=0; i<nBarOffset; i++ ) {
168 sprintf( brname, "t0offset%i", i );
169 btofcommontree-> SetBranchAddress( brname, &cnvBarOffset[i]);
170 }
171
172 int entries = btofcommontree->GetEntries();
173 for(cnt=0;cnt<entries;cnt++){
174 btofcommontree->GetEntry(cnt);
175 bTofCommon.setOffset( cnvBarOffset );
176 tmpbTofCommon.push_back(bTofCommon);
177 }
178
179 CalibData::TofCalibData *tmpObject = new CalibData::TofCalibData(&tmpbTof,&tmpbTofCommon,&tmpeTof,&tofinfoCol);
180
181 refpObject=tmpObject;
182
183 return StatusCode::SUCCESS;
184}
185
186StatusCode RootEstTofCalibDataCnv::createRoot(const std::string& fname,
187 CalibData::CalibBase1* pTDSObj) {
188 MsgStream log(msgSvc(), "RootEstTofCalibDataCnv");
189
190 // Open the file, create the branch
191 StatusCode sc = openWrite(fname);
192 if(!sc)
193 { log<<MSG::ERROR<<"unable to open files"<<endreq;
194 }
195 // write the Data in the TCDS to RootFile
196 CalibData::TofCalibData* btof = dynamic_cast<CalibData::TofCalibData*>(pTDSObj);
197
198 // write btoftree----------------------------------------------------------------
199 double cnvBarPar1[nBarPar];
200 double cnvBarPar2[nBarPar];
201
202 char brname[8], ibrname[8];
203 TTree *btoftree = new TTree("BarTofPar", "BarTofPar");
204 for( unsigned int i=0; i<nBarPar; i++ ) {
205 sprintf( brname, "P%i", i );
206 sprintf( ibrname, "P%i/D", i );
207 btoftree -> Branch( brname, &cnvBarPar1[i], ibrname );
208 }
209
210 for( int i=0; i<176; i++ ) {
211 for( int j=0;j<static_cast<int>(nBarPar);j++){
212 cnvBarPar1[j] = btof->getBTofPleft(i,j);
213 cnvBarPar2[j] = btof->getBTofPright(i,j);
214 }
215 btoftree -> Fill();
216 }
217
218 //write etoftree----------------------------------------------------------------
219 double cnvEndPar[nEndPar];
220
221 char ecname[8], iecname[8];
222 TTree *etoftree = new TTree("EndTofPar", "EndTofPar");
223 for( unsigned int i=0; i<nEndPar; i++ ) {
224 sprintf( ecname, "P%i", i );
225 sprintf( iecname, "P%i/D", i );
226 etoftree -> Branch( ecname, &cnvEndPar[i], iecname );
227 }
228
229 for(int i=0; i<96; i++){
230 for(int j=0;j<static_cast<int>(nEndPar);j++){
231 cnvEndPar[j] = btof->getETofP(i,j);
232 }
233 etoftree->Fill();
234 }
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"<<endreq;
243
244 return sc;
245}
const CLID CLID_Calib_EstTofCal
Definition: CalibModel.h:53
data SetBranchAddress("time",&time)
data GetEntry(0)
const unsigned int nBarOffset
const unsigned int nBarParOff
const unsigned int nEndPar
const unsigned int nBarPar
IMessageSvc * msgSvc()
double getETofP(int index, int pardex)
double getBTofPleft(int index, int pardex)
double getBTofPright(int index, int pardex)
void setP2(const double *TofP2)
void setPoff1_bunch3(const double *TofPoff1_bunch3)
void setPoff2_bunch1(const double *TofPoff2_bunch1)
void setPoff1_bunch0(const double *TofPoff1_bunch0)
void setPoff2_bunch2(const double *TofPoff2_bunch2)
void setPoff1_bunch1(const double *TofPoff1_bunch1)
void setPoff1_bunch2(const double *TofPoff1_bunch2)
void setPoff2_bunch3(const double *TofPoff2_bunch3)
void setPoff2_bunch0(const double *TofPoff2_bunch0)
void setP1(const double *TofP1)
void setOffset(const double *offset)
void setP(const double *TofP)
StatusCode openRead(const std::string &fname)
StatusCode closeWrite()
virtual StatusCode openWrite(const std::string &fname)
const CLID & objType() const
RootEstTofCalibDataCnv(ISvcLocator *svc)
virtual StatusCode createRoot(const std::string &fname, CalibData::CalibBase1 *pTDSObj)
static const CLID & classID()
virtual StatusCode i_createObj(const std::string &fname, DataObject *&refpObject)