BOSS 7.1.2
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
 

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
 

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
 

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.

41 :
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) {}
unsigned const char CALIBROOT_StorageType
IInstrumentName * m_instrSvc
ICalibMetaCnvSvc * m_metaSvc
TDirectory * m_saveDir
ICalibRootSvc * m_rootSvc

Member Function Documentation

◆ closeRead()

StatusCode RootCalBaseCnv::closeRead ( )
protected

Clean up when we've finished reading in

Definition at line 133 of file RootCalBaseCnv.cxx.

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

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 180 of file RootCalBaseCnv.cxx.

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

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 250 of file RootCalBaseCnv.cxx.

251 {
252 // StatusCode ret;
253
254 // first do the things we always need:
255 // First string parameter of opaque address is file ident
256 MsgStream log(msgSvc(), "RootCalBaseCnv");
257 log << MSG::DEBUG<<"RootCalBaseCnv::createObj( starting ...."<<endreq;
258 const std::string* par = addr->par();
259
260 std::string par0 = par[0];
261
262 return internalCreateObj(par0, refpObject, addr);
263
264}
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 RootCorrectedETSCnv, RootDedxCalibDataCnv, RootDedxSimDataCnv, RootEmcCalibDataCnv, RootEsTimeCalibDataCnv, RootEstTofCalibDataCnv, RootInjSigIntervalCnv, RootInjSigTimeCnv, RootMdcCalibDataCnv, RootMucCalibDataCnv, RootOffEvtFilterCnv, RootTofCalibDataCnv, and RootTofSimDataCnv.

Definition at line 87 of file RootCalBaseCnv.cxx.

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

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 239 of file RootCalBaseCnv.cxx.

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

◆ finalize()

StatusCode RootCalBaseCnv::finalize ( )
virtual

Definition at line 80 of file RootCalBaseCnv.cxx.

80 {
81 return Converter::finalize();
82}

◆ 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 RootCorrectedETSCnv, RootDedxCalibDataCnv, RootDedxSimDataCnv, RootEmcCalibDataCnv, RootEsTimeCalibDataCnv, RootEstTofCalibDataCnv, RootInjSigIntervalCnv, RootInjSigTimeCnv, RootMdcCalibDataCnv, RootMucCalibDataCnv, RootOffEvtFilterCnv, RootTofCalibDataCnv, RootTofElecDataCnv, and RootTofSimDataCnv.

Definition at line 314 of file RootCalBaseCnv.cxx.

315 {
316 return StatusCode::FAILURE; // shouldn't ever get here
317}

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 320 of file RootCalBaseCnv.cxx.

321 {
322 return StatusCode::SUCCESS;
323}

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 // Locate the Root Conversion Service
61 serviceLocator()->getService ("CalibRootCnvSvc",
62 ICalibRootSvc::interfaceID(),
63 (IInterface*&) m_rootSvc);
64
65 // Locate meta conversion service
66 // Will anything need to be changed here to accommodate possibility
67 // of two concrete implementations of ICalibMetaCnvSvc? Would
68 // have different storage types. Could specify type desired
69 // as job option. Ditto for name of class?
70 serviceLocator()->getService("CalibMySQLCnvSvc",
71 ICalibMetaCnvSvc::interfaceID(),
72 (IInterface*&)m_metaSvc);
73 serviceLocator()->getService ("CalibDataSvc",
75 (IInterface*&)m_instrSvc);
76
77 return status;
78}
static const InterfaceID & interfaceID()

◆ 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 266 of file RootCalBaseCnv.cxx.

268 {
269 MsgStream log(msgSvc(), "RootCalBaseCnv");
270 log << MSG::DEBUG<<"RootCalBaseCnv::internalCreateObj( starting ..... "<<endreq;
271 RootCalBaseCnv* converter = this;
272 CLID classId = address->clID();
273
274 IConverter* conv = this->conversionSvc()->converter(classId);
275 if (0 == conv) {
276 log << MSG::WARNING
277 << "No proper converter found for classID " << classId
278 << ", the default converter"
279 << " will be used. " << endreq;
280 } else {
281 converter = dynamic_cast <RootCalBaseCnv*> (conv);
282 if (0 == converter) {
283 log << MSG::ERROR
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;
288 converter = this;
289 }
290 }
291
292 m_runfrm =*( address->ipar());
293 m_runto =*( address->ipar()+1);
294 // creates an object for the node found
295 StatusCode sc = converter->i_createObj(fname, refpObject);
296 if (sc.isFailure()) {
297 return sc;
298 }
299 CalibData::CalibBase1* tmpObject = dynamic_cast <CalibData::CalibBase1*> (refpObject);
300 setBaseInfo(tmpObject);
301 // ends up the object construction
302 sc = converter->i_processObj(refpObject, address);
303 if (sc.isSuccess()) {
304 log << MSG::DEBUG << "Successfully created calib. object " << endreq;
305 }
306 closeRead();
307 return sc;
308}
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 96 of file RootCalBaseCnv.cxx.

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

Referenced by RootCorrectedETSCnv::i_createObj(), RootDedxCalibDataCnv::i_createObj(), RootDedxSimDataCnv::i_createObj(), RootEmcCalibDataCnv::i_createObj(), RootEsTimeCalibDataCnv::i_createObj(), RootEstTofCalibDataCnv::i_createObj(), RootInjSigIntervalCnv::i_createObj(), RootInjSigTimeCnv::i_createObj(), RootMdcCalibDataCnv::i_createObj(), RootMucCalibDataCnv::i_createObj(), RootOffEvtFilterCnv::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 146 of file RootCalBaseCnv.cxx.

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

Referenced by RootCorrectedETSCnv::createRoot(), RootDedxCalibDataCnv::createRoot(), RootDedxSimDataCnv::createRoot(), RootEmcCalibDataCnv::createRoot(), RootEsTimeCalibDataCnv::createRoot(), RootEstTofCalibDataCnv::createRoot(), RootInjSigIntervalCnv::createRoot(), RootInjSigTimeCnv::createRoot(), RootMdcCalibDataCnv::createRoot(), RootOffEvtFilterCnv::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 196 of file RootCalBaseCnv.cxx.

198 {
199 TTree* pTree = (TTree*)m_inFile->Get(treename.c_str());
200
201 return readRootObj(pTree, branch, pObj, ix);
202 }
virtual StatusCode readRootObj(const std::string &treename, const std::string &branch, TObject *&pCalib, unsigned index=0)

Referenced by readRootObj().

◆ readRootObj() [2/2]

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

Definition at line 204 of file RootCalBaseCnv.cxx.

206 {
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;
211 }

◆ 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 326 of file RootCalBaseCnv.cxx.

326 {
327 MsgStream log(msgSvc(), "RootCalBaseCnv");
328 log << MSG::DEBUG<<"set the runfrm and runto Numbers in the converter"<<endreq;
329 pObj->setrunfrm(m_runfrm);
330 pObj->setrunto(m_runto);
331}
void setrunto(int runto)
Definition CalibBase1.h:56
void setrunfrm(int runfrm)
Definition CalibBase1.h:55

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: