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 XERCES_CPP_NAMESPACE_USE
42 
44 {
45 
46  public:
47 
48  typedef struct _loaderBaseConfig
49  {
64 
65  typedef struct _LMapRowHBEF
66  {
67  int side;
68  int eta;
69  int phi;
70  int dphi;
71  int depth;
74  int wedge;
75  int rm;
76  int pixel;
77  int qie;
78  int adc;
79  int rm_fi;
80  int fi_ch;
81  int crate;
82  int htr;
84  int htr_fi;
85  int dcc_sl;
86  int spigo;
87  int dcc;
88  int slb;
92  int rctcra;
93  int rctcar;
94  int rctcon;
96  int fedid;
97  } LMapRowHBEF;
98 
99  typedef struct _LMapRowHO
100  {
101  int sideO;
102  int etaO;
103  int phiO;
104  int dphiO;
105  int depthO;
108  int sectorO;
109  int rmO;
110  int pixelO;
111  int qieO;
112  int adcO;
113  int rm_fiO;
114  int fi_chO;
116  int crateO;
117  int htrO;
119  int htr_fiO;
120  int dcc_slO;
121  int spigoO;
122  int dccO;
123  int fedidO;
124  } LMapRowHO;
125 
126  typedef struct _DBConfig
127  {
128  _DBConfig();
133  } DBConfig;
134 
135  typedef struct _lutDBConfig : public _DBConfig
136  {
138  } lutDBConfig;
139 
140  typedef struct _checksumsDBConfig : public _DBConfig
141  {
144 
145  // this class is a singleton
147  {
148  if (!instance) instance = new XMLProcessor();
149  return instance;
150  }
151 
152  // returns XML std::string if target == "string" otherwise NULL
153  XMLCh * serializeDOM( DOMNode* node, std::string target = "stdout" );
154 
155  inline static XMLCh * _toXMLCh( std::string temp );
156  inline static XMLCh * _toXMLCh( int temp );
157  inline static XMLCh * _toXMLCh( double temp );
158  inline static XMLCh * _toXMLCh( time_t temp );
159  virtual ~XMLProcessor();
160 
161  int test( void );
162  int init( void );
163  int terminate( void );
164 
165  XMLDOMBlock * createLMapHBEFXMLBase( std::string templateFileName );
166  XMLDOMBlock * createLMapHOXMLBase( std::string templateFileName );
167 
168  int addLMapHBEFDataset( XMLDOMBlock * doc, LMapRowHBEF * row, std::string templateFileName );
169  int addLMapHODataset( XMLDOMBlock * doc, LMapRowHO * row, std::string templateFileName );
170 
171  int write( XMLDOMBlock * doc, std::string target = "stdout" );
172 
173  private:
174  XMLProcessor();
175 
176  XMLProcessor(const XMLProcessor&); // stop default
177 
178  //const XMLProcessor& operator=(const XMLProcessor&); // stop default
179 
180  // ---------- member data --------------------------------
182 };
183 
185 {
186  XMLCh* buff = XMLString::transcode(temp.c_str());
187  return buff;
188 }
189 
190 inline XMLCh* XMLProcessor::_toXMLCh( int temp )
191 {
192  char buf[100];
193  int status = snprintf( buf, 100, "%d", temp );
194  if ( status >= 100 )
195  {
196  std::cout << "XMLProcessor::_toXMLCh(int temp): buffer overflow, the std::string will be truncated!" << std::endl;
197  }
198  else if ( status <0 )
199  {
200  std::cout << "XMLProcessor::_toXMLCh(int temp): output error" << std::endl;
201  }
202  XMLCh* buff = XMLString::transcode( buf );
203  return buff;
204 }
205 
206 inline XMLCh* XMLProcessor::_toXMLCh( double temp )
207 {
208  char buf[100];
209  int status = snprintf( buf, 100, "%.10e", temp );
210  if ( status >= 100 )
211  {
212  std::cout << "XMLProcessor::_toXMLCh(int temp): buffer overflow, the std::string will be truncated!" << std::endl;
213  }
214  else if ( status <0 )
215  {
216  std::cout << "XMLProcessor::_toXMLCh(int temp): output error" << std::endl;
217  }
218  XMLCh* buff = XMLString::transcode( buf );
219  return buff;
220 }
221 
222 inline XMLCh* XMLProcessor::_toXMLCh( time_t temp )
223 {
224  char buf[100];
225  int status = strftime( buf, 50, "%c", gmtime( &temp ) );
226  if ( status == 0 )
227  {
228  std::cout << "XML Processor::_toXMLCh(int temp): buffer overflow, the std::string is indeterminate!" << std::endl;
229  }
230  XMLCh* buff = XMLString::transcode( buf );
231  return buff;
232 }
233 
234 
235 #endif
236 
XMLDOMBlock * createLMapHBEFXMLBase(std::string templateFileName)
Definition: XMLProcessor.cc:81
struct XMLProcessor::_loaderBaseConfig loaderBaseConfig
tuple node
Definition: Node.py:50
XMLProcessor::_checksumsDBConfig checksumsDBConfig
int addLMapHBEFDataset(XMLDOMBlock *doc, LMapRowHBEF *row, std::string templateFileName)
Definition: XMLProcessor.cc:94
struct XMLProcessor::_LMapRowHO LMapRowHO
int terminate(void)
int addLMapHODataset(XMLDOMBlock *doc, LMapRowHO *row, std::string templateFileName)
tuple doc
Definition: asciidump.py:381
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:184
XMLProcessor::_lutDBConfig lutDBConfig
int init(void)
int write(XMLDOMBlock *doc, std::string target="stdout")
tuple cout
Definition: gather_cfg.py:121
static XMLProcessor * instance
Definition: XMLProcessor.h:181
tuple status
Definition: ntuplemaker.py:245
int test(void)
XMLCh * serializeDOM(DOMNode *node, std::string target="stdout")
static XMLProcessor * getInstance()
Definition: XMLProcessor.h:146
std::string created_by_user
Definition: XMLProcessor.h:132