CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
TreeTofCalibDataCnv.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
6#include "TFile.h"
7#include "TTree.h"
8#include "TDirectory.h"
9#include "TObject.h"
10#include "TBuffer.h"
11
12#include "GaudiKernel/CnvFactory.h"
13#include "GaudiKernel/IOpaqueAddress.h"
14#include "GaudiKernel/DataObject.h"
15#include "GaudiKernel/IAddressCreator.h"
16#include "GaudiKernel/IDataProviderSvc.h"
17#include "GaudiKernel/IConversionSvc.h"
18#include "GaudiKernel/GenericAddress.h"
19
20#include "CalibDataSvc/ICalibTreeSvc.h" //maybe
22
23// Temporary. Hope to find a better way to do this
25using namespace CalibData;
26//static CnvFactory<TreeTofCalibDataCnv> TofCal_factory;
27//const ICnvFactory& TreeTofCalibDataCnvFactory = TofCal_factory;
28
29const unsigned int nBarAtten = 8;
30const unsigned int nBarSpeed = 2;
31const unsigned int nBarPar = 10;
32const unsigned int nBarParOff = 20;
33const unsigned int nBarSigma = 5;
34const unsigned int nBarSigCnt = 10;
35
36const unsigned int nBarSigCor = 8;
37const unsigned int nBarOffset = 2;
38
39const unsigned int nEndAtten = 5;
40const unsigned int nEndSpeed = 4;
41const unsigned int nEndPar = 8;
42const unsigned int nEndSigma = 5;
43
48
49
50const CLID& TreeTofCalibDataCnv::objType() const {
51 return CLID_Calib_TofCal;
52}
53
55 return CLID_Calib_TofCal;
56}
57
58StatusCode TreeTofCalibDataCnv::i_createObj(IOpaqueAddress* addr,
59 DataObject*& refpObject) {
60
61 MsgStream log(msgSvc(), "TreeTofCalibDataCnv");
62 log<<MSG::DEBUG<<"SetProperty"<<endreq;
63
64 TreeAddress* add = dynamic_cast<TreeAddress*>(addr);
65
66 DatabaseRecord *records=add->pp();
67
68 TBufferFile *buf1 = new TBufferFile(TBuffer::kRead);
69 TBufferFile *buf2 = new TBufferFile(TBuffer::kRead);
70 TBufferFile *buf3 = new TBufferFile(TBuffer::kRead);
71 TBufferFile *buf4 = new TBufferFile(TBuffer::kRead);
72
73 buf1->SetBuffer((*records)["BarTofPar"],512000,kFALSE);
74 buf2->SetBuffer((*records)["EndTofPar"],512000,kFALSE);
75 buf3->SetBuffer((*records)["TofConPar"],512000,kFALSE);
76 buf4->SetBuffer((*records)["BarTof"],512000,kFALSE);
77
78 std::cout<<" SftVer is "<<(*records)["SftVer"];
79 std::cout<<" CalVerSft is "<<(*records)["CalParVer"];
80 std::cout<<" File name is "<<(*records)["FileName"]<<std::endl;
81
82 TTree *btoftree= new TTree();
83 TTree *etoftree= new TTree();
84 TTree *btofcommontree = new TTree();
85 TTree *CalibInfo = new TTree();
86
87 btoftree->Streamer(*buf1);
88 etoftree->Streamer(*buf2);
89 btofcommontree->Streamer(*buf3);
90 CalibInfo->Streamer(*buf4);
91
92 int nentri = btoftree -> GetEntries();
93 int nentri1 = etoftree -> GetEntries();
94 int nentri2 = btofcommontree->GetEntries();
95 int nentri3 = CalibInfo->GetEntries();
96
101
102 std::vector<CalibData::bTofCalibBase> tmpbTof;
103 std::vector<CalibData::eTofCalibBase> tmpeTof;
104 std::vector<CalibData::bTofCommonCalibBase> tmpbTofCommon;
105 std::vector<CalibData::tofCalibInfoBase> tofinfoCol;
106
107 // Read in the object
108 int cnt;
109 // read btoftree ------------------------------------------------------------
110 double cnvBarAtten[nBarAtten];
111 double cnvBarSpeed[nBarSpeed];
112 double cnvBarPar1[nBarPar];
113 double cnvBarPar2[nBarPar];
114 double cnvBarParOff1_bunch0[nBarParOff];
115 double cnvBarParOff2_bunch0[nBarParOff];
116 double cnvBarParOff1_bunch1[nBarParOff];
117 double cnvBarParOff2_bunch1[nBarParOff];
118 double cnvBarParOff1_bunch2[nBarParOff];
119 double cnvBarParOff2_bunch2[nBarParOff];
120 double cnvBarParOff1_bunch3[nBarParOff];
121 double cnvBarParOff2_bunch3[nBarParOff];
122 double cnvFLeft[nBarSigma];
123 double cnvFRight[nBarSigma];
124 double cnvFCount[nBarSigCnt];
125
126 char brname[10];
127 for( unsigned int i=0; i<nBarAtten; i++ ) {
128 sprintf( brname, "Atten%i", i );
129 btoftree -> SetBranchAddress( brname, &cnvBarAtten[i] );
130 }
131 for( unsigned int i=0; i<nBarSpeed; i++ ) {
132 sprintf( brname, "Speed%i", i );
133 btoftree -> SetBranchAddress( brname, &cnvBarSpeed[i] );
134 }
135 for( unsigned int i=0; i<nBarPar; i++ ) {
136 sprintf( brname, "P%i", i );
137 btoftree -> SetBranchAddress( brname, &cnvBarPar1[i] );
138 }
139 for( unsigned int i=0; i<nBarPar; i++ ) {
140 sprintf( brname, "P%i", i+nBarPar );
141 btoftree -> SetBranchAddress( brname, &cnvBarPar2[i] );
142 }
143 for( unsigned int i=0; i<nBarParOff; i++ ) {
144 sprintf( brname, "Bunch0_Poff%i", i );
145 btoftree -> SetBranchAddress( brname, &cnvBarParOff1_bunch0[i] );
146 }
147 for( unsigned int i=0; i<nBarParOff; i++ ) {
148 sprintf( brname, "Bunch0_Poff%i", i+nBarParOff );
149 btoftree -> SetBranchAddress( brname, &cnvBarParOff2_bunch0[i] );
150 }
151 for( unsigned int i=0; i<nBarParOff; i++ ) {
152 sprintf( brname, "Bunch1_Poff%i", i );
153 btoftree -> SetBranchAddress( brname, &cnvBarParOff1_bunch1[i] );
154 }
155 for( unsigned int i=0; i<nBarParOff; i++ ) {
156 sprintf( brname, "Bunch1_Poff%i", i+nBarParOff );
157 btoftree -> SetBranchAddress( brname, &cnvBarParOff2_bunch1[i] );
158 }
159 for( unsigned int i=0; i<nBarParOff; i++ ) {
160 sprintf( brname, "Bunch2_Poff%i", i );
161 btoftree -> SetBranchAddress( brname, &cnvBarParOff1_bunch2[i] );
162 }
163 for( unsigned int i=0; i<nBarParOff; i++ ) {
164 sprintf( brname, "Bunch2_Poff%i", i+nBarParOff );
165 btoftree -> SetBranchAddress( brname, &cnvBarParOff2_bunch2[i] );
166 }
167 for( unsigned int i=0; i<nBarParOff; i++ ) {
168 sprintf( brname, "Bunch3_Poff%i", i );
169 btoftree -> SetBranchAddress( brname, &cnvBarParOff1_bunch3[i] );
170 }
171 for( unsigned int i=0; i<nBarParOff; i++ ) {
172 sprintf( brname, "Bunch3_Poff%i", i+nBarParOff );
173 btoftree -> SetBranchAddress( brname, &cnvBarParOff2_bunch3[i] );
174 }
175 for( unsigned int i=0; i<nBarSigma; i++ ) {
176 sprintf( brname, "FLeft%i", i );
177 btoftree -> SetBranchAddress( brname, &cnvFLeft[i] );
178 }
179 for( unsigned int i=0; i<nBarSigma; i++ ) {
180 sprintf( brname, "FRight%i", i );
181 btoftree -> SetBranchAddress( brname, &cnvFRight[i] );
182 }
183 for( unsigned int i=0; i<nBarSigCnt; i++ ) {
184 sprintf( brname, "FCounter%i", i );
185 btoftree -> SetBranchAddress( brname, &cnvFCount[i] );
186 }
187
188 for(cnt=0; cnt<176; cnt++){
189 btoftree -> GetEntry(cnt);
190 bTof.setAtten( cnvBarAtten );
191 bTof.setSpeed( cnvBarSpeed );
192 bTof.setP1( cnvBarPar1 );
193 bTof.setP2( cnvBarPar2 );
194 bTof.setPoff1_bunch0( cnvBarParOff1_bunch0 );
195 bTof.setPoff2_bunch0( cnvBarParOff2_bunch0 );
196 bTof.setPoff1_bunch1( cnvBarParOff1_bunch1 );
197 bTof.setPoff2_bunch1( cnvBarParOff2_bunch1 );
198 bTof.setPoff1_bunch2( cnvBarParOff1_bunch2 );
199 bTof.setPoff2_bunch2( cnvBarParOff2_bunch2 );
200 bTof.setPoff1_bunch3( cnvBarParOff1_bunch3 );
201 bTof.setPoff2_bunch3( cnvBarParOff2_bunch3 );
202 bTof.setFPleft( cnvFLeft );
203 bTof.setFPright( cnvFRight );
204 bTof.setFPcounter( cnvFCount );
205 tmpbTof.push_back(bTof);
206 }
207
208 //read etoftree
209 double cnvEndAtten[nEndAtten];
210 double cnvEndSpeed[nEndSpeed];
211 double cnvEndPar[nEndPar];
212 double cnvEndFPar[nEndSigma];
213
214 char ecname[10];
215 for( unsigned int i=0; i<nEndAtten; i++ ) {
216 sprintf( ecname, "Atten%i", i );
217 etoftree -> SetBranchAddress( ecname, &cnvEndAtten[i] );
218 }
219 for( unsigned int i=0; i<nEndSpeed; i++ ) {
220 sprintf( ecname, "Speed%i", i );
221 etoftree -> SetBranchAddress( ecname, &cnvEndSpeed[i] );
222 }
223 for( unsigned int i=0; i<nEndPar; i++ ) {
224 sprintf( ecname, "P%i", i );
225 etoftree -> SetBranchAddress( ecname, &cnvEndPar[i] );
226 }
227 for( unsigned int i=0; i<nEndSigma; i++ ) {
228 sprintf( ecname, "FCounter%i", i );
229 etoftree -> SetBranchAddress( ecname, &cnvEndFPar[i] );
230 }
231
232 for(cnt=0; cnt<96; cnt++){
233 etoftree -> GetEntry(cnt);
234 eTof.setAtten( cnvEndAtten );
235 eTof.setSpeed( cnvEndSpeed );
236 eTof.setP( cnvEndPar );
237 eTof.setFP( cnvEndFPar );
238 tmpeTof.push_back(eTof);
239 }
240
241 //read bTofCommonCalibBase
242 double cnvBarSigCor[nBarSigCor];
243 double cnvBarOffset[nBarOffset];
244 for( unsigned int i=0; i<nBarSigCor; i++ ) {
245 sprintf( brname, "sigmaCorr%i", i );
246 btofcommontree-> SetBranchAddress( brname, &cnvBarSigCor[i] );
247 }
248 for( unsigned int i=0; i<nBarOffset; i++ ) {
249 sprintf( brname, "t0offset%i", i );
250 btofcommontree-> SetBranchAddress( brname, &cnvBarOffset[i]);
251 }
252
253 int entries = btofcommontree->GetEntries();
254 for(cnt=0;cnt<entries;cnt++){
255 btofcommontree->GetEntry(cnt);
256 bTofCommon.setSigmaCorr( cnvBarSigCor );
257 bTofCommon.setOffset( cnvBarOffset );
258 tmpbTofCommon.push_back(bTofCommon);
259 }
260
261 int m_run1, m_run2, m_version;
262 int m_qCorr, m_qElec, m_misLable;
263 int m_tofidEast[5], m_tofidWest[5], m_tofidEndcap[5];
264
265 // TTree *CalibInfo = (TTree*)m_inFile -> Get("CalibInfo");
266 CalibInfo->SetBranchAddress("Run1",&m_run1);
267 CalibInfo->SetBranchAddress("Run2",&m_run2);
268 CalibInfo->SetBranchAddress("Version",&m_version);
269 CalibInfo->SetBranchAddress("ebrId0",&m_tofidEast[0]);
270 CalibInfo->SetBranchAddress("ebrId1",&m_tofidEast[1]);
271 CalibInfo->SetBranchAddress("ebrId2",&m_tofidEast[2]);
272 CalibInfo->SetBranchAddress("ebrId3",&m_tofidEast[3]);
273 CalibInfo->SetBranchAddress("ebrId4",&m_tofidEast[4]);
274 CalibInfo->SetBranchAddress("ecId0",&m_tofidEndcap[0]);
275 CalibInfo->SetBranchAddress("ecId1",&m_tofidEndcap[1]);
276 CalibInfo->SetBranchAddress("ecId2",&m_tofidEndcap[2]);
277 CalibInfo->SetBranchAddress("ecId3",&m_tofidEndcap[3]);
278 CalibInfo->SetBranchAddress("ecId4",&m_tofidEndcap[4]);
279 CalibInfo->SetBranchAddress("wbrId0",&m_tofidWest[0]);
280 CalibInfo->SetBranchAddress("wbrId1",&m_tofidWest[1]);
281 CalibInfo->SetBranchAddress("wbrId2",&m_tofidWest[2]);
282 CalibInfo->SetBranchAddress("wbrId3",&m_tofidWest[3]);
283 CalibInfo->SetBranchAddress("wbrId4",&m_tofidWest[4]);
284 CalibInfo->SetBranchAddress("misLable",&m_misLable);
285 CalibInfo->SetBranchAddress("qCorr",&m_qCorr);
286 CalibInfo->SetBranchAddress("qElec",&m_qElec);
287
288 entries= CalibInfo->GetEntries();
289 for(cnt=0;cnt<entries;cnt++){
290 CalibInfo->GetEntry(cnt);
291 tofinfo.setRunBegin(m_run1);
292 tofinfo.setRunEnd(m_run2);
293 tofinfo.setVersion(m_version);
294 tofinfo.setQCorr(m_qCorr);
295 tofinfo.setQElec(m_qElec);
296 tofinfo.setMisLable(m_misLable);
297 tofinfo.setBrEast(m_tofidEast);
298 tofinfo.setBrWest(m_tofidWest);
299 tofinfo.setEndcap(m_tofidEndcap);
300 tofinfoCol.push_back(tofinfo);
301 }
302
303 CalibData::TofCalibData *tmpObject = new CalibData::TofCalibData(&tmpbTof,&tmpbTofCommon,&tmpeTof,&tofinfoCol);
304
305 refpObject=tmpObject;
306 delete btoftree;
307 delete etoftree;
308 delete btofcommontree;
309 delete CalibInfo;
310
311 return StatusCode::SUCCESS;
312}
313
const CLID CLID_Calib_TofCal
Definition CalibModel.h:43
data SetBranchAddress("time",&time)
data GetEntry(0)
const unsigned int nBarOffset
const unsigned int nBarParOff
const unsigned int nEndPar
const unsigned int nBarPar
const unsigned int nBarSigma
const unsigned int nEndSigma
const unsigned int nBarSigCor
const unsigned int nEndSpeed
const unsigned int nBarSpeed
const unsigned int nEndAtten
const unsigned int nBarAtten
const unsigned int nBarSigCnt
IMessageSvc * msgSvc()
const unsigned int nBarSigma
const unsigned int nEndSigma
const unsigned int nBarSigCor
const unsigned int nEndSpeed
const unsigned int nBarOffset
const unsigned int nBarParOff
const unsigned int nEndPar
const unsigned int nBarSpeed
const unsigned int nEndAtten
const unsigned int nBarAtten
const unsigned int nBarSigCnt
const unsigned int nBarPar
void setP2(const double *TofP2)
void setPoff1_bunch3(const double *TofPoff1_bunch3)
void setFPleft(const double *FP1)
void setPoff2_bunch1(const double *TofPoff2_bunch1)
void setSpeed(const double *Speed)
void setAtten(const double *Atten)
void setPoff1_bunch0(const double *TofPoff1_bunch0)
void setPoff2_bunch2(const double *TofPoff2_bunch2)
void setPoff1_bunch1(const double *TofPoff1_bunch1)
void setFPcounter(const double *FP3)
void setPoff1_bunch2(const double *TofPoff1_bunch2)
void setPoff2_bunch3(const double *TofPoff2_bunch3)
void setFPright(const double *FP2)
void setPoff2_bunch0(const double *TofPoff2_bunch0)
void setP1(const double *TofP1)
void setSigmaCorr(const double *sigmaCorr)
void setOffset(const double *offset)
void setAtten(const double *Atten)
void setP(const double *TofP)
void setFP(const double *FP)
void setSpeed(const double *Speed)
void setBrWest(const int *tofidWest)
void setRunEnd(const int run2)
void setVersion(const int version)
void setMisLable(const int misLable)
void setRunBegin(const int run1)
void setBrEast(const int *tofidEast)
void setQElec(const int qElec)
void setQCorr(const int qCorr)
void setEndcap(const int *tofidEndcap)
virtual DatabaseRecord * pp()
const CLID & objType() const
virtual StatusCode i_createObj(IOpaqueAddress *address, DataObject *&refpObject)
static const CLID & classID()
TreeTofCalibDataCnv(ISvcLocator *svc)