BOSS 8.0.0
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
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
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
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 41 of file XmlBaseCnv.cxx.

41{}

◆ 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 45 of file XmlBaseCnv.cxx.

46 : Converter( XML_StorageType, clid, svc )
47 , m_xmlSvc( 0 )
48 , m_metaSvc( 0 )
49 , m_vstart( 0 )
50 , m_vend( 0 ) /*,
51m_nRow(10000), m_nCol(10000), m_nLayer(10000), m_nXtal(10000),
52m_nFace(10000), m_nRange(10000) */
53{}
ICalibMetaCnvSvc * m_metaSvc
Definition XmlBaseCnv.h:136
ICalibXmlSvc * m_xmlSvc
Definition XmlBaseCnv.h:135
ITime * m_vend
Definition XmlBaseCnv.h:140
ITime * m_vstart
Definition XmlBaseCnv.h:139

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

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 82 of file XmlBaseCnv.cxx.

82 {
83
84 // creates a msg stream for debug purposes
85 MsgStream log( msgSvc(), "XmlBaseCnv" );
86
87 if ( 0 == addr ) { return StatusCode::FAILURE; }
88
89 // first do the things we always need:
90 // First string parameter of opaque address is file ident
91 // Parse file into DOM representation
92 const std::string* par = addr->par();
93
94 std::string par0 = par[0];
95
96 // Ignore trailing white space.
98
99 // Just in case there are environment variables in the file specification
100 // int nSub =
102
103 // XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* doc =
104 DOMDocument* doc = m_xmlSvc->parse( par0.c_str() );
105
106 if ( doc == 0 )
107 {
108 log << MSG::FATAL << "Unable to parse document " << par[0] << " aka " << par0 << endmsg;
109 return StatusCode::FAILURE;
110 }
111 else
112 {
113 log << MSG::INFO << "successfully parsed document " << par[0] << " aka " << par0 << endmsg;
114 }
115
116 // Could conceivably write some code here to handle generic
117 // parts of document. Or, alternatively, add services to
118 // CalibXmlCnvSvc for converters to invoke to do this.
119
120 // Then do some fancy footwork in internalCreateObj to get the
121 // appropriate specific converter invoked to interpret the DOM
122 // correctly and make a new object of the correct kind.
123
124 return internalCreateObj( doc->getDocumentElement(), refpObject, addr );
125}
IMessageSvc * msgSvc()
virtual StatusCode internalCreateObj(const DOMElement *element, DataObject *&refpObject, IOpaqueAddress *address)
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{ return Converter::finalize(); }

◆ findFirstDacCol()

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

Another one to find first dac collection element.

Definition at line 221 of file XmlBaseCnv.cxx.

221 {
222 return xmlBase::Dom::findFirstChildByName( docElt, "dac" );
223}
static DOMElement * findFirstChildByName(const DOMElement *parent, const char *const name)
Definition Dom.cxx:58

◆ 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 104 of file XmlBaseCnv.h.

104{ 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 225 of file XmlBaseCnv.cxx.

225 {
226 DOMElement* next = xmlBase::Dom::getSiblingElement( dacElt );
227 if ( xmlBase::Dom::checkTagName( next, "dac" ) ) return next;
228 else return 0;
229}
static DOMElement * getSiblingElement(const DOMNode *child)
Return next element sibling, if any.
Definition Dom.cxx:90
static bool checkTagName(const DOMElement *element, const std::string &tagName)
Definition Dom.cxx:136
Index next(Index i)

◆ 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 107 of file XmlBaseCnv.h.

107{ return 0; }

◆ getCalibXmlSvc()

ICalibXmlSvc * XmlBaseCnv::getCalibXmlSvc ( )
inline

Definition at line 52 of file XmlBaseCnv.h.

52{ return m_xmlSvc; }

◆ 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 193 of file XmlBaseCnv.cxx.

193 {
194 return StatusCode::FAILURE;
195}

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

188 {
189 return StatusCode::SUCCESS;
190}

Referenced by internalCreateObj().

◆ initialize()

StatusCode XmlBaseCnv::initialize ( )
virtual

Definition at line 55 of file XmlBaseCnv.cxx.

55 {
56 StatusCode status = Converter::initialize();
57
58 IDataProviderSvc* dp;
59
60 // I guess the service names are assigned in jobOptions?
61
62 serviceLocator()->getService( "CalibDataSvc", IID_IDataProviderSvc, (IInterface*&)dp );
63 setDataProvider( dp );
64
65 // Locate the Xml Conversion Service
66 serviceLocator()->getService( "CalibXmlCnvSvc", IID_ICalibXmlSvc, (IInterface*&)m_xmlSvc );
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", 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 132 of file XmlBaseCnv.cxx.

133 {
134 // creates a msg stream for debug purposes
135 MsgStream log( msgSvc(), "XmlBaseCnv" );
136
137 // We're the default if we can't find anything better
138 XmlBaseCnv* converter = this;
139
140 CLID classId = address->clID();
141
142 IConverter* conv = this->conversionSvc()->converter( classId );
143
144 if ( 0 == conv )
145 {
146 log << MSG::WARNING << "No proper converter found for classID " << classId
147 << ", the default converter"
148 << " will be used. " << endmsg;
149 }
150 else
151 {
152 converter = dynamic_cast<XmlBaseCnv*>( conv );
153 if ( 0 == converter )
154 {
155 log << MSG::ERROR << "The converter found for classID " << classId
156 << " was not a descendent of XmlBaseCnv as it should be "
157 << "( was of type " << typeid( *converter ).name() << "). "
158 << "The default converter will be used" << endmsg;
159 converter = this;
160 }
161 }
162
163 unsigned int serNo = *( address->ipar() );
164 m_serNo = serNo;
165 /* maqm comment for remove getValidInterval()
166 StatusCode sc = m_metaSvc->getValidInterval(serNo,
167 &m_vstart,
168 &m_vend );
169
170
171 // creates an object for the node found
172
173
174 if (sc.isSuccess()) sc = converter->i_createObj (docElt, refpObject);
175 */
176 StatusCode sc = converter->i_createObj( docElt, refpObject );
177 if ( sc.isFailure() ) { return sc; }
178
179 // ends up the object construction
180 sc = converter->i_processObj( refpObject, address );
181 if ( sc.isSuccess() )
182 { log << MSG::DEBUG << "Successfully created calib. object " << endmsg; }
183 return sc;
184}
virtual StatusCode i_processObj(DataObject *pObject, IOpaqueAddress *address)
In case there is additional work to do on the created object.
XmlBaseCnv(ISvcLocator *svc, const CLID &clid)
virtual StatusCode i_createObj(const DOMElement *element, DataObject *&refpObject)

Referenced by createObj().

◆ processDacCol()

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

Definition at line 231 of file XmlBaseCnv.cxx.

231 {
232
233 using xmlBase::Dom;
234 // maqm comment using idents::CalXtalId;
235
236 std::string att = Dom::getAttribute( dacColElt, "range" );
237 /* maqm comment
238 if (att.compare(std::string("LEX8")) == 0) *range = CalXtalId::LEX8;
239 if (att.compare(std::string("LEX1")) == 0) *range = CalXtalId::LEX1;
240 if (att.compare(std::string("HEX8")) == 0) *range = CalXtalId::HEX8;
241 if (att.compare(std::string("HEX1")) == 0) *range = CalXtalId::HEX1;
242 */
243 // *range = Dom::getIntAttribute(dacColElt, "range");
244 std::vector<int> vals;
245
246 Dom::getIntsAttribute( dacColElt, "values", vals );
247
248 CalibData::DacCol* pDacCol = new CalibData::DacCol( &vals );
249 return pDacCol;
250}

◆ 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 269 of file XmlBaseCnv.cxx.

270 {
271 if ( elt == 0 ) return 0;
272 CalibData::ValSig* pValSig = new CalibData::ValSig;
273 pValSig->m_val = xmlBase::Dom::getDoubleAttribute( elt, valName );
274 pValSig->m_sig = xmlBase::Dom::getDoubleAttribute( elt, sigName );
275 return pValSig;
276}
static double getDoubleAttribute(const DOMNode *elt, std::string attName)
Definition Dom.cxx:231

◆ 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 279 of file XmlBaseCnv.cxx.

279 {
280
281 // creates a msg stream for debug purposes
282 MsgStream log( msgSvc(), "XmlBaseCnv" );
283
284 if ( elt == 0 ) return 0;
285 std::vector<float> vals;
286 std::vector<float> sigs;
287
288 xmlBase::Dom::getFloatsAttribute( elt, valName, vals );
289 xmlBase::Dom::getFloatsAttribute( elt, sigName, sigs );
290 if ( vals.size() != sigs.size() )
291 {
292 log << MSG::ERROR << "#values <> #sigmas " << endmsg;
293 return 0;
294 }
295 unsigned n = vals.size();
296 std::vector<CalibData::ValSig>* pValSigs = new std::vector<CalibData::ValSig>( n );
297 for ( unsigned i = 0; i < n; i++ )
298 {
299 ( *pValSigs )[i].m_val = vals[i];
300 ( *pValSigs )[i].m_sig = sigs[i];
301 }
302 return pValSigs;
303}
const Int_t n
static unsigned getFloatsAttribute(const DOMNode *elt, std::string attName, std::vector< float > &values, bool clear=true)
Definition Dom.cxx:271

◆ readHeader()

StatusCode XmlBaseCnv::readHeader ( const DOMElement * )
protectedvirtual

Definition at line 208 of file XmlBaseCnv.cxx.

208{ return StatusCode::SUCCESS; }

◆ 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 216 of file XmlBaseCnv.cxx.

216 {
217 pObj->setValidity( *m_vstart, *m_vend );
218 pObj->setSerNo( m_serNo );
219}

◆ storageType()

const unsigned char XmlBaseCnv::storageType ( )
static

Definition at line 210 of file XmlBaseCnv.cxx.

210{ return XML_StorageType; }

Member Data Documentation

◆ m_metaSvc

ICalibMetaCnvSvc* XmlBaseCnv::m_metaSvc
protected

Definition at line 136 of file XmlBaseCnv.h.

Referenced by initialize(), and XmlBaseCnv().

◆ m_serNo

int XmlBaseCnv::m_serNo
protected

Definition at line 138 of file XmlBaseCnv.h.

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

◆ m_vend

ITime* XmlBaseCnv::m_vend
protected

Definition at line 140 of file XmlBaseCnv.h.

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

◆ m_vstart

ITime* XmlBaseCnv::m_vstart
protected

Definition at line 139 of file XmlBaseCnv.h.

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

◆ m_xmlSvc

ICalibXmlSvc* XmlBaseCnv::m_xmlSvc
protected

Definition at line 135 of file XmlBaseCnv.h.

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


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