BOSS 7.0.5
BESIII Offline Software System
Loading...
Searching...
No Matches
XmlBaseCnv.cxx
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/CalibSvc/CalibXmlCnvSvc/src/cnv/XmlBaseCnv.cxx,v 1.1.1.1 2006/04/03 03:04:32 maqm Exp $
2
3#include "XmlBaseCnv.h"
4
5#include "GaudiKernel/CnvFactory.h"
6#include "GaudiKernel/IOpaqueAddress.h"
7#include "GaudiKernel/DataObject.h"
8#include "GaudiKernel/IAddressCreator.h"
9#include "GaudiKernel/IDataProviderSvc.h"
10#include "GaudiKernel/IConversionSvc.h"
11#include "GaudiKernel/MsgStream.h"
12
13#include "CalibSvc/ICalibXmlSvc.h"
14#include "CalibSvc/ICalibMetaCnvSvc.h"
15#include "CalibData/CalibTime.h"
16#include "CalibData/CalibBase.h"
17//#include "CalibData/Cal/Xpos.h"
18
19// Needed for ValSig
20#include "CalibData/RangeBase.h"
21#include "xmlBase/Dom.h"
22
23// A little ugly to include this here. It's needed for
24// CAL-specific utilities involving dac collections (maybe should be
25// moved to XmlCalbaseCnv ?)
26//#include "idents/CalXtalId.h"
27
28// Similarly this is needed for calibrations involving dac settings
29#include "CalibData/DacCol.h"
30
31#include "facilities/Util.h"
32
33#include <xercesc/dom/DOMDocument.hpp>
34// #include <xercesc/dom/DOM_NodeList.hpp>
35
36using namespace CalibData;
37XERCES_CPP_NAMESPACE_USE
38
39
41
42// static CnvFactory<XmlBaseCnv> s_factory;
43// const ICnvFactory& XmlBaseCnvFactory = s_factory;
44XmlBaseCnv::XmlBaseCnv( ISvcLocator* svc, const CLID& clid) :
45 Converter (XML_StorageType, clid, svc),
46 m_xmlSvc (0), m_metaSvc(0), m_vstart(0), m_vend(0) /*,
47 m_nRow(10000), m_nCol(10000), m_nLayer(10000), m_nXtal(10000),
48 m_nFace(10000), m_nRange(10000) */ {}
49
51 StatusCode status = Converter::initialize();
52
53 IDataProviderSvc* dp;
54
55 // I guess the service names are assigned in jobOptions?
56
57 serviceLocator()->getService ("CalibDataSvc",
58 IID_IDataProviderSvc,
59 (IInterface*&)dp);
60 setDataProvider(dp);
61
62 // Locate the Xml Conversion Service
63 serviceLocator()->getService ("CalibXmlCnvSvc",
64 IID_ICalibXmlSvc,
65 (IInterface*&)m_xmlSvc);
66
67 // Locate meta conversion service
68 // Will anything need to be changed here to accommodate possibility
69 // of two concrete implementations of ICalibMetaCnvSvc? Would
70 // have different storage types. Could specify type desired
71 // as job option. Ditto for name of class?
72 serviceLocator()->getService("CalibMySQLCnvSvc",
73 IID_ICalibMetaCnvSvc,
74 (IInterface*&)m_metaSvc);
75 return status;
76}
77
79 return Converter::finalize();
80}
81
82// Create transient representation
83
84StatusCode XmlBaseCnv::createObj(IOpaqueAddress* addr,
85 DataObject*& refpObject) {
86
87 // creates a msg stream for debug purposes
88 MsgStream log( msgSvc(), "XmlBaseCnv" );
89
90 if (0 == addr) {
91 return StatusCode::FAILURE;
92 }
93
94 // first do the things we always need:
95 // First string parameter of opaque address is file ident
96 // Parse file into DOM representation
97 const std::string* par = addr->par();
98
99 std::string par0 = par[0];
100
101 // Ignore trailing white space.
103
104 // Just in case there are environment variables in the file specification
105 // int nSub =
107
108 // XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* doc =
109 DOMDocument* doc =
110 m_xmlSvc->parse(par0.c_str());
111
112 if (doc == 0 ) {
113 log << MSG::FATAL
114 << "Unable to parse document " << par[0] << " aka "
115 << par0 << endreq;
116 return StatusCode::FAILURE;
117 }
118 else {
119 log << MSG::INFO
120 << "successfully parsed document " << par[0] << " aka "
121 << par0 << endreq;
122 }
123
124 // Could conceivably write some code here to handle generic
125 // parts of document. Or, alternatively, add services to
126 // CalibXmlCnvSvc for converters to invoke to do this.
127
128 // Then do some fancy footwork in internalCreateObj to get the
129 // appropriate specific converter invoked to interpret the DOM
130 // correctly and make a new object of the correct kind.
131
132 return internalCreateObj(doc->getDocumentElement(), refpObject, addr);
133}
134
135
136/** In a backhanded way, invoke the right specific converter
137 for the type of the object to be created
138 @param elt Document elt from XML document (input)
139 @param refpObject
140*/
141StatusCode XmlBaseCnv::internalCreateObj(const DOMElement* docElt,
142 DataObject*& refpObject,
143 IOpaqueAddress* address) {
144 // creates a msg stream for debug purposes
145 MsgStream log( msgSvc(), "XmlBaseCnv" );
146
147 // We're the default if we can't find anything better
148 XmlBaseCnv* converter = this;
149
150 CLID classId = address->clID();
151
152 IConverter* conv = this->conversionSvc()->converter(classId);
153
154 if (0 == conv) {
155 log << MSG::WARNING
156 << "No proper converter found for classID " << classId
157 << ", the default converter"
158 << " will be used. " << endreq;
159 } else {
160 converter = dynamic_cast <XmlBaseCnv*> (conv);
161 if (0 == converter) {
162 log << MSG::ERROR
163 << "The converter found for classID " << classId
164 << " was not a descendent of XmlBaseCnv as it should be "
165 << "( was of type " << typeid (*converter).name() << "). "
166 << "The default converter will be used" << endreq;
167 converter = this;
168 }
169 }
170
171 unsigned int serNo = *(address->ipar());
172 m_serNo = serNo;
173/* maqm comment for remove getValidInterval()
174 StatusCode sc = m_metaSvc->getValidInterval(serNo,
175 &m_vstart,
176 &m_vend );
177
178
179 // creates an object for the node found
180
181
182 if (sc.isSuccess()) sc = converter->i_createObj (docElt, refpObject);
183 */
184 StatusCode sc = converter->i_createObj (docElt, refpObject);
185 if (sc.isFailure()) {
186 return sc;
187 }
188
189 // ends up the object construction
190 sc = converter->i_processObj(refpObject, address);
191 if (sc.isSuccess()) {
192 log << MSG::DEBUG << "Successfully created calib. object " << endreq;
193 }
194 return sc;
195}
196
197// Default is to do nothing. Derived classes may override.
198StatusCode XmlBaseCnv::i_processObj(DataObject*, // pObject,
199 IOpaqueAddress* ) /* address */ {
200 return StatusCode::SUCCESS;
201}
202
203
204// Shouldn't ever really get here
205StatusCode XmlBaseCnv::i_createObj(const DOMElement*, DataObject*&) {
206 return StatusCode::FAILURE;
207}
208
209/*
210// Not sure yet whether this needs a real implementation or not
211StatusCode XmlBaseCnv::updateObj(IOpaqueAddress* ,
212 DataObject*& ) {
213 return StatusCode::FAILURE;
214}
215
216// Since we're not expecting to support writing back to persistent
217// store, don't implement the converter *Rep functions.
218*/
219
220StatusCode XmlBaseCnv::readHeader(const DOMElement*) {
221 return StatusCode::SUCCESS;
222}
223
224const unsigned char XmlBaseCnv::storageType() {
225 return XML_StorageType;
226}
227
228/*
229
230*/
231/// Another utility for derived classes to use
233 pObj->setValidity(*m_vstart, *m_vend);
234 pObj->setSerNo(m_serNo);
235}
236
237
238DOMElement* XmlBaseCnv::findFirstDacCol(const DOMElement* docElt) {
239 return xmlBase::Dom::findFirstChildByName(docElt, "dac");
240}
241
242DOMElement* XmlBaseCnv::findNextDacCol(const DOMElement* dacElt) {
243 DOMElement* next = xmlBase::Dom::getSiblingElement(dacElt);
244 if (xmlBase::Dom::checkTagName(next, "dac")) return next;
245 else return 0;
246}
247
249 unsigned* range) {
250
251 using xmlBase::Dom;
252//maqm comment using idents::CalXtalId;
253
254 std::string att = Dom::getAttribute(dacColElt, "range");
255/* maqm comment
256 if (att.compare(std::string("LEX8")) == 0) *range = CalXtalId::LEX8;
257 if (att.compare(std::string("LEX1")) == 0) *range = CalXtalId::LEX1;
258 if (att.compare(std::string("HEX8")) == 0) *range = CalXtalId::HEX8;
259 if (att.compare(std::string("HEX1")) == 0) *range = CalXtalId::HEX1;
260*/
261 // *range = Dom::getIntAttribute(dacColElt, "range");
262 std::vector<int> vals;
263
264 Dom::getIntsAttribute(dacColElt, "values", vals);
265
266 CalibData::DacCol* pDacCol = new CalibData::DacCol(&vals);
267 return pDacCol;
268
269}
270
271/* maqm comment
272 DOMElement* XmlBaseCnv::findXpos(const DOMElement* docElt) {
273 return xmlBase::Dom::findFirstChildByName(docElt, "xpos");
274}
275
276CalibData::Xpos* XmlBaseCnv::processXpos(DOMElement* xposElt) {
277 using xmlBase::Dom;
278
279 std::vector<float> vals;
280
281 Dom::getFloatsAttribute(xposElt, "values", vals);
282 CalibData::Xpos* pXpos = new CalibData::Xpos(&vals);
283
284 return pXpos;
285}
286*/
287/// Read in what will become a CalibData::ValSig
289 std::string valName,
290 std::string sigName) {
291 if (elt == 0 ) return 0;
293 pValSig->m_val = xmlBase::Dom::getDoubleAttribute(elt, valName);
294 pValSig->m_sig = xmlBase::Dom::getDoubleAttribute(elt, sigName);
295 return pValSig;
296}
297
298std::vector<CalibData::ValSig>*
299XmlBaseCnv::processValSigs(DOMElement* elt, std::string valName,
300 std::string sigName) {
301
302 // creates a msg stream for debug purposes
303 MsgStream log( msgSvc(), "XmlBaseCnv" );
304
305 if (elt == 0 ) return 0;
306 std::vector<float> vals;
307 std::vector<float> sigs;
308
309 xmlBase::Dom::getFloatsAttribute(elt, valName, vals);
310 xmlBase::Dom::getFloatsAttribute(elt, sigName, sigs);
311 if (vals.size() != sigs.size() ) {
312 log << MSG::ERROR << "#values <> #sigmas " << endreq;
313 return 0;
314 }
315 unsigned n = vals.size();
316 std::vector<CalibData::ValSig>* pValSigs =
317 new std::vector<CalibData::ValSig>(n);
318 for (unsigned i = 0; i < n; i++) {
319 (*pValSigs)[i].m_val = vals[i];
320 (*pValSigs)[i].m_sig = sigs[i];
321 }
322 return pValSigs;
323}
const Int_t n
virtual XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * parse(const char *filename)=0
ICalibMetaCnvSvc * m_metaSvc
Definition: XmlBaseCnv.h:148
CalibData::ValSig * processValSig(DOMElement *elt, std::string valName, std::string sigName)
Read in what will become a CalibData::ValSig.
Definition: XmlBaseCnv.cxx:288
ICalibXmlSvc * m_xmlSvc
Definition: XmlBaseCnv.h:147
std::vector< CalibData::ValSig > * processValSigs(DOMElement *elt, std::string valName, std::string sigName)
Read in what will become a vector of CalibData::ValSig.
Definition: XmlBaseCnv.cxx:299
virtual StatusCode readHeader(const DOMElement *)
Definition: XmlBaseCnv.cxx:220
ITime * m_vend
Definition: XmlBaseCnv.h:152
virtual ~XmlBaseCnv()
Definition: XmlBaseCnv.cxx:40
virtual StatusCode initialize()
Definition: XmlBaseCnv.cxx:50
void setBaseInfo(CalibData::CalibBase *pObj)
Another utility for derived classes to use.
Definition: XmlBaseCnv.cxx:232
static const unsigned char storageType()
Definition: XmlBaseCnv.cxx:224
CalibData::DacCol * processDacCol(DOMElement *dacColElt, unsigned *range)
Definition: XmlBaseCnv.cxx:248
virtual StatusCode i_processObj(DataObject *pObject, IOpaqueAddress *address)
In case there is additional work to do on the created object.
Definition: XmlBaseCnv.cxx:198
DOMElement * findNextDacCol(const DOMElement *rangeElt)
Still another one to navigate XML file and find next dac collection.
Definition: XmlBaseCnv.cxx:242
DOMElement * findFirstDacCol(const DOMElement *docElt)
Another one to find first dac collection element.
Definition: XmlBaseCnv.cxx:238
virtual StatusCode internalCreateObj(const DOMElement *element, DataObject *&refpObject, IOpaqueAddress *address)
Definition: XmlBaseCnv.cxx:141
ITime * m_vstart
Definition: XmlBaseCnv.h:151
virtual StatusCode finalize()
Definition: XmlBaseCnv.cxx:78
virtual StatusCode createObj(IOpaqueAddress *addr, DataObject *&refpObject)
Definition: XmlBaseCnv.cxx:84
XmlBaseCnv(ISvcLocator *svc, const CLID &clid)
Definition: XmlBaseCnv.cxx:44
virtual StatusCode i_createObj(const DOMElement *element, DataObject *&refpObject)
Definition: XmlBaseCnv.cxx:205
static int expandEnvVar(std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")"))
static unsigned trimTrailing(std::string *toTrim)
static DOMElement * getSiblingElement(const DOMNode *child)
Return next element sibling, if any.
Definition: Dom.cxx:96
static unsigned getFloatsAttribute(const DOMNode *elt, std::string attName, std::vector< float > &values, bool clear=true)
Definition: Dom.cxx:302
static double getDoubleAttribute(const DOMNode *elt, std::string attName)
Definition: Dom.cxx:263
static DOMElement * findFirstChildByName(const DOMElement *parent, const char *const name)
Definition: Dom.cxx:60
static bool checkTagName(const DOMElement *element, const std::string &tagName)
Definition: Dom.cxx:146