BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TreeEstTofCalibDataCnv.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<TreeEstTofCalibDataCnv> TofCal_factory;
26// const ICnvFactory& TreeEstTofCalibDataCnvFactory = TofCal_factory;
27
28const unsigned int nBarPar = 10;
29const unsigned int nBarParOff = 20;
30const unsigned int nEndPar = 8;
31const unsigned int nEtfPar = 20;
32const unsigned int nBarOffset = 2;
33
36
38
40
41StatusCode TreeEstTofCalibDataCnv::i_createObj( IOpaqueAddress* addr,
42 DataObject*& refpObject ) {
43
44 MsgStream log( msgSvc(), "TreeEstTofCalibDataCnv" );
45 log << MSG::DEBUG << "SetProperty" << endmsg;
46
47 TreeAddress* add = dynamic_cast<TreeAddress*>( addr );
48 DatabaseRecord* records = add->pp();
49
50 TBufferFile* buf1 = new TBufferFile( TBuffer::kRead );
51 TBufferFile* buf2 = new TBufferFile( TBuffer::kRead );
52 TBufferFile* buf3 = new TBufferFile( TBuffer::kRead );
53 TBufferFile* buf4 = new TBufferFile( TBuffer::kRead );
54 TBufferFile* buf5 = nullptr;
55
56 buf1->SetBuffer( ( *records )["BarTofPar"], 1024000, kFALSE );
57 buf2->SetBuffer( ( *records )["EndTofPar"], 1024000, kFALSE );
58 buf3->SetBuffer( ( *records )["TofConPar"], 1024000, kFALSE );
59 buf4->SetBuffer( ( *records )["BarTof"], 1024000, kFALSE );
60
61 if ( ( *records )["EtfTofPar"] != 0 )
62 {
63 buf5 = new TBufferFile( TBuffer::kRead );
64 buf5->SetBuffer( ( *records )["EtfTofPar"], 1024000, kFALSE );
65 }
66
67 std::cout << " CalVerSft is " << ( *records )["CalParVer"];
68 std::cout << " File name is " << ( *records )["FileName"] << std::endl;
69
70 TTree* btoftree = new TTree();
71 TTree* etoftree = new TTree();
72 TTree* etftree = new TTree();
73 TTree* btofcommontree = new TTree();
74 TTree* CalibInfo = new TTree();
75
76 btoftree->Streamer( *buf1 );
77 etoftree->Streamer( *buf2 );
78 btofcommontree->Streamer( *buf3 );
79 CalibInfo->Streamer( *buf4 );
80 if ( buf5 ) { etftree->Streamer( *buf5 ); }
81
82 // CalibData::bTofCalibBase bTof;
83 // CalibData::eTofCalibBase eTof;
84 // CalibData::etfCalibBase etf;
85 // CalibData::bTofCommonCalibBase bTofCommon;
86 // CalibData::tofCalibInfoBase tofinfo;
87
88 std::vector<CalibData::bTofCalibBase> tmpbTof;
89 std::vector<CalibData::eTofCalibBase> tmpeTof;
90 std::vector<CalibData::etfCalibBase> tmpetf;
91 std::vector<CalibData::bTofCommonCalibBase> tmpbTofCommon;
92 std::vector<CalibData::tofCalibInfoBase> tofinfoCol;
93
94 // Read in the object
95 int cnt;
96 // read btoftree ------------------------------------------------------------
97 double cnvBarPar1[nBarPar];
98 double cnvBarPar2[nBarPar];
99 double cnvBarParOff1_bunch0[nBarParOff];
100 double cnvBarParOff2_bunch0[nBarParOff];
101 double cnvBarParOff1_bunch1[nBarParOff];
102 double cnvBarParOff2_bunch1[nBarParOff];
103 double cnvBarParOff1_bunch2[nBarParOff];
104 double cnvBarParOff2_bunch2[nBarParOff];
105 double cnvBarParOff1_bunch3[nBarParOff];
106 double cnvBarParOff2_bunch3[nBarParOff];
107
108 char brname[10];
109 for ( unsigned int i = 0; i < nBarPar; i++ )
110 {
111 sprintf( brname, "P%i", i );
112 btoftree->SetBranchAddress( brname, &cnvBarPar1[i] );
113 }
114 for ( unsigned int i = 0; i < nBarPar; i++ )
115 {
116 sprintf( brname, "P%i", i + nBarPar );
117 btoftree->SetBranchAddress( brname, &cnvBarPar2[i] );
118 }
119 for ( unsigned int i = 0; i < nBarParOff; i++ )
120 {
121 sprintf( brname, "Bunch0_Poff%i", i );
122 btoftree->SetBranchAddress( brname, &cnvBarParOff1_bunch0[i] );
123 }
124 for ( unsigned int i = 0; i < nBarParOff; i++ )
125 {
126 sprintf( brname, "Bunch0_Poff%i", i + nBarParOff );
127 btoftree->SetBranchAddress( brname, &cnvBarParOff2_bunch0[i] );
128 }
129 for ( unsigned int i = 0; i < nBarParOff; i++ )
130 {
131 sprintf( brname, "Bunch1_Poff%i", i );
132 btoftree->SetBranchAddress( brname, &cnvBarParOff1_bunch1[i] );
133 }
134 for ( unsigned int i = 0; i < nBarParOff; i++ )
135 {
136 sprintf( brname, "Bunch1_Poff%i", i + nBarParOff );
137 btoftree->SetBranchAddress( brname, &cnvBarParOff2_bunch1[i] );
138 }
139 for ( unsigned int i = 0; i < nBarParOff; i++ )
140 {
141 sprintf( brname, "Bunch2_Poff%i", i );
142 btoftree->SetBranchAddress( brname, &cnvBarParOff1_bunch2[i] );
143 }
144 for ( unsigned int i = 0; i < nBarParOff; i++ )
145 {
146 sprintf( brname, "Bunch2_Poff%i", i + nBarParOff );
147 btoftree->SetBranchAddress( brname, &cnvBarParOff2_bunch2[i] );
148 }
149 for ( unsigned int i = 0; i < nBarParOff; i++ )
150 {
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 {
156 sprintf( brname, "Bunch3_Poff%i", i + nBarParOff );
157 btoftree->SetBranchAddress( brname, &cnvBarParOff2_bunch3[i] );
158 }
159
160 int entries = btoftree->GetEntries();
161 for ( cnt = 0; cnt < entries; cnt++ )
162 {
164 btoftree->GetEntry( cnt );
165 bTof.setP1( cnvBarPar1 );
166 bTof.setP2( cnvBarPar2 );
167 bTof.setPoff1_bunch0( cnvBarParOff1_bunch0 );
168 bTof.setPoff2_bunch0( cnvBarParOff2_bunch0 );
169 bTof.setPoff1_bunch1( cnvBarParOff1_bunch1 );
170 bTof.setPoff2_bunch1( cnvBarParOff2_bunch1 );
171 bTof.setPoff1_bunch2( cnvBarParOff1_bunch2 );
172 bTof.setPoff2_bunch2( cnvBarParOff2_bunch2 );
173 bTof.setPoff1_bunch3( cnvBarParOff1_bunch3 );
174 bTof.setPoff2_bunch3( cnvBarParOff2_bunch3 );
175 tmpbTof.push_back( bTof );
176 }
177
178 // read etoftree
179 double cnvEndPar[nEndPar];
180
181 char ecname[10];
182 for ( unsigned int i = 0; i < nEndPar; i++ )
183 {
184 sprintf( ecname, "P%i", i );
185 etoftree->SetBranchAddress( ecname, &cnvEndPar[i] );
186 }
187
188 entries = etoftree->GetEntries();
189 for ( cnt = 0; cnt < entries; cnt++ )
190 {
192 etoftree->GetEntry( cnt );
193 eTof.setP( cnvEndPar );
194 tmpeTof.push_back( eTof );
195 }
196
197 // read etftree
198 if ( etftree->GetEntries() != 0 )
199 {
200
201 double cnvEtfPar[nEtfPar];
202 double cnvEtfPar1[nEtfPar];
203 double cnvEtfPar2[nEtfPar];
204
205 char etfname[10];
206 for ( unsigned int i = 0; i < nEtfPar; i++ )
207 {
208 sprintf( etfname, "P%i", i );
209 etftree->SetBranchAddress( etfname, &cnvEtfPar[i] );
210 sprintf( etfname, "P%i", nEtfPar + i );
211 etftree->SetBranchAddress( etfname, &cnvEtfPar1[i] );
212 sprintf( etfname, "P%i", 2 * nEtfPar + i );
213 etftree->SetBranchAddress( etfname, &cnvEtfPar2[i] );
214 }
215
216 entries = etftree->GetEntries();
217 for ( cnt = 0; cnt < entries; cnt++ )
218 {
220 etftree->GetEntry( cnt );
221 etf.setP( cnvEtfPar );
222 etf.setP1( cnvEtfPar1 );
223 etf.setP2( cnvEtfPar2 );
224 tmpetf.push_back( etf );
225 }
226 }
227
228 // read bTofCommonCalibBase
229 double cnvBarOffset[nBarOffset];
230 for ( unsigned int i = 0; i < nBarOffset; i++ )
231 {
232 sprintf( brname, "t0offset%i", i );
233 btofcommontree->SetBranchAddress( brname, &cnvBarOffset[i] );
234 }
235
236 entries = btofcommontree->GetEntries();
237 for ( cnt = 0; cnt < entries; cnt++ )
238 {
240 btofcommontree->GetEntry( cnt );
241 bTofCommon.setOffset( cnvBarOffset );
242 tmpbTofCommon.push_back( bTofCommon );
243 }
244
245 int m_runFrom, m_runTo, m_eventFrom, m_eventTo; // Modify for n files, wensp
246 if ( CalibInfo->GetBranchStatus( "runFrom" ) )
247 {
248 CalibInfo->SetBranchAddress( "runFrom", &m_runFrom );
249 CalibInfo->SetBranchAddress( "runTo", &m_runTo );
250 CalibInfo->SetBranchAddress( "eventFrom", &m_eventFrom );
251 CalibInfo->SetBranchAddress( "eventTo", &m_eventTo );
252 }
253 else
254 {
255 m_runFrom = -1;
256 m_runTo = -1;
257 m_eventFrom = -1;
258 m_eventTo = -1;
259 }
260
261 entries = CalibInfo->GetEntries();
262 for ( cnt = 0; cnt < entries; cnt++ )
263 {
265 CalibInfo->GetEntry( cnt );
266 tofinfo.setRunFrom( m_runFrom );
267 tofinfo.setRunTo( m_runTo );
268 tofinfo.setEventFrom( m_eventFrom );
269 tofinfo.setEventTo( m_eventTo );
270 tofinfoCol.push_back( tofinfo );
271 }
272
273 CalibData::TofCalibData* tmpObject =
274 new CalibData::TofCalibData( tmpbTof, tmpbTofCommon, tmpeTof, tmpetf, tofinfoCol );
275
276 refpObject = tmpObject;
277 delete btoftree;
278 delete etoftree;
279 delete etftree;
280 delete btofcommontree;
281 delete CalibInfo;
282
283 return StatusCode::SUCCESS;
284}
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
IMessageSvc * msgSvc()
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)
TreeCalBaseCnv(ISvcLocator *svc, const CLID &clid)
TreeEstTofCalibDataCnv(ISvcLocator *svc)
static const CLID & classID()
virtual StatusCode i_createObj(IOpaqueAddress *address, DataObject *&refpObject)