BOSS 7.0.1
BESIII Offline Software System
Loading...
Searching...
No Matches
XmlBaseCnv Class Reference

#include <XmlBaseCnv.h>

+ Inheritance diagram for XmlBaseCnv:

Public Member Functions

virtual ~XmlBaseCnv ()
 
virtual StatusCode initialize ()
 
virtual StatusCode finalize ()
 
virtual StatusCode createObj (IOpaqueAddress *addr, DataObject *&refpObject)
 
ICalibXmlSvcgetCalibXmlSvc ()
 
 XmlBaseCnv (ISvcLocator *svc, const CLID &clid)
 
- Public Member Functions inherited from Converter< Ty1, Ty2 >
destinationoperator (const source &) const
 
destinationoperator (const source &) const
 

Static Public Member Functions

static const unsigned char storageType ()
 

Protected Member Functions

virtual StatusCode internalCreateObj (const DOMElement *element, DataObject *&refpObject, IOpaqueAddress *address)
 
virtual StatusCode i_createObj (const DOMElement *element, DataObject *&refpObject)
 
virtual StatusCode i_processObj (DataObject *pObject, IOpaqueAddress *address)
 In case there is additional work to do on the created object.
 
virtual StatusCode readHeader (const DOMElement *)
 
DOMElement * findFirstRange (const DOMElement *docElt)
 
DOMElement * findNextRange (const DOMElement *rangeElt)
 Still another one to navigate XML file and find next set of range data.
 
DOMElement * findFirstDacCol (const DOMElement *docElt)
 Another one to find first dac collection element.
 
DOMElement * findNextDacCol (const DOMElement *rangeElt)
 Still another one to navigate XML file and find next dac collection.
 
CalibData::DacColprocessDacCol (DOMElement *dacColElt, unsigned *range)
 
CalibData::ValSigprocessValSig (DOMElement *elt, std::string valName, std::string sigName)
 Read in what will become a CalibData::ValSig.
 
std::vector< CalibData::ValSig > * processValSigs (DOMElement *elt, std::string valName, std::string sigName)
 Read in what will become a vector of CalibData::ValSig.
 
void setBaseInfo (CalibData::CalibBase *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
 

Protected Attributes

ICalibXmlSvcm_xmlSvc
 
ICalibMetaCnvSvcm_metaSvc
 
int m_serNo
 
ITime * m_vstart
 
ITime * m_vend
 

Additional Inherited Members

- Public Types inherited from Converter< Ty1, Ty2 >
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 36 of file XmlBaseCnv.h.

Constructor & Destructor Documentation

◆ ~XmlBaseCnv()

XERCES_CPP_NAMESPACE_USE XmlBaseCnv::~XmlBaseCnv ( )
virtual

Definition at line 40 of file XmlBaseCnv.cxx.

40{}

◆ XmlBaseCnv()

XmlBaseCnv::XmlBaseCnv ( 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 44 of file XmlBaseCnv.cxx.

44 :
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) */ {}
ICalibMetaCnvSvc * m_metaSvc
Definition: XmlBaseCnv.h:148
ICalibXmlSvc * m_xmlSvc
Definition: XmlBaseCnv.h:147
ITime * m_vend
Definition: XmlBaseCnv.h:152
ITime * m_vstart
Definition: XmlBaseCnv.h:151

Member Function Documentation

◆ createObj()

StatusCode XmlBaseCnv::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 84 of file XmlBaseCnv.cxx.

85 {
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}
virtual XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * parse(const char *filename)=0
virtual StatusCode internalCreateObj(const DOMElement *element, DataObject *&refpObject, IOpaqueAddress *address)
Definition: XmlBaseCnv.cxx:141
static int expandEnvVar(std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")"))
static unsigned trimTrailing(std::string *toTrim)

◆ finalize()

StatusCode XmlBaseCnv::finalize ( )
virtual

Definition at line 78 of file XmlBaseCnv.cxx.

78 {
79 return Converter::finalize();
80}

◆ findFirstDacCol()

DOMElement * XmlBaseCnv::findFirstDacCol ( const DOMElement *  docElt)
protected

Another one to find first dac collection element.

Definition at line 238 of file XmlBaseCnv.cxx.

238 {
239 return xmlBase::Dom::findFirstChildByName(docElt, "dac");
240}
static DOMElement * findFirstChildByName(const DOMElement *parent, const char *const name)
Definition: Dom.cxx:60

◆ findFirstRange()

DOMElement * XmlBaseCnv::findFirstRange ( const DOMElement *  docElt)
inlineprotected

Find first range element. Derived classes which need it must define their own implementation.

Definition at line 112 of file XmlBaseCnv.h.

112 {
113 return 0;}

◆ findNextDacCol()

DOMElement * XmlBaseCnv::findNextDacCol ( const DOMElement *  rangeElt)
protected

Still another one to navigate XML file and find next dac collection.

Definition at line 242 of file XmlBaseCnv.cxx.

242 {
243 DOMElement* next = xmlBase::Dom::getSiblingElement(dacElt);
244 if (xmlBase::Dom::checkTagName(next, "dac")) return next;
245 else return 0;
246}
static DOMElement * getSiblingElement(const DOMNode *child)
Return next element sibling, if any.
Definition: Dom.cxx:96
static bool checkTagName(const DOMElement *element, const std::string &tagName)
Definition: Dom.cxx:146
Index next(Index i)
Definition: EvtCyclic3.cc:107

◆ findNextRange()

DOMElement * XmlBaseCnv::findNextRange ( const DOMElement *  rangeElt)
inlineprotected

Still another one to navigate XML file and find next set of range data.

Definition at line 117 of file XmlBaseCnv.h.

117 {
118 return 0;}

◆ getCalibXmlSvc()

ICalibXmlSvc * XmlBaseCnv::getCalibXmlSvc ( )
inline

Definition at line 54 of file XmlBaseCnv.h.

54 {
55 return m_xmlSvc;
56 }

◆ i_createObj()

StatusCode XmlBaseCnv::i_createObj ( const DOMElement *  element,
DataObject *&  refpObject 
)
protectedvirtual

This creates the transient representation of an object from the DOM_Element representing it. 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
elementthe DOM_Element (typically root element of document) to be used to builds the object
refpObjectthe object to be built
Returns
status depending on the completion of the call

Reimplemented in XmlTest1Cnv.

Definition at line 205 of file XmlBaseCnv.cxx.

205 {
206 return StatusCode::FAILURE;
207}

Referenced by internalCreateObj().

◆ i_processObj()

StatusCode XmlBaseCnv::i_processObj ( DataObject *  pObject,
IOpaqueAddress *  address 
)
protectedvirtual

In case there is additional work to do on the created object.

Definition at line 198 of file XmlBaseCnv.cxx.

199 {
200 return StatusCode::SUCCESS;
201}

Referenced by internalCreateObj().

◆ initialize()

StatusCode XmlBaseCnv::initialize ( )
virtual

Definition at line 50 of file XmlBaseCnv.cxx.

50 {
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}

◆ internalCreateObj()

StatusCode XmlBaseCnv::internalCreateObj ( const DOMElement *  docElt,
DataObject *&  refpObject,
IOpaqueAddress *  address 
)
protectedvirtual

This creates the transient representation of an object from the DOMElement representing 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
elementthe DOMElement (typically the root element of the document) to be used to build the object
refpObjectthe object to be built
addressthe opaque address for this object
Returns
status depending on the completion of the call

In a backhanded way, invoke the right specific converter for the type of the object to be created

Parameters
eltDocument elt from XML document (input)
refpObject

Definition at line 141 of file XmlBaseCnv.cxx.

143 {
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}
virtual StatusCode i_processObj(DataObject *pObject, IOpaqueAddress *address)
In case there is additional work to do on the created object.
Definition: XmlBaseCnv.cxx:198
virtual StatusCode i_createObj(const DOMElement *element, DataObject *&refpObject)
Definition: XmlBaseCnv.cxx:205

Referenced by createObj().

◆ processDacCol()

CalibData::DacCol * XmlBaseCnv::processDacCol ( DOMElement *  dacColElt,
unsigned *  range 
)
protected

Definition at line 248 of file XmlBaseCnv.cxx.

249 {
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}

◆ processValSig()

CalibData::ValSig * XmlBaseCnv::processValSig ( DOMElement *  elt,
std::string  valName,
std::string  sigName 
)
protected

Read in what will become a CalibData::ValSig.

Definition at line 288 of file XmlBaseCnv.cxx.

290 {
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}
static double getDoubleAttribute(const DOMNode *elt, std::string attName)
Definition: Dom.cxx:263

◆ processValSigs()

std::vector< CalibData::ValSig > * XmlBaseCnv::processValSigs ( DOMElement *  elt,
std::string  valName,
std::string  sigName 
)
protected

Read in what will become a vector of CalibData::ValSig.

Definition at line 299 of file XmlBaseCnv.cxx.

300 {
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
static unsigned getFloatsAttribute(const DOMNode *elt, std::string attName, std::vector< float > &values, bool clear=true)
Definition: Dom.cxx:302

◆ readHeader()

StatusCode XmlBaseCnv::readHeader ( const DOMElement *  )
protectedvirtual

Definition at line 220 of file XmlBaseCnv.cxx.

220 {
221 return StatusCode::SUCCESS;
222}

◆ setBaseInfo()

void XmlBaseCnv::setBaseInfo ( CalibData::CalibBase 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 232 of file XmlBaseCnv.cxx.

232 {
233 pObj->setValidity(*m_vstart, *m_vend);
234 pObj->setSerNo(m_serNo);
235}

◆ storageType()

const unsigned char XmlBaseCnv::storageType ( )
static

Definition at line 224 of file XmlBaseCnv.cxx.

224 {
225 return XML_StorageType;
226}

Member Data Documentation

◆ m_metaSvc

ICalibMetaCnvSvc* XmlBaseCnv::m_metaSvc
protected

Definition at line 148 of file XmlBaseCnv.h.

Referenced by initialize().

◆ m_serNo

int XmlBaseCnv::m_serNo
protected

Definition at line 150 of file XmlBaseCnv.h.

Referenced by XmlTest1Cnv::i_createObj(), internalCreateObj(), and setBaseInfo().

◆ m_vend

ITime* XmlBaseCnv::m_vend
protected

Definition at line 152 of file XmlBaseCnv.h.

Referenced by XmlTest1Cnv::i_createObj(), and setBaseInfo().

◆ m_vstart

ITime* XmlBaseCnv::m_vstart
protected

Definition at line 151 of file XmlBaseCnv.h.

Referenced by XmlTest1Cnv::i_createObj(), and setBaseInfo().

◆ m_xmlSvc

ICalibXmlSvc* XmlBaseCnv::m_xmlSvc
protected

Definition at line 147 of file XmlBaseCnv.h.

Referenced by createObj(), getCalibXmlSvc(), and initialize().


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