BOSS 7.0.1
BESIII Offline Software System
Loading...
Searching...
No Matches
TreeEstTofCalibDataCnv.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
3#include "CalibData/Tof/TofCalibData.h"
4#include "CalibDataSvc/IInstrumentName.h"
5#include "CalibMySQLCnv/TreeAddress.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
21#include "CalibDataSvc/ICalibMetaCnvSvc.h"
22
23// Temporary. Hope to find a better way to do this
24#include "CalibData/CalibModel.h"
25using namespace CalibData;
26//static CnvFactory<TreeEstTofCalibDataCnv> TofCal_factory;
27//const ICnvFactory& TreeEstTofCalibDataCnvFactory = TofCal_factory;
28
29const unsigned int nBarPar = 10;
30const unsigned int nBarParOff = 20;
31const unsigned int nEndPar = 8;
32const unsigned int nEtfPar = 20;
33const unsigned int nBarOffset = 2;
34
37
38}
39
40
43}
44
47}
48
49StatusCode TreeEstTofCalibDataCnv::i_createObj(IOpaqueAddress* addr,
50 DataObject*& refpObject) {
51
52 MsgStream log(msgSvc(), "TreeEstTofCalibDataCnv");
53 log<<MSG::DEBUG<<"SetProperty"<<endreq;
54
55 TreeAddress* add = dynamic_cast<TreeAddress*>(addr);
56 DatabaseRecord *records=add->pp();
57
58 TBufferFile *buf1 = new TBufferFile(TBuffer::kRead);
59 TBufferFile *buf2 = new TBufferFile(TBuffer::kRead);
60 TBufferFile *buf3 = new TBufferFile(TBuffer::kRead);
61 TBufferFile *buf4 = new TBufferFile(TBuffer::kRead);
62 TBufferFile *buf5 = 0;
63
64 buf1->SetBuffer((*records)["BarTofPar"],512000,kFALSE);
65 buf2->SetBuffer((*records)["EndTofPar"],512000,kFALSE);
66 buf3->SetBuffer((*records)["TofConPar"],512000,kFALSE);
67 buf4->SetBuffer((*records)["BarTof"],512000,kFALSE);
68
69 if( (*records)["EtfTofPar"]!=0 ) {
70 buf5 = new TBufferFile(TBuffer::kRead);
71 buf5->SetBuffer((*records)["EtfTofPar"],512000,kFALSE);
72 }
73
74 std::cout<<" CalVerSft is "<<(*records)["CalParVer"];
75 std::cout<<" File name is "<<(*records)["FileName"]<<std::endl;
76
77 TTree *btoftree = new TTree();
78 TTree *etoftree = new TTree();
79 TTree *etftree = new TTree();
80 TTree *btofcommontree = new TTree();
81 TTree *CalibInfo = new TTree();
82
83 btoftree->Streamer(*buf1);
84 etoftree->Streamer(*buf2);
85 btofcommontree->Streamer(*buf3);
86 CalibInfo->Streamer(*buf4);
87 if( buf5 ) {
88 etftree->Streamer(*buf5);
89 }
90
96
97 std::vector<CalibData::bTofCalibBase> tmpbTof;
98 std::vector<CalibData::eTofCalibBase> tmpeTof;
99 std::vector<CalibData::etfCalibBase> tmpetf;
100 std::vector<CalibData::bTofCommonCalibBase> tmpbTofCommon;
101 std::vector<CalibData::tofCalibInfoBase> tofinfoCol;
102
103 // Read in the object
104 int cnt;
105 // read btoftree ------------------------------------------------------------
106 double cnvBarPar1[nBarPar];
107 double cnvBarPar2[nBarPar];
108 double cnvBarParOff1_bunch0[nBarParOff];
109 double cnvBarParOff2_bunch0[nBarParOff];
110 double cnvBarParOff1_bunch1[nBarParOff];
111 double cnvBarParOff2_bunch1[nBarParOff];
112 double cnvBarParOff1_bunch2[nBarParOff];
113 double cnvBarParOff2_bunch2[nBarParOff];
114 double cnvBarParOff1_bunch3[nBarParOff];
115 double cnvBarParOff2_bunch3[nBarParOff];
116
117 char brname[10];
118 for( unsigned int i=0; i<nBarPar; i++ ) {
119 sprintf( brname, "P%i", i );
120 btoftree -> SetBranchAddress( brname, &cnvBarPar1[i] );
121 }
122 for( unsigned int i=0; i<nBarPar; i++ ) {
123 sprintf( brname, "P%i", i+nBarPar );
124 btoftree -> SetBranchAddress( brname, &cnvBarPar2[i] );
125 }
126 for( unsigned int i=0; i<nBarParOff; i++ ) {
127 sprintf( brname, "Bunch0_Poff%i", i );
128 btoftree -> SetBranchAddress( brname, &cnvBarParOff1_bunch0[i] );
129 }
130 for( unsigned int i=0; i<nBarParOff; i++ ) {
131 sprintf( brname, "Bunch0_Poff%i", i+nBarParOff );
132 btoftree -> SetBranchAddress( brname, &cnvBarParOff2_bunch0[i] );
133 }
134 for( unsigned int i=0; i<nBarParOff; i++ ) {
135 sprintf( brname, "Bunch1_Poff%i", i );
136 btoftree -> SetBranchAddress( brname, &cnvBarParOff1_bunch1[i] );
137 }
138 for( unsigned int i=0; i<nBarParOff; i++ ) {
139 sprintf( brname, "Bunch1_Poff%i", i+nBarParOff );
140 btoftree -> SetBranchAddress( brname, &cnvBarParOff2_bunch1[i] );
141 }
142 for( unsigned int i=0; i<nBarParOff; i++ ) {
143 sprintf( brname, "Bunch2_Poff%i", i );
144 btoftree -> SetBranchAddress( brname, &cnvBarParOff1_bunch2[i] );
145 }
146 for( unsigned int i=0; i<nBarParOff; i++ ) {
147 sprintf( brname, "Bunch2_Poff%i", i+nBarParOff );
148 btoftree -> SetBranchAddress( brname, &cnvBarParOff2_bunch2[i] );
149 }
150 for( unsigned int i=0; i<nBarParOff; i++ ) {
151 sprintf( brname, "Bunch3_Poff%i", i );
152 btoftree -> SetBranchAddress( brname, &cnvBarParOff1_bunch3[i] );
153 }
154 for( unsigned int i=0; i<nBarParOff; i++ ) {
155 sprintf( brname, "Bunch3_Poff%i", i+nBarParOff );
156 btoftree -> SetBranchAddress( brname, &cnvBarParOff2_bunch3[i] );
157 }
158
159 for(cnt=0; cnt<176; cnt++){
160 btoftree -> GetEntry( cnt );
161 bTof.setP1( cnvBarPar1 );
162 bTof.setP2( cnvBarPar2 );
163 bTof.setPoff1_bunch0( cnvBarParOff1_bunch0 );
164 bTof.setPoff2_bunch0( cnvBarParOff2_bunch0 );
165 bTof.setPoff1_bunch1( cnvBarParOff1_bunch1 );
166 bTof.setPoff2_bunch1( cnvBarParOff2_bunch1 );
167 bTof.setPoff1_bunch2( cnvBarParOff1_bunch2 );
168 bTof.setPoff2_bunch2( cnvBarParOff2_bunch2 );
169 bTof.setPoff1_bunch3( cnvBarParOff1_bunch3 );
170 bTof.setPoff2_bunch3( cnvBarParOff2_bunch3 );
171 tmpbTof.push_back(bTof);
172 }
173
174
175 //read etoftree
176 double cnvEndPar[nEndPar];
177
178 char ecname[10];
179 for( unsigned int i=0; i<nEndPar; i++ ) {
180 sprintf( ecname, "P%i", i );
181 etoftree -> SetBranchAddress( ecname, &cnvEndPar[i] );
182 }
183
184 for( cnt=0; cnt<96; cnt++ ) {
185 etoftree -> GetEntry( cnt );
186 eTof.setP( cnvEndPar );
187 tmpeTof.push_back( eTof );
188 }
189
190
191 //read etftree
192 if( etftree->GetEntries() != 0 ) {
193
194 double cnvEtfPar[nEtfPar];
195 double cnvEtfPar1[nEtfPar];
196 double cnvEtfPar2[nEtfPar];
197
198 char etfname[10];
199 for( unsigned int i=0; i<nEtfPar; i++ ) {
200 sprintf( etfname, "P%i", i );
201 etftree -> SetBranchAddress( etfname, &cnvEtfPar[i] );
202 sprintf( etfname, "P%i", nEtfPar+i );
203 etftree -> SetBranchAddress( etfname, &cnvEtfPar1[i] );
204 sprintf( etfname, "P%i", 2*nEtfPar+i );
205 etftree -> SetBranchAddress( etfname, &cnvEtfPar2[i] );
206 }
207
208 for(cnt=0; cnt<(72*12); cnt++){
209 etftree -> GetEntry(cnt);
210 etf.setP( cnvEtfPar );
211 etf.setP1( cnvEtfPar1 );
212 etf.setP2( cnvEtfPar2 );
213 tmpetf.push_back(etf);
214 }
215
216 }
217
218
219 //read bTofCommonCalibBase
220 double cnvBarOffset[nBarOffset];
221 for( unsigned int i=0; i<nBarOffset; i++ ) {
222 sprintf( brname, "t0offset%i", i );
223 btofcommontree-> SetBranchAddress( brname, &cnvBarOffset[i]);
224 }
225
226 int entries = btofcommontree->GetEntries();
227 for(cnt=0;cnt<entries;cnt++){
228 btofcommontree->GetEntry(cnt);
229 bTofCommon.setOffset( cnvBarOffset );
230 tmpbTofCommon.push_back(bTofCommon);
231 }
232
233 CalibData::TofCalibData *tmpObject = new CalibData::TofCalibData(&tmpbTof,&tmpbTofCommon,&tmpeTof,&tmpetf,&tofinfoCol);
234
235 refpObject=tmpObject;
236 delete btoftree;
237 delete etoftree;
238 delete etftree;
239 delete btofcommontree;
240 delete CalibInfo;
241
242 return StatusCode::SUCCESS;
243}
244
data SetBranchAddress("time",&time)
data GetEntry(0)
const unsigned int nBarOffset
const unsigned int nBarParOff
const unsigned int nEndPar
const unsigned int nEtfPar
const unsigned int nBarPar
const unsigned int nBarOffset
const unsigned int nBarParOff
const unsigned int nEndPar
const unsigned int nEtfPar
const unsigned int nBarPar
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)
void setP(const double *etfP)
void setP1(const double *etfP1)
void setP2(const double *etfP2)
TreeEstTofCalibDataCnv(ISvcLocator *svc)
const CLID & objType() const
static const CLID & classID()
virtual StatusCode i_createObj(IOpaqueAddress *address, DataObject *&refpObject)