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"
43 m_rootSvc (0), m_metaSvc(0), m_instrSvc(0), m_vstart(0), m_vend(0),
44 m_outFile(0), m_ttree(0), m_inFile(0), m_saveDir(0) {}
47 StatusCode status = Converter::initialize();
56 serviceLocator()->getService (
"CalibDataSvc",
57 IDataProviderSvc::interfaceID(),
61 serviceLocator()->getService (
"CalibRootCnvSvc",
62 ICalibRootSvc::interfaceID(),
70 serviceLocator()->getService(
"CalibMySQLCnvSvc",
71 ICalibMetaCnvSvc::interfaceID(),
73 serviceLocator()->getService (
"CalibDataSvc",
81 return Converter::finalize();
89 MsgStream log(
msgSvc(),
"RootCalBaseCnv");
91 <<
"createRoot method not implemented for this calibration type"
93 return StatusCode::FAILURE;
98 MsgStream log(
msgSvc(),
"RootCalBaseCnv");
101 if (fname == std::string(
""))
return StatusCode::FAILURE;
104 log << MSG::WARNING <<
"Previous operation didn't clean up! " << endreq;
108 std::string ourName(fname);
111 m_inFile =
new TFile(ourName.c_str());
114 log << MSG::ERROR <<
"ROOT file " << ourName
115 <<
"could not be opened for reading " << endreq;
118 return StatusCode::FAILURE;
122 <<
"Successfully opened ROOT file " << fname <<
" aka " << ourName
123 <<
" for reading " << endreq;
130 return StatusCode::SUCCESS;
143 return StatusCode::SUCCESS;
148 MsgStream log(
msgSvc(),
"RootCalBaseCnv");
151 if (fname == std::string(
""))
return StatusCode::FAILURE;
153 std::string ourName(fname);
157 log << MSG::WARNING <<
"Previous operation didn't clean up! " << endreq;
163 m_outFile =
new TFile(ourName.c_str(),
"RECREATE");
165 log << MSG::ERROR <<
"ROOT file " << fname <<
" aka " << ourName
166 <<
" could not be opened for writing" << endreq;
169 return StatusCode::FAILURE;
173 <<
"Successfully opened ROOT file " << fname <<
" aka " << ourName
174 <<
" for writing " << endreq;
177 return StatusCode::SUCCESS;
182 MsgStream log(
msgSvc(),
"RootCalBaseCnv");
184 StatusCode ret = StatusCode::SUCCESS;
197 const std::string& branch,
198 TObject*& pObj,
unsigned ix){
199 TTree* pTree = (TTree*)
m_inFile->Get(treename.c_str());
205 const std::string& branch,
206 TObject*& pObj,
unsigned ix){
207 TBranch* pBranch=pTree->GetBranch(branch.c_str());
208 pBranch->SetAddress(&pObj);
209 int nBytes = pBranch->GetEntry(
ix);
210 return (nBytes > 0) ? StatusCode::SUCCESS : StatusCode::FAILURE;
213bool RootCalBaseCnv::doClean() {
246 return StatusCode::SUCCESS;
251 DataObject*& refpObject) {
256 MsgStream log(
msgSvc(),
"RootCalBaseCnv");
257 log << MSG::DEBUG<<
"RootCalBaseCnv::createObj( starting ...."<<endreq;
258 const std::string* par = addr->par();
260 std::string par0 = par[0];
267 DataObject*& refpObject,
269 MsgStream log(
msgSvc(),
"RootCalBaseCnv");
270 log << MSG::DEBUG<<
"RootCalBaseCnv::internalCreateObj( starting ..... "<<endreq;
272 CLID classId =
address->clID();
274 IConverter* conv = this->conversionSvc()->converter(classId);
277 <<
"No proper converter found for classID " << classId
278 <<
", the default converter"
279 <<
" will be used. " << endreq;
282 if (0 == converter) {
284 <<
"The converter found for classID " << classId
285 <<
" was not a descendent of RootCalBaseCnv as it should be "
286 <<
"( was of type " <<
typeid (*converter).name() <<
"). "
287 <<
"The default converter will be used" << endreq;
295 StatusCode sc = converter->
i_createObj(fname, refpObject);
296 if (sc.isFailure()) {
303 if (sc.isSuccess()) {
304 log << MSG::DEBUG <<
"Successfully created calib. object " << endreq;
316 return StatusCode::FAILURE;
322 return StatusCode::SUCCESS;
327 MsgStream log(
msgSvc(),
"RootCalBaseCnv");
328 log << MSG::DEBUG<<
"set the runfrm and runto Numbers in the converter"<<endreq;
unsigned const char CALIBROOT_StorageType
void setrunfrm(int runfrm)
static const InterfaceID & interfaceID()
virtual StatusCode i_createObj(const std::string &fname, DataObject *&refpObject)
virtual StatusCode createRoot(const std::string &fname, CalibData::CalibBase1 *pTDSObj)
StatusCode openRead(const std::string &fname)
IInstrumentName * m_instrSvc
virtual StatusCode i_processObj(DataObject *pObject, IOpaqueAddress *address)
In case there is additional work to do on the created object.
virtual StatusCode finalize()
virtual StatusCode createObj(IOpaqueAddress *addr, DataObject *&refpObject)
virtual StatusCode readRootObj(const std::string &treename, const std::string &branch, TObject *&pCalib, unsigned index=0)
virtual StatusCode internalCreateObj(const std::string &fname, DataObject *&refpObject, IOpaqueAddress *address)
ICalibMetaCnvSvc * m_metaSvc
RootCalBaseCnv(ISvcLocator *svc, const CLID &clid)
virtual StatusCode initialize()
virtual StatusCode fillRoot(CalibData::CalibBase *pTDSObj, TObject *pRootObj)
virtual ~RootCalBaseCnv()
ICalibRootSvc * m_rootSvc
virtual StatusCode openWrite(const std::string &fname)
void setBaseInfo(CalibData::CalibBase1 *pObj)
Another utility for derived classes to use.
static int expandEnvVar(std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")"))