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