BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
RootCalBaseCnv.h
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/CalibSvc/CalibROOTCnv/src/cnv/RootCalBaseCnv.h,v 1.2
2// 2006/04/06 03:01:49 maqm Exp $
3#ifndef RootCalBaseCnv_h
4#define RootCalBaseCnv_h
5
6/** @class RootCalBaseCnv
7
8 Base class for calibration converters from XML files to TCDS.
9 All such converters need to do certain things, which are
10 handled here.
11
12 @author J. Bogart
13*/
14#include "GaudiKernel/Converter.h"
15#include <string>
16
17#include "CalibDataSvc/ICalibRootSvc.h"
18#include "TObject.h"
19
20class ISvcLocator;
21class GenericAddress;
22class ICalibRootSvc;
24class IInstrumentName;
25class ITime;
26
27class TFile;
28class TTree;
29class TDirectory;
30class TObject;
31
32namespace CalibData {
33 class CalibTime;
34 class CalibBase;
35 class CalibBase1;
36 class DacCol;
37} // namespace CalibData
38
39class RootCalBaseCnv : public Converter {
40
41public:
42 virtual ~RootCalBaseCnv();
43
44 // Standard public converter stuff
45 virtual StatusCode initialize();
46 virtual StatusCode finalize();
47
48 /**
49 Create the transient representation of an object, given an opaque
50 address. This and the following update method comprise the core
51 functionality of calibration converters.
52 */
53 virtual StatusCode createObj( IOpaqueAddress* addr, DataObject*& refpObject );
54
56
57 static const unsigned char storageType() { return CALIBROOT_StorageType; }
58
59 /**
60 Constructor for this converter
61 @param svc a ISvcLocator interface to find services
62 @param clid the type of object the converter is able to convert
63 */
64 RootCalBaseCnv( ISvcLocator* svc, const CLID& clid );
65
66 // End standard public converter stuff
67
68 /**
69 Create ROOT file corresponding to TDS object input.
70 Default implementation is to return an error. Must be separately
71 implemented for each calibration type.
72
73
74 @param fname Filename for output file
75 @param pTDSObj Pointer to tds object to be converted
76 */
77 virtual StatusCode createRoot( const std::string& fname, CalibData::CalibBase1* pTDSObj );
78
79 /**
80 Read in object (by default the first) from specified branch.
81 */
82 virtual StatusCode readRootObj( const std::string& treename, const std::string& branch,
83 TObject*& pCalib, unsigned index = 0 );
84
85 virtual StatusCode readRootObj( TTree* tree, const std::string& branch, TObject*& pCalib,
86 unsigned index = 0 );
87
88protected:
89 /** This creates the transient representation of an object from the
90 * corresponding ROOT object it, then fills it and process it.
91 * This implementation actually only calls the i_* methods of the
92 * "right" converter to do the job; so the very first thing it
93 * does is get a pointer to the appropriate derived converter.
94 * Converters typically don't need to override this method
95 * but only to override/implement some of the i_* methods.
96
97 * @param pRootObj pointer to the ROOT object
98 * @param refpObject the object to be built
99 * @param address the opaque address for this object
100 * @return status depending on the completion of the call
101 */
102 virtual StatusCode internalCreateObj( const std::string& fname,
103 // was TObject* pRootObj,
104 DataObject*& refpObject, IOpaqueAddress* address );
105
106 /** This creates the transient representation of an object from the
107 * corresponding ROOT object. This actually does the "new" operation
108 * and deals with the attributes of the node. This base class implementation
109 * does nothing; it should not normally be called because it doesn't
110 * correspond to any TCDS class. Instead,
111 * i_createObj of some derived class will be called.
112 * @param fname The ROOT file to be read in
113 * to be used to builds the object
114 * @param refpObject the object to be built
115 * @return status depending on the completion of the call
116 */
117 virtual StatusCode i_createObj( const std::string& fname, DataObject*& refpObject );
118
119 /// In case there is additional work to do on the created object
120 virtual StatusCode i_processObj( DataObject* pObject, IOpaqueAddress* address );
121
122 /**
123 Given a pointer to a TDS object which can be cast to "our" type, fill
124 in corresponding information in the corresponding root class
125
126 @param pTDSObj Pointer to tds object to be converted
127 @param pRootObj Pointer to destination root object
128
129 ...maybe don't need pRootObj argument; keep this as the (protected)
130 data member m_rootObj. Or else this routine could set the protected
131 member to this passed-in value
132 */
133 virtual StatusCode fillRoot( CalibData::CalibBase* pTDSObj, TObject* pRootObj );
134
135 /**
136 Utility used by derived converters to start writing a ROOT file
137 (open TFile, make a TTree, give it a branch)
138 @param fname Name for new file
139 @param className Name of class for object specified in next parameter;
140 used to name branch as well)
141 @param pCalib pointer to object used to create the branch
142
143 */
144 virtual StatusCode openWrite( const std::string& fname );
145
146 /**
147 Finish up writing file opened with openWrite:
148 fill the tree
149 write the file
150 close the file
151 Delete TFile (causes associated Tree to be deleted)
152 */
153 StatusCode closeWrite();
154
155 /**
156 Utility for "leaf" converters to call
157 @param Root file to open for read
158// @param Name of branch to be read in
159// @param ref. to pCalib pointer which will be set to address of
160 read-in object
161 */
162 // StatusCode openRead(const std::string& fname, const std::string& branch,
163 // TObject*& pCalib);
164 StatusCode openRead( const std::string& fname );
165
166 /** Clean up when we've finished reading in */
167 StatusCode closeRead();
168
169 /// Another convenience for derived classes: sets information belonging
170 /// to the calibration base class, namely validity interval and serial
171 /// number.
173
174 // Might want to verify that instrument, calType are correct,
175 // for example. If so, might as well provide the service in
176 // the base converter.
177 ////// virtual StatusCode readHeader(const DOM_Element&);
178
182
184 ITime* m_vstart;
185 ITime* m_vend;
188 // Note by keeping this stuff here we're disallowing possibility of
189 // interleaved writes of different calibrations
190 TFile* m_outFile;
191 TTree* m_ttree;
192
193 TFile* m_inFile;
194
195 TDirectory* m_saveDir;
196
197 // Don't think we want this after all
198 // store pointer to intermediate (between TDS and permanent file) form
199 // of calibration data as root obj. It will normally be the responsibility
200 // of the "leaf" calibration converter to create and delete it.
201 // calibRootData::Base* m_rootObj;
202
203 // Is it reasonable to always call our TTree "Calib" ?
204 // Branches will be named after calibration type
205private:
206 // Return true if something was there to be cleaned
207 bool doClean();
208};
209
210#endif
Simple interface to keep track of which instrument (LAT, EM, etc.) the process is concerned with....
virtual StatusCode i_createObj(const std::string &fname, DataObject *&refpObject)
static const unsigned char storageType()
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()
StatusCode closeRead()
virtual StatusCode createObj(IOpaqueAddress *addr, DataObject *&refpObject)
virtual StatusCode readRootObj(const std::string &treename, const std::string &branch, TObject *&pCalib, unsigned index=0)
ICalibRootSvc * getCalibRootSvc()
virtual StatusCode internalCreateObj(const std::string &fname, DataObject *&refpObject, IOpaqueAddress *address)
ICalibMetaCnvSvc * m_metaSvc
RootCalBaseCnv(ISvcLocator *svc, const CLID &clid)
StatusCode closeWrite()
virtual StatusCode initialize()
virtual StatusCode fillRoot(CalibData::CalibBase *pTDSObj, TObject *pRootObj)
TDirectory * m_saveDir
virtual ~RootCalBaseCnv()
ICalibRootSvc * m_rootSvc
virtual StatusCode openWrite(const std::string &fname)
void setBaseInfo(CalibData::CalibBase1 *pObj)
Another utility for derived classes to use.