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