BOSS 7.1.2
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
44const unsigned int nEtfSpeed = 4;
45const unsigned int nEtfPar = 20;
46const unsigned int nEtfBunch = 4;
47
52
53
54const CLID& TreeTofCalibDataCnv::objType() const {
55 return CLID_Calib_TofCal;
56}
57
59 return CLID_Calib_TofCal;
60}
61
62StatusCode TreeTofCalibDataCnv::i_createObj(IOpaqueAddress* addr,
63 DataObject*& refpObject) {
64
65 MsgStream log(msgSvc(), "TreeTofCalibDataCnv");
66 log<<MSG::DEBUG<<"SetProperty"<<endreq;
67
68 TreeAddress* add = dynamic_cast<TreeAddress*>(addr);
69
70 DatabaseRecord *records=add->pp();
71
72 TBufferFile *buf1 = new TBufferFile(TBuffer::kRead);
73 TBufferFile *buf2 = new TBufferFile(TBuffer::kRead);
74 TBufferFile *buf3 = new TBufferFile(TBuffer::kRead);
75 TBufferFile *buf4 = new TBufferFile(TBuffer::kRead);
76 TBufferFile *buf5 = 0;
77 TBufferFile *buf6 = 0;
78
79 buf1->SetBuffer((*records)["BarTofPar"],2048000,kFALSE);
80 buf2->SetBuffer((*records)["EndTofPar"],2048000,kFALSE);
81 buf3->SetBuffer((*records)["TofConPar"],2048000,kFALSE);
82 buf4->SetBuffer((*records)["BarTof"], 2048000,kFALSE);
83 if( (*records)["EtfTofPar"]!=0 ) {
84 buf5 = new TBufferFile(TBuffer::kRead);
85 buf5->SetBuffer((*records)["EtfTofPar"],2048000,kFALSE);
86 }
87 if( (*records)["EtfTofBunch"]!=0 ) {
88 buf6 = new TBufferFile(TBuffer::kRead);
89 buf6->SetBuffer((*records)["EtfTofBunch"],2048000,kFALSE);
90 }
91
92 std::cout<<" SftVer is "<<(*records)["SftVer"];
93 std::cout<<" CalVerSft is "<<(*records)["CalParVer"];
94 std::cout<<" File name is "<<(*records)["FileName"]<<std::endl;
95
96 TTree *btoftree = new TTree();
97 TTree *etoftree = new TTree();
98 TTree *etftree = new TTree();
99 TTree *etfbunchtree = new TTree();
100 TTree *btofcommontree = new TTree();
101 TTree *CalibInfo = new TTree();
102
103 btoftree->Streamer(*buf1);
104 etoftree->Streamer(*buf2);
105 btofcommontree->Streamer(*buf3);
106 CalibInfo->Streamer(*buf4);
107 if( buf5 ) {
108 etftree->Streamer(*buf5);
109 }
110 if( buf6 ) {
111 etfbunchtree->Streamer(*buf6);
112 }
113
120
121 std::vector<CalibData::bTofCalibBase> tmpbTof;
122 std::vector<CalibData::eTofCalibBase> tmpeTof;
123 std::vector<CalibData::etfCalibBase> tmpetf;
124 std::vector<CalibData::etfBunchCalibBase> tmpetfBunch;
125 std::vector<CalibData::bTofCommonCalibBase> tmpbTofCommon;
126 std::vector<CalibData::tofCalibInfoBase> tofinfoCol;
127
128 // Read in the object
129 int cnt;
130 // read btoftree ------------------------------------------------------------
131 double cnvBarAtten[nBarAtten];
132 double cnvBarSpeed[nBarSpeed];
133 double cnvBarPar1[nBarPar];
134 double cnvBarPar2[nBarPar];
135 double cnvBarParOff1_bunch0[nBarParOff];
136 double cnvBarParOff2_bunch0[nBarParOff];
137 double cnvBarParOff1_bunch1[nBarParOff];
138 double cnvBarParOff2_bunch1[nBarParOff];
139 double cnvBarParOff1_bunch2[nBarParOff];
140 double cnvBarParOff2_bunch2[nBarParOff];
141 double cnvBarParOff1_bunch3[nBarParOff];
142 double cnvBarParOff2_bunch3[nBarParOff];
143 double cnvFLeft[nBarSigma];
144 double cnvFRight[nBarSigma];
145 double cnvFCount[nBarSigCnt];
146
147 char brname[10];
148 for( unsigned int i=0; i<nBarAtten; i++ ) {
149 sprintf( brname, "Atten%i", i );
150 btoftree -> SetBranchAddress( brname, &cnvBarAtten[i] );
151 }
152 for( unsigned int i=0; i<nBarSpeed; i++ ) {
153 sprintf( brname, "Speed%i", i );
154 btoftree -> SetBranchAddress( brname, &cnvBarSpeed[i] );
155 }
156 for( unsigned int i=0; i<nBarPar; i++ ) {
157 sprintf( brname, "P%i", i );
158 btoftree -> SetBranchAddress( brname, &cnvBarPar1[i] );
159 }
160 for( unsigned int i=0; i<nBarPar; i++ ) {
161 sprintf( brname, "P%i", i+nBarPar );
162 btoftree -> SetBranchAddress( brname, &cnvBarPar2[i] );
163 }
164 for( unsigned int i=0; i<nBarParOff; i++ ) {
165 sprintf( brname, "Bunch0_Poff%i", i );
166 btoftree -> SetBranchAddress( brname, &cnvBarParOff1_bunch0[i] );
167 }
168 for( unsigned int i=0; i<nBarParOff; i++ ) {
169 sprintf( brname, "Bunch0_Poff%i", i+nBarParOff );
170 btoftree -> SetBranchAddress( brname, &cnvBarParOff2_bunch0[i] );
171 }
172 for( unsigned int i=0; i<nBarParOff; i++ ) {
173 sprintf( brname, "Bunch1_Poff%i", i );
174 btoftree -> SetBranchAddress( brname, &cnvBarParOff1_bunch1[i] );
175 }
176 for( unsigned int i=0; i<nBarParOff; i++ ) {
177 sprintf( brname, "Bunch1_Poff%i", i+nBarParOff );
178 btoftree -> SetBranchAddress( brname, &cnvBarParOff2_bunch1[i] );
179 }
180 for( unsigned int i=0; i<nBarParOff; i++ ) {
181 sprintf( brname, "Bunch2_Poff%i", i );
182 btoftree -> SetBranchAddress( brname, &cnvBarParOff1_bunch2[i] );
183 }
184 for( unsigned int i=0; i<nBarParOff; i++ ) {
185 sprintf( brname, "Bunch2_Poff%i", i+nBarParOff );
186 btoftree -> SetBranchAddress( brname, &cnvBarParOff2_bunch2[i] );
187 }
188 for( unsigned int i=0; i<nBarParOff; i++ ) {
189 sprintf( brname, "Bunch3_Poff%i", i );
190 btoftree -> SetBranchAddress( brname, &cnvBarParOff1_bunch3[i] );
191 }
192 for( unsigned int i=0; i<nBarParOff; i++ ) {
193 sprintf( brname, "Bunch3_Poff%i", i+nBarParOff );
194 btoftree -> SetBranchAddress( brname, &cnvBarParOff2_bunch3[i] );
195 }
196 for( unsigned int i=0; i<nBarSigma; i++ ) {
197 sprintf( brname, "FLeft%i", i );
198 btoftree -> SetBranchAddress( brname, &cnvFLeft[i] );
199 }
200 for( unsigned int i=0; i<nBarSigma; i++ ) {
201 sprintf( brname, "FRight%i", i );
202 btoftree -> SetBranchAddress( brname, &cnvFRight[i] );
203 }
204 for( unsigned int i=0; i<nBarSigCnt; i++ ) {
205 sprintf( brname, "FCounter%i", i );
206 btoftree -> SetBranchAddress( brname, &cnvFCount[i] );
207 }
208
209 unsigned int btofN = btoftree->GetEntries(); // Modify for n flies 176 ==> btoftree->GetEntries() wensp
210 for(cnt=0; cnt<btofN; cnt++){
211 btoftree -> GetEntry(cnt);
212 bTof.setAtten( cnvBarAtten );
213 bTof.setSpeed( cnvBarSpeed );
214 bTof.setP1( cnvBarPar1 );
215 bTof.setP2( cnvBarPar2 );
216 bTof.setPoff1_bunch0( cnvBarParOff1_bunch0 );
217 bTof.setPoff2_bunch0( cnvBarParOff2_bunch0 );
218 bTof.setPoff1_bunch1( cnvBarParOff1_bunch1 );
219 bTof.setPoff2_bunch1( cnvBarParOff2_bunch1 );
220 bTof.setPoff1_bunch2( cnvBarParOff1_bunch2 );
221 bTof.setPoff2_bunch2( cnvBarParOff2_bunch2 );
222 bTof.setPoff1_bunch3( cnvBarParOff1_bunch3 );
223 bTof.setPoff2_bunch3( cnvBarParOff2_bunch3 );
224 bTof.setFPleft( cnvFLeft );
225 bTof.setFPright( cnvFRight );
226 bTof.setFPcounter( cnvFCount );
227 tmpbTof.push_back(bTof);
228 }
229
230 //read etoftree
231 double cnvEndAtten[nEndAtten];
232 double cnvEndSpeed[nEndSpeed];
233 double cnvEndPar[nEndPar];
234 double cnvEndFPar[nEndSigma];
235
236 char ecname[10];
237 for( unsigned int i=0; i<nEndAtten; i++ ) {
238 sprintf( ecname, "Atten%i", i );
239 etoftree -> SetBranchAddress( ecname, &cnvEndAtten[i] );
240 }
241 for( unsigned int i=0; i<nEndSpeed; i++ ) {
242 sprintf( ecname, "Speed%i", i );
243 etoftree -> SetBranchAddress( ecname, &cnvEndSpeed[i] );
244 }
245 for( unsigned int i=0; i<nEndPar; i++ ) {
246 sprintf( ecname, "P%i", i );
247 etoftree -> SetBranchAddress( ecname, &cnvEndPar[i] );
248 }
249 for( unsigned int i=0; i<nEndSigma; i++ ) {
250 sprintf( ecname, "FCounter%i", i );
251 etoftree -> SetBranchAddress( ecname, &cnvEndFPar[i] );
252 }
253
254 unsigned int etofN = etoftree->GetEntries(); // Modify for n flies 96 ==> etoftree->GetEntries() wensp
255 for(cnt=0; cnt<etofN; cnt++){
256 etoftree -> GetEntry(cnt);
257 eTof.setAtten( cnvEndAtten );
258 eTof.setSpeed( cnvEndSpeed );
259 eTof.setP( cnvEndPar );
260 eTof.setFP( cnvEndFPar );
261 tmpeTof.push_back(eTof);
262 }
263
264
265 //read etftree
266 if( etftree->GetEntries() != 0 ) {
267
268 double cnvEtfSpeed[nEtfSpeed];
269 double cnvEtfPar[nEtfPar];
270 double cnvEtfPar1[nEtfPar];
271 double cnvEtfPar2[nEtfPar];
272
273 char etfname[10];
274 for( unsigned int i=0; i<nEtfSpeed; i++ ) {
275 sprintf( etfname, "Speed%i", i );
276 etftree -> SetBranchAddress( etfname, &cnvEtfSpeed[i] );
277 }
278 for( unsigned int i=0; i<nEtfPar; i++ ) {
279 sprintf( etfname, "P%i", i );
280 etftree -> SetBranchAddress( etfname, &cnvEtfPar[i] );
281 sprintf( etfname, "P%i", nEtfPar+i );
282 etftree -> SetBranchAddress( etfname, &cnvEtfPar1[i] );
283 sprintf( etfname, "P%i", 2*nEtfPar+i );
284 etftree -> SetBranchAddress( etfname, &cnvEtfPar2[i] );
285 }
286
287 unsigned int etfN = etftree->GetEntries(); // Modify for n flies 72*12 ==> etftree->GetEntries() wensp
288 for(cnt=0; cnt<etfN; cnt++){
289 etftree -> GetEntry(cnt);
290 etf.setSpeed( cnvEtfSpeed );
291 etf.setP( cnvEtfPar );
292 etf.setP1( cnvEtfPar1 );
293 etf.setP2( cnvEtfPar2 );
294 tmpetf.push_back(etf);
295 }
296
297 }
298
299
300 //read etftree
301 if( etfbunchtree->GetEntries() != 0 ) {
302 double cnvEtfBunchP[nEtfBunch];
303 char etfbunchname[10];
304 for( unsigned int i=0; i<nEtfBunch; i++ ) {
305 sprintf( etfbunchname, "pbunch%i", i );
306 etfbunchtree -> SetBranchAddress( etfbunchname, &cnvEtfBunchP[i] );
307 }
308 int entries= etfbunchtree->GetEntries();
309 for(cnt=0;cnt<entries;cnt++){
310 etfbunchtree -> GetEntry(cnt);
311 etfBunch.setPBunch( cnvEtfBunchP );
312 tmpetfBunch.push_back( etfBunch );
313 }
314 }
315
316
317 //read bTofCommonCalibBase
318 double cnvBarSigCor[nBarSigCor];
319 double cnvBarOffset[nBarOffset];
320 for( unsigned int i=0; i<nBarSigCor; i++ ) {
321 sprintf( brname, "sigmaCorr%i", i );
322 btofcommontree-> SetBranchAddress( brname, &cnvBarSigCor[i] );
323 }
324 for( unsigned int i=0; i<nBarOffset; i++ ) {
325 sprintf( brname, "t0offset%i", i );
326 btofcommontree-> SetBranchAddress( brname, &cnvBarOffset[i]);
327 }
328
329 int entries = btofcommontree->GetEntries();
330 for(cnt=0;cnt<entries;cnt++){
331 btofcommontree->GetEntry(cnt);
332 bTofCommon.setSigmaCorr( cnvBarSigCor );
333 bTofCommon.setOffset( cnvBarOffset );
334 tmpbTofCommon.push_back(bTofCommon);
335 }
336
337 int m_runFrom, m_runTo, m_eventFrom, m_eventTo; // Modify for n files, wensp
338 int m_run1, m_run2, m_version;
339 int m_qCorr, m_qElec, m_misLable;
340 int m_tofidEast[5], m_tofidWest[5], m_tofidEndcap[5];
341
342 if( CalibInfo->GetBranchStatus( "runFrom" ) ) {
343 CalibInfo->SetBranchAddress("runFrom", &m_runFrom );
344 CalibInfo->SetBranchAddress("runTo", &m_runTo );
345 CalibInfo->SetBranchAddress("eventFrom",&m_eventFrom );
346 CalibInfo->SetBranchAddress("eventTo", &m_eventTo );
347 }
348 else {
349 m_runFrom = -1;
350 m_runTo = -1;
351 m_eventFrom = -1;
352 m_eventTo = -1;
353 }
354 CalibInfo->SetBranchAddress("Run1", &m_run1 );
355 CalibInfo->SetBranchAddress("Run2", &m_run2 );
356 CalibInfo->SetBranchAddress("Version", &m_version );
357 CalibInfo->SetBranchAddress("ebrId0", &m_tofidEast[0] );
358 CalibInfo->SetBranchAddress("ebrId1", &m_tofidEast[1] );
359 CalibInfo->SetBranchAddress("ebrId2", &m_tofidEast[2] );
360 CalibInfo->SetBranchAddress("ebrId3", &m_tofidEast[3] );
361 CalibInfo->SetBranchAddress("ebrId4", &m_tofidEast[4] );
362 CalibInfo->SetBranchAddress("ecId0", &m_tofidEndcap[0]);
363 CalibInfo->SetBranchAddress("ecId1", &m_tofidEndcap[1]);
364 CalibInfo->SetBranchAddress("ecId2", &m_tofidEndcap[2]);
365 CalibInfo->SetBranchAddress("ecId3", &m_tofidEndcap[3]);
366 CalibInfo->SetBranchAddress("ecId4", &m_tofidEndcap[4]);
367 CalibInfo->SetBranchAddress("wbrId0", &m_tofidWest[0] );
368 CalibInfo->SetBranchAddress("wbrId1", &m_tofidWest[1] );
369 CalibInfo->SetBranchAddress("wbrId2", &m_tofidWest[2] );
370 CalibInfo->SetBranchAddress("wbrId3", &m_tofidWest[3] );
371 CalibInfo->SetBranchAddress("wbrId4", &m_tofidWest[4] );
372 CalibInfo->SetBranchAddress("misLable", &m_misLable );
373 CalibInfo->SetBranchAddress("qCorr", &m_qCorr );
374 CalibInfo->SetBranchAddress("qElec", &m_qElec );
375
376 entries = CalibInfo->GetEntries();
377 for(cnt=0;cnt<entries;cnt++){
378 CalibInfo->GetEntry(cnt);
379 tofinfo.setRunFrom(m_runFrom);
380 tofinfo.setRunTo(m_runTo);
381 tofinfo.setEventFrom(m_eventFrom);
382 tofinfo.setEventTo(m_eventTo);
383 tofinfo.setRunBegin(m_run1);
384 tofinfo.setRunEnd(m_run2);
385 tofinfo.setVersion(m_version);
386 tofinfo.setQCorr(m_qCorr);
387 tofinfo.setQElec(m_qElec);
388 tofinfo.setMisLable(m_misLable);
389 tofinfo.setBrEast(m_tofidEast);
390 tofinfo.setBrWest(m_tofidWest);
391 tofinfo.setEndcap(m_tofidEndcap);
392 tofinfoCol.push_back(tofinfo);
393 }
394
395 CalibData::TofCalibData *tmpObject = new CalibData::TofCalibData(&tmpbTof,&tmpbTofCommon,&tmpeTof,&tmpetf,&tmpetfBunch,&tofinfoCol);
396
397 refpObject=tmpObject;
398 delete btoftree;
399 delete etoftree;
400 delete etftree;
401 delete etfbunchtree;
402 delete btofcommontree;
403 delete CalibInfo;
404
405 return StatusCode::SUCCESS;
406}
407
const CLID CLID_Calib_TofCal
Definition CalibModel.h:43
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
data GetEntry(0)
data SetBranchAddress("time",&time)
const unsigned int nBarOffset
const unsigned int nBarParOff
const unsigned int nEndPar
const unsigned int nEtfPar
const unsigned int nBarPar
const unsigned int nBarSigma
const unsigned int nEndSigma
const unsigned int nBarSigCor
const unsigned int nEndSpeed
const unsigned int nEtfSpeed
const unsigned int nEtfBunch
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 nEtfSpeed
const unsigned int nEtfBunch
const unsigned int nEndPar
const unsigned int nEtfPar
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 setPBunch(const double *etfBunchP)
void setSpeed(const double *Speed)
void setP(const double *etfP)
void setP1(const double *etfP1)
void setP2(const double *etfP2)
void setRunFrom(const int runFrom)
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 setEventTo(const int eventTo)
void setRunTo(const int runTo)
void setBrEast(const int *tofidEast)
void setQElec(const int qElec)
void setEventFrom(const int eventFrom)
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)