BOSS 8.0.0
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
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
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
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 30 of file RootCalBaseCnv.cxx.

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

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

40 : Converter( CALIBROOT_StorageType, clid, svc )
41 , m_rootSvc( 0 )
42 , m_metaSvc( 0 )
43 , m_instrSvc( 0 )
44 , m_vstart( 0 )
45 , m_vend( 0 )
46 , m_outFile( 0 )
47 , m_ttree( 0 )
48 , m_inFile( 0 )
49 , m_saveDir( 0 ) {}
IInstrumentName * m_instrSvc
ICalibMetaCnvSvc * m_metaSvc
TDirectory * m_saveDir
ICalibRootSvc * m_rootSvc

Referenced by internalCreateObj(), RootCorrectedETSCnv::RootCorrectedETSCnv(), RootDedxCalibDataCnv::RootDedxCalibDataCnv(), RootDedxSimDataCnv::RootDedxSimDataCnv(), RootEmcCalibDataCnv::RootEmcCalibDataCnv(), RootEsTimeCalibDataCnv::RootEsTimeCalibDataCnv(), RootEstTofCalibDataCnv::RootEstTofCalibDataCnv(), RootInjSigIntervalCnv::RootInjSigIntervalCnv(), RootInjSigTimeCnv::RootInjSigTimeCnv(), RootMdcCalibDataCnv::RootMdcCalibDataCnv(), RootMucCalibDataCnv::RootMucCalibDataCnv(), RootOffEvtFilterCnv::RootOffEvtFilterCnv(), RootTofCalibDataCnv::RootTofCalibDataCnv(), RootTofElecDataCnv::RootTofElecDataCnv(), and RootTofSimDataCnv::RootTofSimDataCnv().

Member Function Documentation

◆ closeRead()

StatusCode RootCalBaseCnv::closeRead ( )
protected

Clean up when we've finished reading in

Definition at line 126 of file RootCalBaseCnv.cxx.

126 {
127 m_inFile->Close();
128
129 delete m_inFile;
130 m_inFile = 0;
131
132 if ( m_saveDir )
133 {
134 m_saveDir->cd();
135 m_saveDir = 0;
136 }
137 return StatusCode::SUCCESS;
138}

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

172 {
173
174 MsgStream log( msgSvc(), "RootCalBaseCnv" );
175
176 StatusCode ret = StatusCode::SUCCESS;
177
178 m_outFile->cd();
179 m_outFile->Close();
180 delete m_outFile;
181 m_outFile = 0;
182 if ( m_saveDir ) m_saveDir->cd();
183 m_saveDir = 0;
184 return ret;
185}
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 241 of file RootCalBaseCnv.cxx.

241 {
242 // StatusCode ret;
243
244 // first do the things we always need:
245 // First string parameter of opaque address is file ident
246 MsgStream log( msgSvc(), "RootCalBaseCnv" );
247 log << MSG::DEBUG << "RootCalBaseCnv::createObj( starting ...." << endmsg;
248 const std::string* par = addr->par();
249
250 std::string par0 = par[0];
251
252 return internalCreateObj( par0, refpObject, addr );
253}
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 85 of file RootCalBaseCnv.cxx.

86 {
87 MsgStream log( msgSvc(), "RootCalBaseCnv" );
88 log << MSG::ERROR << "createRoot method not implemented for this calibration type" << endmsg;
89 return StatusCode::FAILURE;
90}

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

231 {
232
233 // Get instrument name from InstrumentName service Now handled by
234 // RootCalBaseCnv
235 // TString instr = TString((m_instrSvc->getInstrumentName()).c_str());
236 // pRootObj->setInstrument(instr);
237 return StatusCode::SUCCESS;
238}

◆ finalize()

StatusCode RootCalBaseCnv::finalize ( )
virtual

Definition at line 81 of file RootCalBaseCnv.cxx.

81{ return Converter::finalize(); }

◆ getCalibRootSvc()

ICalibRootSvc * RootCalBaseCnv::getCalibRootSvc ( )
inline

Definition at line 55 of file RootCalBaseCnv.h.

55{ return m_rootSvc; }

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

303 {
304 return StatusCode::FAILURE; // shouldn't ever get here
305}

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

309 {
310 return StatusCode::SUCCESS;
311}

Referenced by internalCreateObj().

◆ initialize()

StatusCode RootCalBaseCnv::initialize ( )
virtual

Definition at line 51 of file RootCalBaseCnv.cxx.

51 {
52 StatusCode status = Converter::initialize();
53
54 IDataProviderSvc* dp;
55
56 // I guess the service names are assigned in jobOptions?
57
58 /*serviceLocator()->getService ("CalibDataSvc",
59 IID_IDataProviderSvc,
60 (IInterface*&)dp);*/
61 serviceLocator()->getService( "CalibDataSvc", IDataProviderSvc::interfaceID(),
62 (IInterface*&)dp );
63 setDataProvider( dp );
64 // Locate the Root Conversion Service
65 serviceLocator()->getService( "CalibRootCnvSvc", ICalibRootSvc::interfaceID(),
66 (IInterface*&)m_rootSvc );
67
68 // Locate meta conversion service
69 // Will anything need to be changed here to accommodate possibility
70 // of two concrete implementations of ICalibMetaCnvSvc? Would
71 // have different storage types. Could specify type desired
72 // as job option. Ditto for name of class?
73 serviceLocator()->getService( "CalibMySQLCnvSvc", ICalibMetaCnvSvc::interfaceID(),
74 (IInterface*&)m_metaSvc );
75 serviceLocator()->getService( "CalibDataSvc", IInstrumentName::interfaceID(),
76 (IInterface*&)m_instrSvc );
77
78 return status;
79}

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

257 {
258 MsgStream log( msgSvc(), "RootCalBaseCnv" );
259 log << MSG::DEBUG << "RootCalBaseCnv::internalCreateObj( starting ..... " << endmsg;
260 RootCalBaseCnv* converter = this;
261 CLID classId = address->clID();
262
263 IConverter* conv = this->conversionSvc()->converter( classId );
264 if ( 0 == conv )
265 {
266 log << MSG::WARNING << "No proper converter found for classID " << classId
267 << ", the default converter"
268 << " will be used. " << endmsg;
269 }
270 else
271 {
272 converter = dynamic_cast<RootCalBaseCnv*>( conv );
273 if ( 0 == converter )
274 {
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;
279 converter = this;
280 }
281 }
282
283 m_runfrm = *( address->ipar() );
284 m_runto = *( address->ipar() + 1 );
285 // creates an object for the node found
286 StatusCode sc = converter->i_createObj( fname, refpObject );
287 if ( sc.isFailure() ) { return sc; }
288 CalibData::CalibBase1* tmpObject = dynamic_cast<CalibData::CalibBase1*>( refpObject );
289 setBaseInfo( tmpObject );
290 // ends up the object construction
291 sc = converter->i_processObj( refpObject, address );
292 if ( sc.isSuccess() )
293 { log << MSG::DEBUG << "Successfully created calib. object " << endmsg; }
294 closeRead();
295 return sc;
296}
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()
RootCalBaseCnv(ISvcLocator *svc, const CLID &clid)
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 92 of file RootCalBaseCnv.cxx.

92 {
93
94 MsgStream log( msgSvc(), "RootCalBaseCnv" );
95
96 // Check fname isn't empty
97 if ( fname == std::string( "" ) ) return StatusCode::FAILURE;
98
99 if ( doClean() ) { log << MSG::WARNING << "Previous operation didn't clean up! " << endmsg; }
100 m_saveDir = gDirectory;
101
102 std::string ourName( fname );
104
105 m_inFile = new TFile( ourName.c_str() );
106
107 if ( !m_inFile->IsOpen() )
108 {
109 log << MSG::ERROR << "ROOT file " << ourName << "could not be opened for reading "
110 << endmsg;
111 delete m_inFile;
112 m_inFile = 0;
113 return StatusCode::FAILURE;
114 }
115 else
116 {
117 log << MSG::INFO << "Successfully opened ROOT file " << fname << " aka " << ourName
118 << " for reading " << endmsg;
119 }
120
121 m_inFile->cd(); // Maybe will need this
122
123 return StatusCode::SUCCESS;
124}
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 140 of file RootCalBaseCnv.cxx.

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

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

188 {
189 TTree* pTree = (TTree*)m_inFile->Get( treename.c_str() );
190
191 return readRootObj( pTree, branch, pObj, ix );
192}
virtual StatusCode readRootObj(const std::string &treename, const std::string &branch, TObject *&pCalib, unsigned index=0)
#define ix(i)

Referenced by readRootObj().

◆ readRootObj() [2/2]

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

Definition at line 194 of file RootCalBaseCnv.cxx.

195 {
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;
200}

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

314 {
315 MsgStream log( msgSvc(), "RootCalBaseCnv" );
316 log << MSG::DEBUG << "set the runfrm and runto Numbers in the converter" << endmsg;
317 pObj->setrunfrm( m_runfrm );
318 pObj->setrunto( m_runto );
319}

Referenced by internalCreateObj().

◆ storageType()

const unsigned char RootCalBaseCnv::storageType ( )
inlinestatic

Definition at line 57 of file RootCalBaseCnv.h.

57{ return CALIBROOT_StorageType; }

Member Data Documentation

◆ m_inFile

◆ m_instrSvc

IInstrumentName* RootCalBaseCnv::m_instrSvc
protected

Definition at line 181 of file RootCalBaseCnv.h.

Referenced by initialize(), and RootCalBaseCnv().

◆ m_metaSvc

ICalibMetaCnvSvc* RootCalBaseCnv::m_metaSvc
protected

Definition at line 180 of file RootCalBaseCnv.h.

Referenced by initialize(), and RootCalBaseCnv().

◆ m_outFile

TFile* RootCalBaseCnv::m_outFile
protected

Definition at line 190 of file RootCalBaseCnv.h.

Referenced by closeWrite(), openWrite(), and RootCalBaseCnv().

◆ m_rootSvc

ICalibRootSvc* RootCalBaseCnv::m_rootSvc
protected

Definition at line 179 of file RootCalBaseCnv.h.

Referenced by getCalibRootSvc(), initialize(), and RootCalBaseCnv().

◆ m_runfrm

int RootCalBaseCnv::m_runfrm
protected

Definition at line 186 of file RootCalBaseCnv.h.

Referenced by internalCreateObj(), and setBaseInfo().

◆ m_runto

int RootCalBaseCnv::m_runto
protected

Definition at line 187 of file RootCalBaseCnv.h.

Referenced by internalCreateObj(), and setBaseInfo().

◆ m_saveDir

TDirectory* RootCalBaseCnv::m_saveDir
protected

Definition at line 195 of file RootCalBaseCnv.h.

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

◆ m_serNo

int RootCalBaseCnv::m_serNo
protected

Definition at line 183 of file RootCalBaseCnv.h.

◆ m_ttree

TTree* RootCalBaseCnv::m_ttree
protected

Definition at line 191 of file RootCalBaseCnv.h.

Referenced by RootCalBaseCnv().

◆ m_vend

ITime* RootCalBaseCnv::m_vend
protected

Definition at line 185 of file RootCalBaseCnv.h.

Referenced by RootCalBaseCnv().

◆ m_vstart

ITime* RootCalBaseCnv::m_vstart
protected

Definition at line 184 of file RootCalBaseCnv.h.

Referenced by RootCalBaseCnv().


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