BOSS 7.1.2
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.8 2022/02/21 06:45:17 maqm 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 IInterface* m_treeSvc = serviceLocator()->service("CalibTreeCnvSvc");
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 IInterface* m_metaSvc = serviceLocator()->service("CalibMySQLCnvSvc");
76 /*serviceLocator()->getService ("CalibDataSvc",
77 IID_IInstrumentName,
78 (IInterface*&)m_instrSvc);*/
79 IInterface* m_instrSvc = serviceLocator()->service("CalibDataSvc");
80
81 return status;
82}
83
85 return Converter::finalize();
86}
87
88
89 /****** ROOT services *****/
90
91StatusCode TreeCalBaseCnv::createRoot(const std::string& /* fname */,
92 CalibData::CalibBase1* /* pTDSObj */) {
93 MsgStream log(msgSvc(), "TreeCalBaseCnv");
94 log << MSG::ERROR
95 << "createRoot method not implemented for this calibration type"
96 << endreq;
97 return StatusCode::FAILURE;
98}
99
100
101// Do our part to write out object -- which is nothing
103 TObject* /* pRootObj */) {
104
105 // Get instrument name from InstrumentName service Now handled by
106 // TreeCalBaseCnv
107 // TString instr = TString((m_instrSvc->getInstrumentName()).c_str());
108 // pRootObj->setInstrument(instr);
109 return StatusCode::SUCCESS;
110}
111
112// (To TDS) Conversion stuff
113StatusCode TreeCalBaseCnv::createObj(IOpaqueAddress* addr,
114 DataObject*& refpObject) {
115 // StatusCode ret;
116
117 // first do the things we always need:
118 // First string parameter of opaque address is file ident
119 MsgStream log(msgSvc(), "TreeCalBaseCnv");
120 log << MSG::DEBUG<<"TreeCalBaseCnv::createObj( starting ...."<<endreq;
121 // const std::string* par = addr->par();
122
123 // std::string par0 = par[0];
124
125// return internalCreateObj(par0, refpObject, addr);
126 return internalCreateObj(refpObject, addr);
127
128}
129
130//StatusCode TreeCalBaseCnv::internalCreateObj(const std::string& fname,
131// DataObject*& refpObject,
132// IOpaqueAddress* address) {
133 StatusCode TreeCalBaseCnv::internalCreateObj(DataObject*& refpObject,
134 IOpaqueAddress* address) {
135
136 MsgStream log(msgSvc(), "TreeCalBaseCnv");
137 log << MSG::DEBUG<<"TreeCalBaseCnv::internalCreateObj( starting ..... "<<endreq;
138 TreeCalBaseCnv* converter = this;
139 CLID classId = address->clID();
140
141 IConverter* conv = this->conversionSvc()->converter(classId);
142 if (0 == conv) {
143 log << MSG::WARNING
144 << "No proper converter found for classID " << classId
145 << ", the default converter"
146 << " will be used. " << endreq;
147 } else {
148 converter = dynamic_cast <TreeCalBaseCnv*> (conv);
149 if (0 == converter) {
150 log << MSG::ERROR
151 << "The converter found for classID " << classId
152 << " was not a descendent of TreeCalBaseCnv as it should be "
153 << "( was of type " << typeid (*converter).name() << "). "
154 << "The default converter will be used" << endreq;
155 converter = this;
156 }
157 }
158
159 TreeAddress* treeAddress = dynamic_cast <TreeAddress*> (address);
160 m_runfrm = treeAddress->getRunFrom();
161 m_runto = treeAddress->getRunTo();
162 //m_runfrm =*( address->ipar());
163 //m_runto =*( address->ipar()+1);
164 // m_runfrm = 100;
165 // m_runto =1000;
166 // creates an object for the node found
167 StatusCode sc = converter->i_createObj(address, refpObject);
168 if (sc.isFailure()) {
169 return sc;
170 }
171 CalibData::CalibBase1* tmpObject = dynamic_cast <CalibData::CalibBase1*> (refpObject);
172 setBaseInfo(tmpObject);
173 // ends up the object construction
174 sc = converter->i_processObj(refpObject, address);
175 if (sc.isSuccess()) {
176 log << MSG::DEBUG << "Successfully created calib. object " << endreq;
177 }
178 // closeRead();
179 return sc;
180}
181
182/*
183 Base class version of this routine shouldn't really be called
184 since it doesn't correspond to a TDS object.
185*/
186StatusCode TreeCalBaseCnv::i_createObj (IOpaqueAddress* address,
187 DataObject*& /* refpObject */) {
188 return StatusCode::FAILURE; // shouldn't ever get here
189}
190
191// Default is to do nothing. Derived classes may override.
192StatusCode TreeCalBaseCnv::i_processObj(DataObject*, // pObject,
193 IOpaqueAddress* ) /* address */ {
194 return StatusCode::SUCCESS;
195}
196
197/// Another utility for derived classes to use
199 MsgStream log(msgSvc(), "TreeCalBaseCnv");
200 log << MSG::DEBUG<<"set the runfrm and runto Numbers in the converter"<<endreq;
201 pObj->setrunfrm(m_runfrm);
202 pObj->setrunto(m_runto);
203}
unsigned const char CALIBTREE_StorageType
IMessageSvc * msgSvc()
void setrunto(int runto)
Definition CalibBase1.h:56
void setrunfrm(int runfrm)
Definition CalibBase1.h:55
int getRunFrom()
get run from
int getRunTo()
get run to
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.