CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/CaloOnlineTools/HcalOnlineDb/src/HcalHardwareXml.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     XMLTools
00004 // Class  :     HcalHardwareXml
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Gena Kukartsev, kukarzev@fnal.gov
00010 //         Created:  Tue Feb 25 14:30:20 CDT 2008
00011 // $Id: HcalHardwareXml.cc,v 1.6 2010/08/06 20:24:13 wmtan Exp $
00012 
00013 #include <sstream>
00014 
00015 #include "CaloOnlineTools/HcalOnlineDb/interface/HcalHardwareXml.h"
00016 #include "CalibCalorimetry/HcalTPGAlgos/interface/XMLProcessor.h"
00017 
00018 HcalHardwareXml::HcalHardwareXml() : XMLDOMBlock()
00019 {
00020 
00021   DOMElement* rootElem = document -> getDocumentElement();
00022 
00023   partsElem = document->createElement( XMLString::transcode("PARTS") );
00024   rootElem->appendChild(partsElem);
00025 }
00026 
00027 
00028 HcalHardwareXml::HcalHardwareXml( std::string _type ) : XMLDOMBlock()
00029 {
00030 
00031   DOMElement* rootElem = document -> getDocumentElement();
00032 
00033   partsElem = document->createElement( XMLString::transcode("PARTS") );
00034   rootElem->appendChild(partsElem);
00035 }
00036 
00037 
00038 
00039 
00040 int HcalHardwareXml::addHardware( std::map<std::string,std::map<std::string,std::map<std::string,std::map<int,std::string> > > > & hw_map )
00041 {
00042   //hw_map["HO001"]["HORBX09"]["200351"][2]="101295";
00043 
00044   std::map<std::string,int> double_entry; // to check for double entries
00045 
00046   std::map<std::string,std::map<std::string,std::map<std::string,std::map<int,std::string> > > >::const_iterator rbx_slot;
00047   for (rbx_slot = hw_map . begin(); rbx_slot != hw_map . end(); rbx_slot++){
00048 
00049     HcalPart _p;
00050     _p . mode = "find";
00051     _p . kind_of_part = "HCAL RBX Slot";
00052     _p . name_label = rbx_slot -> first;
00053     DOMElement * rbx_slot_elem = addPart( partsElem, _p );
00054     DOMElement * rbx_slot_children_elem = (DOMElement *)rbx_slot_elem -> getElementsByTagName(XMLString::transcode("CHILDREN"))->item(0);
00055 
00056     std::map<std::string,std::map<std::string,std::map<int,std::string> > >::const_iterator rbx;
00057     for (rbx = rbx_slot->second . begin(); rbx != rbx_slot->second . end(); rbx++){
00058       HcalPart _p2;
00059       _p2 . mode = "find";
00060       _p2 . kind_of_part = "HCAL RBX";
00061       _p2 . name_label = rbx -> first;
00062       DOMElement * rbx_elem = addPart( rbx_slot_children_elem, _p2 );
00063       DOMElement * rbx_children_elem = (DOMElement *)rbx_elem -> getElementsByTagName(XMLString::transcode("CHILDREN"))->item(0);
00064 
00065       std::map<std::string,std::map<int,std::string> >::const_iterator rm;
00066       for (rm = rbx->second . begin(); rm != rbx->second . end(); rm++){
00067         HcalPart _p3;
00068         _p3 . mode = "find";
00069         _p3 . kind_of_part = "HCAL Readout Module";
00070         _p3 . barcode = rm -> first;
00071         DOMElement * rm_elem = addPart( rbx_children_elem, _p3 );
00072         DOMElement * rm_children_elem = (DOMElement *)rm_elem -> getElementsByTagName(XMLString::transcode("CHILDREN"))->item(0);
00073         
00074         std::map<int,std::string>::const_iterator qie;
00075         for (qie = rm->second . begin(); qie != rm->second . end(); qie++){
00076           HcalPart _p4;
00077           _p4 . mode = "find";
00078           _p4 . kind_of_part = "HCAL QIE Card";
00079           _p4 . barcode = qie -> second;
00080           _p4 . comment = "HCAL hardware remapping by Gena Kukartsev";
00081           _p4 . attr_name = "QIE Card Position";
00082           std::stringstream _buffer;
00083           _buffer . str("");
00084           _buffer << qie->first;
00085           _p4 . attr_value = _buffer . str();
00086 
00087           // check for multiple QIE entries
00088           unsigned int _nqie = double_entry.size();
00089           double_entry[_p4 . barcode]++;
00090           if (double_entry.size() == _nqie){
00091             std::cout << "QIE #" << _p4.barcode << " found " << double_entry[_p4 . barcode] << "times!" << std::endl;
00092           }else{
00093             addPart( rm_children_elem, _p4 );
00094           }
00095         }      
00096       }      
00097     }
00098   }
00099 
00100   return 0;
00101 }
00102 
00103 DOMElement * HcalHardwareXml::addPart( DOMElement * parent, HcalPart & part )
00104 {
00105   
00106   DOMElement * child    = document -> createElement( XMLString::transcode( "PART" ) );
00107   child -> setAttribute( XMLString::transcode("mode"), XMLString::transcode(part.mode.c_str()) );
00108 
00109   DOMElement * kindElem = document -> createElement( XMLString::transcode( "KIND_OF_PART" ) );
00110   DOMElement * nameElem = document -> createElement( XMLString::transcode( "NAME_LABEL" ) );
00111   DOMElement * barElem  = document -> createElement( XMLString::transcode( "BARCODE" ) );
00112   DOMElement * childrenElem  = document -> createElement( XMLString::transcode( "CHILDREN" ) );
00113   DOMElement * commentElem  = document -> createElement( XMLString::transcode( "COMMENT_DESCRIPTION" ) );
00114 
00115   child -> appendChild( kindElem );
00116   DOMText * _kind = document -> createTextNode( XMLString::transcode(part.kind_of_part.c_str()));
00117   kindElem -> appendChild( _kind );
00118   if (part.name_label . size() > 0){
00119     child -> appendChild( nameElem );
00120     DOMText * _name = document -> createTextNode( XMLString::transcode(part.name_label.c_str()));
00121     nameElem -> appendChild( _name );
00122   }
00123   if (part.barcode . size() > 0){
00124     child -> appendChild( barElem );
00125     DOMText * _code = document -> createTextNode( XMLString::transcode(part.barcode.c_str()));
00126     barElem -> appendChild( _code );
00127   }
00128   if (part.comment . size() > 0){
00129     child -> appendChild( commentElem );
00130     DOMText * _comment = document -> createTextNode( XMLString::transcode(part.comment.c_str()));
00131     commentElem -> appendChild( _comment );
00132   }
00133   if (part.attr_name . size() > 0 || part.attr_value . size() > 0){
00134     DOMElement * predefined_attr_elem  = document -> createElement( XMLString::transcode( "PREDEFINED_ATTRIBUTES" ) );
00135     child -> appendChild( predefined_attr_elem );
00136     DOMElement * attr_elem  = document -> createElement( XMLString::transcode( "ATTRIBUTE" ) );
00137     predefined_attr_elem -> appendChild( attr_elem );
00138     DOMElement * attr_name_elem  = document -> createElement( XMLString::transcode( "NAME" ) );
00139     attr_elem -> appendChild( attr_name_elem );
00140     DOMText * _name = document -> createTextNode( XMLString::transcode(part.attr_name.c_str()));
00141     attr_name_elem -> appendChild( _name );
00142     DOMElement * attr_value_elem  = document -> createElement( XMLString::transcode( "VALUE" ) );
00143     attr_elem -> appendChild( attr_value_elem );
00144     DOMText * _value = document -> createTextNode( XMLString::transcode(part.attr_value.c_str()));
00145     attr_value_elem -> appendChild( _value );
00146   }
00147   child -> appendChild( childrenElem );
00148 
00149   parent -> appendChild( child );
00150 
00151   return child;
00152 }
00153 
00154 
00155 
00156 HcalHardwareXml::~HcalHardwareXml()
00157 {
00158 }
00159 
00160