CMS 3D CMS Logo

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 <ctime>
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 class XMLProcessor {
41 public:
42  typedef struct _loaderBaseConfig {
57 
58  typedef struct _LMapRowHBEF {
59  int side;
60  int eta;
61  int phi;
62  int dphi;
63  int depth;
66  int wedge;
67  int rm;
68  int pixel;
69  int qie;
70  int adc;
71  int rm_fi;
72  int fi_ch;
73  int crate;
74  int htr;
76  int htr_fi;
77  int dcc_sl;
78  int spigo;
79  int dcc;
80  int slb;
84  int rctcra;
85  int rctcar;
86  int rctcon;
88  int fedid;
89  } LMapRowHBEF;
90 
91  typedef struct _LMapRowHO {
92  int sideO;
93  int etaO;
94  int phiO;
95  int dphiO;
96  int depthO;
99  int sectorO;
100  int rmO;
101  int pixelO;
102  int qieO;
103  int adcO;
104  int rm_fiO;
105  int fi_chO;
107  int crateO;
108  int htrO;
110  int htr_fiO;
111  int dcc_slO;
112  int spigoO;
113  int dccO;
114  int fedidO;
115  } LMapRowHO;
116 
117  typedef struct _DBConfig {
118  _DBConfig();
123  } DBConfig;
124 
125  typedef struct _lutDBConfig : public _DBConfig {
127  } lutDBConfig;
128 
129  typedef struct _checksumsDBConfig : public _DBConfig {
132 
133  // this class is a singleton
135  if (!instance)
136  instance = new XMLProcessor();
137  return instance;
138  }
139 
140  XMLProcessor(const XMLProcessor&) = delete; // stop default
141 
142  // returns XML std::string if target == "string" otherwise NULL
143  XMLCh* serializeDOM(XERCES_CPP_NAMESPACE::DOMNode* node, std::string target = "stdout");
144 
145  inline static XMLCh* _toXMLCh(std::string temp);
146  inline static XMLCh* _toXMLCh(int temp);
147  inline static XMLCh* _toXMLCh(double temp);
148  inline static XMLCh* _toXMLCh(time_t temp);
149  virtual ~XMLProcessor();
150 
151  int test(void);
152  int init(void);
153  int terminate(void);
154 
155  XMLDOMBlock* createLMapHBEFXMLBase(std::string templateFileName);
156  XMLDOMBlock* createLMapHOXMLBase(std::string templateFileName);
157 
158  int addLMapHBEFDataset(XMLDOMBlock* doc, LMapRowHBEF* row, std::string templateFileName);
159  int addLMapHODataset(XMLDOMBlock* doc, LMapRowHO* row, std::string templateFileName);
160 
161  int write(XMLDOMBlock* doc, std::string target = "stdout");
162 
163 private:
164  XMLProcessor();
165 
166  //const XMLProcessor& operator=(const XMLProcessor&); // stop default
167 
168  // ---------- member data --------------------------------
170 };
171 
173  XMLCh* buff = XERCES_CPP_NAMESPACE::XMLString::transcode(temp.c_str());
174  return buff;
175 }
176 
177 inline XMLCh* XMLProcessor::_toXMLCh(int temp) {
178  char buf[100];
179  int status = snprintf(buf, 100, "%d", temp);
180  if (status >= 100) {
181  std::cout << "XMLProcessor::_toXMLCh(int temp): buffer overflow, the std::string will be truncated!" << std::endl;
182  } else if (status < 0) {
183  std::cout << "XMLProcessor::_toXMLCh(int temp): output error" << std::endl;
184  }
185  XMLCh* buff = XERCES_CPP_NAMESPACE::XMLString::transcode(buf);
186  return buff;
187 }
188 
189 inline XMLCh* XMLProcessor::_toXMLCh(double temp) {
190  char buf[100];
191  int status = snprintf(buf, 100, "%.10e", temp);
192  if (status >= 100) {
193  std::cout << "XMLProcessor::_toXMLCh(int temp): buffer overflow, the std::string will be truncated!" << std::endl;
194  } else if (status < 0) {
195  std::cout << "XMLProcessor::_toXMLCh(int temp): output error" << std::endl;
196  }
197  XMLCh* buff = XERCES_CPP_NAMESPACE::XMLString::transcode(buf);
198  return buff;
199 }
200 
201 inline XMLCh* XMLProcessor::_toXMLCh(time_t temp) {
202  char buf[100];
203  int status = strftime(buf, 50, "%c", gmtime(&temp));
204  if (status == 0) {
205  std::cout << "XML Processor::_toXMLCh(int temp): buffer overflow, the std::string is indeterminate!" << std::endl;
206  }
207  XMLCh* buff = XERCES_CPP_NAMESPACE::XMLString::transcode(buf);
208  return buff;
209 }
210 
211 #endif
XMLCh * serializeDOM(XERCES_CPP_NAMESPACE::DOMNode *node, std::string target="stdout")
XMLDOMBlock * createLMapHBEFXMLBase(std::string templateFileName)
Definition: XMLProcessor.cc:77
struct XMLProcessor::_loaderBaseConfig loaderBaseConfig
XMLProcessor::_checksumsDBConfig checksumsDBConfig
int addLMapHBEFDataset(XMLDOMBlock *doc, LMapRowHBEF *row, std::string templateFileName)
Definition: XMLProcessor.cc:92
struct XMLProcessor::_LMapRowHO LMapRowHO
int terminate(void)
int addLMapHODataset(XMLDOMBlock *doc, LMapRowHO *row, std::string templateFileName)
virtual ~XMLProcessor()
Definition: XMLProcessor.cc:49
struct XMLProcessor::_DBConfig DBConfig
struct XMLProcessor::_LMapRowHBEF LMapRowHBEF
XMLDOMBlock * createLMapHOXMLBase(std::string templateFileName)
static XMLCh * _toXMLCh(std::string temp)
Definition: XMLProcessor.h:172
XMLProcessor::_lutDBConfig lutDBConfig
int init(void)
int write(XMLDOMBlock *doc, std::string target="stdout")
static XMLProcessor * instance
Definition: XMLProcessor.h:169
int test(void)
static XMLProcessor * getInstance()
Definition: XMLProcessor.h:134
std::string created_by_user
Definition: XMLProcessor.h:122