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.5 2009/10/25 21:19:45 kvtsang 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  {
52  std::string extention_table_name;
53  std::string name;
54  std::string run_mode;
55  std::string data_set_id;
56  std::string iov_id;
57  std::string iov_begin;
58  std::string iov_end;
59  std::string tag_id;
60  std::string tag_mode;
61  std::string tag_name;
62  std::string detector_name;
63  std::string comment_description;
65 
66  typedef struct _LMapRowHBEF
67  {
68  int side;
69  int eta;
70  int phi;
71  int dphi;
72  int depth;
73  std::string det;
74  std::string rbx;
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;
84  std::string fpga;
85  int htr_fi;
86  int dcc_sl;
87  int spigo;
88  int dcc;
89  int slb;
90  std::string slbin;
91  std::string slbin2;
92  std::string slnam;
93  int rctcra;
94  int rctcar;
95  int rctcon;
96  std::string rctnam;
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;
107  std::string detO;
108  std::string rbxO;
109  int sectorO;
110  int rmO;
111  int pixelO;
112  int qieO;
113  int adcO;
114  int rm_fiO;
115  int fi_chO;
116  std::string let_codeO;
117  int crateO;
118  int htrO;
119  std::string fpgaO;
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();
130  std::string version;
131  std::string subversion;
133  std::string created_by_user;
134  } DBConfig;
135 
136  typedef struct _lutDBConfig : public _DBConfig
137  {
139  } lutDBConfig;
140 
141  typedef struct _checksumsDBConfig : public _DBConfig
142  {
143  std::string comment;
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 
185 inline XMLCh* XMLProcessor::_toXMLCh( std::string temp )
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:41
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