BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
RootEsTimeCalibDataCnv.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
5
6#include "TFile.h"
7#include "TTree.h"
8#include "TDirectory.h"
9#include "TObject.h"
10
11#include "GaudiKernel/CnvFactory.h"
12#include "GaudiKernel/IOpaqueAddress.h"
13#include "GaudiKernel/DataObject.h"
14#include "GaudiKernel/IAddressCreator.h"
15#include "GaudiKernel/IDataProviderSvc.h"
16#include "GaudiKernel/IConversionSvc.h"
17#include "GaudiKernel/GenericAddress.h"
18
19#include "CalibDataSvc/ICalibRootSvc.h" //maybe
21
22// Temporary. Hope to find a better way to do this
24using namespace CalibData;
25//static CnvFactory<RootEsTimeCalibDataCnv> EsTimeCal_factory;
26//const ICnvFactory& RootEsTimeCalibDataCnvFactory = EsTimeCal_factory;
27
28
29
32
33}
34
35
38}
39
42}
43
44StatusCode RootEsTimeCalibDataCnv::i_createObj(const std::string& fname,
45 DataObject*& refpObject) {
46
47 MsgStream log(msgSvc(), "RootEsTimeCalibDataCnv");
48 log<<MSG::DEBUG<<"SetProperty"<<endreq;
49
50 StatusCode sc = openRead(fname);
51 if(!sc)
52 { log<<MSG::ERROR<<"unable to open files"<<endreq;
53 }
54
56 // Read in our object
57 int i;
58 int nentries;
59
60 // read TestCalibConst ------------------------------------------------------------
61
62 int no;
63 double EsTimeCalibConst;
64 vector<double> TestCalibConst;
65 if( m_inFile->Read("h2") ) {
66 TTree *Testtree = (TTree*)m_inFile -> Get("h2");
67 Testtree -> SetBranchAddress("meant0", &EsTimeCalibConst);
68
69 no= Testtree -> GetEntries();
70 for(i=0; i<no; i++){
71 Testtree->GetEntry(i);
72 TestCalibConst.push_back(EsTimeCalibConst);
73 }
74 }
75
76 double t0offsete,t0offsetb;
77 int bunchtime, runFrom, runTo, eventFrom, eventTo;
78 TTree *tree2 = (TTree*)m_inFile -> Get("calibconst");
79 tree2->SetBranchAddress("t0offsete", &t0offsete);
80 tree2->SetBranchAddress("t0offsetb", &t0offsetb);
81 tree2->SetBranchAddress("bunchtime", &bunchtime);
82 if( tree2->GetBranchStatus( "runFrom" ) ) {
83 tree2->SetBranchAddress("runFrom", &runFrom );
84 tree2->SetBranchAddress("runTo", &runTo );
85 tree2->SetBranchAddress("eventFrom", &eventFrom );
86 tree2->SetBranchAddress("eventTo", &eventTo );
87 }
88 else {
89 runFrom = -1;
90 runTo = -1;
91 eventFrom = -1;
92 eventTo = -1;
93 }
94
95 no = tree2->GetEntries();
96 for(i=0; i<no; i++){
97 tree2->GetEntry(i);
98 tmpObject ->setToffsetb(t0offsetb);
99 tmpObject ->setToffsete(t0offsete);
100 tmpObject ->setBunchTime(bunchtime);
101 tmpObject ->setRunFrom(runFrom);
102 tmpObject ->setRunTo(runTo);
103 tmpObject ->setEventFrom(eventFrom);
104 tmpObject ->setEventTo(eventTo);
105 }
106
107 tmpObject -> setTestCalibConst(&TestCalibConst);
108 refpObject=tmpObject;
109
110 return StatusCode::SUCCESS;
111}
112
113StatusCode RootEsTimeCalibDataCnv::createRoot(const std::string& fname,
114 CalibData::CalibBase1* pTDSObj) {
115
116 MsgStream log(msgSvc(), "RootEsTimeCalibDataCnv");
117
118 // Open the file, create the branch
119 StatusCode sc = openWrite(fname);
120 if(!sc)
121 { log<<MSG::ERROR<<"unable to open files"<<endreq;
122 }
123 // write the Data in the TCDS to RootFile
124 /* CalibData::EsTimeCalibData* tmpObject = dynamic_cast<CalibData::EsTimeCalibData*>(pTDSObj);
125 int tmpNo;
126 double EsTimeCalibConst;
127 int i;
128
129 //TestCalibConst------------------------------------------------------------------
130 TTree *Testtree = new TTree("TestCalibConst", "TestCalibConst");
131 Testtree -> Branch("TestCalibConst", &EsTimeCalibConst, "EsTimeCalibConst/D");
132 tmpNo = tmpObject -> getTestCalibConstNo();
133 for(i=0; i<tmpNo; i++){
134 EsTimeCalibConst = tmpObject -> getTestCalibConst(i);
135 Testtree -> Fill();
136 }
137
138
139 Testtree -> Write();
140
141
142 delete Testtree;
143
144 closeWrite();*/
145 log<<MSG::INFO<<"successfully create RootFile"<<endreq;
146 return sc;
147
148}
const CLID CLID_Calib_EsTimeCal
Definition: CalibModel.h:51
const int no
data SetBranchAddress("time",&time)
Int_t nentries
IMessageSvc * msgSvc()
void setRunFrom(const int runFrom)
void setEventTo(const int eventTo)
void setToffsetb(const double toffsetb)
void setEventFrom(const int eventFrom)
void setBunchTime(const int bunchtime)
void setRunTo(const int runTo)
void setToffsete(const double toffsete)
StatusCode openRead(const std::string &fname)
virtual StatusCode openWrite(const std::string &fname)
const CLID & objType() const
RootEsTimeCalibDataCnv(ISvcLocator *svc)
virtual StatusCode i_createObj(const std::string &fname, DataObject *&refpObject)
virtual StatusCode createRoot(const std::string &fname, CalibData::CalibBase1 *pTDSObj)
static const CLID & classID()