CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CaloOnlineTools/HcalOnlineDb/src/HcalChannelDataXml.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     CaloOnlineTools/HcalOnlineDb
00004 // Class  :     HcalChannelDataXml
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Gena Kukartsev, kukarzev@fnal.gov
00010 //         Created:  Wed Jul 01 06:30:00 CDT 2009
00011 // $Id: HcalChannelDataXml.cc,v 1.5 2009/10/26 02:55:16 kukartse Exp $
00012 //
00013 
00014 #include <iostream>
00015 #include <string>
00016 #include <vector>
00017 #include <sstream>
00018 #include <iconv.h>
00019 #include <sys/time.h>
00020 #include "CaloOnlineTools/HcalOnlineDb/interface/HcalChannelDataXml.h"
00021 
00022 using namespace std;
00023 
00024 
00025 
00026 
00027 HcalChannelDataXml::HcalChannelDataXml(){
00028   comment = hcal_ass.getRandomQuote();
00029   //init_data();
00030   dataset_count = 0;
00031   global_timestamp = time(NULL);
00032 }
00033 
00034 
00035 HcalChannelDataXml::~HcalChannelDataXml()
00036 {
00037   delete _root;
00038   delete _dataset;
00039 }
00040 
00041 
00042 int HcalChannelDataXml::init_data( void )
00043 {
00044   static const char * _str = "\
00045 <ROOT>\n\
00046   <HEADER>\n\
00047     <TYPE>\n\
00048       <EXTENSION_TABLE_NAME>HCAL_CHANNEL_QUALITY_V1</EXTENSION_TABLE_NAME>\n\
00049       <NAME>HCAL Channel Quality [V1]</NAME>\n\
00050     </TYPE>\n\
00051     <RUN>\n\
00052       <RUN_NUMBER>1</RUN_NUMBER>\n\
00053     </RUN>\n\
00054     <HINTS channelmap='HCAL_CHANNELS'/>\n\
00055   </HEADER>\n\
00056   <ELEMENTS>\n\
00057     <DATA_SET id='-1'/>\n\
00058     <IOV id='1'>\n\
00059       <INTERVAL_OF_VALIDITY_BEGIN>1</INTERVAL_OF_VALIDITY_BEGIN>\n\
00060       <INTERVAL_OF_VALIDITY_END>-1</INTERVAL_OF_VALIDITY_END>\n\
00061     </IOV>\n\
00062     <TAG id='2' mode='auto'>\n\
00063       <TAG_NAME>test-channel-status-01jul2009-v4</TAG_NAME>\n\
00064       <DETECTOR_NAME>HCAL</DETECTOR_NAME>\n\
00065       <COMMENT_DESCRIPTION>testing channel status recording</COMMENT_DESCRIPTION>\n\
00066     </TAG>\n\
00067   </ELEMENTS>\n\
00068   <MAPS>\n\
00069     <TAG idref='2'>\n\
00070       <IOV idref='1'>\n\
00071         <DATA_SET idref='-1'/>\n\
00072       </IOV>\n\
00073     </TAG>\n\
00074   </MAPS>\n\
00075   </ROOT>\n\
00076   ";
00077   const XMLByte * _template = (const XMLByte *)_str;
00078   _root = new MemBufInputSource( _template, strlen( (const char *)_template ), "_root", false );
00079   parse(*_root);
00080   //
00081   //_____ fill header tags that will be redefined in the derived classes
00082   //
00083   set_header_table_name(extension_table_name);
00084   set_header_type(type_name);
00085   set_header_run_number(run_number);
00086   set_header_channel_map(channel_map);
00087   set_elements_dataset_id(data_set_id);
00088   set_elements_iov_id(iov_id);
00089   set_elements_iov_begin(iov_begin);
00090   set_elements_iov_end(iov_end);
00091   set_elements_tag_id(tag_id);
00092   set_elements_tag_mode(tag_mode);
00093   set_elements_tag_name(tag_name);
00094   set_elements_detector_name(detector_name);
00095   set_elements_comment(comment);
00096   set_maps_tag_idref(tag_idref);
00097   set_maps_iov_idref(iov_idref);
00098   set_maps_dataset_idref(data_set_idref);
00099   //
00100   static const char * _str2 =  "\
00101   <DATA_SET>\n\
00102     <COMMENT_DESCRIPTION>test-channel-status-26jun2009-v1</COMMENT_DESCRIPTION>\n\
00103     <CREATE_TIMESTAMP>2009-04-06 17:36:40.0</CREATE_TIMESTAMP>\n\
00104     <CREATED_BY_USER>user</CREATED_BY_USER>\n\
00105     <VERSION>test-channel-status-26jun2009-v1</VERSION>\n\
00106     <SUBVERSION>1</SUBVERSION>\n\
00107     <CHANNEL>\n\
00108       <EXTENSION_TABLE_NAME>HCAL_CHANNELS</EXTENSION_TABLE_NAME>\n\
00109     </CHANNEL>\n\
00110     <DATA>\n\
00111     </DATA>\n\
00112   </DATA_SET>\n\
00113   ";
00114   const XMLByte * _template2 = (const XMLByte *)_str2;
00115   _dataset = new MemBufInputSource( _template2, strlen( (const char *)_template2 ), "_dataset", false );
00116 
00117   //
00118   //_____ some more default initialization
00119   username = hcal_ass.getUserName();
00120   dataset_comment = hcal_ass.getRandomQuote();
00121   //
00122   return 0;
00123 }
00124 
00125 
00126 DOMNode * HcalChannelDataXml::add_hcal_channel( DOMNode * _dataset, int ieta, int iphi, int depth, std::string subdetector ){
00127   DOMElement * _channel = get_channel_element(_dataset);
00128   if (_channel){
00129     add_element(_channel, XMLProcessor::_toXMLCh("IETA"), XMLProcessor::_toXMLCh(ieta));
00130     add_element(_channel, XMLProcessor::_toXMLCh("IPHI"), XMLProcessor::_toXMLCh(iphi));
00131     add_element(_channel, XMLProcessor::_toXMLCh("DEPTH"), XMLProcessor::_toXMLCh(depth));
00132     add_element(_channel, XMLProcessor::_toXMLCh("SUBDET"), XMLProcessor::_toXMLCh(subdetector));
00133   }
00134   
00135   return (DOMNode *)_channel;
00136 }
00137 
00138 
00139 DOMNode * HcalChannelDataXml::add_dataset( void ){
00140   XMLDOMBlock dataset_block( *_dataset );
00141   DOMDocument * dataset_doc = dataset_block . getDocument();
00142   DOMElement * root_elem = (DOMElement *)(document -> getElementsByTagName( XMLProcessor::_toXMLCh( "ROOT" ) ) -> item(0));
00143   DOMNode * dataset_node = document -> importNode( dataset_doc -> getDocumentElement(), true );
00144   root_elem -> appendChild( dataset_node );
00145   //
00146   //_____ set defaults
00147   //
00148   //
00149   //_____ fix due to the new convention: version/subversion combo must be unique for every payload
00150   //
00151   char _buf[128];
00152   //time_t _offset = time(NULL);
00153   time_t _offset = global_timestamp;
00154   sprintf( _buf, "%d", (uint32_t)_offset );
00155   std::string _version;
00156   _version.clear();
00157   _version.append(tag_name);
00158   _version.append(".");
00159   _version.append(_buf);
00160   //
00161   DOMElement * dataset_elem = (DOMElement *)dataset_node;
00162   setTagValue(dataset_elem, "COMMENT_DESCRIPTION", dataset_comment);
00163   setTagValue(dataset_elem, "CREATE_TIMESTAMP", getTimestamp(time(0)));
00164   setTagValue(dataset_elem, "CREATED_BY_USER", username);
00165   setTagValue(dataset_elem, "VERSION", _version);
00166   setTagValue(dataset_elem, "SUBVERSION", dataset_count);
00167   //
00168   //_____ set the chanel table name consistent with the header HINT
00169   //
00170   setTagValue(dataset_elem, "EXTENSION_TABLE_NAME", channel_map);
00171   //
00172   if (dataset_node) ++dataset_count;
00173   return dataset_node;
00174 }
00175 
00176 
00177 DOMElement * HcalChannelDataXml::get_data_element( DOMNode * _dataset ){
00178   DOMElement * _element = 0;
00179   if (_dataset){
00180     _element = (DOMElement *)(((DOMElement *)_dataset) -> getElementsByTagName(XMLProcessor::_toXMLCh("DATA"))->item( 0 ));
00181   }
00182   return _element;
00183 }
00184 
00185 
00186 DOMElement * HcalChannelDataXml::get_channel_element( DOMNode * _dataset ){
00187   DOMElement * _element = 0;
00188   if (_dataset){
00189     _element = (DOMElement *)(((DOMElement *)_dataset) -> getElementsByTagName(XMLProcessor::_toXMLCh("CHANNEL"))->item( 0 ));
00190   }
00191   return _element;
00192 }
00193 
00194 
00195 DOMNode * HcalChannelDataXml::set_header_table_name(std::string name){
00196   extension_table_name = name;
00197   DOMElement * _header = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("HEADER") ) -> item(0));
00198   return setTagValue(_header, "EXTENSION_TABLE_NAME", extension_table_name);
00199 }
00200 
00201 
00202 DOMNode * HcalChannelDataXml::set_header_type(std::string type){
00203   type_name = type;
00204   DOMElement * _header = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("HEADER") ) -> item(0));
00205   return setTagValue(_header, "NAME", type_name);
00206 }
00207 
00208 
00209 DOMNode * HcalChannelDataXml::set_header_run_number(int run){
00210   run_number = run;
00211   DOMElement * _header = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("HEADER") ) -> item(0));
00212   return setTagValue(_header, "RUN_NUMBER", run_number);
00213 }
00214 
00215 
00216 DOMNode * HcalChannelDataXml::set_header_channel_map(std::string name){
00217   channel_map = name;
00218   DOMElement * _header = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("HEADER") ) -> item(0));
00219   return setTagAttribute(_header, "HINTS", "channelmap", channel_map);
00220 }
00221 
00222 
00223 DOMNode * HcalChannelDataXml::set_elements_dataset_id(int id){
00224   data_set_id = id;
00225   DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
00226   return setTagAttribute(_elements, "DATA_SET", "id", data_set_id);
00227 }
00228 
00229 
00230 DOMNode * HcalChannelDataXml::set_elements_iov_id(int id){
00231   iov_id = id;
00232   DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
00233   return setTagAttribute(_elements, "IOV", "id", iov_id);
00234 }
00235 
00236 
00237 DOMNode * HcalChannelDataXml::set_elements_iov_begin(int value){
00238   iov_begin = value;
00239   DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
00240   return setTagValue(_elements, "INTERVAL_OF_VALIDITY_BEGIN", iov_begin);
00241 }
00242 
00243 
00244 DOMNode * HcalChannelDataXml::set_elements_iov_end(int value){
00245   iov_end = value;
00246   DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
00247   return setTagValue(_elements, "INTERVAL_OF_VALIDITY_END", iov_end);
00248 }
00249 
00250 
00251 DOMNode * HcalChannelDataXml::set_elements_tag_id(int value){
00252   tag_id = value;
00253   DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
00254   return setTagAttribute(_elements, "TAG", "id", tag_id);
00255 }
00256 
00257 
00258 DOMNode * HcalChannelDataXml::set_elements_tag_mode(std::string value){
00259   tag_mode = value;
00260   DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
00261   return setTagAttribute(_elements, "TAG", "mode", tag_mode);
00262 }
00263 
00264 
00265 DOMNode * HcalChannelDataXml::set_elements_tag_name(std::string value){
00266   tag_name = value;
00267   DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
00268   return setTagValue(_elements, "TAG_NAME", tag_name);
00269 }
00270 
00271 
00272 DOMNode * HcalChannelDataXml::set_elements_detector_name(std::string value){
00273   detector_name = value;
00274   DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
00275   return setTagValue(_elements, "DETECTOR_NAME", detector_name);
00276 }
00277 
00278 
00279 DOMNode * HcalChannelDataXml::set_elements_comment(std::string value){
00280   comment = value;
00281   DOMElement * _elements = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("ELEMENTS") ) -> item(0));
00282   return setTagValue(_elements, "COMMENT_DESCRIPTION", comment);
00283 }
00284 
00285 
00286 DOMNode * HcalChannelDataXml::set_maps_tag_idref(int value){
00287   tag_idref = value;
00288   DOMElement * _maps = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("MAPS") ) -> item(0));
00289   return setTagAttribute(_maps, "TAG", "idref", tag_idref);
00290 }
00291 
00292 
00293 DOMNode * HcalChannelDataXml::set_maps_iov_idref(int value){
00294   iov_idref = value;
00295   DOMElement * _maps = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("MAPS") ) -> item(0));
00296   return setTagAttribute(_maps, "IOV", "idref", iov_idref);
00297 }
00298 
00299 
00300 DOMNode * HcalChannelDataXml::set_maps_dataset_idref(int value){
00301   data_set_idref = value;
00302   DOMElement * _maps = (DOMElement *)(document -> getElementsByTagName( XMLString::transcode("MAPS") ) -> item(0));
00303   return setTagAttribute(_maps, "DATA_SET", "idref", data_set_idref);
00304 }
00305 
00306 
00307 
00308 
00309 
00310 
00311 
00312