File indexing completed on 2024-04-06 11:58:10
0001 #ifndef HCALConfigDBTools_XMLTools_XMLProcessor_h
0002 #define HCALConfigDBTools_XMLTools_XMLProcessor_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <vector>
0023 #include <string>
0024 #include <ctime>
0025 #include <xercesc/dom/DOM.hpp>
0026 #include <xercesc/util/XMLString.hpp>
0027 #include "Utilities/Xerces/interface/Xerces.h"
0028 #include <xercesc/dom/DOMNode.hpp>
0029 #include <xercesc/framework/MemBufInputSource.hpp>
0030 #include <cstdio>
0031
0032 #if defined(XERCES_NEW_IOSTREAMS)
0033 #include <iostream>
0034 #else
0035 #include <iostream.h>
0036 #endif
0037
0038 #include "CalibCalorimetry/HcalTPGAlgos/interface/XMLDOMBlock.h"
0039
0040 class XMLProcessor {
0041 public:
0042 typedef struct _loaderBaseConfig {
0043 _loaderBaseConfig();
0044 std::string extention_table_name;
0045 std::string name;
0046 std::string run_mode;
0047 std::string data_set_id;
0048 std::string iov_id;
0049 std::string iov_begin;
0050 std::string iov_end;
0051 std::string tag_id;
0052 std::string tag_mode;
0053 std::string tag_name;
0054 std::string detector_name;
0055 std::string comment_description;
0056 } loaderBaseConfig;
0057
0058 typedef struct _LMapRowHBEF {
0059 int side;
0060 int eta;
0061 int phi;
0062 int dphi;
0063 int depth;
0064 std::string det;
0065 std::string rbx;
0066 int wedge;
0067 int rm;
0068 int pixel;
0069 int qie;
0070 int adc;
0071 int rm_fi;
0072 int fi_ch;
0073 int crate;
0074 int htr;
0075 std::string fpga;
0076 int htr_fi;
0077 int dcc_sl;
0078 int spigo;
0079 int dcc;
0080 int slb;
0081 std::string slbin;
0082 std::string slbin2;
0083 std::string slnam;
0084 int rctcra;
0085 int rctcar;
0086 int rctcon;
0087 std::string rctnam;
0088 int fedid;
0089 } LMapRowHBEF;
0090
0091 typedef struct _LMapRowHO {
0092 int sideO;
0093 int etaO;
0094 int phiO;
0095 int dphiO;
0096 int depthO;
0097 std::string detO;
0098 std::string rbxO;
0099 int sectorO;
0100 int rmO;
0101 int pixelO;
0102 int qieO;
0103 int adcO;
0104 int rm_fiO;
0105 int fi_chO;
0106 std::string let_codeO;
0107 int crateO;
0108 int htrO;
0109 std::string fpgaO;
0110 int htr_fiO;
0111 int dcc_slO;
0112 int spigoO;
0113 int dccO;
0114 int fedidO;
0115 } LMapRowHO;
0116
0117 typedef struct _DBConfig {
0118 _DBConfig();
0119 std::string version;
0120 std::string subversion;
0121 time_t create_timestamp;
0122 std::string created_by_user;
0123 } DBConfig;
0124
0125 typedef struct _lutDBConfig : public _DBConfig {
0126 int crateNumber;
0127 } lutDBConfig;
0128
0129 typedef struct _checksumsDBConfig : public _DBConfig {
0130 std::string comment;
0131 } checksumsDBConfig;
0132
0133
0134 static XMLProcessor* getInstance() {
0135 if (!instance)
0136 instance = new XMLProcessor();
0137 return instance;
0138 }
0139
0140 XMLProcessor(const XMLProcessor&) = delete;
0141
0142
0143 XMLCh* serializeDOM(XERCES_CPP_NAMESPACE::DOMNode* node, std::string target = "stdout");
0144
0145 inline static XMLCh* _toXMLCh(std::string temp);
0146 inline static XMLCh* _toXMLCh(int temp);
0147 inline static XMLCh* _toXMLCh(double temp);
0148 inline static XMLCh* _toXMLCh(time_t temp);
0149 virtual ~XMLProcessor();
0150
0151 int test(void);
0152 int init(void);
0153 int terminate(void);
0154
0155 XMLDOMBlock* createLMapHBEFXMLBase(std::string templateFileName);
0156 XMLDOMBlock* createLMapHOXMLBase(std::string templateFileName);
0157
0158 int addLMapHBEFDataset(XMLDOMBlock* doc, LMapRowHBEF* row, std::string templateFileName);
0159 int addLMapHODataset(XMLDOMBlock* doc, LMapRowHO* row, std::string templateFileName);
0160
0161 int write(XMLDOMBlock* doc, std::string target = "stdout");
0162
0163 private:
0164 XMLProcessor();
0165
0166
0167
0168
0169 static XMLProcessor* instance;
0170 };
0171
0172 inline XMLCh* XMLProcessor::_toXMLCh(std::string temp) {
0173 XMLCh* buff = XERCES_CPP_NAMESPACE::XMLString::transcode(temp.c_str());
0174 return buff;
0175 }
0176
0177 inline XMLCh* XMLProcessor::_toXMLCh(int temp) {
0178 char buf[100];
0179 int status = snprintf(buf, 100, "%d", temp);
0180 if (status >= 100) {
0181 std::cout << "XMLProcessor::_toXMLCh(int temp): buffer overflow, the std::string will be truncated!" << std::endl;
0182 } else if (status < 0) {
0183 std::cout << "XMLProcessor::_toXMLCh(int temp): output error" << std::endl;
0184 }
0185 XMLCh* buff = XERCES_CPP_NAMESPACE::XMLString::transcode(buf);
0186 return buff;
0187 }
0188
0189 inline XMLCh* XMLProcessor::_toXMLCh(double temp) {
0190 char buf[100];
0191 int status = snprintf(buf, 100, "%.10e", temp);
0192 if (status >= 100) {
0193 std::cout << "XMLProcessor::_toXMLCh(int temp): buffer overflow, the std::string will be truncated!" << std::endl;
0194 } else if (status < 0) {
0195 std::cout << "XMLProcessor::_toXMLCh(int temp): output error" << std::endl;
0196 }
0197 XMLCh* buff = XERCES_CPP_NAMESPACE::XMLString::transcode(buf);
0198 return buff;
0199 }
0200
0201 inline XMLCh* XMLProcessor::_toXMLCh(time_t temp) {
0202 char buf[100];
0203 int status = strftime(buf, 50, "%c", gmtime(&temp));
0204 if (status == 0) {
0205 std::cout << "XML Processor::_toXMLCh(int temp): buffer overflow, the std::string is indeterminate!" << std::endl;
0206 }
0207 XMLCh* buff = XERCES_CPP_NAMESPACE::XMLString::transcode(buf);
0208 return buff;
0209 }
0210
0211 #endif