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