CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
XMLLUTLoader.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: XMLTools
4 // Class : XMLLUTLoader
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 // $Id: XMLLUTLoader.cc,v 1.4 2010/08/06 20:24:13 wmtan Exp $
12 //
13 
14 // system include files
15 
16 // user include files
19 #include <cstdio>
20 
21 //
22 // constants, enums and typedefs
23 //
24 
25 //
26 // static data member definitions
27 //
28 
29 //
30 // constructors and destructor
31 //
33 {
34  kind_of_part = "HCAL HTR Crate";
35  name_label = "CRATE17";
36  trig_prim_lookuptbl_data_file = "testLUT_17.xml";
37  crate = 17;
38 }
39 
41 {
42  comment_description = "checksum for all crates version test:2";
43  name_label = "CMS-HCAL-ROOT";
44  trig_prim_lookuptbl_data_file = "./testLUT_checksums.xml";
45  crate = -1;
46 }
47 
49 {
50 }
51 
52 XMLLUTLoader::XMLLUTLoader( XMLProcessor::loaderBaseConfig * config, std::string templateBase ) : XMLDOMBlock( templateBase )
53 {
54  setTagValue( "EXTENSION_TABLE_NAME", config -> extention_table_name );
55  setTagValue( "NAME", config -> name );
56  setTagAttribute( "RUN", "mode", config -> run_mode );
57  setTagAttribute( "DATA_SET", "id", config -> data_set_id );
58  setTagAttribute( "IOV", "id", config -> iov_id );
59  setTagValue( "INTERVAL_OF_VALIDITY_BEGIN", config -> iov_begin );
60  setTagValue( "INTERVAL_OF_VALIDITY_END", config -> iov_end );
61  setTagAttribute( "TAG", "id", config -> tag_id );
62  setTagAttribute( "TAG", "mode", config -> tag_mode );
63  setTagValue( "TAG_NAME", config -> tag_name );
64  setTagValue( "DETECTOR_NAME", config -> detector_name );
65  setTagValue( "COMMENT_DESCRIPTION", config -> comment_description );
66 
67  setTagAttribute( "TAG", "idref", config -> tag_id, 1 );
68  setTagAttribute( "IOV", "idref", config -> iov_id, 1 );
69  setTagAttribute( "DATA_SET", "idref", config -> data_set_id, 1 );
70 }
71 
72 // XMLLUTLoader::XMLLUTLoader(const XMLLUTLoader& rhs)
73 // {
74 // // do actual copying here;
75 // }
76 
78 {
79 }
80 
81 //
82 // assignment operators
83 //
84 // const XMLLUTLoader& XMLLUTLoader::operator=(const XMLLUTLoader& rhs)
85 // {
86 // //An exception safe implementation is
87 // XMLLUTLoader temp(rhs);
88 // swap(rhs);
89 //
90 // return *this;
91 // }
92 
93 //
94 // member functions
95 //
96 int XMLLUTLoader::addLUT( lutDBConfig * config, std::string templateFileName )
97 {
98  DOMElement * root = document -> getDocumentElement();
99 
100  XMLDOMBlock dataSetDoc( templateFileName );
101  DOMDocument * dataSet = dataSetDoc . getDocument();
102 
103  // changes to the LUT <data_set> node
104  setTagValue( "VERSION", config -> version, 0, dataSet );
105  setTagValue( "SUBVERSION", config -> subversion, 0, dataSet );
106  char timebuf[50];
107  //strftime( timebuf, 50, "%c", gmtime( &(config -> create_timestamp) ) );
108  strftime( timebuf, 50, "%Y-%m-%d %H:%M:%S.0", gmtime( &(config -> create_timestamp) ) );
109  setTagValue( "CREATE_TIMESTAMP", timebuf , 0, dataSet );
110  setTagValue( "CREATED_BY_USER", config -> created_by_user, 0, dataSet );
111  setTagValue( "KIND_OF_PART", config -> kind_of_part, 0, dataSet );
112  setTagValue( "NAME_LABEL", config -> name_label, 0, dataSet );
113  setTagValue( "TRIG_PRIM_LOOKUPTBL_DATA_FILE", config -> trig_prim_lookuptbl_data_file, 0, dataSet );
114  setTagValue( "CRATE", config -> crate, 0, dataSet );
115 
116  // copy the <data_set> node into the final XML
117  DOMNode * cloneDataSet = document -> importNode( dataSet -> getDocumentElement(), true );
118  root -> appendChild( cloneDataSet );
119 
120  return 0;
121 }
122 
123 int XMLLUTLoader::addChecksums( checksumsDBConfig * config, std::string templateFileName )
124 {
125  DOMElement * root = document -> getDocumentElement();
126 
127  XMLDOMBlock dataSetDoc( templateFileName );
128  DOMDocument * dataSet = dataSetDoc . getDocument();
129 
130  // changes to the Checksums <data_set> node
131  setTagValue( "VERSION", config -> version, 0, dataSet );
132  setTagValue( "SUBVERSION", config -> subversion, 0, dataSet );
133  char timebuf[50];
134  //strftime( timebuf, 50, "%c", gmtime( &(config -> create_timestamp) ) );
135  strftime( timebuf, 50, "%Y-%m-%d %H:%M:%S.0", gmtime( &(config -> create_timestamp) ) );
136  setTagValue( "CREATE_TIMESTAMP", timebuf , 0, dataSet );
137  setTagValue( "CREATED_BY_USER", config -> created_by_user, 0, dataSet );
138  setTagValue( "COMMENT_DESCRIPTION", config -> comment_description, 0, dataSet );
139  setTagValue( "NAME_LABEL", config -> name_label, 0, dataSet );
140  setTagValue( "TRIG_PRIM_LOOKUPTBL_DATA_FILE", config -> trig_prim_lookuptbl_data_file, 0, dataSet );
141  setTagValue( "CRATE", config -> crate, 0, dataSet );
142 
143  // copy the <data_set> node into the final XML
144  DOMNode * cloneDataSet = document -> importNode( dataSet -> getDocumentElement(), true );
145  root -> appendChild( cloneDataSet );
146 
147  return 0;
148 }
149 
150 int XMLLUTLoader::createLoader( std::vector<int> crate_number, std::vector<std::string> file_name )
151 {
154 
155  for ( std::vector<std::string>::const_iterator _file = file_name . begin(); _file != file_name . end(); _file++ )
156  {
157  conf . trig_prim_lookuptbl_data_file = *_file;
158  conf . trig_prim_lookuptbl_data_file += ".dat";
159  conf . crate = crate_number[ _file - file_name . begin() ];
160 
161  char _buf[128];
162  sprintf( _buf, "CRATE%.2d", conf . crate );
163  std::string _namelabel;
164  _namelabel . append( _buf );
165  conf . name_label = _namelabel;
166  addLUT( &conf );
167  }
168 
169  CSconf . trig_prim_lookuptbl_data_file += ".dat";
170  addChecksums( &CSconf );
171  write( "LUTLoader.xml" );
172 
173  return 0;
174 }
175 
176 //
177 // const member functions
178 //
179 
180 //
181 // static member functions
182 //
int addLUT(lutDBConfig *config, std::string templateFileName="HCAL_TRIG_PRIM_LOOKUP_TABLE.dataset.template")
Definition: XMLLUTLoader.cc:96
int write(std::string target="stdout")
Definition: XMLDOMBlock.cc:323
DOMDocument * document
Definition: XMLDOMBlock.h:98
int createLoader(std::vector< int > crate_number, std::vector< std::string > file_name)
virtual ~XMLLUTLoader()
Definition: XMLLUTLoader.cc:77
DOMDocument * getDocument(void)
Definition: XMLDOMBlock.cc:313
#define end
Definition: vmac.h:38
tuple conf
Definition: dbtoconf.py:185
#define begin
Definition: vmac.h:31
int addChecksums(checksumsDBConfig *config, std::string templateFileName="HCAL_TRIG_PRIM_LOOKUP_TABLE.checksums.template")
std::string trig_prim_lookuptbl_data_file
Definition: XMLLUTLoader.h:45
DOMNode * setTagValue(const std::string &tagName, const std::string &tagValue, int _item=0, DOMDocument *_document=NULL)
Definition: XMLDOMBlock.cc:365
DOMNode * setTagAttribute(const std::string &tagName, const std::string &attrName, const std::string &attrValue, int _item=0)
Definition: XMLDOMBlock.cc:409
string root
initialization
Definition: dbtoconf.py:70