XmlBaseCnv Class Reference

#include <XmlBaseCnv.h>

Inheritance diagram for XmlBaseCnv:

Converter< Ty1, Ty2 > XmlTest1Cnv List of all members.

Public Types

typedef Ty1 source
typedef Ty2 destination

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)
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.
virtual destinationconvert (const source &) const =0

Protected Attributes

ICalibXmlSvcm_xmlSvc
ICalibMetaCnvSvcm_metaSvc
int m_serNo
ITime * m_vstart
ITime * m_vend

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.


Member Typedef Documentation

template<class Ty1, class Ty2>
typedef Ty2 Converter< Ty1, Ty2 >::destination [inherited]

Definition at line 19 of file Converter.h.

template<class Ty1, class Ty2>
typedef Ty1 Converter< Ty1, Ty2 >::source [inherited]

Definition at line 18 of file Converter.h.


Constructor & Destructor Documentation

XERCES_CPP_NAMESPACE_USE XmlBaseCnv::~XmlBaseCnv (  )  [virtual]

Definition at line 40 of file XmlBaseCnv.cxx.

00040 {}

XmlBaseCnv::XmlBaseCnv ( ISvcLocator *  svc,
const CLID &  clid 
)

Constructor for this converter

Parameters:
svc a ISvcLocator interface to find services
clid the type of object the converter is able to convert

Definition at line 44 of file XmlBaseCnv.cxx.

00044                                                           :
00045   Converter (XML_StorageType, clid, svc),
00046   m_xmlSvc (0), m_metaSvc(0), m_vstart(0), m_vend(0) /*,
00047   m_nRow(10000), m_nCol(10000), m_nLayer(10000), m_nXtal(10000),
00048   m_nFace(10000), m_nRange(10000) */  {}


Member Function Documentation

template<class Ty1, class Ty2>
virtual destination* Converter< Ty1, Ty2 >::convert ( const source  )  const [protected, pure virtual, inherited]

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.

References Bes_Common::FATAL, Bes_Common::INFO, internalCreateObj(), m_xmlSvc, msgSvc(), ICalibXmlSvc::parse(), and deljobs::string.

00085                                                             {
00086 
00087    // creates a msg stream for debug purposes
00088    MsgStream log( msgSvc(), "XmlBaseCnv" );
00089    
00090    if (0 == addr) {
00091      return StatusCode::FAILURE;
00092    }
00093 
00094   // first do the things we always need:
00095   //   First string parameter of opaque address is file ident
00096   //   Parse file into DOM representation
00097   const std::string* par = addr->par();
00098 
00099   std::string par0 = par[0];
00100 
00101   // Ignore trailing white space.
00102   facilities::Util::trimTrailing(&par0);
00103 
00104   // Just in case there are environment variables in the file specification
00105   //  int nSub = 
00106   facilities::Util::expandEnvVar(&par0);
00107 
00108   //  XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* doc = 
00109   DOMDocument* doc = 
00110     m_xmlSvc->parse(par0.c_str());
00111 
00112   if (doc == 0 ) {
00113     log << MSG::FATAL 
00114         << "Unable to parse document " << par[0] << " aka " 
00115         << par0 << endreq;
00116     return StatusCode::FAILURE;
00117   }
00118   else {
00119     log << MSG::INFO
00120         << "successfully parsed document " << par[0] << " aka " 
00121         << par0 << endreq;
00122   }
00123 
00124   // Could conceivably write some code here to handle generic
00125   // parts of document.  Or, alternatively, add services to
00126   // CalibXmlCnvSvc for converters to invoke to do this.
00127 
00128   // Then do some fancy footwork in internalCreateObj to get the 
00129   // appropriate specific converter invoked to interpret the DOM 
00130   // correctly and make a new object of the correct kind.
00131 
00132   return internalCreateObj(doc->getDocumentElement(), refpObject, addr);
00133 }

StatusCode XmlBaseCnv::finalize (  )  [virtual]

Definition at line 78 of file XmlBaseCnv.cxx.

00078                                 {
00079   return Converter::finalize();
00080 }

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

Another one to find first dac collection element.

Definition at line 238 of file XmlBaseCnv.cxx.

References xmlBase::Dom::findFirstChildByName().

00238                                                                 {
00239   return  xmlBase::Dom::findFirstChildByName(docElt, "dac");
00240 }

DOMElement* XmlBaseCnv::findFirstRange ( const DOMElement *  docElt  )  [inline, protected]

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

Definition at line 112 of file XmlBaseCnv.h.

00112                                                        {
00113     return 0;}

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.

References xmlBase::Dom::checkTagName(), xmlBase::Dom::getSiblingElement(), and next.

00242                                                                {
00243   DOMElement* next = xmlBase::Dom::getSiblingElement(dacElt);
00244   if (xmlBase::Dom::checkTagName(next, "dac")) return next;
00245   else return 0;
00246 }

DOMElement* XmlBaseCnv::findNextRange ( const DOMElement *  rangeElt  )  [inline, protected]

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

Definition at line 117 of file XmlBaseCnv.h.

00117                                                         {
00118     return 0;}

ICalibXmlSvc* XmlBaseCnv::getCalibXmlSvc (  )  [inline]

Definition at line 54 of file XmlBaseCnv.h.

References m_xmlSvc.

00054                                  {
00055     return m_xmlSvc;
00056   }

StatusCode XmlBaseCnv::i_createObj ( const DOMElement *  element,
DataObject *&  refpObject 
) [protected, virtual]

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:
element the DOM_Element (typically root element of document) to be used to builds the object
refpObject the object to be built
Returns:
status depending on the completion of the call

Reimplemented in XmlTest1Cnv.

Definition at line 205 of file XmlBaseCnv.cxx.

Referenced by internalCreateObj().

00205                                                                   {
00206   return StatusCode::FAILURE;
00207 }

StatusCode XmlBaseCnv::i_processObj ( DataObject *  pObject,
IOpaqueAddress *  address 
) [protected, virtual]

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

Definition at line 198 of file XmlBaseCnv.cxx.

Referenced by internalCreateObj().

00199                                                                      {
00200   return StatusCode::SUCCESS;
00201 }

StatusCode XmlBaseCnv::initialize (  )  [virtual]

Definition at line 50 of file XmlBaseCnv.cxx.

References IID_ICalibMetaCnvSvc(), IID_ICalibXmlSvc(), m_metaSvc, and m_xmlSvc.

00050                                   {
00051   StatusCode status = Converter::initialize();
00052 
00053   IDataProviderSvc* dp;
00054 
00055   // I guess the service names are assigned in jobOptions?
00056 
00057   serviceLocator()->getService ("CalibDataSvc",
00058                                 IID_IDataProviderSvc,
00059                                 (IInterface*&)dp);
00060   setDataProvider(dp);
00061   
00062   // Locate the Xml Conversion Service
00063   serviceLocator()->getService ("CalibXmlCnvSvc",
00064                                 IID_ICalibXmlSvc,
00065                                 (IInterface*&)m_xmlSvc);
00066 
00067   // Locate meta conversion service
00068   // Will anything need to be changed here to accommodate possibility
00069   // of two concrete implementations of ICalibMetaCnvSvc?  Would
00070   // have different storage types.  Could specify type desired
00071   // as job option.  Ditto for name of class?
00072   serviceLocator()->getService("CalibMySQLCnvSvc", 
00073                                IID_ICalibMetaCnvSvc,
00074                                 (IInterface*&)m_metaSvc);
00075   return status;
00076 }

StatusCode XmlBaseCnv::internalCreateObj ( const DOMElement *  element,
DataObject *&  refpObject,
IOpaqueAddress *  address 
) [protected, virtual]

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:
element the DOMElement (typically the root element of the document) to be used to build the object
refpObject the object to be built
address the opaque address for this object
Returns:
status depending on the completion of the call

Definition at line 141 of file XmlBaseCnv.cxx.

References Bes_Common::DEBUG, calibUtil::ERROR, i_createObj(), i_processObj(), m_serNo, msgSvc(), and Bes_Common::WARNING.

Referenced by createObj().

00143                                                                   {
00144   // creates a msg stream for debug purposes
00145   MsgStream log( msgSvc(), "XmlBaseCnv" );
00146   
00147   // We're the default if we can't find anything better
00148   XmlBaseCnv* converter = this;      
00149 
00150   CLID classId = address->clID();
00151 
00152   IConverter* conv = this->conversionSvc()->converter(classId);
00153 
00154   if (0 == conv) {
00155     log << MSG::WARNING
00156         << "No proper converter found for classID " << classId
00157             << ", the default converter"
00158             << " will be used. " << endreq;
00159   } else {
00160     converter = dynamic_cast <XmlBaseCnv*> (conv);
00161     if (0 == converter) {
00162       log << MSG::ERROR
00163           << "The converter found for classID " << classId
00164               << " was not a descendent of XmlBaseCnv as it should be "
00165               << "( was of type " << typeid (*converter).name() << "). "
00166               << "The default converter will be used" << endreq;
00167       converter = this;
00168     }
00169   }
00170 
00171   unsigned int serNo = *(address->ipar());
00172   m_serNo = serNo;
00173 /* maqm comment for remove getValidInterval()
00174  StatusCode sc = m_metaSvc->getValidInterval(serNo, 
00175                                               &m_vstart, 
00176                                               &m_vend );
00177 
00178 
00179   // creates an object for the node found
00180 
00181   
00182    if (sc.isSuccess()) sc = converter->i_createObj (docElt, refpObject);
00183  */ 
00184    StatusCode sc = converter->i_createObj (docElt, refpObject);
00185    if (sc.isFailure()) {
00186     return sc;
00187   }
00188 
00189   // ends up the object construction
00190   sc = converter->i_processObj(refpObject, address);
00191   if (sc.isSuccess()) {
00192     log << MSG::DEBUG << "Successfully created calib. object " << endreq;
00193   }
00194   return sc;
00195 } 

template<class Ty1, class Ty2>
destination* Converter< Ty1, Ty2 >::operator ( const source  )  const [inline, inherited]

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

Definition at line 248 of file XmlBaseCnv.cxx.

References deljobs::string.

00249                                                               {
00250 
00251   using xmlBase::Dom;
00252 //maqm comment  using idents::CalXtalId;
00253 
00254   std::string att = Dom::getAttribute(dacColElt, "range");
00255 /* maqm comment
00256   if (att.compare(std::string("LEX8")) == 0) *range = CalXtalId::LEX8;
00257   if (att.compare(std::string("LEX1")) == 0) *range = CalXtalId::LEX1;
00258   if (att.compare(std::string("HEX8")) == 0) *range = CalXtalId::HEX8;
00259   if (att.compare(std::string("HEX1")) == 0) *range = CalXtalId::HEX1; 
00260 */
00261   //  *range = Dom::getIntAttribute(dacColElt, "range");
00262   std::vector<int> vals;
00263 
00264   Dom::getIntsAttribute(dacColElt, "values", vals);
00265 
00266   CalibData::DacCol* pDacCol = new CalibData::DacCol(&vals);
00267   return pDacCol;
00268 
00269 }

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.

References xmlBase::Dom::getDoubleAttribute(), CalibData::ValSig::m_sig, and CalibData::ValSig::m_val.

00290                                                                 {
00291   if (elt == 0 ) return 0;
00292   CalibData::ValSig *pValSig = new CalibData::ValSig;
00293   pValSig->m_val = xmlBase::Dom::getDoubleAttribute(elt, valName);
00294   pValSig->m_sig = xmlBase::Dom::getDoubleAttribute(elt, sigName);
00295   return pValSig;
00296 }

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.

References calibUtil::ERROR, xmlBase::Dom::getFloatsAttribute(), genRecEmupikp::i, and msgSvc().

00300                                               {
00301 
00302   // creates a msg stream for debug purposes
00303   MsgStream log( msgSvc(), "XmlBaseCnv" );
00304 
00305   if (elt == 0 ) return 0;
00306   std::vector<float> vals;
00307   std::vector<float> sigs;
00308 
00309   xmlBase::Dom::getFloatsAttribute(elt, valName, vals);
00310   xmlBase::Dom::getFloatsAttribute(elt, sigName, sigs);
00311   if (vals.size() != sigs.size() ) {
00312     log << MSG::ERROR << "#values <> #sigmas " << endreq;
00313     return 0;
00314   }
00315   unsigned n = vals.size();
00316   std::vector<CalibData::ValSig>* pValSigs = 
00317     new std::vector<CalibData::ValSig>(n);
00318   for (unsigned i = 0; i < n; i++) {
00319     (*pValSigs)[i].m_val = vals[i];
00320     (*pValSigs)[i].m_sig = sigs[i];
00321   }
00322   return pValSigs;
00323 }

StatusCode XmlBaseCnv::readHeader ( const DOMElement *   )  [protected, virtual]

Definition at line 220 of file XmlBaseCnv.cxx.

00220                                                    {
00221   return StatusCode::SUCCESS;
00222 }

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.

References m_serNo, m_vend, m_vstart, and CalibData::CalibBase::setSerNo().

00232                                                      {
00233   pObj->setValidity(*m_vstart, *m_vend);
00234   pObj->setSerNo(m_serNo);
00235 }

const unsigned char XmlBaseCnv::storageType (  )  [static]

Definition at line 224 of file XmlBaseCnv.cxx.

00224                                             {
00225   return XML_StorageType;
00226 }


Member Data Documentation

ICalibMetaCnvSvc* XmlBaseCnv::m_metaSvc [protected]

Definition at line 148 of file XmlBaseCnv.h.

Referenced by initialize().

int XmlBaseCnv::m_serNo [protected]

Definition at line 150 of file XmlBaseCnv.h.

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

ITime* XmlBaseCnv::m_vend [protected]

Definition at line 152 of file XmlBaseCnv.h.

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

ITime* XmlBaseCnv::m_vstart [protected]

Definition at line 151 of file XmlBaseCnv.h.

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

ICalibXmlSvc* XmlBaseCnv::m_xmlSvc [protected]

Definition at line 147 of file XmlBaseCnv.h.

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


Generated on Tue Nov 29 23:36:22 2016 for BOSS_7.0.2 by  doxygen 1.4.7