CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
XMLProcessor.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: XMLTools
4 // Class : XMLProcessor
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author:
10 // Created: Fri Sep 21 15:56:27 CEST 2007
11 //
12 
13 // system include files
14 #include <vector>
15 #include <string>
16 #include <iostream>
17 #include <sys/types.h>
18 #include <pwd.h>
19 #include <unistd.h>
20 #include <xercesc/parsers/XercesDOMParser.hpp>
21 #include <xercesc/dom/DOM.hpp>
22 #include <xercesc/sax/HandlerBase.hpp>
23 #include <xercesc/util/XMLString.hpp>
25 #include <xercesc/dom/DOMNode.hpp>
26 #include <xercesc/framework/StdOutFormatTarget.hpp>
27 #include <xercesc/framework/LocalFileFormatTarget.hpp>
28 
29 // xalan-c init
30 //#include <xalanc/Include/PlatformDefinitions.hpp>
31 //#include <xalanc/XPath/XPathEvaluator.hpp>
32 //#include <xalanc/XalanTransformer/XalanTransformer.hpp>
33 //using namespace xalanc;
34 
35 using namespace std;
36 XERCES_CPP_NAMESPACE_USE
37 
38 // user include files
41 
43 
45 {
46  // initializes Xerces, must be done only once
47  init();
48 }
49 
51 {
52  // terminates Xerces
53  terminate();
54 }
55 
56 //_loaderBaseConfig::_loaderBaseConfig
58 {
59  extention_table_name = "HCAL_TRIG_PRIM_LOOKUP_TABLES";
60  name = "HCAL trigger primitive lookup table";
61  run_mode = "no-run";
62  data_set_id = "-1";
63  iov_id = "1";
64  iov_begin = "0";
65  iov_end = "1";
66  tag_id = "2";
67  tag_mode = "auto";
68  tag_name = "dummy tag";
69  detector_name = "HCAL";
70  comment_description = "empty comment";
71 }
72 
74 {
75  version = "test:2";
76  subversion = "1";
77  create_timestamp = time( NULL );
78  created_by_user = getpwuid( getuid() ) -> pw_name;
79 }
80 
82 {
83  XMLDOMBlock * result = new XMLDOMBlock( templateFileName );
84  DOMDocument * loader = result -> getDocument();
85  //DOMElement * root = loader -> getDocumentElement();
86 
87  loader -> getElementsByTagName( _toXMLCh( "NAME" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( "HCAL LMAP for HB, HE, HF" ) );
88  //DOMElement * _tag = (DOMElement *)(loader -> getElementsByTagName( _toXMLCh( "TAG" ) ) -> item(0));
89  //_tag -> setAttribute( _toXMLCh("mode"), _toXMLCh("test_mode") );
90 
91  return result;
92 }
93 
95 {
96  DOMDocument * loader = doc -> getDocument();
97  DOMElement * root = loader -> getDocumentElement();
98 
99  XMLDOMBlock dataSetDoc( templateFileName );
100  DOMDocument * dataSet = dataSetDoc . getDocument();
101 
102  //Dataset
103  dataSet -> getElementsByTagName( _toXMLCh( "SIDE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> side ) );
104  dataSet -> getElementsByTagName( _toXMLCh( "ETA" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> eta) );
105  dataSet -> getElementsByTagName( _toXMLCh( "PHI" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> phi ) );
106  dataSet -> getElementsByTagName( _toXMLCh( "DELTA_PHI" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> dphi ) );
107 
108  dataSet -> getElementsByTagName( _toXMLCh( "DEPTH" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> depth ) );
109  dataSet -> getElementsByTagName( _toXMLCh( "SUBDETECTOR" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> det ) );
110  dataSet -> getElementsByTagName( _toXMLCh( "RBX_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rbx ) );
111  dataSet -> getElementsByTagName( _toXMLCh( "WEDGE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> wedge ) );
112 
113  dataSet -> getElementsByTagName( _toXMLCh( "RM_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rm ) );
114  dataSet -> getElementsByTagName( _toXMLCh( "HPD_PIXEL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> pixel ) );
115  dataSet -> getElementsByTagName( _toXMLCh( "QIE_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> qie ) );
116  dataSet -> getElementsByTagName( _toXMLCh( "ADC" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> adc ) );
117  dataSet -> getElementsByTagName( _toXMLCh( "RM_FIBER" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rm_fi ) );
118 
119  dataSet -> getElementsByTagName( _toXMLCh( "FIBER_CHANNEL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> fi_ch));
120  dataSet -> getElementsByTagName( _toXMLCh( "CRATE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> crate ) );
121  dataSet -> getElementsByTagName( _toXMLCh( "HTR_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> htr ) );
122  dataSet -> getElementsByTagName( _toXMLCh( "HTR_FPGA" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> fpga ) );
123 
124  dataSet -> getElementsByTagName( _toXMLCh( "HTR_FIBER" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> htr_fi ));
125  dataSet -> getElementsByTagName( _toXMLCh( "DCC_SL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> dcc_sl ) );
126  dataSet -> getElementsByTagName( _toXMLCh( "SPIGOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> spigo ) );
127  dataSet -> getElementsByTagName( _toXMLCh( "DCC_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> dcc ) );
128  dataSet -> getElementsByTagName( _toXMLCh( "SLB_SITE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> slb ) );
129  dataSet -> getElementsByTagName( _toXMLCh( "SLB_CHANNEL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> slbin ));
130  dataSet -> getElementsByTagName( _toXMLCh( "SLB_CHANNEL2" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> slbin2));
131 
132  dataSet -> getElementsByTagName( _toXMLCh( "SLB_CABLE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> slnam ) );
133  dataSet -> getElementsByTagName( _toXMLCh( "RCT_CRATE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rctcra ) );
134  dataSet -> getElementsByTagName( _toXMLCh( "RCT_CARD" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rctcar ) );
135  dataSet -> getElementsByTagName( _toXMLCh( "RCT_CONNECTOR" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row ->rctcon));
136  dataSet -> getElementsByTagName( _toXMLCh( "RCT_NAME" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rctnam ) );
137  dataSet -> getElementsByTagName( _toXMLCh( "FED_ID" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> fedid ) );
138 
139 
140  // copy the <data_set> node into the final XML
141  DOMNode * cloneDataSet = loader -> importNode( dataSet -> getDocumentElement(), true );
142  root -> appendChild( cloneDataSet );
143 
144  return 0;
145 }
146 
148 {
149  XMLDOMBlock * result = new XMLDOMBlock( templateFileName );
150  DOMDocument * loader = result -> getDocument();
151  //DOMElement * root = loader -> getDocumentElement();
152 
153  loader -> getElementsByTagName( _toXMLCh( "NAME" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( "HCAL LMAP for HO" ) );
154  //DOMElement * _tag = (DOMElement *)(loader -> getElementsByTagName( _toXMLCh( "TAG" ) ) -> item(0));
155  //_tag -> setAttribute( _toXMLCh("mode"), _toXMLCh("test_mode") );
156 
157  return result;
158 }
159 
161 {
162  DOMDocument * loader = doc -> getDocument();
163  DOMElement * root = loader -> getDocumentElement();
164 
165  XMLDOMBlock dataSetDoc( templateFileName );
166  DOMDocument * dataSet = dataSetDoc . getDocument();
167 
168  //Dataset
169  dataSet -> getElementsByTagName( _toXMLCh( "SIDE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> sideO ) );
170  dataSet -> getElementsByTagName( _toXMLCh( "ETA" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> etaO ) );
171  dataSet -> getElementsByTagName( _toXMLCh( "PHI" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> phiO ) );
172  dataSet -> getElementsByTagName( _toXMLCh( "DELTA_PHI" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> dphiO ) );
173 
174  dataSet -> getElementsByTagName( _toXMLCh( "DEPTH" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> depthO ) );
175  dataSet -> getElementsByTagName( _toXMLCh( "SUBDETECTOR" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> detO ) );
176  dataSet -> getElementsByTagName( _toXMLCh( "RBX_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rbxO ) );
177  dataSet -> getElementsByTagName( _toXMLCh( "SECTOR" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> sectorO ) );
178 
179  dataSet -> getElementsByTagName( _toXMLCh( "RM_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rmO ) );
180  dataSet -> getElementsByTagName( _toXMLCh( "HPD_PIXEL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> pixelO ) );
181  dataSet -> getElementsByTagName( _toXMLCh( "QIE_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> qieO ) );
182  dataSet -> getElementsByTagName( _toXMLCh( "ADC" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> adcO ) );
183  dataSet -> getElementsByTagName( _toXMLCh( "RM_FIBER" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> rm_fiO ) );
184  dataSet -> getElementsByTagName( _toXMLCh( "FIBER_CHANNEL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row ->fi_chO));
185 
186  dataSet -> getElementsByTagName( _toXMLCh( "LETTER_CODE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh(row ->let_codeO));
187  dataSet -> getElementsByTagName( _toXMLCh( "CRATE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> crateO ) );
188  dataSet -> getElementsByTagName( _toXMLCh( "HTR_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> htrO ) );
189  dataSet -> getElementsByTagName( _toXMLCh( "HTR_FPGA" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> fpgaO ) );
190 
191  dataSet -> getElementsByTagName( _toXMLCh( "HTR_FIBER" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> htr_fiO ) );
192  dataSet -> getElementsByTagName( _toXMLCh( "DCC_SL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> dcc_slO ) );
193  dataSet -> getElementsByTagName( _toXMLCh( "SPIGOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> spigoO ) );
194  dataSet -> getElementsByTagName( _toXMLCh( "DCC_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> dccO ) );
195  dataSet -> getElementsByTagName( _toXMLCh( "FED_ID" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( row -> fedidO ) );
196 
197 
198  // copy the <data_set> node into the final XML
199  DOMNode * cloneDataSet = loader -> importNode( dataSet -> getDocumentElement(), true );
200  root -> appendChild( cloneDataSet );
201 
202  return 0;
203 }
204 
206 {
207  DOMDocument * loader = doc -> getDocument();
208  //DOMElement * root = loader -> getDocumentElement();
209 
210  XMLCh * _t;
211  _t = serializeDOM( loader, target );
212  delete _t;
213 
214  return 0;
215 }
216 
218 {
219  //if ( init() != 0 ) return 1;
220 
221  XMLDOMBlock dataBlock( "HCAL_TRIG_PRIM_LOOKUP_TABLE.datablock.template" );
222 
223  DOMDocument * dataBlockDocument = dataBlock . getDocument();
224 
225  std::cout << "===> Tag length: " << dataBlockDocument -> getElementsByTagName( _toXMLCh( "CREATED_BY_USER" ) ) -> getLength() << std::endl;
226  std::cout << "===> Tag name: " << XMLString::transcode( dataBlockDocument -> getElementsByTagName( _toXMLCh( "CREATED_BY_USER" ) ) -> item(0) -> getNodeName() ) << std::endl;
227  dataBlockDocument -> getElementsByTagName( _toXMLCh( "CREATED_BY_USER" ) ) -> item(0) -> getFirstChild() -> setNodeValue( _toXMLCh( "kukarzev test" ) );
228 
229  XMLCh * _t;
230  _t = serializeDOM( dataBlockDocument );
231  delete _t;
232 
233  //terminate();
234 
235  return 0;
236 }
237 
239 {
240  XMLCh tempStr[100];
241  XMLString::transcode("LS", tempStr, 99);
242  DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
243  DOMWriter* theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();
244 
245  if (theSerializer->canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true))
246  theSerializer->setFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true);
247 
248  if (theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
249  theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
250 
251  XMLFormatTarget * myFormTarget = 0;
252  XMLCh * _string = 0;
253  if ( target == "stdout" || target == "string" )
254  {
255  myFormTarget = new StdOutFormatTarget();
256  }
257  //else if ( target == "memory" )
258  // {
259  // myFormTarget = new MemBufFormatTarget();
260  // }
261  else
262  {
263  myFormTarget = new LocalFileFormatTarget( _toXMLCh( target ) );
264  }
265 
266  try {
267  if ( target == "string" ){
268  _string = theSerializer->writeToString( *node );
269  }
270  else{
271  theSerializer->writeNode(myFormTarget, *node);
272  }
273  }
274  catch (const XMLException& toCatch) {
275  char* message = XMLString::transcode(toCatch.getMessage());
276  std::cout << "Exception message is: \n"
277  << message << "\n";
278  XMLString::release(&message);
279  return 0;
280  }
281  catch (const DOMException& toCatch) {
282  char* message = XMLString::transcode(toCatch.msg);
283  std::cout << "Exception message is: \n"
284  << message << "\n";
285  XMLString::release(&message);
286  return NULL;
287  }
288  catch (...) {
289  std::cout << "Unexpected Exception \n" ;
290  return NULL;
291  }
292 
293  theSerializer->release();
294  if ( myFormTarget ) delete myFormTarget;
295  return _string;
296 }
297 
299 {
300  std::cerr << "Intializing Xerces-c...";
301  try {
303  //
304  //_____ following removed as a xalan-c component_____________________
305  //
306  //XPathEvaluator::initialize();
307  }
308  catch (const XMLException& toCatch) {
309  std::cout << " FAILED! Exiting..." << std::endl;
310  return 1;
311  }
312  std::cerr << " done" << std::endl;
313 
314  return 0;
315 }
316 
318 {
319  //
320  //_____ following removed as a xalan-c component_____________________
321  //
322  //std::cout << "Terminating Xalan-c...";
323  //XPathEvaluator::terminate();
324  //std::cout << " done" << std::endl;
325 
326  std::cout << "Terminating Xerces-c...";
328  std::cout << " done" << std::endl;
329 
330 
331  // Other terminations and cleanup.
332 
333  return 0;
334 }
335 
336 
int adc(sample_type sample)
get the ADC sample (12 bits)
XMLDOMBlock * createLMapHBEFXMLBase(std::string templateFileName)
Definition: XMLProcessor.cc:81
static int slb(const HcalTriggerPrimitiveSample &theSample)
void xercesTerminate()
Definition: Xerces.cc:22
int init
Definition: HydjetWrapper.h:62
#define NULL
Definition: scimark2.h:8
void xercesInitialize()
Definition: Xerces.cc:17
T eta() const
tuple node
Definition: Node.py:50
int addLMapHBEFDataset(XMLDOMBlock *doc, LMapRowHBEF *row, std::string templateFileName)
Definition: XMLProcessor.cc:94
int terminate(void)
tuple result
Definition: query.py:137
string rm
Definition: submit.py:76
int addLMapHODataset(XMLDOMBlock *doc, LMapRowHO *row, std::string templateFileName)
tuple doc
Definition: asciidump.py:381
virtual ~XMLProcessor()
Definition: XMLProcessor.cc:50
XMLDOMBlock * createLMapHOXMLBase(std::string templateFileName)
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
int test(void)
XMLCh * serializeDOM(DOMNode *node, std::string target="stdout")
string root
initialization
Definition: dbtoconf.py:70
Definition: DDAxes.h:10