CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
XMLHTRPatternLoader.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: XMLTools
4 // Class : XMLHTRPatternLoader
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Gena Kukartsev, kukarzev@fnal.gov
10 // Created: Tue Oct 23 14:30:20 CDT 2007
11 //
12 
13 // system include files
14 
15 // user include files
18 #include <cstdio>
19 
20 //
21 // constants, enums and typedefs
22 //
23 
24 //
25 // static data member definitions
26 //
27 
28 //
29 // constructors and destructor
30 //
32 {
33  extention_table_name = "HCAL_HTR_DATA_PATTERNS";
34  name = "HCAL HRT data patterns";
35  run_mode = "no-run";
36  data_set_id = "-1";
37  iov_id = "1";
38  iov_begin = "0";
39  iov_end = "1";
40  tag_id = "2";
41  tag_mode = "auto";
42  tag_name = "HTR data pattern test";
43  detector_name = "HCAL";
44  comment_description = "empty comment, by kukarzev";
45 }
46 
48 {
49  kind_of_part = "HCAL HTR Crate";
50  name_label = "CRATE17";
51  htr_data_patterns_data_file = "testHTRPatterns_17.xml";
52  crate = 17;
53 }
54 
56 {
57  comment_description = "checksum for all crates version test:2";
58  name_label = "CMS-HCAL-ROOT";
59  htr_data_patterns_data_file = "./testHTRPattern_checksums.xml";
60  crate = -1;
61 }
62 
64 {
65 }
66 
68 {
69  setTagValue( "EXTENSION_TABLE_NAME", config -> extention_table_name );
70  setTagValue( "NAME", config -> name );
71  setTagAttribute( "RUN", "mode", config -> run_mode );
72  setTagAttribute( "DATA_SET", "id", config -> data_set_id );
73  setTagAttribute( "IOV", "id", config -> iov_id );
74  setTagValue( "INTERVAL_OF_VALIDITY_BEGIN", config -> iov_begin );
75  setTagValue( "INTERVAL_OF_VALIDITY_END", config -> iov_end );
76  setTagAttribute( "TAG", "id", config -> tag_id );
77  setTagAttribute( "TAG", "mode", config -> tag_mode );
78  setTagValue( "TAG_NAME", config -> tag_name );
79  setTagValue( "DETECTOR_NAME", config -> detector_name );
80  setTagValue( "COMMENT_DESCRIPTION", config -> comment_description );
81 
82  setTagAttribute( "TAG", "idref", config -> tag_id, 1 );
83  setTagAttribute( "IOV", "idref", config -> iov_id, 1 );
84  setTagAttribute( "DATA_SET", "idref", config -> data_set_id, 1 );
85 }
86 
87 // XMLHTRPatternLoader::XMLHTRPatternLoader(const XMLHTRPatternLoader& rhs)
88 // {
89 // // do actual copying here;
90 // }
91 
93 {
94 }
95 
96 //
97 // assignment operators
98 //
99 // const XMLHTRPatternLoader& XMLHTRPatternLoader::operator=(const XMLHTRPatternLoader& rhs)
100 // {
101 // //An exception safe implementation is
102 // XMLHTRPatternLoader temp(rhs);
103 // swap(rhs);
104 //
105 // return *this;
106 // }
107 
108 //
109 // member functions
110 //
112 {
113  DOMElement * root = document -> getDocumentElement();
114 
115  XMLDOMBlock dataSetDoc( templateFileName );
116  DOMDocument * dataSet = dataSetDoc . getDocument();
117 
118  // changes to the HTRPATTERN <data_set> node
119  setTagValue( "VERSION", config -> version, 0, dataSet );
120  setTagValue( "SUBVERSION", config -> subversion, 0, dataSet );
121  char timebuf[50];
122  //strftime( timebuf, 50, "%c", gmtime( &(config -> create_timestamp) ) );
123  strftime( timebuf, 50, "%Y-%m-%d %H:%M:%S.0", gmtime( &(config -> create_timestamp) ) );
124  setTagValue( "CREATE_TIMESTAMP", timebuf , 0, dataSet );
125  setTagValue( "CREATED_BY_USER", config -> created_by_user, 0, dataSet );
126  setTagValue( "KIND_OF_PART", config -> kind_of_part, 0, dataSet );
127  setTagValue( "NAME_LABEL", config -> name_label, 0, dataSet );
128  setTagValue( "HTR_DATA_PATTERNS_DATA_FILE", config -> htr_data_patterns_data_file, 0, dataSet );
129  setTagValue( "CRATE", config -> crate, 0, dataSet );
130 
131  // copy the <data_set> node into the final XML
132  DOMNode * cloneDataSet = document -> importNode( dataSet -> getDocumentElement(), true );
133  root -> appendChild( cloneDataSet );
134 
135  return 0;
136 }
137 
139 {
140  DOMElement * root = document -> getDocumentElement();
141 
142  XMLDOMBlock dataSetDoc( templateFileName );
143  DOMDocument * dataSet = dataSetDoc . getDocument();
144 
145  // changes to the Checksums <data_set> node
146  setTagValue( "VERSION", config -> version, 0, dataSet );
147  setTagValue( "SUBVERSION", config -> subversion, 0, dataSet );
148  char timebuf[50];
149  //strftime( timebuf, 50, "%c", gmtime( &(config -> create_timestamp) ) );
150  strftime( timebuf, 50, "%Y-%m-%d %H:%M:%S.0", gmtime( &(config -> create_timestamp) ) );
151  setTagValue( "CREATE_TIMESTAMP", timebuf , 0, dataSet );
152  setTagValue( "CREATED_BY_USER", config -> created_by_user, 0, dataSet );
153  setTagValue( "COMMENT_DESCRIPTION", config -> comment_description, 0, dataSet );
154  setTagValue( "NAME_LABEL", config -> name_label, 0, dataSet );
155  setTagValue( "HTR_DATA_PATTERNS_DATA_FILE", config -> htr_data_patterns_data_file, 0, dataSet );
156  setTagValue( "CRATE", config -> crate, 0, dataSet );
157 
158  // copy the <data_set> node into the final XML
159  DOMNode * cloneDataSet = document -> importNode( dataSet -> getDocumentElement(), true );
160  root -> appendChild( cloneDataSet );
161 
162  return 0;
163 }
164 
165 int XMLHTRPatternLoader::createLoader( const std::vector<int>& crate_number, const std::vector<std::string>& file_name )
166 {
168 
169  for ( std::vector<std::string>::const_iterator _file = file_name . begin(); _file != file_name . end(); _file++ )
170  {
171  conf . htr_data_patterns_data_file = *_file;
172  conf . htr_data_patterns_data_file += ".dat";
173  conf . crate = crate_number[ _file - file_name . begin() ];
174 
175  char _buf[128];
176  sprintf( _buf, "CRATE%.2d", conf . crate );
177  std::string _namelabel;
178  _namelabel . append( _buf );
179  conf . name_label = _namelabel;
180  addPattern( &conf );
181  }
182 
183  write( "HTRPatternLoader.xml" );
184 
185  return 0;
186 }
187 
188 //
189 // const member functions
190 //
191 
192 //
193 // static member functions
194 //
int write(std::string target="stdout")
Definition: XMLDOMBlock.cc:322
DOMDocument * document
Definition: XMLDOMBlock.h:97
int addChecksums(checksumsDBConfig *config, std::string templateFileName="HCAL_HTR_DATA_PATTERNS.checksums.template")
int addPattern(datasetDBConfig *config, std::string templateFileName="HCAL_HTR_DATA_PATTERNS.dataset.template")
DOMDocument * getDocument(void)
Definition: XMLDOMBlock.cc:312
#define end
Definition: vmac.h:37
tuple conf
Definition: dbtoconf.py:185
#define begin
Definition: vmac.h:30
int createLoader(const std::vector< int > &crate_number, const std::vector< std::string > &file_name)
DOMNode * setTagValue(const std::string &tagName, const std::string &tagValue, int _item=0, DOMDocument *_document=NULL)
Definition: XMLDOMBlock.cc:364
DOMNode * setTagAttribute(const std::string &tagName, const std::string &attrName, const std::string &attrValue, int _item=0)
Definition: XMLDOMBlock.cc:408
string root
initialization
Definition: dbtoconf.py:70