BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
TreeCalBaseCnv.cxx
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/CalibSvc/CalibTreeCnv/src/cnv/TreeCalBaseCnv.cxx,v 1.4 2012/01/05 03:53:29 zhangy Exp $
2/**
3 @file TreeCalBaseCnv.cxx
4
5 Implementation file for Root calibration converter base class
6*/
7
8#include "TreeCalBaseCnv.h"
9
10#include "GaudiKernel/CnvFactory.h"
11#include "GaudiKernel/IOpaqueAddress.h"
12#include "GaudiKernel/DataObject.h"
13#include "GaudiKernel/IAddressCreator.h"
14#include "GaudiKernel/IDataProviderSvc.h"
15#include "GaudiKernel/IConversionSvc.h"
16#include "GaudiKernel/MsgStream.h"
17
18#include "facilities/Util.h" // for translating env variables
22#include "CalibData/CalibBase.h"
24// Guessing at needed Root includes
25#include "TROOT.h" // need this for cd??
26#include "TFile.h"
27#include "TTree.h"
28#include "TObject.h"
31
33 // release TFile, TTree if they need releasing. With normal
34 // termination they should already have been released.
35
36 // doClean();
37
38}
39
40// static CnvFactory<TreeCalBaseCnv> s_factory;
41// const ICnvFactory& TreeCalBaseCnvFactory = s_factory;
42TreeCalBaseCnv::TreeCalBaseCnv( ISvcLocator* svc, const CLID& clid) :
44 m_treeSvc (0), m_metaSvc(0), m_instrSvc(0),m_outFile(0), m_ttree(0), m_inFile(0), m_saveDir(0) {}
45
47 StatusCode status = Converter::initialize();
48
49 IDataProviderSvc* dp;
50
51 // I guess the service names are assigned in jobOptions?
52
53/* serviceLocator()->getService ("CalibDataSvc",
54 IID_IDataProviderSvc,
55 (IInterface*&)dp);*/
56 serviceLocator()->getService ("CalibDataSvc",
57 IDataProviderSvc::interfaceID(),
58 (IInterface*&)dp);
59 setDataProvider(dp);
60
61 // Locate the Root Conversion Service
62 serviceLocator()->getService ("CalibTreeCnvSvc",
63 IID_ICalibTreeSvc,
64 (IInterface*&) m_treeSvc);
65
66 // Locate meta conversion service
67 // Will anything need to be changed here to accommodate possibility
68 // of two concrete implementations of ICalibMetaCnvSvc? Would
69 // have different storage types. Could specify type desired
70 // as job option. Ditto for name of class?
71 serviceLocator()->getService("CalibMySQLCnvSvc",
72 IID_ICalibMetaCnvSvc,
73 (IInterface*&)m_metaSvc);
74
75 serviceLocator()->getService ("CalibDataSvc",
76 IID_IInstrumentName,
77 (IInterface*&)m_instrSvc);
78
79 return status;
80}
81
83 return Converter::finalize();
84}
85
86
87 /****** ROOT services *****/
88
89StatusCode TreeCalBaseCnv::createRoot(const std::string& /* fname */,
90 CalibData::CalibBase1* /* pTDSObj */) {
91 MsgStream log(msgSvc(), "TreeCalBaseCnv");
92 log << MSG::ERROR
93 << "createRoot method not implemented for this calibration type"
94 << endreq;
95 return StatusCode::FAILURE;
96}
97
98
99// Do our part to write out object -- which is nothing
101 TObject* /* pRootObj */) {
102
103 // Get instrument name from InstrumentName service Now handled by
104 // TreeCalBaseCnv
105 // TString instr = TString((m_instrSvc->getInstrumentName()).c_str());
106 // pRootObj->setInstrument(instr);
107 return StatusCode::SUCCESS;
108}
109
110// (To TDS) Conversion stuff
111StatusCode TreeCalBaseCnv::createObj(IOpaqueAddress* addr,
112 DataObject*& refpObject) {
113 // StatusCode ret;
114
115 // first do the things we always need:
116 // First string parameter of opaque address is file ident
117 MsgStream log(msgSvc(), "TreeCalBaseCnv");
118 log << MSG::DEBUG<<"TreeCalBaseCnv::createObj( starting ...."<<endreq;
119 // const std::string* par = addr->par();
120
121 // std::string par0 = par[0];
122
123// return internalCreateObj(par0, refpObject, addr);
124 return internalCreateObj(refpObject, addr);
125
126}
127
128//StatusCode TreeCalBaseCnv::internalCreateObj(const std::string& fname,
129// DataObject*& refpObject,
130// IOpaqueAddress* address) {
131 StatusCode TreeCalBaseCnv::internalCreateObj(DataObject*& refpObject,
132 IOpaqueAddress* address) {
133
134 MsgStream log(msgSvc(), "TreeCalBaseCnv");
135 log << MSG::DEBUG<<"TreeCalBaseCnv::internalCreateObj( starting ..... "<<endreq;
136 TreeCalBaseCnv* converter = this;
137 CLID classId = address->clID();
138
139 IConverter* conv = this->conversionSvc()->converter(classId);
140 if (0 == conv) {
141 log << MSG::WARNING
142 << "No proper converter found for classID " << classId
143 << ", the default converter"
144 << " will be used. " << endreq;
145 } else {
146 converter = dynamic_cast <TreeCalBaseCnv*> (conv);
147 if (0 == converter) {
148 log << MSG::ERROR
149 << "The converter found for classID " << classId
150 << " was not a descendent of TreeCalBaseCnv as it should be "
151 << "( was of type " << typeid (*converter).name() << "). "
152 << "The default converter will be used" << endreq;
153 converter = this;
154 }
155 }
156
157 TreeAddress* treeAddress = dynamic_cast <TreeAddress*> (address);
158 m_runfrm = treeAddress->getRunFrom();
159 m_runto = treeAddress->getRunTo();
160 //m_runfrm =*( address->ipar());
161 //m_runto =*( address->ipar()+1);
162 // m_runfrm = 100;
163 // m_runto =1000;
164 // creates an object for the node found
165 StatusCode sc = converter->i_createObj(address, refpObject);
166 if (sc.isFailure()) {
167 return sc;
168 }
169 CalibData::CalibBase1* tmpObject = dynamic_cast <CalibData::CalibBase1*> (refpObject);
170 setBaseInfo(tmpObject);
171 // ends up the object construction
172 sc = converter->i_processObj(refpObject, address);
173 if (sc.isSuccess()) {
174 log << MSG::DEBUG << "Successfully created calib. object " << endreq;
175 }
176 // closeRead();
177 return sc;
178}
179
180/*
181 Base class version of this routine shouldn't really be called
182 since it doesn't correspond to a TDS object.
183*/
184StatusCode TreeCalBaseCnv::i_createObj (IOpaqueAddress* address,
185 DataObject*& /* refpObject */) {
186 return StatusCode::FAILURE; // shouldn't ever get here
187}
188
189// Default is to do nothing. Derived classes may override.
190StatusCode TreeCalBaseCnv::i_processObj(DataObject*, // pObject,
191 IOpaqueAddress* ) /* address */ {
192 return StatusCode::SUCCESS;
193}
194
195/// Another utility for derived classes to use
197 MsgStream log(msgSvc(), "TreeCalBaseCnv");
198 log << MSG::DEBUG<<"set the runfrm and runto Numbers in the converter"<<endreq;
199 pObj->setrunfrm(m_runfrm);
200 pObj->setrunto(m_runto);
201}
unsigned const char CALIBTREE_StorageType
Definition: ICalibTreeSvc.h:20
IMessageSvc * msgSvc()
void setrunto(int runto)
Definition: CalibBase1.h:56
void setrunfrm(int runfrm)
Definition: CalibBase1.h:55
int getRunFrom()
get run from
Definition: TreeAddress.h:148
int getRunTo()
get run to
Definition: TreeAddress.h:152
virtual StatusCode initialize()
virtual ~TreeCalBaseCnv()
virtual StatusCode fillRoot(CalibData::CalibBase *pTDSObj, TObject *pRootObj)
virtual StatusCode i_processObj(DataObject *pObject, IOpaqueAddress *address)
In case there is additional work to do on the created object.
virtual StatusCode finalize()
TreeCalBaseCnv(ISvcLocator *svc, const CLID &clid)
ICalibMetaCnvSvc * m_metaSvc
virtual StatusCode i_createObj(IOpaqueAddress *address, DataObject *&refpObject)
virtual StatusCode createObj(IOpaqueAddress *addr, DataObject *&refpObject)
IInstrumentName * m_instrSvc
ICalibTreeSvc * m_treeSvc
virtual StatusCode internalCreateObj(DataObject *&refpObject, IOpaqueAddress *address)
virtual StatusCode createRoot(const std::string &fname, CalibData::CalibBase1 *pTDSObj)
void setBaseInfo(CalibData::CalibBase1 *pObj)
Another utility for derived classes to use.