CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Attributes

XMLProcessor Class Reference

#include <CalibCalorimetry/HcalTPGAlgos/interface/XMLProcessor.h>

List of all members.

Classes

struct  _checksumsDBConfig
struct  _DBConfig
struct  _LMapRowHBEF
struct  _LMapRowHO
struct  _loaderBaseConfig
struct  _lutDBConfig

Public Types

typedef
XMLProcessor::_checksumsDBConfig 
checksumsDBConfig
typedef struct
XMLProcessor::_DBConfig 
DBConfig
typedef struct
XMLProcessor::_LMapRowHBEF 
LMapRowHBEF
typedef struct
XMLProcessor::_LMapRowHO 
LMapRowHO
typedef struct
XMLProcessor::_loaderBaseConfig 
loaderBaseConfig
typedef XMLProcessor::_lutDBConfig lutDBConfig

Public Member Functions

int addLMapHBEFDataset (XMLDOMBlock *doc, LMapRowHBEF *row, std::string templateFileName)
int addLMapHODataset (XMLDOMBlock *doc, LMapRowHO *row, std::string templateFileName)
XMLDOMBlockcreateLMapHBEFXMLBase (std::string templateFileName)
XMLDOMBlockcreateLMapHOXMLBase (std::string templateFileName)
int init (void)
XMLCh * serializeDOM (DOMNode *node, std::string target="stdout")
int terminate (void)
int test (void)
int write (XMLDOMBlock *doc, std::string target="stdout")
virtual ~XMLProcessor ()

Static Public Member Functions

static XMLCh * _toXMLCh (std::string temp)
static XMLCh * _toXMLCh (time_t temp)
static XMLCh * _toXMLCh (double temp)
static XMLCh * _toXMLCh (int temp)
static XMLProcessorgetInstance ()

Private Member Functions

 XMLProcessor ()
 XMLProcessor (const XMLProcessor &)

Static Private Attributes

static XMLProcessorinstance = NULL

Detailed Description

Description: Testing Xerces library for processing HCAL DB XML wrappers

Usage: <usage>

Definition at line 44 of file XMLProcessor.h.


Member Typedef Documentation


Constructor & Destructor Documentation

XMLProcessor::~XMLProcessor ( ) [virtual]

Definition at line 51 of file XMLProcessor.cc.

{
  // terminates Xerces
  terminate();
}
XMLProcessor::XMLProcessor ( ) [private]

Definition at line 45 of file XMLProcessor.cc.

References init.

Referenced by getInstance().

{
  // initializes Xerces, must be done only once
  init();
}
XMLProcessor::XMLProcessor ( const XMLProcessor ) [private]

Member Function Documentation

XMLCh * XMLProcessor::_toXMLCh ( std::string  temp) [inline, static]
XMLCh * XMLProcessor::_toXMLCh ( int  temp) [inline, static]

Definition at line 191 of file XMLProcessor.h.

References gather_cfg::cout, and ntuplemaker::status.

{
  char buf[100];
  int status = snprintf( buf, 100, "%d", temp );
  if ( status >= 100 )
    {
      std::cout << "XMLProcessor::_toXMLCh(int temp): buffer overflow, the std::string will be truncated!" << std::endl;
    }
  else if ( status <0 )
    {
      std::cout << "XMLProcessor::_toXMLCh(int temp): output error" << std::endl;
    }
  XMLCh* buff = XMLString::transcode( buf );    
  return  buff;
}
XMLCh * XMLProcessor::_toXMLCh ( double  temp) [inline, static]

Definition at line 207 of file XMLProcessor.h.

References gather_cfg::cout, and ntuplemaker::status.

{
  char buf[100];
  int status = snprintf( buf, 100, "%.10e", temp );
  if ( status >= 100 )
    {
      std::cout << "XMLProcessor::_toXMLCh(int temp): buffer overflow, the std::string will be truncated!" << std::endl;
    }
  else if ( status <0 )
    {
      std::cout << "XMLProcessor::_toXMLCh(int temp): output error" << std::endl;
    }
  XMLCh* buff = XMLString::transcode( buf );    
  return  buff;
}
XMLCh * XMLProcessor::_toXMLCh ( time_t  temp) [inline, static]

Definition at line 223 of file XMLProcessor.h.

References gather_cfg::cout, and ntuplemaker::status.

{
  char buf[100];
  int status = strftime( buf, 50, "%c", gmtime( &temp ) );
  if ( status == 0 )
    {
      std::cout << "XML  Processor::_toXMLCh(int temp): buffer overflow, the std::string is indeterminate!" << std::endl;
    }
  XMLCh* buff = XMLString::transcode( buf );    
  return  buff;
}
int XMLProcessor::addLMapHBEFDataset ( XMLDOMBlock doc,
LMapRowHBEF row,
std::string  templateFileName 
)

Definition at line 95 of file XMLProcessor.cc.

References ecalMGPA::adc(), eta(), phi, submit::rm, and dbtoconf::root.

{
  DOMDocument * loader = doc -> getDocument();
  DOMElement * root = loader -> getDocumentElement();

  XMLDOMBlock dataSetDoc( templateFileName );
  DOMDocument * dataSet = dataSetDoc . getDocument();
  
  //Dataset
  dataSet -> getElementsByTagName( _toXMLCh( "SIDE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> side ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "ETA" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row ->  eta) );  
  dataSet -> getElementsByTagName( _toXMLCh( "PHI" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> phi ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "DELTA_PHI" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> dphi ) );  

  dataSet -> getElementsByTagName( _toXMLCh( "DEPTH" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> depth  ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "SUBDETECTOR" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> det ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "RBX_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rbx ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "WEDGE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> wedge ) );
 
  dataSet -> getElementsByTagName( _toXMLCh( "RM_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rm  ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "HPD_PIXEL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> pixel ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "QIE_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> qie ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "ADC" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> adc ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "RM_FIBER" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rm_fi ) );

  dataSet -> getElementsByTagName( _toXMLCh( "FIBER_CHANNEL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> fi_ch));
  dataSet -> getElementsByTagName( _toXMLCh( "CRATE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> crate ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "HTR_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row ->  htr ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "HTR_FPGA" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> fpga ) );

  dataSet -> getElementsByTagName( _toXMLCh( "HTR_FIBER" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> htr_fi ));  
  dataSet -> getElementsByTagName( _toXMLCh( "DCC_SL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> dcc_sl ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "SPIGOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row ->  spigo ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "DCC_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> dcc ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "SLB_SITE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> slb ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "SLB_CHANNEL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> slbin )); 
  dataSet -> getElementsByTagName( _toXMLCh( "SLB_CHANNEL2" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> slbin2));

  dataSet -> getElementsByTagName( _toXMLCh( "SLB_CABLE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> slnam ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "RCT_CRATE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rctcra ) ); 
  dataSet -> getElementsByTagName( _toXMLCh( "RCT_CARD" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rctcar ) );
  dataSet -> getElementsByTagName( _toXMLCh( "RCT_CONNECTOR" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row ->rctcon));
  dataSet -> getElementsByTagName( _toXMLCh( "RCT_NAME" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rctnam ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "FED_ID" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> fedid ) );
  
      
  // copy the <data_set> node into the final XML
  DOMNode * cloneDataSet = loader -> importNode( dataSet -> getDocumentElement(), true );
  root -> appendChild( cloneDataSet );

  return 0;
}
int XMLProcessor::addLMapHODataset ( XMLDOMBlock doc,
LMapRowHO row,
std::string  templateFileName 
)

Definition at line 161 of file XMLProcessor.cc.

References dbtoconf::root.

{
  DOMDocument * loader = doc -> getDocument();
  DOMElement * root = loader -> getDocumentElement();

  XMLDOMBlock dataSetDoc( templateFileName );
  DOMDocument * dataSet = dataSetDoc . getDocument();
  
  //Dataset
  dataSet -> getElementsByTagName( _toXMLCh( "SIDE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> sideO ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "ETA" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row ->  etaO ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "PHI" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> phiO ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "DELTA_PHI" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> dphiO ) );
  
  dataSet -> getElementsByTagName( _toXMLCh( "DEPTH" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> depthO  ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "SUBDETECTOR" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> detO ) ); 
  dataSet -> getElementsByTagName( _toXMLCh( "RBX_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rbxO ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "SECTOR" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> sectorO ) );
 
  dataSet -> getElementsByTagName( _toXMLCh( "RM_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rmO  ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "HPD_PIXEL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> pixelO ) ); 
  dataSet -> getElementsByTagName( _toXMLCh( "QIE_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> qieO ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "ADC" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> adcO ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "RM_FIBER" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rm_fiO ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "FIBER_CHANNEL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row ->fi_chO));

  dataSet -> getElementsByTagName( _toXMLCh( "LETTER_CODE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh(row ->let_codeO));
  dataSet -> getElementsByTagName( _toXMLCh( "CRATE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> crateO ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "HTR_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row ->  htrO ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "HTR_FPGA" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> fpgaO ) );

  dataSet -> getElementsByTagName( _toXMLCh( "HTR_FIBER" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> htr_fiO ) );
  dataSet -> getElementsByTagName( _toXMLCh( "DCC_SL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> dcc_slO ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "SPIGOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row ->  spigoO ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "DCC_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> dccO ) );  
  dataSet -> getElementsByTagName( _toXMLCh( "FED_ID" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> fedidO ) );
  
      
  // copy the <data_set> node into the final XML
  DOMNode * cloneDataSet = loader -> importNode( dataSet -> getDocumentElement(), true );
  root -> appendChild( cloneDataSet );

  return 0;
}
XMLDOMBlock * XMLProcessor::createLMapHBEFXMLBase ( std::string  templateFileName)

Definition at line 82 of file XMLProcessor.cc.

References query::result.

{
  XMLDOMBlock * result = new XMLDOMBlock( templateFileName );
  DOMDocument * loader = result -> getDocument();
  //DOMElement * root = loader -> getDocumentElement();

  loader -> getElementsByTagName( _toXMLCh( "NAME" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( "HCAL LMAP for HB, HE, HF" ) );
  //DOMElement * _tag = (DOMElement *)(loader -> getElementsByTagName( _toXMLCh( "TAG" ) ) -> item(0));
  //_tag -> setAttribute( _toXMLCh("mode"), _toXMLCh("test_mode") );

  return result;
}
XMLDOMBlock * XMLProcessor::createLMapHOXMLBase ( std::string  templateFileName)

Definition at line 148 of file XMLProcessor.cc.

References query::result.

{
  XMLDOMBlock * result = new XMLDOMBlock( templateFileName );
  DOMDocument * loader = result -> getDocument();
  //DOMElement * root = loader -> getDocumentElement();

  loader -> getElementsByTagName( _toXMLCh( "NAME" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( "HCAL LMAP for HO" ) );
  //DOMElement * _tag = (DOMElement *)(loader -> getElementsByTagName( _toXMLCh( "TAG" ) ) -> item(0));
  //_tag -> setAttribute( _toXMLCh("mode"), _toXMLCh("test_mode") );

  return result;
}
static XMLProcessor* XMLProcessor::getInstance ( ) [inline, static]
int XMLProcessor::init ( void  )

Definition at line 299 of file XMLProcessor.cc.

References dtNoiseDBValidation_cfg::cerr, and gather_cfg::cout.

{
  std::cerr << "Intializing Xerces-c...";
  try {
    XMLPlatformUtils::Initialize();
    //
    //_____ following removed as a xalan-c component_____________________
    //
    //XPathEvaluator::initialize();
  }
  catch (const XMLException& toCatch) {
    std::cout << " FAILED! Exiting..." << std::endl;
    return 1;
  }
  std::cerr << " done" << std::endl;

  return 0;
}
XMLCh * XMLProcessor::serializeDOM ( DOMNode *  node,
std::string  target = "stdout" 
)

Definition at line 239 of file XMLProcessor.cc.

References gather_cfg::cout, python::rootplot::argparse::message, NULL, and cmsPerfSuiteHarvest::release.

{
  XMLCh tempStr[100];
  XMLString::transcode("LS", tempStr, 99);
  DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
  DOMWriter* theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();
  
  if (theSerializer->canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true))
    theSerializer->setFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true);
  
  if (theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
    theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
    
  XMLFormatTarget * myFormTarget = 0;
  XMLCh * _string = 0;
  if ( target == "stdout" || target == "string" )
    {
      myFormTarget = new StdOutFormatTarget();
    }
  //else if ( target == "memory" )
  //  {
  //    myFormTarget = new MemBufFormatTarget();
  //  }
  else
    {
      myFormTarget = new LocalFileFormatTarget( _toXMLCh( target ) );
    }
  
  try {
    if ( target == "string" ){
      _string = theSerializer->writeToString( *node );
    }
    else{
      theSerializer->writeNode(myFormTarget, *node);
    }
  }
  catch (const XMLException& toCatch) {
    char* message = XMLString::transcode(toCatch.getMessage());
    std::cout << "Exception message is: \n"
         << message << "\n";
    XMLString::release(&message);
    return 0;
  }
  catch (const DOMException& toCatch) {
    char* message = XMLString::transcode(toCatch.msg);
    std::cout << "Exception message is: \n"
         << message << "\n";
    XMLString::release(&message);
    return NULL;
  }
  catch (...) {
    std::cout << "Unexpected Exception \n" ;
    return NULL;
  }
    
  theSerializer->release();
  if ( myFormTarget ) delete myFormTarget;
  return _string;
}
int XMLProcessor::terminate ( void  )

Definition at line 318 of file XMLProcessor.cc.

References gather_cfg::cout.

Referenced by HcaluLUTTPGCoder::updateXML().

{
  //
  //_____ following removed as a xalan-c component_____________________
  //
  //std::cout << "Terminating Xalan-c...";
  //XPathEvaluator::terminate();
  //std::cout << " done" << std::endl;

  std::cout << "Terminating Xerces-c...";
  XMLPlatformUtils::Terminate();
  std::cout << " done" << std::endl;


  // Other terminations and cleanup.

  return 0;
}
int XMLProcessor::test ( void  )

Definition at line 218 of file XMLProcessor.cc.

References gather_cfg::cout.

{
  //if ( init() != 0 ) return 1;

  XMLDOMBlock dataBlock( "HCAL_TRIG_PRIM_LOOKUP_TABLE.datablock.template" );

  DOMDocument * dataBlockDocument = dataBlock . getDocument();

  std::cout << "===> Tag length: " << dataBlockDocument -> getElementsByTagName( _toXMLCh( "CREATED_BY_USER" ) ) -> getLength() << std::endl;
  std::cout << "===> Tag name: " << XMLString::transcode( dataBlockDocument -> getElementsByTagName( _toXMLCh( "CREATED_BY_USER" ) ) -> item(0) -> getNodeName() ) << std::endl;
  dataBlockDocument -> getElementsByTagName( _toXMLCh( "CREATED_BY_USER" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( "kukarzev test" ) );

  XMLCh * _t;
  _t = serializeDOM( dataBlockDocument );
  delete _t;

  //terminate();

  return 0;
}
int XMLProcessor::write ( XMLDOMBlock doc,
std::string  target = "stdout" 
)

Definition at line 206 of file XMLProcessor.cc.

{
  DOMDocument * loader = doc -> getDocument();
  //DOMElement * root = loader -> getDocumentElement();

  XMLCh * _t;
  _t = serializeDOM( loader, target );
  delete _t;

  return 0;
}

Member Data Documentation

XERCES_CPP_NAMESPACE_USE XMLProcessor * XMLProcessor::instance = NULL [static, private]

Definition at line 182 of file XMLProcessor.h.

Referenced by getInstance().