11#include "GaudiKernel/DataObject.h"
12#include "GaudiKernel/IAddressCreator.h"
13#include "GaudiKernel/IConversionSvc.h"
14#include "GaudiKernel/IDataProviderSvc.h"
15#include "GaudiKernel/IOpaqueAddress.h"
16#include "GaudiKernel/MsgStream.h"
18#include "CalibData/CalibBase.h"
19#include "CalibData/CalibBase1.h"
20#include "CalibDataSvc/ICalibMetaCnvSvc.h"
21#include "CalibDataSvc/ICalibRootSvc.h"
22#include "CalibDataSvc/IInstrumentName.h"
23#include "facilities/Util.h"
52 StatusCode status = Converter::initialize();
61 serviceLocator()->getService(
"CalibDataSvc", IDataProviderSvc::interfaceID(),
63 setDataProvider( dp );
65 serviceLocator()->getService(
"CalibRootCnvSvc", ICalibRootSvc::interfaceID(),
73 serviceLocator()->getService(
"CalibMySQLCnvSvc", ICalibMetaCnvSvc::interfaceID(),
87 MsgStream log(
msgSvc(),
"RootCalBaseCnv" );
88 log << MSG::ERROR <<
"createRoot method not implemented for this calibration type" << endmsg;
89 return StatusCode::FAILURE;
94 MsgStream log(
msgSvc(),
"RootCalBaseCnv" );
97 if ( fname == std::string(
"" ) )
return StatusCode::FAILURE;
99 if ( doClean() ) { log << MSG::WARNING <<
"Previous operation didn't clean up! " << endmsg; }
102 std::string ourName( fname );
105 m_inFile =
new TFile( ourName.c_str() );
109 log << MSG::ERROR <<
"ROOT file " << ourName <<
"could not be opened for reading "
113 return StatusCode::FAILURE;
117 log << MSG::INFO <<
"Successfully opened ROOT file " << fname <<
" aka " << ourName
118 <<
" for reading " << endmsg;
123 return StatusCode::SUCCESS;
137 return StatusCode::SUCCESS;
142 MsgStream log(
msgSvc(),
"RootCalBaseCnv" );
145 if ( fname == std::string(
"" ) )
return StatusCode::FAILURE;
147 std::string ourName( fname );
150 if ( doClean() ) { log << MSG::WARNING <<
"Previous operation didn't clean up! " << endmsg; }
154 m_outFile =
new TFile( ourName.c_str(),
"RECREATE" );
157 log << MSG::ERROR <<
"ROOT file " << fname <<
" aka " << ourName
158 <<
" could not be opened for writing" << endmsg;
161 return StatusCode::FAILURE;
165 log << MSG::INFO <<
"Successfully opened ROOT file " << fname <<
" aka " << ourName
166 <<
" for writing " << endmsg;
169 return StatusCode::SUCCESS;
174 MsgStream log(
msgSvc(),
"RootCalBaseCnv" );
176 StatusCode ret = StatusCode::SUCCESS;
188 TObject*& pObj,
unsigned ix ) {
189 TTree* pTree = (TTree*)
m_inFile->Get( treename.c_str() );
195 TObject*& pObj,
unsigned ix ) {
196 TBranch* pBranch = pTree->GetBranch( branch.c_str() );
197 pBranch->SetAddress( &pObj );
198 int nBytes = pBranch->GetEntry(
ix );
199 return ( nBytes > 0 ) ? StatusCode::SUCCESS : StatusCode::FAILURE;
202bool RootCalBaseCnv::doClean() {
237 return StatusCode::SUCCESS;
246 MsgStream log(
msgSvc(),
"RootCalBaseCnv" );
247 log << MSG::DEBUG <<
"RootCalBaseCnv::createObj( starting ...." << endmsg;
248 const std::string* par = addr->par();
250 std::string par0 = par[0];
256 DataObject*& refpObject,
258 MsgStream log(
msgSvc(),
"RootCalBaseCnv" );
259 log << MSG::DEBUG <<
"RootCalBaseCnv::internalCreateObj( starting ..... " << endmsg;
261 CLID classId =
address->clID();
263 IConverter* conv = this->conversionSvc()->converter( classId );
266 log << MSG::WARNING <<
"No proper converter found for classID " << classId
267 <<
", the default converter"
268 <<
" will be used. " << endmsg;
273 if ( 0 == converter )
275 log << MSG::ERROR <<
"The converter found for classID " << classId
276 <<
" was not a descendent of RootCalBaseCnv as it should be "
277 <<
"( was of type " <<
typeid( *converter ).name() <<
"). "
278 <<
"The default converter will be used" << endmsg;
286 StatusCode sc = converter->
i_createObj( fname, refpObject );
287 if ( sc.isFailure() ) {
return sc; }
292 if ( sc.isSuccess() )
293 { log << MSG::DEBUG <<
"Successfully created calib. object " << endmsg; }
304 return StatusCode::FAILURE;
310 return StatusCode::SUCCESS;
315 MsgStream log(
msgSvc(),
"RootCalBaseCnv" );
316 log << MSG::DEBUG <<
"set the runfrm and runto Numbers in the converter" << endmsg;
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(")"))