BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TreeTofSimCnv.cxx
Go to the documentation of this file.
1#include "TreeTofSimCnv.h"
2#include "CalibData/Tof/TofSimData.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<TreeTofSimDataCnv> TofCal_factory;
26// const ICnvFactory& TreeTofSimDataCnvFactory = TofCal_factory;
27
30
31const CLID& TreeTofSimDataCnv::objType() const { return CLID_Calib_TofSim; }
32
34
35StatusCode TreeTofSimDataCnv::i_createObj( IOpaqueAddress* addr, DataObject*& refpObject ) {
36
37 MsgStream log( msgSvc(), "TreeTofSimDataCnv" );
38 log << MSG::DEBUG << "SetProperty" << endmsg;
39
40 TreeAddress* add = dynamic_cast<TreeAddress*>( addr );
41
42 DatabaseRecord* records = add->pp();
43
44 TBufferFile* buf1 = new TBufferFile( TBuffer::kRead );
45 TBufferFile* buf2 = new TBufferFile( TBuffer::kRead );
46 TBufferFile* buf3 = new TBufferFile( TBuffer::kRead );
47
48 buf1->SetBuffer( ( *records )["BTofSim"], 512000, kFALSE );
49 buf2->SetBuffer( ( *records )["ETofSim"], 512000, kFALSE );
50 buf3->SetBuffer( ( *records )["SimConstants"], 512000, kFALSE );
51
52 std::cout << " SftVer is " << ( *records )["SftVer"];
53 std::cout << " CalVerSft is " << ( *records )["TofSimParVer"];
54 std::cout << " File name is " << ( *records )["FileName"] << std::endl;
55
56 TTree* btoftree = new TTree();
57 TTree* etoftree = new TTree();
58 TTree* btofcommontree = new TTree();
59 btoftree->Streamer( *buf1 );
60 etoftree->Streamer( *buf2 );
61 btofcommontree->Streamer( *buf3 );
62
66 std::vector<CalibData::BTofSimBase> tmpbTof; //; = new vector<CalibData::bTofCalibBase>;
67 std::vector<CalibData::ETofSimBase> tmpeTof;
68 std::vector<CalibData::TofSimConstBase> tofbaseCol;
69 // Read in the object
70 int cnt;
71 // read btoftree ------------------------------------------------------------
72 double AttenLength;
73 double Gain;
74 double Ratio;
75 double NoiseSmear;
76 btoftree->SetBranchAddress( "AttenLength", &AttenLength );
77 btoftree->SetBranchAddress( "Gain", &Gain );
78 btoftree->SetBranchAddress( "Ratio", &Ratio );
79 int entries = btoftree->GetEntries();
80 for ( cnt = 0; cnt < entries; cnt++ )
81 {
82 btoftree->GetEntry( cnt );
83 bTof.setGain( Gain );
84 bTof.setRatio( Ratio );
85 bTof.setAttenLength( AttenLength );
86 tmpbTof.push_back( bTof );
87 }
88 // read etoftree
89 etoftree->SetBranchAddress( "Gain", &Gain );
90 etoftree->SetBranchAddress( "AttenLength", &AttenLength );
91 etoftree->SetBranchAddress( "NoiseSmear", &NoiseSmear );
92 entries = etoftree->GetEntries();
93 for ( cnt = 0; cnt < entries; cnt++ )
94 {
95 etoftree->GetEntry( cnt );
96 eTof.setGain( Gain );
97 eTof.setAttenLength( AttenLength );
98 eTof.setNoiseSmear( NoiseSmear );
99 tmpeTof.push_back( eTof );
100 }
101 // read SimConstants
102 double BarConstant, BarPMTGain, BarHighThres, BarLowThres, EndConstant, EndPMTGain,
103 EndHighThres, EndLowThres, EndNoiseSwitch;
104 btofcommontree->SetBranchAddress( "BarConstant", &BarConstant );
105 btofcommontree->SetBranchAddress( "BarPMTGain", &BarPMTGain );
106 btofcommontree->SetBranchAddress( "BarHighThres", &BarHighThres );
107 btofcommontree->SetBranchAddress( "BarLowThres", &BarLowThres );
108 btofcommontree->SetBranchAddress( "EndConstant", &EndConstant );
109 btofcommontree->SetBranchAddress( "EndPMTGain", &EndPMTGain );
110 btofcommontree->SetBranchAddress( "EndHighThres", &EndHighThres );
111 btofcommontree->SetBranchAddress( "EndLowThres", &EndLowThres );
112 btofcommontree->SetBranchAddress( "EndNoiseSwitch", &EndNoiseSwitch );
113 entries = btofcommontree->GetEntries();
114 for ( cnt = 0; cnt < entries; cnt++ )
115 {
116 btofcommontree->GetEntry( cnt );
117 tofbase.setBarLowThres( BarLowThres );
118 tofbase.setBarHighThres( BarHighThres );
119 tofbase.setEndLowThres( EndLowThres );
120 tofbase.setEndHighThres( EndHighThres );
121 tofbase.setBarPMTGain( BarPMTGain );
122 tofbase.setEndPMTGain( EndPMTGain );
123 tofbase.setBarConstant( BarConstant );
124 tofbase.setEndConstant( EndConstant );
125 tofbase.setEndNoiseSwitch( EndNoiseSwitch );
126 tofbaseCol.push_back( tofbase );
127 }
128
129 CalibData::TofSimData* tmpObject =
130 new CalibData::TofSimData( &tofbaseCol, &tmpbTof, &tmpeTof );
131 refpObject = tmpObject;
132 delete btoftree;
133 delete etoftree;
134 delete btofcommontree;
135
136 return StatusCode::SUCCESS;
137}
IMessageSvc * msgSvc()
TreeCalBaseCnv(ISvcLocator *svc, const CLID &clid)
virtual StatusCode i_createObj(IOpaqueAddress *address, DataObject *&refpObject)
const CLID & objType() const
TreeTofSimDataCnv(ISvcLocator *svc)
static const CLID & classID()