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  DOMLSSerializer* theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
244  DOMConfiguration* dc = theSerializer->getDomConfig();
245  dc->setParameter(XMLUni::fgDOMWRTDiscardDefaultContent, true);
246  dc->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
247 
248  XMLFormatTarget * myFormTarget = 0;
249  XMLCh * _string = 0;
250  if ( target == "stdout" || target == "string" )
251  {
252  myFormTarget = new StdOutFormatTarget();
253  }
254  //else if ( target == "memory" )
255  // {
256  // myFormTarget = new MemBufFormatTarget();
257  // }
258  else
259  {
260  myFormTarget = new LocalFileFormatTarget( _toXMLCh( target ) );
261  }
262 
263  try {
264  if ( target == "string" ){
265  _string = theSerializer->writeToString( node );
266  }
267  else{
268  DOMLSOutput* outputDesc = ((DOMImplementationLS*)impl)->createLSOutput();
269  outputDesc->setByteStream(myFormTarget);
270  theSerializer->write(node, outputDesc);
271  }
272  }
273  catch (const XMLException& toCatch) {
274  char* message = XMLString::transcode(toCatch.getMessage());
275  std::cout << "Exception message is: \n"
276  << message << "\n";
277  XMLString::release(&message);
278  return 0;
279  }
280  catch (const DOMException& toCatch) {
281  char* message = XMLString::transcode(toCatch.msg);
282  std::cout << "Exception message is: \n"
283  << message << "\n";
284  XMLString::release(&message);
285  return NULL;
286  }
287  catch (...) {
288  std::cout << "Unexpected Exception \n" ;
289  return NULL;
290  }
291 
292  theSerializer->release();
293  if ( myFormTarget ) delete myFormTarget;
294  return _string;
295 }
296 
298 {
299  std::cerr << "Intializing Xerces-c...";
300  try {
302  //
303  //_____ following removed as a xalan-c component_____________________
304  //
305  //XPathEvaluator::initialize();
306  }
307  catch (const XMLException& toCatch) {
308  std::cout << " FAILED! Exiting..." << std::endl;
309  return 1;
310  }
311  std::cerr << " done" << std::endl;
312 
313  return 0;
314 }
315 
317 {
318  //
319  //_____ following removed as a xalan-c component_____________________
320  //
321  //std::cout << "Terminating Xalan-c...";
322  //XPathEvaluator::terminate();
323  //std::cout << " done" << std::endl;
324 
325  std::cout << "Terminating Xerces-c...";
327  std::cout << " done" << std::endl;
328 
329 
330  // Other terminations and cleanup.
331 
332  return 0;
333 }
334 
335 
int adc(sample_type sample)
get the ADC sample (12 bits)
XMLCh * serializeDOM(XERCES_CPP_NAMESPACE::DOMNode *node, std::string target="stdout")
XMLDOMBlock * createLMapHBEFXMLBase(std::string templateFileName)
Definition: XMLProcessor.cc:81
static int slb(const HcalTriggerPrimitiveSample &theSample)
void xercesTerminate()
Definition: Xerces.cc:23
#define NULL
Definition: scimark2.h:8
void xercesInitialize()
Definition: Xerces.cc:18
tuple result
Definition: mps_fire.py:84
int addLMapHBEFDataset(XMLDOMBlock *doc, LMapRowHBEF *row, std::string templateFileName)
Definition: XMLProcessor.cc:94
int terminate(void)
string rm
Definition: submit.py:76
int addLMapHODataset(XMLDOMBlock *doc, LMapRowHO *row, std::string templateFileName)
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:145
static XMLProcessor * instance
Definition: XMLProcessor.h:180
int test(void)