BOSS 7.0.5
BESIII Offline Software System
Loading...
Searching...
No Matches
RootCalBaseCnv Class Reference

#include <RootCalBaseCnv.h>

+ Inheritance diagram for RootCalBaseCnv:

Public Member Functions

virtual ~RootCalBaseCnv ()
 
virtual StatusCode initialize ()
 
virtual StatusCode finalize ()
 
virtual StatusCode createObj (IOpaqueAddress *addr, DataObject *&refpObject)
 
ICalibRootSvcgetCalibRootSvc ()
 
 RootCalBaseCnv (ISvcLocator *svc, const CLID &clid)
 
virtual StatusCode createRoot (const std::string &fname, CalibData::CalibBase1 *pTDSObj)
 
virtual StatusCode readRootObj (const std::string &treename, const std::string &branch, TObject *&pCalib, unsigned index=0)
 
virtual StatusCode readRootObj (TTree *tree, const std::string &branch, TObject *&pCalib, unsigned index=0)
 
- Public Member Functions inherited from Converter< Ty1, Ty2 >
destinationoperator (const source &) const
 
destinationoperator (const source &) const
 

Static Public Member Functions

static const unsigned char storageType ()
 

Protected Member Functions

virtual StatusCode internalCreateObj (const std::string &fname, DataObject *&refpObject, IOpaqueAddress *address)
 
virtual StatusCode i_createObj (const std::string &fname, DataObject *&refpObject)
 
virtual StatusCode i_processObj (DataObject *pObject, IOpaqueAddress *address)
 In case there is additional work to do on the created object.
 
virtual StatusCode fillRoot (CalibData::CalibBase *pTDSObj, TObject *pRootObj)
 
virtual StatusCode openWrite (const std::string &fname)
 
StatusCode closeWrite ()
 
StatusCode openRead (const std::string &fname)
 
StatusCode closeRead ()
 
void setBaseInfo (CalibData::CalibBase1 *pObj)
 Another utility for derived classes to use.
 
- Protected Member Functions inherited from Converter< Ty1, Ty2 >
virtual destinationconvert (const source &) const =0
 
virtual destinationconvert (const source &) const =0
 

Protected Attributes

ICalibRootSvcm_rootSvc
 
ICalibMetaCnvSvcm_metaSvc
 
IInstrumentNamem_instrSvc
 
int m_serNo
 
ITime * m_vstart
 
ITime * m_vend
 
int m_runfrm
 
int m_runto
 
TFile * m_outFile
 
TTree * m_ttree
 
TFile * m_inFile
 
TDirectory * m_saveDir
 

Additional Inherited Members

- Public Types inherited from Converter< Ty1, Ty2 >
typedef Ty1 source
 
typedef Ty2 destination
 
typedef Ty1 source
 
typedef Ty2 destination
 

Detailed Description

Base class for calibration converters from XML files to TCDS. All such converters need to do certain things, which are handled here.

Author
J. Bogart

Definition at line 39 of file RootCalBaseCnv.h.

Constructor & Destructor Documentation

◆ ~RootCalBaseCnv()

RootCalBaseCnv::~RootCalBaseCnv ( )
virtual
     @file  RootCalBaseCnv.cxx

Implementation file for Root calibration converter base class

Definition at line 31 of file RootCalBaseCnv.cxx.

31 {
32 // release TFile, TTree if they need releasing. With normal
33 // termination they should already have been released.
34
35 // doClean();
36
37}

◆ RootCalBaseCnv()

RootCalBaseCnv::RootCalBaseCnv ( ISvcLocator *  svc,
const CLID &  clid 
)

Constructor for this converter

Parameters
svca ISvcLocator interface to find services
clidthe type of object the converter is able to convert

Definition at line 41 of file RootCalBaseCnv.cxx.

Member Function Documentation

◆ closeRead()

StatusCode RootCalBaseCnv::closeRead ( )
protected

Clean up when we've finished reading in

Definition at line 135 of file RootCalBaseCnv.cxx.

135 {
136 m_inFile->Close();
137
138 delete m_inFile;
139 m_inFile = 0;
140
141 if (m_saveDir) {
142 m_saveDir->cd();
143 m_saveDir = 0;
144 }
145 return StatusCode::SUCCESS;
146}

Referenced by internalCreateObj().

◆ closeWrite()

StatusCode RootCalBaseCnv::closeWrite ( )
protected

Finish up writing file opened with openWrite: fill the tree write the file close the file Delete TFile (causes associated Tree to be deleted)

Definition at line 182 of file RootCalBaseCnv.cxx.

182 {
183
184 MsgStream log(msgSvc(), "RootCalBaseCnv");
185
186 StatusCode ret = StatusCode::SUCCESS;
187
188 m_outFile->cd();
189 m_outFile->Close();
190 delete m_outFile;
191 m_outFile = 0;
192 if (m_saveDir) m_saveDir->cd();
193 m_saveDir = 0;
194 return ret;
195}

Referenced by RootDedxCalibDataCnv::createRoot(), RootEmcCalibDataCnv::createRoot(), RootEstTofCalibDataCnv::createRoot(), RootMdcCalibDataCnv::createRoot(), and RootTofCalibDataCnv::createRoot().

◆ createObj()

StatusCode RootCalBaseCnv::createObj ( IOpaqueAddress *  addr,
DataObject *&  refpObject 
)
virtual

Create the transient representation of an object, given an opaque address. This and the following update method comprise the core functionality of calibration converters.

Definition at line 252 of file RootCalBaseCnv.cxx.

253 {
254 // StatusCode ret;
255
256 // first do the things we always need:
257 // First string parameter of opaque address is file ident
258 MsgStream log(msgSvc(), "RootCalBaseCnv");
259 log << MSG::DEBUG<<"RootCalBaseCnv::createObj( starting ...."<<endreq;
260 const std::string* par = addr->par();
261
262 std::string par0 = par[0];
263
264 return internalCreateObj(par0, refpObject, addr);
265
266}
virtual StatusCode internalCreateObj(const std::string &fname, DataObject *&refpObject, IOpaqueAddress *address)

◆ createRoot()

StatusCode RootCalBaseCnv::createRoot ( const std::string &  fname,
CalibData::CalibBase1 pTDSObj 
)
virtual

Create ROOT file corresponding to TDS object input.
Default implementation is to return an error. Must be separately implemented for each calibration type.

Parameters
fnameFilename for output file
pTDSObjPointer to tds object to be converted

Reimplemented in RootDedxCalibDataCnv, RootDedxSimDataCnv, RootEmcCalibDataCnv, RootEsTimeCalibDataCnv, RootEstTofCalibDataCnv, RootMdcCalibDataCnv, RootMucCalibDataCnv, RootTofCalibDataCnv, and RootTofSimDataCnv.

Definition at line 89 of file RootCalBaseCnv.cxx.

90 {
91 MsgStream log(msgSvc(), "RootCalBaseCnv");
92 log << MSG::ERROR
93 << "createRoot method not implemented for this calibration type"
94 << endreq;
95 return StatusCode::FAILURE;
96}

Referenced by CalibRootCnvSvc::writeToRoot().

◆ fillRoot()

StatusCode RootCalBaseCnv::fillRoot ( CalibData::CalibBase pTDSObj,
TObject *  pRootObj 
)
protectedvirtual

Given a pointer to a TDS object which can be cast to "our" type, fill in corresponding information in the corresponding root class

Parameters
pTDSObjPointer to tds object to be converted
pRootObjPointer to destination root object

...maybe don't need pRootObj argument; keep this as the (protected) data member m_rootObj. Or else this routine could set the protected member to this passed-in value

Definition at line 241 of file RootCalBaseCnv.cxx.

242 {
243
244 // Get instrument name from InstrumentName service Now handled by
245 // RootCalBaseCnv
246 // TString instr = TString((m_instrSvc->getInstrumentName()).c_str());
247 // pRootObj->setInstrument(instr);
248 return StatusCode::SUCCESS;
249}

◆ finalize()

StatusCode RootCalBaseCnv::finalize ( )
virtual

Definition at line 82 of file RootCalBaseCnv.cxx.

82 {
83 return Converter::finalize();
84}

◆ getCalibRootSvc()

ICalibRootSvc * RootCalBaseCnv::getCalibRootSvc ( )
inline

Definition at line 58 of file RootCalBaseCnv.h.

58 {
59 return m_rootSvc;
60 }

◆ i_createObj()

StatusCode RootCalBaseCnv::i_createObj ( const std::string &  fname,
DataObject *&  refpObject 
)
protectedvirtual

This creates the transient representation of an object from the corresponding ROOT object. This actually does the "new" operation and deals with the attributes of the node. This base class implementation does nothing; it should not normally be called because it doesn't correspond to any TCDS class. Instead, i_createObj of some derived class will be called.

Parameters
fnameThe ROOT file to be read in to be used to builds the object
refpObjectthe object to be built
Returns
status depending on the completion of the call

Reimplemented in RootDedxCalibDataCnv, RootDedxSimDataCnv, RootEmcCalibDataCnv, RootEsTimeCalibDataCnv, RootEstTofCalibDataCnv, RootMdcCalibDataCnv, RootMucCalibDataCnv, RootTofCalibDataCnv, RootTofElecDataCnv, and RootTofSimDataCnv.

Definition at line 316 of file RootCalBaseCnv.cxx.

317 {
318 return StatusCode::FAILURE; // shouldn't ever get here
319}

Referenced by internalCreateObj().

◆ i_processObj()

StatusCode RootCalBaseCnv::i_processObj ( DataObject *  pObject,
IOpaqueAddress *  address 
)
protectedvirtual

In case there is additional work to do on the created object.

Definition at line 322 of file RootCalBaseCnv.cxx.

323 {
324 return StatusCode::SUCCESS;
325}

Referenced by internalCreateObj().

◆ initialize()

StatusCode RootCalBaseCnv::initialize ( )
virtual

Definition at line 46 of file RootCalBaseCnv.cxx.

46 {
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 ("CalibRootCnvSvc",
63 IID_ICalibRootSvc,
64 (IInterface*&) m_rootSvc);
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}

◆ internalCreateObj()

StatusCode RootCalBaseCnv::internalCreateObj ( const std::string &  fname,
DataObject *&  refpObject,
IOpaqueAddress *  address 
)
protectedvirtual

This creates the transient representation of an object from the corresponding ROOT object it, then fills it and process it. This implementation actually only calls the i_* methods of the "right" converter to do the job; so the very first thing it does is get a pointer to the appropriate derived converter. Converters typically don't need to override this method but only to override/implement some of the i_* methods.

Parameters
pRootObjpointer to the ROOT object
refpObjectthe object to be built
addressthe opaque address for this object
Returns
status depending on the completion of the call

Definition at line 268 of file RootCalBaseCnv.cxx.

270 {
271 MsgStream log(msgSvc(), "RootCalBaseCnv");
272 log << MSG::DEBUG<<"RootCalBaseCnv::internalCreateObj( starting ..... "<<endreq;
273 RootCalBaseCnv* converter = this;
274 CLID classId = address->clID();
275
276 IConverter* conv = this->conversionSvc()->converter(classId);
277 if (0 == conv) {
278 log << MSG::WARNING
279 << "No proper converter found for classID " << classId
280 << ", the default converter"
281 << " will be used. " << endreq;
282 } else {
283 converter = dynamic_cast <RootCalBaseCnv*> (conv);
284 if (0 == converter) {
285 log << MSG::ERROR
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;
290 converter = this;
291 }
292 }
293
294 m_runfrm =*( address->ipar());
295 m_runto =*( address->ipar()+1);
296 // creates an object for the node found
297 StatusCode sc = converter->i_createObj(fname, refpObject);
298 if (sc.isFailure()) {
299 return sc;
300 }
301 CalibData::CalibBase1* tmpObject = dynamic_cast <CalibData::CalibBase1*> (refpObject);
302 setBaseInfo(tmpObject);
303 // ends up the object construction
304 sc = converter->i_processObj(refpObject, address);
305 if (sc.isSuccess()) {
306 log << MSG::DEBUG << "Successfully created calib. object " << endreq;
307 }
308 closeRead();
309 return sc;
310}
virtual StatusCode i_createObj(const std::string &fname, DataObject *&refpObject)
virtual StatusCode i_processObj(DataObject *pObject, IOpaqueAddress *address)
In case there is additional work to do on the created object.
StatusCode closeRead()
void setBaseInfo(CalibData::CalibBase1 *pObj)
Another utility for derived classes to use.

Referenced by createObj().

◆ openRead()

StatusCode RootCalBaseCnv::openRead ( const std::string &  fname)
protected
 Utility for "leaf" converters to call
 @param    Root file to open for read
Parameters
Nameof branch to be read in
ref.to pCalib pointer which will be set to address of read-in object

Definition at line 98 of file RootCalBaseCnv.cxx.

98 {
99
100 MsgStream log(msgSvc(), "RootCalBaseCnv");
101
102 // Check fname isn't empty
103 if (fname == std::string("")) return StatusCode::FAILURE;
104
105 if (doClean() ) {
106 log << MSG::WARNING << "Previous operation didn't clean up! " << endreq;
107 }
108 m_saveDir = gDirectory;
109
110 std::string ourName(fname);
112
113 m_inFile = new TFile(ourName.c_str());
114
115 if (!m_inFile->IsOpen() ) {
116 log << MSG::ERROR << "ROOT file " << ourName
117 << "could not be opened for reading " << endreq;
118 delete m_inFile;
119 m_inFile = 0;
120 return StatusCode::FAILURE;
121 }
122 else {
123 log << MSG::INFO
124 << "Successfully opened ROOT file " << fname << " aka " << ourName
125 << " for reading " << endreq;
126 }
127
128
129 m_inFile->cd(); // Maybe will need this
130
131
132 return StatusCode::SUCCESS;
133}
static int expandEnvVar(std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")"))

Referenced by RootDedxCalibDataCnv::i_createObj(), RootDedxSimDataCnv::i_createObj(), RootEmcCalibDataCnv::i_createObj(), RootEsTimeCalibDataCnv::i_createObj(), RootEstTofCalibDataCnv::i_createObj(), RootMdcCalibDataCnv::i_createObj(), RootMucCalibDataCnv::i_createObj(), RootTofCalibDataCnv::i_createObj(), RootTofElecDataCnv::i_createObj(), and RootTofSimDataCnv::i_createObj().

◆ openWrite()

StatusCode RootCalBaseCnv::openWrite ( const std::string &  fname)
protectedvirtual

Utility used by derived converters to start writing a ROOT file (open TFile, make a TTree, give it a branch)

Parameters
fnameName for new file
classNameName of class for object specified in next parameter; used to name branch as well)
pCalibpointer to object used to create the branch

Definition at line 148 of file RootCalBaseCnv.cxx.

148 {
149
150 MsgStream log(msgSvc(), "RootCalBaseCnv");
151
152 // Check fname isn't empty
153 if (fname == std::string("")) return StatusCode::FAILURE;
154
155 std::string ourName(fname);
157
158 if (doClean() ) {
159 log << MSG::WARNING << "Previous operation didn't clean up! " << endreq;
160 }
161
162 m_saveDir = gDirectory;
163
164
165 m_outFile = new TFile(ourName.c_str(), "RECREATE");
166 if (!m_outFile->IsOpen()) {
167 log << MSG::ERROR << "ROOT file " << fname << " aka " << ourName
168 << " could not be opened for writing" << endreq;
169 delete m_outFile;
170 m_outFile = 0;
171 return StatusCode::FAILURE;
172 }
173 else {
174 log << MSG::INFO
175 << "Successfully opened ROOT file " << fname << " aka " << ourName
176 << " for writing " << endreq;
177 }
178 m_outFile->cd();
179 return StatusCode::SUCCESS;
180}

Referenced by RootDedxCalibDataCnv::createRoot(), RootDedxSimDataCnv::createRoot(), RootEmcCalibDataCnv::createRoot(), RootEsTimeCalibDataCnv::createRoot(), RootEstTofCalibDataCnv::createRoot(), RootMdcCalibDataCnv::createRoot(), RootTofCalibDataCnv::createRoot(), and RootTofSimDataCnv::createRoot().

◆ readRootObj() [1/2]

StatusCode RootCalBaseCnv::readRootObj ( const std::string &  treename,
const std::string &  branch,
TObject *&  pCalib,
unsigned  index = 0 
)
virtual

Read in object (by default the first) from specified branch.

Definition at line 198 of file RootCalBaseCnv.cxx.

200 {
201 TTree* pTree = (TTree*)m_inFile->Get(treename.c_str());
202
203 return readRootObj(pTree, branch, pObj, ix);
204 }
virtual StatusCode readRootObj(const std::string &treename, const std::string &branch, TObject *&pCalib, unsigned index=0)
#define ix(i)
Definition: minoreval.cpp:387

Referenced by readRootObj().

◆ readRootObj() [2/2]

StatusCode RootCalBaseCnv::readRootObj ( TTree *  tree,
const std::string &  branch,
TObject *&  pCalib,
unsigned  index = 0 
)
virtual

Definition at line 206 of file RootCalBaseCnv.cxx.

208 {
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;
213 }

◆ setBaseInfo()

void RootCalBaseCnv::setBaseInfo ( CalibData::CalibBase1 pObj)
protected

Another utility for derived classes to use.

Another convenience for derived classes: sets information belonging to the calibration base class, namely validity interval and serial number.

Definition at line 328 of file RootCalBaseCnv.cxx.

328 {
329 MsgStream log(msgSvc(), "RootCalBaseCnv");
330 log << MSG::DEBUG<<"set the runfrm and runto Numbers in the converter"<<endreq;
331 pObj->setrunfrm(m_runfrm);
332 pObj->setrunto(m_runto);
333}

Referenced by internalCreateObj().

◆ storageType()

static const unsigned char RootCalBaseCnv::storageType ( )
inlinestatic

Definition at line 62 of file RootCalBaseCnv.h.

Member Data Documentation

◆ m_inFile

◆ m_instrSvc

IInstrumentName* RootCalBaseCnv::m_instrSvc
protected

Definition at line 195 of file RootCalBaseCnv.h.

Referenced by initialize().

◆ m_metaSvc

ICalibMetaCnvSvc* RootCalBaseCnv::m_metaSvc
protected

Definition at line 194 of file RootCalBaseCnv.h.

Referenced by initialize().

◆ m_outFile

TFile* RootCalBaseCnv::m_outFile
protected

Definition at line 204 of file RootCalBaseCnv.h.

Referenced by closeWrite(), and openWrite().

◆ m_rootSvc

ICalibRootSvc* RootCalBaseCnv::m_rootSvc
protected

Definition at line 193 of file RootCalBaseCnv.h.

Referenced by getCalibRootSvc(), and initialize().

◆ m_runfrm

int RootCalBaseCnv::m_runfrm
protected

Definition at line 200 of file RootCalBaseCnv.h.

Referenced by internalCreateObj(), and setBaseInfo().

◆ m_runto

int RootCalBaseCnv::m_runto
protected

Definition at line 201 of file RootCalBaseCnv.h.

Referenced by internalCreateObj(), and setBaseInfo().

◆ m_saveDir

TDirectory* RootCalBaseCnv::m_saveDir
protected

Definition at line 209 of file RootCalBaseCnv.h.

Referenced by closeRead(), closeWrite(), openRead(), and openWrite().

◆ m_serNo

int RootCalBaseCnv::m_serNo
protected

Definition at line 197 of file RootCalBaseCnv.h.

◆ m_ttree

TTree* RootCalBaseCnv::m_ttree
protected

Definition at line 205 of file RootCalBaseCnv.h.

◆ m_vend

ITime* RootCalBaseCnv::m_vend
protected

Definition at line 199 of file RootCalBaseCnv.h.

◆ m_vstart

ITime* RootCalBaseCnv::m_vstart
protected

Definition at line 198 of file RootCalBaseCnv.h.


The documentation for this class was generated from the following files: