CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
XMLProcessor.h
Go to the documentation of this file.
1 #ifndef HCALConfigDBTools_XMLTools_XMLProcessor_h
2 #define HCALConfigDBTools_XMLTools_XMLProcessor_h
3 // -*- C++ -*-
4 //
5 // Package: XMLTools
6 // Class : XMLProcessor
7 //
16 //
17 // Original Author: Gena Kukartsev
18 // Created: Sun Sep 23 16:57:06 CEST 2007
19 //
20 
21 // system include files
22 #include <vector>
23 #include <string>
24 #include <time.h>
25 #include <xercesc/dom/DOM.hpp>
26 #include <xercesc/util/XMLString.hpp>
28 #include <xercesc/dom/DOMNode.hpp>
29 #include <xercesc/framework/MemBufInputSource.hpp>
30 #include <cstdio>
31 
32 #if defined(XERCES_NEW_IOSTREAMS)
33 #include <iostream>
34 #else
35 #include <iostream.h>
36 #endif
37 
39 
40 
41 
43 {
44 
45  public:
46 
47  typedef struct _loaderBaseConfig
48  {
63 
64  typedef struct _LMapRowHBEF
65  {
66  int side;
67  int eta;
68  int phi;
69  int dphi;
70  int depth;
73  int wedge;
74  int rm;
75  int pixel;
76  int qie;
77  int adc;
78  int rm_fi;
79  int fi_ch;
80  int crate;
81  int htr;
83  int htr_fi;
84  int dcc_sl;
85  int spigo;
86  int dcc;
87  int slb;
91  int rctcra;
92  int rctcar;
93  int rctcon;
95  int fedid;
96  } LMapRowHBEF;
97 
98  typedef struct _LMapRowHO
99  {
100  int sideO;
101  int etaO;
102  int phiO;
103  int dphiO;
104  int depthO;
107  int sectorO;
108  int rmO;
109  int pixelO;
110  int qieO;
111  int adcO;
112  int rm_fiO;
113  int fi_chO;
115  int crateO;
116  int htrO;
118  int htr_fiO;
119  int dcc_slO;
120  int spigoO;
121  int dccO;
122  int fedidO;
123  } LMapRowHO;
124 
125  typedef struct _DBConfig
126  {
127  _DBConfig();
132  } DBConfig;
133 
134  typedef struct _lutDBConfig : public _DBConfig
135  {
137  } lutDBConfig;
138 
139  typedef struct _checksumsDBConfig : public _DBConfig
140  {
143 
144  // this class is a singleton
146  {
147  if (!instance) instance = new XMLProcessor();
148  return instance;
149  }
150 
151  // returns XML std::string if target == "string" otherwise NULL
152  XMLCh * serializeDOM( XERCES_CPP_NAMESPACE::DOMNode* node, std::string target = "stdout" );
153 
154  inline static XMLCh * _toXMLCh( std::string temp );
155  inline static XMLCh * _toXMLCh( int temp );
156  inline static XMLCh * _toXMLCh( double temp );
157  inline static XMLCh * _toXMLCh( time_t temp );
158  virtual ~XMLProcessor();
159 
160  int test( void );
161  int init( void );
162  int terminate( void );
163 
164  XMLDOMBlock * createLMapHBEFXMLBase( std::string templateFileName );
165  XMLDOMBlock * createLMapHOXMLBase( std::string templateFileName );
166 
167  int addLMapHBEFDataset( XMLDOMBlock * doc, LMapRowHBEF * row, std::string templateFileName );
168  int addLMapHODataset( XMLDOMBlock * doc, LMapRowHO * row, std::string templateFileName );
169 
170  int write( XMLDOMBlock * doc, std::string target = "stdout" );
171 
172  private:
173  XMLProcessor();
174 
175  XMLProcessor(const XMLProcessor&); // stop default
176 
177  //const XMLProcessor& operator=(const XMLProcessor&); // stop default
178 
179  // ---------- member data --------------------------------
181 };
182 
184 {
185  XMLCh* buff = XERCES_CPP_NAMESPACE::XMLString::transcode(temp.c_str());
186  return buff;
187 }
188 
189 inline XMLCh* XMLProcessor::_toXMLCh( int temp )
190 {
191  char buf[100];
192  int status = snprintf( buf, 100, "%d", temp );
193  if ( status >= 100 )
194  {
195  std::cout << "XMLProcessor::_toXMLCh(int temp): buffer overflow, the std::string will be truncated!" << std::endl;
196  }
197  else if ( status <0 )
198  {
199  std::cout << "XMLProcessor::_toXMLCh(int temp): output error" << std::endl;
200  }
201  XMLCh* buff = XERCES_CPP_NAMESPACE::XMLString::transcode( buf );
202  return buff;
203 }
204 
205 inline XMLCh* XMLProcessor::_toXMLCh( double temp )
206 {
207  char buf[100];
208  int status = snprintf( buf, 100, "%.10e", temp );
209  if ( status >= 100 )
210  {
211  std::cout << "XMLProcessor::_toXMLCh(int temp): buffer overflow, the std::string will be truncated!" << std::endl;
212  }
213  else if ( status <0 )
214  {
215  std::cout << "XMLProcessor::_toXMLCh(int temp): output error" << std::endl;
216  }
217  XMLCh* buff = XERCES_CPP_NAMESPACE::XMLString::transcode( buf );
218  return buff;
219 }
220 
221 inline XMLCh* XMLProcessor::_toXMLCh( time_t temp )
222 {
223  char buf[100];
224  int status = strftime( buf, 50, "%c", gmtime( &temp ) );
225  if ( status == 0 )
226  {
227  std::cout << "XML Processor::_toXMLCh(int temp): buffer overflow, the std::string is indeterminate!" << std::endl;
228  }
229  XMLCh* buff = XERCES_CPP_NAMESPACE::XMLString::transcode( buf );
230  return buff;
231 }
232 
233 
234 #endif
235 
XMLCh * serializeDOM(XERCES_CPP_NAMESPACE::DOMNode *node, std::string target="stdout")
XMLDOMBlock * createLMapHBEFXMLBase(std::string templateFileName)
Definition: XMLProcessor.cc:81
struct XMLProcessor::_loaderBaseConfig loaderBaseConfig
XMLProcessor::_checksumsDBConfig checksumsDBConfig
int addLMapHBEFDataset(XMLDOMBlock *doc, LMapRowHBEF *row, std::string templateFileName)
Definition: XMLProcessor.cc:94
struct XMLProcessor::_LMapRowHO LMapRowHO
int terminate(void)
XMLCh * transcode(const T &fInput)
int addLMapHODataset(XMLDOMBlock *doc, LMapRowHO *row, std::string templateFileName)
virtual ~XMLProcessor()
Definition: XMLProcessor.cc:50
struct XMLProcessor::_DBConfig DBConfig
struct XMLProcessor::_LMapRowHBEF LMapRowHBEF
XMLDOMBlock * createLMapHOXMLBase(std::string templateFileName)
static XMLCh * _toXMLCh(std::string temp)
Definition: XMLProcessor.h:183
XMLProcessor::_lutDBConfig lutDBConfig
int init(void)
int write(XMLDOMBlock *doc, std::string target="stdout")
tuple cout
Definition: gather_cfg.py:145
static XMLProcessor * instance
Definition: XMLProcessor.h:180
int test(void)
static XMLProcessor * getInstance()
Definition: XMLProcessor.h:145
tuple status
Definition: mps_update.py:57
std::string created_by_user
Definition: XMLProcessor.h:131