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 
12 #include <sstream>
13 
16 XERCES_CPP_NAMESPACE_USE
18 {
19 
20  DOMElement* rootElem = document -> getDocumentElement();
21 
22  partsElem = document->createElement( XMLString::transcode("PARTS") );
23  rootElem->appendChild(partsElem);
24 }
25 
26 
28 {
29 
30  DOMElement* rootElem = document -> getDocumentElement();
31 
32  partsElem = document->createElement( XMLString::transcode("PARTS") );
33  rootElem->appendChild(partsElem);
34 }
35 
36 
37 
38 
39 int HcalHardwareXml::addHardware( std::map<std::string,std::map<std::string,std::map<std::string,std::map<int,std::string> > > > & hw_map )
40 {
41  //hw_map["HO001"]["HORBX09"]["200351"][2]="101295";
42 
43  std::map<std::string,int> double_entry; // to check for double entries
44 
45  std::map<std::string,std::map<std::string,std::map<std::string,std::map<int,std::string> > > >::const_iterator rbx_slot;
46  for (rbx_slot = hw_map . begin(); rbx_slot != hw_map . end(); rbx_slot++){
47 
48  HcalPart _p;
49  _p . mode = "find";
50  _p . kind_of_part = "HCAL RBX Slot";
51  _p . name_label = rbx_slot -> first;
52  DOMElement * rbx_slot_elem = addPart( partsElem, _p );
53  DOMElement * rbx_slot_children_elem = (DOMElement *)rbx_slot_elem -> getElementsByTagName(XMLString::transcode("CHILDREN"))->item(0);
54 
55  std::map<std::string,std::map<std::string,std::map<int,std::string> > >::const_iterator rbx;
56  for (rbx = rbx_slot->second . begin(); rbx != rbx_slot->second . end(); rbx++){
57  HcalPart _p2;
58  _p2 . mode = "find";
59  _p2 . kind_of_part = "HCAL RBX";
60  _p2 . name_label = rbx -> first;
61  DOMElement * rbx_elem = addPart( rbx_slot_children_elem, _p2 );
62  DOMElement * rbx_children_elem = (DOMElement *)rbx_elem -> getElementsByTagName(XMLString::transcode("CHILDREN"))->item(0);
63 
64  std::map<std::string,std::map<int,std::string> >::const_iterator rm;
65  for (rm = rbx->second . begin(); rm != rbx->second . end(); rm++){
66  HcalPart _p3;
67  _p3 . mode = "find";
68  _p3 . kind_of_part = "HCAL Readout Module";
69  _p3 . barcode = rm -> first;
70  DOMElement * rm_elem = addPart( rbx_children_elem, _p3 );
71  DOMElement * rm_children_elem = (DOMElement *)rm_elem -> getElementsByTagName(XMLString::transcode("CHILDREN"))->item(0);
72 
73  std::map<int,std::string>::const_iterator qie;
74  for (qie = rm->second . begin(); qie != rm->second . end(); qie++){
75  HcalPart _p4;
76  _p4 . mode = "find";
77  _p4 . kind_of_part = "HCAL QIE Card";
78  _p4 . barcode = qie -> second;
79  _p4 . comment = "HCAL hardware remapping by Gena Kukartsev";
80  _p4 . attr_name = "QIE Card Position";
81  std::stringstream _buffer;
82  _buffer . str("");
83  _buffer << qie->first;
84  _p4 . attr_value = _buffer . str();
85 
86  // check for multiple QIE entries
87  unsigned int _nqie = double_entry.size();
88  double_entry[_p4 . barcode]++;
89  if (double_entry.size() == _nqie){
90  std::cout << "QIE #" << _p4.barcode << " found " << double_entry[_p4 . barcode] << "times!" << std::endl;
91  }else{
92  addPart( rm_children_elem, _p4 );
93  }
94  }
95  }
96  }
97  }
98 
99  return 0;
100 }
101 
102 DOMElement * HcalHardwareXml::addPart( DOMElement * parent, HcalPart & part )
103 {
104 
105  DOMElement * child = document -> createElement( XMLString::transcode( "PART" ) );
106  child -> setAttribute( XMLString::transcode("mode"), XMLString::transcode(part.mode.c_str()) );
107 
108  DOMElement * kindElem = document -> createElement( XMLString::transcode( "KIND_OF_PART" ) );
109  DOMElement * nameElem = document -> createElement( XMLString::transcode( "NAME_LABEL" ) );
110  DOMElement * barElem = document -> createElement( XMLString::transcode( "BARCODE" ) );
111  DOMElement * childrenElem = document -> createElement( XMLString::transcode( "CHILDREN" ) );
112  DOMElement * commentElem = document -> createElement( XMLString::transcode( "COMMENT_DESCRIPTION" ) );
113 
114  child -> appendChild( kindElem );
115  DOMText * _kind = document -> createTextNode( XMLString::transcode(part.kind_of_part.c_str()));
116  kindElem -> appendChild( _kind );
117  if (part.name_label . size() > 0){
118  child -> appendChild( nameElem );
119  DOMText * _name = document -> createTextNode( XMLString::transcode(part.name_label.c_str()));
120  nameElem -> appendChild( _name );
121  }
122  if (part.barcode . size() > 0){
123  child -> appendChild( barElem );
124  DOMText * _code = document -> createTextNode( XMLString::transcode(part.barcode.c_str()));
125  barElem -> appendChild( _code );
126  }
127  if (part.comment . size() > 0){
128  child -> appendChild( commentElem );
129  DOMText * _comment = document -> createTextNode( XMLString::transcode(part.comment.c_str()));
130  commentElem -> appendChild( _comment );
131  }
132  if (part.attr_name . size() > 0 || part.attr_value . size() > 0){
133  DOMElement * predefined_attr_elem = document -> createElement( XMLString::transcode( "PREDEFINED_ATTRIBUTES" ) );
134  child -> appendChild( predefined_attr_elem );
135  DOMElement * attr_elem = document -> createElement( XMLString::transcode( "ATTRIBUTE" ) );
136  predefined_attr_elem -> appendChild( attr_elem );
137  DOMElement * attr_name_elem = document -> createElement( XMLString::transcode( "NAME" ) );
138  attr_elem -> appendChild( attr_name_elem );
139  DOMText * _name = document -> createTextNode( XMLString::transcode(part.attr_name.c_str()));
140  attr_name_elem -> appendChild( _name );
141  DOMElement * attr_value_elem = document -> createElement( XMLString::transcode( "VALUE" ) );
142  attr_elem -> appendChild( attr_value_elem );
143  DOMText * _value = document -> createTextNode( XMLString::transcode(part.attr_value.c_str()));
144  attr_value_elem -> appendChild( _value );
145  }
146  child -> appendChild( childrenElem );
147 
148  parent -> appendChild( child );
149 
150  return child;
151 }
152 
153 
154 
156 {
157 }
158 
159 
XERCES_CPP_NAMESPACE::DOMDocument * document
Definition: XMLDOMBlock.h:96
virtual ~HcalHardwareXml()
std::string mode
parent
Definition: confdb.py:1052
std::string kind_of_part
std::string barcode
U second(std::pair< T, U > const &p)
string rm
Definition: submit.py:76
XMLCh * transcode(const T &fInput)
std::string name_label
#define end
Definition: vmac.h:37
XERCES_CPP_NAMESPACE::DOMElement * partsElem
std::string comment
part
Definition: HCALResponse.h:20
XERCES_CPP_NAMESPACE::DOMElement * addPart(XERCES_CPP_NAMESPACE::DOMElement *parent, HcalPart &part)
#define begin
Definition: vmac.h:30
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:145
std::string attr_value
std::string attr_name
tuple size
Write out results.
#define comment(par)
Definition: vmac.h:161