CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalChannelDataXml.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CaloOnlineTools/HcalOnlineDb
4 // Class : HcalChannelDataXml
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Gena Kukartsev, kukarzev@fnal.gov
10 // Created: Wed Jul 01 06:30:00 CDT 2009
11 //
12 
13 #include <iostream>
14 #include <string>
15 #include <vector>
16 #include <sstream>
17 #include <iconv.h>
18 #include <sys/time.h>
20 XERCES_CPP_NAMESPACE_USE
21 using namespace std;
22 
23 
24 
25 
27  comment = hcal_ass.getRandomQuote();
28  //init_data();
29  dataset_count = 0;
30  global_timestamp = time(NULL);
31 }
32 
33 
35 {
36  delete _root;
37  delete _dataset;
38 }
39 
40 
42 {
43  static const char * _str = "\
44 <ROOT>\n\
45  <HEADER>\n\
46  <TYPE>\n\
47  <EXTENSION_TABLE_NAME>HCAL_CHANNEL_QUALITY_V1</EXTENSION_TABLE_NAME>\n\
48  <NAME>HCAL Channel Quality [V1]</NAME>\n\
49  </TYPE>\n\
50  <RUN>\n\
51  <RUN_NUMBER>1</RUN_NUMBER>\n\
52  </RUN>\n\
53  <HINTS channelmap='HCAL_CHANNELS'/>\n\
54  </HEADER>\n\
55  <ELEMENTS>\n\
56  <DATA_SET id='-1'/>\n\
57  <IOV id='1'>\n\
58  <INTERVAL_OF_VALIDITY_BEGIN>1</INTERVAL_OF_VALIDITY_BEGIN>\n\
59  <INTERVAL_OF_VALIDITY_END>-1</INTERVAL_OF_VALIDITY_END>\n\
60  </IOV>\n\
61  <TAG id='2' mode='auto'>\n\
62  <TAG_NAME>test-channel-status-01jul2009-v4</TAG_NAME>\n\
63  <DETECTOR_NAME>HCAL</DETECTOR_NAME>\n\
64  <COMMENT_DESCRIPTION>testing channel status recording</COMMENT_DESCRIPTION>\n\
65  </TAG>\n\
66  </ELEMENTS>\n\
67  <MAPS>\n\
68  <TAG idref='2'>\n\
69  <IOV idref='1'>\n\
70  <DATA_SET idref='-1'/>\n\
71  </IOV>\n\
72  </TAG>\n\
73  </MAPS>\n\
74  </ROOT>\n\
75  ";
76  const XMLByte * _template = (const XMLByte *)_str;
77  _root = new MemBufInputSource( _template, strlen( (const char *)_template ), "_root", false );
78  parse(*_root);
79  //
80  //_____ fill header tags that will be redefined in the derived classes
81  //
82  set_header_table_name(extension_table_name);
83  set_header_type(type_name);
84  set_header_run_number(run_number);
85  set_header_channel_map(channel_map);
86  set_elements_dataset_id(data_set_id);
87  set_elements_iov_id(iov_id);
88  set_elements_iov_begin(iov_begin);
89  set_elements_iov_end(iov_end);
90  set_elements_tag_id(tag_id);
91  set_elements_tag_mode(tag_mode);
92  set_elements_tag_name(tag_name);
93  set_elements_detector_name(detector_name);
94  set_elements_comment(comment);
95  set_maps_tag_idref(tag_idref);
96  set_maps_iov_idref(iov_idref);
97  set_maps_dataset_idref(data_set_idref);
98  //
99  static const char * _str2 = "\
100  <DATA_SET>\n\
101  <COMMENT_DESCRIPTION>test-channel-status-26jun2009-v1</COMMENT_DESCRIPTION>\n\
102  <CREATE_TIMESTAMP>2009-04-06 17:36:40.0</CREATE_TIMESTAMP>\n\
103  <CREATED_BY_USER>user</CREATED_BY_USER>\n\
104  <VERSION>test-channel-status-26jun2009-v1</VERSION>\n\
105  <SUBVERSION>1</SUBVERSION>\n\
106  <CHANNEL>\n\
107  <EXTENSION_TABLE_NAME>HCAL_CHANNELS</EXTENSION_TABLE_NAME>\n\
108  </CHANNEL>\n\
109  <DATA>\n\
110  </DATA>\n\
111  </DATA_SET>\n\
112  ";
113  const XMLByte * _template2 = (const XMLByte *)_str2;
114  _dataset = new MemBufInputSource( _template2, strlen( (const char *)_template2 ), "_dataset", false );
115 
116  //
117  //_____ some more default initialization
118  username = hcal_ass.getUserName();
119  dataset_comment = hcal_ass.getRandomQuote();
120  //
121  return 0;
122 }
123 
124 
125 DOMNode * HcalChannelDataXml::add_hcal_channel( DOMNode * _dataset, int ieta, int iphi, int depth, std::string subdetector ){
126  DOMElement * _channel = get_channel_element(_dataset);
127  if (_channel){
128  add_element(_channel, XMLProcessor::_toXMLCh("IETA"), XMLProcessor::_toXMLCh(ieta));
129  add_element(_channel, XMLProcessor::_toXMLCh("IPHI"), XMLProcessor::_toXMLCh(iphi));
130  add_element(_channel, XMLProcessor::_toXMLCh("DEPTH"), XMLProcessor::_toXMLCh(depth));
131  add_element(_channel, XMLProcessor::_toXMLCh("SUBDET"), XMLProcessor::_toXMLCh(subdetector));
132  }
133 
134  return (DOMNode *)_channel;
135 }
136 
137 
139  XMLDOMBlock dataset_block( *_dataset );
140  DOMDocument * dataset_doc = dataset_block . getDocument();
141  DOMElement * root_elem = (DOMElement *)(document -> getElementsByTagName( XMLProcessor::_toXMLCh( "ROOT" ) ) -> item(0));
142  DOMNode * dataset_node = document -> importNode( dataset_doc -> getDocumentElement(), true );
143  root_elem -> appendChild( dataset_node );
144  //
145  //_____ set defaults
146  //
147  //
148  //_____ fix due to the new convention: version/subversion combo must be unique for every payload
149  //
150  char _buf[128];
151  //time_t _offset = time(NULL);
152  time_t _offset = global_timestamp;
153  sprintf( _buf, "%d", (uint32_t)_offset );
154  std::string _version;
155  _version.clear();
156  _version.append(tag_name);
157  _version.append(".");
158  _version.append(_buf);
159  //
160  DOMElement * dataset_elem = (DOMElement *)dataset_node;
161  setTagValue(dataset_elem, "COMMENT_DESCRIPTION", dataset_comment);
162  setTagValue(dataset_elem, "CREATE_TIMESTAMP", getTimestamp(time(0)));
163  setTagValue(dataset_elem, "CREATED_BY_USER", username);
164  setTagValue(dataset_elem, "VERSION", _version);
165  setTagValue(dataset_elem, "SUBVERSION", dataset_count);
166  //
167  //_____ set the chanel table name consistent with the header HINT
168  //
169  setTagValue(dataset_elem, "EXTENSION_TABLE_NAME", channel_map);
170  //
171  if (dataset_node) ++dataset_count;
172  return dataset_node;
173 }
174 
175 
176 DOMElement * HcalChannelDataXml::get_data_element( DOMNode * _dataset ){
177  DOMElement * _element = 0;
178  if (_dataset){
179  _element = (DOMElement *)(((DOMElement *)_dataset) -> getElementsByTagName(XMLProcessor::_toXMLCh("DATA"))->item( 0 ));
180  }
181  return _element;
182 }
183 
184 
185 DOMElement * HcalChannelDataXml::get_channel_element( DOMNode * _dataset ){
186  DOMElement * _element = 0;
187  if (_dataset){
188  _element = (DOMElement *)(((DOMElement *)_dataset) -> getElementsByTagName(XMLProcessor::_toXMLCh("CHANNEL"))->item( 0 ));
189  }
190  return _element;
191 }
192 
193 
195  extension_table_name = name;
196  DOMElement * _header = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("HEADER") ) -> item(0));
197  return setTagValue(_header, "EXTENSION_TABLE_NAME", extension_table_name);
198 }
199 
200 
202  type_name = type;
203  DOMElement * _header = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("HEADER") ) -> item(0));
204  return setTagValue(_header, "NAME", type_name);
205 }
206 
207 
209  run_number = run;
210  DOMElement * _header = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("HEADER") ) -> item(0));
211  return setTagValue(_header, "RUN_NUMBER", run_number);
212 }
213 
214 
216  channel_map = name;
217  DOMElement * _header = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("HEADER") ) -> item(0));
218  return setTagAttribute(_header, "HINTS", "channelmap", channel_map);
219 }
220 
221 
223  data_set_id = id;
224  DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
225  return setTagAttribute(_elements, "DATA_SET", "id", data_set_id);
226 }
227 
228 
230  iov_id = id;
231  DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
232  return setTagAttribute(_elements, "IOV", "id", iov_id);
233 }
234 
235 
237  iov_begin = value;
238  DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
239  return setTagValue(_elements, "INTERVAL_OF_VALIDITY_BEGIN", iov_begin);
240 }
241 
242 
244  iov_end = value;
245  DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
246  return setTagValue(_elements, "INTERVAL_OF_VALIDITY_END", iov_end);
247 }
248 
249 
251  tag_id = value;
252  DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
253  return setTagAttribute(_elements, "TAG", "id", tag_id);
254 }
255 
256 
258  tag_mode = value;
259  DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
260  return setTagAttribute(_elements, "TAG", "mode", tag_mode);
261 }
262 
263 
265  tag_name = value;
266  DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
267  return setTagValue(_elements, "TAG_NAME", tag_name);
268 }
269 
270 
272  detector_name = value;
273  DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
274  return setTagValue(_elements, "DETECTOR_NAME", detector_name);
275 }
276 
277 
279  comment = value;
280  DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
281  return setTagValue(_elements, "COMMENT_DESCRIPTION", comment);
282 }
283 
284 
286  tag_idref = value;
287  DOMElement * _maps = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("MAPS") ) -> item(0));
288  return setTagAttribute(_maps, "TAG", "idref", tag_idref);
289 }
290 
291 
293  iov_idref = value;
294  DOMElement * _maps = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("MAPS") ) -> item(0));
295  return setTagAttribute(_maps, "IOV", "idref", iov_idref);
296 }
297 
298 
300  data_set_idref = value;
301  DOMElement * _maps = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("MAPS") ) -> item(0));
302  return setTagAttribute(_maps, "DATA_SET", "idref", data_set_idref);
303 }
304 
305 
306 
307 
308 
309 
310 
311 
XERCES_CPP_NAMESPACE::DOMNode * set_header_channel_map(std::string name)
type
Definition: HCALResponse.h:21
XERCES_CPP_NAMESPACE::DOMNode * set_elements_detector_name(std::string value)
XERCES_CPP_NAMESPACE::DOMNode * add_hcal_channel(XERCES_CPP_NAMESPACE::DOMNode *_dataset, int ieta, int iphi, int depth, std::string subdetector)
XERCES_CPP_NAMESPACE::DOMNode * set_header_run_number(int run)
XERCES_CPP_NAMESPACE::DOMElement * get_data_element(XERCES_CPP_NAMESPACE::DOMNode *_dataset)
Evaluator * parse(const T &text)
TString subdetector
#define NULL
Definition: scimark2.h:8
XERCES_CPP_NAMESPACE::DOMNode * add_dataset(void)
XERCES_CPP_NAMESPACE::DOMNode * set_maps_iov_idref(int value)
XERCES_CPP_NAMESPACE::DOMNode * set_elements_iov_begin(int value)
XERCES_CPP_NAMESPACE::DOMNode * set_header_table_name(std::string name)
XERCES_CPP_NAMESPACE::DOMNode * set_maps_dataset_idref(int value)
XERCES_CPP_NAMESPACE::DOMNode * set_header_type(std::string type)
XERCES_CPP_NAMESPACE::DOMNode * set_maps_tag_idref(int value)
XMLCh * transcode(const T &fInput)
XERCES_CPP_NAMESPACE::DOMNode * set_elements_comment(std::string value)
XERCES_CPP_NAMESPACE::DOMElement * get_channel_element(XERCES_CPP_NAMESPACE::DOMNode *_dataset)
XERCES_CPP_NAMESPACE::DOMNode * set_elements_dataset_id(int id)
XERCES_CPP_NAMESPACE::DOMNode * set_elements_iov_id(int id)
static XMLCh * _toXMLCh(std::string temp)
Definition: XMLProcessor.h:183
XERCES_CPP_NAMESPACE::DOMNode * set_elements_tag_id(int value)
XERCES_CPP_NAMESPACE::DOMNode * set_elements_tag_mode(std::string value)
XERCES_CPP_NAMESPACE::DOMNode * set_elements_iov_end(int value)
XERCES_CPP_NAMESPACE::DOMNode * set_elements_tag_name(std::string value)
#define comment(par)
Definition: vmac.h:161