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