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