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"
18#include "facilities/Util.h"
19#include "CalibDataSvc/ICalibRootSvc.h"
20#include "CalibDataSvc/ICalibMetaCnvSvc.h"
21#include "CalibDataSvc/IInstrumentName.h"
22#include "CalibData/CalibBase.h"
23#include "CalibData/CalibBase1.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(),
62 serviceLocator()->getService (
"CalibRootCnvSvc",
71 serviceLocator()->getService(
"CalibMySQLCnvSvc",
75 serviceLocator()->getService (
"CalibDataSvc",
83 return Converter::finalize();
91 MsgStream log(
msgSvc(),
"RootCalBaseCnv");
93 <<
"createRoot method not implemented for this calibration type"
95 return StatusCode::FAILURE;
100 MsgStream log(
msgSvc(),
"RootCalBaseCnv");
103 if (fname == std::string(
""))
return StatusCode::FAILURE;
106 log << MSG::WARNING <<
"Previous operation didn't clean up! " << endreq;
110 std::string ourName(fname);
113 m_inFile =
new TFile(ourName.c_str());
116 log << MSG::ERROR <<
"ROOT file " << ourName
117 <<
"could not be opened for reading " << endreq;
120 return StatusCode::FAILURE;
124 <<
"Successfully opened ROOT file " << fname <<
" aka " << ourName
125 <<
" for reading " << endreq;
132 return StatusCode::SUCCESS;
145 return StatusCode::SUCCESS;
150 MsgStream log(
msgSvc(),
"RootCalBaseCnv");
153 if (fname == std::string(
""))
return StatusCode::FAILURE;
155 std::string ourName(fname);
159 log << MSG::WARNING <<
"Previous operation didn't clean up! " << endreq;
165 m_outFile =
new TFile(ourName.c_str(),
"RECREATE");
167 log << MSG::ERROR <<
"ROOT file " << fname <<
" aka " << ourName
168 <<
" could not be opened for writing" << endreq;
171 return StatusCode::FAILURE;
175 <<
"Successfully opened ROOT file " << fname <<
" aka " << ourName
176 <<
" for writing " << endreq;
179 return StatusCode::SUCCESS;
184 MsgStream log(
msgSvc(),
"RootCalBaseCnv");
186 StatusCode ret = StatusCode::SUCCESS;
199 const std::string& branch,
200 TObject*& pObj,
unsigned ix){
201 TTree* pTree = (TTree*)
m_inFile->Get(treename.c_str());
207 const std::string& branch,
208 TObject*& pObj,
unsigned ix){
209 TBranch* pBranch=pTree->GetBranch(branch.c_str());
210 pBranch->SetAddress(&pObj);
211 int nBytes = pBranch->GetEntry(ix);
212 return (nBytes > 0) ? StatusCode::SUCCESS : StatusCode::FAILURE;
215bool RootCalBaseCnv::doClean() {
248 return StatusCode::SUCCESS;
253 DataObject*& refpObject) {
258 MsgStream log(
msgSvc(),
"RootCalBaseCnv");
259 log << MSG::DEBUG<<
"RootCalBaseCnv::createObj( starting ...."<<endreq;
260 const std::string* par = addr->par();
262 std::string par0 = par[0];
269 DataObject*& refpObject,
270 IOpaqueAddress* address) {
271 MsgStream log(
msgSvc(),
"RootCalBaseCnv");
272 log << MSG::DEBUG<<
"RootCalBaseCnv::internalCreateObj( starting ..... "<<endreq;
274 CLID classId = address->clID();
276 IConverter* conv = this->conversionSvc()->converter(classId);
279 <<
"No proper converter found for classID " << classId
280 <<
", the default converter"
281 <<
" will be used. " << endreq;
284 if (0 == converter) {
286 <<
"The converter found for classID " << classId
287 <<
" was not a descendent of RootCalBaseCnv as it should be "
288 <<
"( was of type " <<
typeid (*converter).name() <<
"). "
289 <<
"The default converter will be used" << endreq;
295 m_runto =*( address->ipar()+1);
297 StatusCode sc = converter->
i_createObj(fname, refpObject);
298 if (sc.isFailure()) {
305 if (sc.isSuccess()) {
306 log << MSG::DEBUG <<
"Successfully created calib. object " << endreq;
318 return StatusCode::FAILURE;
324 return StatusCode::SUCCESS;
329 MsgStream log(
msgSvc(),
"RootCalBaseCnv");
330 log << MSG::DEBUG<<
"set the runfrm and runto Numbers in the converter"<<endreq;
unsigned const char CALIBROOT_StorageType
void setrunfrm(int runfrm)
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(")"))