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