CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
XMLRBXPedestalsLoader.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: XMLTools
4 // Class : XMLRBXPedestalsLoader
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
19 
20 XERCES_CPP_NAMESPACE_USE
21 
22 //
23 // constants, enums and typedefs
24 //
25 
26 //
27 // static data member definitions
28 //
29 
30 //
31 // constructors and destructor
32 //
34 {
35  extention_table_name = "HCAL_RBX_CONFIGURATION_TYPE01";
36  name = "HCAL RBX configuration [PEDESTAL]";
37  run_mode = "auto";
38  data_set_id = "-1";
39  iov_id = "1";
40  iov_begin = 1;
41  iov_end = -1;
42  tag_id = "2";
43  tag_mode = "auto";
44  tag_name = "test_kukartsev_v1";
45  detector_name = "HCAL";
46  elements_comment_description = "RBX pedestals";
47 }
48 
50 {
51  comment_description = "RBX pedestals for an RBX slot";
52  name_label = "HEM10";
53  kind_of_part = "HCAL RBX Slot";
54 }
55 
57 {
58 
59  init();
60 
61  setTagValue( "EXTENSION_TABLE_NAME", config -> extention_table_name );
62  setTagValue( "NAME", config -> name );
63  setTagAttribute( "RUN", "mode", config -> run_mode );
64  setTagAttribute( "DATA_SET", "id", config -> data_set_id );
65  setTagAttribute( "IOV", "id", config -> iov_id );
66  setTagValue( "INTERVAL_OF_VALIDITY_BEGIN", config -> iov_begin );
67  setTagValue( "INTERVAL_OF_VALIDITY_END", config -> iov_end );
68  setTagAttribute( "TAG", "id", config -> tag_id );
69  setTagAttribute( "TAG", "mode", config -> tag_mode );
70  setTagValue( "TAG_NAME", config -> tag_name );
71  setTagValue( "DETECTOR_NAME", config -> detector_name );
72  setTagValue( "COMMENT_DESCRIPTION", config -> elements_comment_description );
73  setTagAttribute( "TAG", "idref", config -> tag_id, 1 );
74  setTagAttribute( "IOV", "idref", config -> iov_id, 1 );
75  setTagAttribute( "DATA_SET", "idref", config -> data_set_id, 1 );
76 }
77 
78 
80 {
81  if( _data_ped_delay ) delete _data_ped_delay;
82  if( _data_gol ) delete _data_gol;
83  if( _data_led ) delete _data_led;
84 }
85 
86 
87 int XMLRBXPedestalsLoader::addRBXSlot( datasetDBConfig * config, std::string brickFileName, std::string rbx_config_type, std::string templateFileName )
88 {
89  DOMElement * root = document -> getDocumentElement();
90 
91  XMLDOMBlock dataSetDoc( templateFileName );
92  DOMDocument * dataSet = dataSetDoc . getDocument();
93 
94  char timebuf[50];
95  strftime( timebuf, 50, "%Y-%m-%d %H:%M:%S.0", gmtime( &(config -> create_timestamp) ) );
96  setTagValue( "CREATE_TIMESTAMP", timebuf , 0, dataSet );
97  setTagValue( "CREATED_BY_USER", config -> created_by_user, 0, dataSet );
98  setTagValue( "VERSION", config -> version, 0, dataSet );
99  setTagValue( "SUBVERSION", config -> subversion, 0, dataSet );
100  setTagValue( "COMMENT_DESCRIPTION", config -> comment_description, 0, dataSet );
101  setTagValue( "NAME_LABEL", config -> name_label, 0, dataSet );
102  setTagValue( "KIND_OF_PART", config -> kind_of_part, 0, dataSet );
103 
104  // <DATA/>
105  //XMLDOMBlock rbxBrickDoc( "rbx_HBM01_PEDESTAL.xml" );
106  XMLDOMBlock rbxBrickDoc( brickFileName );
107  DOMDocument * rbxBrick = rbxBrickDoc . getDocument();
108  if ( rbx_config_type == "pedestals" || rbx_config_type == "delays" || rbx_config_type == "gols" ){
109  for ( unsigned int _item = 0; _item < rbxBrick -> getElementsByTagName( XMLProcessor::_toXMLCh( "Data" ) ) -> getLength(); _item++ ){
110  DOMElement * dataset_root = dataSet -> getDocumentElement();
111 
112  std::string _rm;
113  std::string _qie;
114  std::string _adc;
115  //string _led_item;
116 
117  MemBufInputSource * _data; // a container for the XML template for a data block
118  if ( rbx_config_type == "pedestals" || rbx_config_type == "delays" ){
119  _rm = rbxBrickDoc . getTagAttribute( "Data", "rm", _item );
120  _qie = rbxBrickDoc . getTagAttribute( "Data", "card", _item );
121  _adc = rbxBrickDoc . getTagAttribute( "Data", "qie", _item );
122  _data = _data_ped_delay;
123  }
124  else if ( rbx_config_type == "gols" ){
125  _rm = rbxBrickDoc . getTagAttribute( "Data", "rm", _item );
126  _qie = rbxBrickDoc . getTagAttribute( "Data", "card", _item );
127  _adc = rbxBrickDoc . getTagAttribute( "Data", "gol", _item );
128  _data = _data_gol;
129  }
130  //else if ( rbx_config_type == "leds" ){
131  //_led_item = rbxBrickDoc . getTagAttribute( "Data", "item", _item );
132  //_data = _data_led;
133  //}
134  else{
135  std::cout << "XMLRBXPedestalsLoader::addRBXSlot(): Unknown config type... exiting" << std::endl;
136  exit(1);
137  }
138  XMLDOMBlock dataDoc( *_data );
139  DOMDocument * data = dataDoc . getDocument();
140  std::string _value = rbxBrickDoc . getTagValue( "Data", _item );
141  if ( rbx_config_type == "pedestals" || rbx_config_type == "delays" ){
142  setTagValue( "MODULE_POSITION", _rm, 0, data );
143  setTagValue( "QIE_CARD_POSITION", _qie, 0, data );
144  setTagValue( "QIE_ADC_NUMBER", _adc, 0, data );
145  }
146  else if ( rbx_config_type == "gols" ){
147  setTagValue( "MODULE_POSITION", _rm, 0, data );
148  setTagValue( "QIE_CARD_POSITION", _qie, 0, data );
149  setTagValue( "FIBER_NUMBER", _adc, 0, data );
150  }
151  else if ( rbx_config_type == "gols" ){
152  setTagValue( "MODULE_POSITION", _rm, 0, data );
153  setTagValue( "QIE_CARD_POSITION", _qie, 0, data );
154  setTagValue( "FIBER_NUMBER", _adc, 0, data );
155  }
156  else if ( rbx_config_type == "leds" ){
157  setTagValue( "MODULE_POSITION", _rm, 0, data );
158  setTagValue( "QIE_CARD_POSITION", _qie, 0, data );
159  setTagValue( "FIBER_NUMBER", _adc, 0, data );
160  }
161  else{
162  std::cout << "XMLRBXPedestalsLoader::addRBXSlot(): Unknown config type... exiting" << std::endl;
163  exit(1);
164  }
165  setTagValue( "INTEGER_VALUE", _value, 0, data );
166  DOMNode * cloneData = dataSet -> importNode( data -> getDocumentElement(), true );
167  dataset_root -> appendChild( cloneData );
168  }
169  }
170  else if ( rbx_config_type == "leds" ){
171  DOMElement * dataset_root = dataSet -> getDocumentElement();
172 
173  std::string _led_item;
174 
175  MemBufInputSource * _data; // a container for the XML template for a data block
176  _data = _data_led;
177  std::string _value;
178 
179  XMLDOMBlock dataDoc( *_data );
180  DOMDocument * data = dataDoc . getDocument();
181 
182  int _item = 0;
183  _led_item = rbxBrickDoc . getTagAttribute( "Data", "item", _item );
184  // FIXME: need to check that the right data tag (_led_item) from the original brick is being processed
185  _value = rbxBrickDoc . getTagValue( "Data", _item );
186  setTagValue( "LED1_ON_IS_CHECKED", _value, 0, data );
187  setTagValue( "SET_LEDS_IS_CHECKED", _value, 0, data );
188  _item = 1;
189  _led_item = rbxBrickDoc . getTagAttribute( "Data", "item", _item );
190  _value = rbxBrickDoc . getTagValue( "Data", _item );
191  setTagValue( "LED2_ON_IS_CHECKED", _value, 0, data );
192  if (_value.find("0")==std::string::npos){
193  setTagValue( "SET_LEDS_IS_CHECKED", _value, 0, data );
194  }
195  _item = 2;
196  _led_item = rbxBrickDoc . getTagAttribute( "Data", "item", _item );
197  _value = rbxBrickDoc . getTagValue( "Data", _item );
198  setTagValue( "LED_AMPLITUDE", _value, 0, data );
199  _item = 3;
200  _led_item = rbxBrickDoc . getTagAttribute( "Data", "item", _item );
201  _value = rbxBrickDoc . getTagValue( "Data", _item );
202  setTagValue( "BUNCH_NUMBER", _value, 0, data );
203 
204  DOMNode * cloneData = dataSet -> importNode( data -> getDocumentElement(), true );
205  dataset_root -> appendChild( cloneData );
206  }
207 
208  // copy the <data_set> node into the final XML
209  DOMNode * cloneDataSet = document -> importNode( dataSet -> getDocumentElement(), true );
210  root -> appendChild( cloneDataSet );
211 
212  // update header from the brick
213  std::string _name;
214  int parameter_iter = -1;
215  do
216  {
217  parameter_iter++;
218  _name = rbxBrickDoc . getTagAttribute( "Parameter", "name", parameter_iter );
219  //std::cout << _name << std::endl;
220  } while( _name != "CREATIONTAG" );
221  std::string _creationtag = rbxBrickDoc . getTagValue( "Parameter", parameter_iter );
222  //std::cout << _creationtag << std::endl;
223  //setTagValue( "TAG_NAME", _creationtag ); // uncomment if want to pick up tag name from the brick set
224 
225  parameter_iter = -1;
226  do
227  {
228  parameter_iter++;
229  _name = rbxBrickDoc . getTagAttribute( "Parameter", "name", parameter_iter );
230  //std::cout << _name << std::endl;
231  } while( _name != "RBX" );
232  std::string _rbx = rbxBrickDoc . getTagValue( "Parameter", parameter_iter );
233 
234  // name_label fix - should be temporary
235  //fixRbxName( _rbx );
236  std::cout << _rbx << std::endl;
237  setTagValue( "NAME_LABEL", _rbx );
238 
239  // change kind of part name if this is ZDC (there is only one - ZDC01)
240  if (_rbx.find("ZDC01")!=std::string::npos){
241  setTagValue( "KIND_OF_PART", "HCAL ZDC RBX" );
242  std::cout << " --> ZDC RBX!" << std::endl;
243  }
244 
245  return 0;
246 }
247 
249 {
250  std::string _fourth = rbx . substr(0,4);
251  if ( _fourth == "HBM0" || _fourth == "HBP0" || _fourth == "HEP0" || _fourth == "HFP0" || _fourth == "HOP0" || _fourth == "HOM0" ) rbx . erase( 3, 1 );
252 
253  if ( rbx == "HO0M02" ) rbx = "HO0M2";
254  if ( rbx == "HO0M04" ) rbx = "HO0M4";
255  if ( rbx == "HO0M06" ) rbx = "HO0M6";
256  if ( rbx == "HO0M08" ) rbx = "HO0M8";
257  if ( rbx == "HO0M10" ) rbx = "HO0M10";
258  if ( rbx == "HO0M12" ) rbx = "HO0M12";
259  if ( rbx == "HO0P02" ) rbx = "HO0P2";
260  if ( rbx == "HO0P04" ) rbx = "HO0P4";
261  if ( rbx == "HO0P06" ) rbx = "HO0P6";
262  if ( rbx == "HO0P08" ) rbx = "HO0P8";
263  if ( rbx == "HO0P10" ) rbx = "HO0P10";
264  if ( rbx == "HO0P12" ) rbx = "HO0P12";
265 
266  return 0;
267 }
268 
270 {
271  // define the <DATA/> template for pedestals and zero delays
272  static const char * _str = "\
273  <DATA>\n\
274  <MODULE_POSITION>2</MODULE_POSITION>\n\
275  <QIE_CARD_POSITION>1</QIE_CARD_POSITION>\n\
276  <QIE_ADC_NUMBER>0</QIE_ADC_NUMBER>\n\
277  <INTEGER_VALUE>4</INTEGER_VALUE>\n\
278  </DATA>\n\
279  ";
280  const XMLByte * _template = (const XMLByte *)_str;
281  _data_ped_delay = new MemBufInputSource( _template, strlen( (const char *)_template ), "_data_ped_delay", false );
282 
283  // define the <DATA/> template for gol currents
284  static const char * _str2 = "\
285  <DATA>\n\
286  <MODULE_POSITION>2</MODULE_POSITION>\n\
287  <QIE_CARD_POSITION>1</QIE_CARD_POSITION>\n\
288  <FIBER_NUMBER>0</FIBER_NUMBER>\n\
289  <INTEGER_VALUE>4</INTEGER_VALUE>\n\
290  </DATA>\n\
291  ";
292  const XMLByte * _template2 = (const XMLByte *)_str2;
293  _data_gol = new MemBufInputSource( _template2, strlen( (const char *)_template2 ), "_data_gol", false );
294 
295  // define the <DATA/> template for LED data
296  static const char * _str3 = "\
297  <DATA>\n\
298  <RM1_IS_CHECKED>1</RM1_IS_CHECKED>\n\
299  <RM2_IS_CHECKED>1</RM2_IS_CHECKED>\n\
300  <RM3_IS_CHECKED>1</RM3_IS_CHECKED>\n\
301  <RM4_IS_CHECKED>1</RM4_IS_CHECKED>\n\
302  <CALIB_IS_CHECKED>1</CALIB_IS_CHECKED>\n\
303  <RESET1_IS_CHECKED>1</RESET1_IS_CHECKED>\n\
304  <RESET1_VALUE>40</RESET1_VALUE>\n\
305  <RESET1_WAIT_CYCLES>3</RESET1_WAIT_CYCLES>\n\
306  <RESET2_IS_CHECKED>1</RESET2_IS_CHECKED>\n\
307  <RESET2_VALUE>40</RESET2_VALUE>\n\
308  <RESET2_WAIT_CYCLES>3</RESET2_WAIT_CYCLES>\n\
309  <SET_LEDS_IS_CHECKED>0</SET_LEDS_IS_CHECKED>\n\
310  <LED1_ON_IS_CHECKED>0</LED1_ON_IS_CHECKED>\n\
311  <LED2_ON_IS_CHECKED>0</LED2_ON_IS_CHECKED>\n\
312  <LED_AMPLITUDE>128</LED_AMPLITUDE>\n\
313  <LED_DELAY>1000</LED_DELAY>\n\
314  <TTCRX_PHASE>100</TTCRX_PHASE>\n\
315  <BROADCAST_SETTINGS>1</BROADCAST_SETTINGS>\n\
316  <QIE_RESET_DELAY>5</QIE_RESET_DELAY>\n\
317  <BUNCH_NUMBER>2000</BUNCH_NUMBER>\n\
318  </DATA>\n\
319  ";
320  const XMLByte * _template3 = (const XMLByte *)_str3;
321  _data_led = new MemBufInputSource( _template3, strlen( (const char *)_template3 ), "_data_led", false );
322 
323  return 0;
324 }
325 
326 //
327 // const member functions
328 //
329 
330 //
331 // static member functions
332 //
XERCES_CPP_NAMESPACE::MemBufInputSource * _data_ped_delay
XERCES_CPP_NAMESPACE::DOMDocument * document
Definition: XMLDOMBlock.h:96
XERCES_CPP_NAMESPACE::MemBufInputSource * _data_gol
XMLRBXPedestalsLoader(loaderBaseConfig *config, std::string templateBase="HCAL_RBX_PEDESTALS_TYPE01.XMLloader.template")
XERCES_CPP_NAMESPACE::DOMDocument * getDocument(void)
Definition: XMLDOMBlock.cc:312
int fixRbxName(std::string &)
XERCES_CPP_NAMESPACE::DOMNode * setTagValue(const std::string &tagName, const std::string &tagValue, int _item=0, XERCES_CPP_NAMESPACE::DOMDocument *_document=NULL)
static XMLCh * _toXMLCh(std::string temp)
Definition: XMLProcessor.h:183
XERCES_CPP_NAMESPACE::MemBufInputSource * _data_led
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
tuple cout
Definition: gather_cfg.py:121
const char * getTagValue(const std::string &tagName, int _item=0, XERCES_CPP_NAMESPACE::DOMDocument *_document=NULL)
int addRBXSlot(datasetDBConfig *config, std::string brickFileName, std::string rbx_config_type="pedestals", std::string templateFileName="HCAL_RBX_PEDESTALS_TYPE01.dataset.template")
XERCES_CPP_NAMESPACE::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
const char * getTagAttribute(const std::string &tagName, const std::string &attrName, int _item=0)
Definition: XMLDOMBlock.cc:400