CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalHardwareXml.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: XMLTools
4 // Class : HcalHardwareXml
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Gena Kukartsev, kukarzev@fnal.gov
10 // Created: Tue Feb 25 14:30:20 CDT 2008
11 // $Id: HcalHardwareXml.cc,v 1.6 2010/08/06 20:24:13 wmtan Exp $
12 
13 #include <sstream>
14 
17 
19 {
20 
21  DOMElement* rootElem = document -> getDocumentElement();
22 
23  partsElem = document->createElement( XMLString::transcode("PARTS") );
24  rootElem->appendChild(partsElem);
25 }
26 
27 
29 {
30 
31  DOMElement* rootElem = document -> getDocumentElement();
32 
33  partsElem = document->createElement( XMLString::transcode("PARTS") );
34  rootElem->appendChild(partsElem);
35 }
36 
37 
38 
39 
41 {
42  //hw_map["HO001"]["HORBX09"]["200351"][2]="101295";
43 
44  std::map<std::string,int> double_entry; // to check for double entries
45 
46  std::map<std::string,std::map<std::string,std::map<std::string,std::map<int,std::string> > > >::const_iterator rbx_slot;
47  for (rbx_slot = hw_map . begin(); rbx_slot != hw_map . end(); rbx_slot++){
48 
49  HcalPart _p;
50  _p . mode = "find";
51  _p . kind_of_part = "HCAL RBX Slot";
52  _p . name_label = rbx_slot -> first;
53  DOMElement * rbx_slot_elem = addPart( partsElem, _p );
54  DOMElement * rbx_slot_children_elem = (DOMElement *)rbx_slot_elem -> getElementsByTagName(XMLString::transcode("CHILDREN"))->item(0);
55 
56  std::map<std::string,std::map<std::string,std::map<int,std::string> > >::const_iterator rbx;
57  for (rbx = rbx_slot->second . begin(); rbx != rbx_slot->second . end(); rbx++){
58  HcalPart _p2;
59  _p2 . mode = "find";
60  _p2 . kind_of_part = "HCAL RBX";
61  _p2 . name_label = rbx -> first;
62  DOMElement * rbx_elem = addPart( rbx_slot_children_elem, _p2 );
63  DOMElement * rbx_children_elem = (DOMElement *)rbx_elem -> getElementsByTagName(XMLString::transcode("CHILDREN"))->item(0);
64 
65  std::map<std::string,std::map<int,std::string> >::const_iterator rm;
66  for (rm = rbx->second . begin(); rm != rbx->second . end(); rm++){
67  HcalPart _p3;
68  _p3 . mode = "find";
69  _p3 . kind_of_part = "HCAL Readout Module";
70  _p3 . barcode = rm -> first;
71  DOMElement * rm_elem = addPart( rbx_children_elem, _p3 );
72  DOMElement * rm_children_elem = (DOMElement *)rm_elem -> getElementsByTagName(XMLString::transcode("CHILDREN"))->item(0);
73 
74  std::map<int,std::string>::const_iterator qie;
75  for (qie = rm->second . begin(); qie != rm->second . end(); qie++){
76  HcalPart _p4;
77  _p4 . mode = "find";
78  _p4 . kind_of_part = "HCAL QIE Card";
79  _p4 . barcode = qie -> second;
80  _p4 . comment = "HCAL hardware remapping by Gena Kukartsev";
81  _p4 . attr_name = "QIE Card Position";
82  std::stringstream _buffer;
83  _buffer . str("");
84  _buffer << qie->first;
85  _p4 . attr_value = _buffer . str();
86 
87  // check for multiple QIE entries
88  unsigned int _nqie = double_entry.size();
89  double_entry[_p4 . barcode]++;
90  if (double_entry.size() == _nqie){
91  std::cout << "QIE #" << _p4.barcode << " found " << double_entry[_p4 . barcode] << "times!" << std::endl;
92  }else{
93  addPart( rm_children_elem, _p4 );
94  }
95  }
96  }
97  }
98  }
99 
100  return 0;
101 }
102 
103 DOMElement * HcalHardwareXml::addPart( DOMElement * parent, HcalPart & part )
104 {
105 
106  DOMElement * child = document -> createElement( XMLString::transcode( "PART" ) );
107  child -> setAttribute( XMLString::transcode("mode"), XMLString::transcode(part.mode.c_str()) );
108 
109  DOMElement * kindElem = document -> createElement( XMLString::transcode( "KIND_OF_PART" ) );
110  DOMElement * nameElem = document -> createElement( XMLString::transcode( "NAME_LABEL" ) );
111  DOMElement * barElem = document -> createElement( XMLString::transcode( "BARCODE" ) );
112  DOMElement * childrenElem = document -> createElement( XMLString::transcode( "CHILDREN" ) );
113  DOMElement * commentElem = document -> createElement( XMLString::transcode( "COMMENT_DESCRIPTION" ) );
114 
115  child -> appendChild( kindElem );
116  DOMText * _kind = document -> createTextNode( XMLString::transcode(part.kind_of_part.c_str()));
117  kindElem -> appendChild( _kind );
118  if (part.name_label . size() > 0){
119  child -> appendChild( nameElem );
120  DOMText * _name = document -> createTextNode( XMLString::transcode(part.name_label.c_str()));
121  nameElem -> appendChild( _name );
122  }
123  if (part.barcode . size() > 0){
124  child -> appendChild( barElem );
125  DOMText * _code = document -> createTextNode( XMLString::transcode(part.barcode.c_str()));
126  barElem -> appendChild( _code );
127  }
128  if (part.comment . size() > 0){
129  child -> appendChild( commentElem );
130  DOMText * _comment = document -> createTextNode( XMLString::transcode(part.comment.c_str()));
131  commentElem -> appendChild( _comment );
132  }
133  if (part.attr_name . size() > 0 || part.attr_value . size() > 0){
134  DOMElement * predefined_attr_elem = document -> createElement( XMLString::transcode( "PREDEFINED_ATTRIBUTES" ) );
135  child -> appendChild( predefined_attr_elem );
136  DOMElement * attr_elem = document -> createElement( XMLString::transcode( "ATTRIBUTE" ) );
137  predefined_attr_elem -> appendChild( attr_elem );
138  DOMElement * attr_name_elem = document -> createElement( XMLString::transcode( "NAME" ) );
139  attr_elem -> appendChild( attr_name_elem );
140  DOMText * _name = document -> createTextNode( XMLString::transcode(part.attr_name.c_str()));
141  attr_name_elem -> appendChild( _name );
142  DOMElement * attr_value_elem = document -> createElement( XMLString::transcode( "VALUE" ) );
143  attr_elem -> appendChild( attr_value_elem );
144  DOMText * _value = document -> createTextNode( XMLString::transcode(part.attr_value.c_str()));
145  attr_value_elem -> appendChild( _value );
146  }
147  child -> appendChild( childrenElem );
148 
149  parent -> appendChild( child );
150 
151  return child;
152 }
153 
154 
155 
157 {
158 }
159 
160 
virtual ~HcalHardwareXml()
DOMDocument * document
Definition: XMLDOMBlock.h:98
std::string mode
list parent
Definition: dbtoconf.py:74
DOMElement * partsElem
std::string kind_of_part
std::string barcode
dictionary map
Definition: Association.py:205
U second(std::pair< T, U > const &p)
string rm
Definition: submit.py:76
std::string name_label
#define end
Definition: vmac.h:38
bool first
Definition: L1TdeRCT.cc:94
DOMElement * addPart(DOMElement *parent, HcalPart &part)
std::string comment
part
Definition: HCALResponse.h:20
#define begin
Definition: vmac.h:31
int addHardware(std::map< std::string, std::map< std::string, std::map< std::string, std::map< int, std::string > > > > &hw_map)
tuple cout
Definition: gather_cfg.py:121
std::string attr_value
std::string attr_name
tuple size
Write out results.
#define comment(par)
Definition: vmac.h:162