CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/CalibCalorimetry/HcalTPGAlgos/src/LutXml.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     CaloOnlineTools/HcalOnlineDb
00004 // Class  :     LutXml
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Gena Kukartsev, kukarzev@fnal.gov
00010 //         Created:  Tue Mar 18 14:30:20 CDT 2008
00011 // $Id: LutXml.cc,v 1.6 2010/08/06 20:24:03 wmtan Exp $
00012 //
00013 
00014 #include <iostream>
00015 #include <string>
00016 #include <vector>
00017 #include <sstream>
00018 #include <iconv.h>
00019 #include <sys/time.h>
00020 
00021 #include "CalibCalorimetry/HcalTPGAlgos/interface/LutXml.h"
00022 #include "CalibCalorimetry/HcalTPGAlgos/interface/XMLProcessor.h"
00023 #include "FWCore/Utilities/interface/md5.h"
00024 #include "CalibCalorimetry/HcalTPGAlgos/interface/HcalEmap.h"
00025 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00026 #include "DataFormats/HcalDetId/interface/HcalTrigTowerDetId.h"
00027 
00028 using namespace std;
00029 
00030 //
00031 //_____ following removed as a xalan-c component_____________________
00032 //
00033 // xalan-c init
00034 //#include <xalanc/Include/PlatformDefinitions.hpp>
00035 //#include <xalanc/XPath/XPathEvaluator.hpp>
00036 //#include <xercesc/framework/LocalFileInputSource.hpp>
00037 //XALAN_USING_XERCES(XMLPlatformUtils)
00038 //#include <xalanc/XSLT/XSLTInputSource.hpp>
00039 //#include <xalanc/PlatformSupport/XSLException.hpp>
00040 //#include <xalanc/DOMSupport/XalanDocumentPrefixResolver.hpp>
00041 //#include <xalanc/XPath/XObject.hpp>
00042 //#include <xalanc/XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
00043 //#include <xalanc/XalanSourceTree/XalanSourceTreeInit.hpp>
00044 //#include <xalanc/XalanSourceTree/XalanSourceTreeParserLiaison.hpp>  
00045 //using namespace xalanc;
00046 
00047 
00048 
00049 /*
00050 LutXml & LutXml::operator+=( const LutXml & other)
00051 {
00052   DOMNodeList * _children = other.getDocumentConst()->getChildNodes();
00053   int _length = _children->getLength();
00054   std::cout << "Nodes added:" << _length << std::endl;
00055   DOMNode * _node;
00056   for(int i=0;i!=_length;i++){
00057     _node = _children->item(i)->cloneNode(true);
00058     this->getDocument()->getDocumentElement()->appendChild(_node);
00059   }
00060   return *this;
00061 }
00062 */
00063 
00064 
00065 
00066 LutXml::Config::_Config()
00067 {
00068   ieta = -1000;
00069   iphi = -1000;
00070   depth = -1;
00071   crate = -1;
00072   slot = -1;
00073   topbottom = -1;
00074   fiber = -1;
00075   fiberchan = -1;
00076   lut_type = -1;
00077   creationtag = "default_tag";
00078 
00079   char timebuf[50];
00080   time_t _time = time( NULL );
00081   //time_t _time = 1193697120;
00082   //strftime( timebuf, 50, "%c", gmtime( &_time ) );
00083   strftime( timebuf, 50, "%Y-%m-%d %H:%M:%S", gmtime( &_time ) );
00084   creationstamp = timebuf;
00085 
00086   formatrevision = "default_revision";
00087   targetfirmware = "default_revision";
00088   generalizedindex = -1;
00089 }
00090 
00091 LutXml::LutXml() : XMLDOMBlock( "CFGBrickSet", 1 )
00092 {
00093   init();
00094 }
00095 
00096 
00097 LutXml::LutXml(InputSource & _source ) : XMLDOMBlock( _source )
00098 {
00099   init();
00100 }
00101 
00102 
00103 LutXml::LutXml( std::string filename ) : XMLDOMBlock( filename )
00104 {
00105   init();
00106 }
00107 
00108 
00109 LutXml::~LutXml()
00110 {
00111   //delete brickElem; // belongs to document that belongs to parser???
00112   XMLString::release(&root);
00113   XMLString::release(&brick);
00114   //delete lut_map;
00115 }
00116 
00117 
00118 void LutXml::init( void )
00119 {
00120   root  = XMLString::transcode("CFGBrickSet");
00121   brick = XMLString::transcode("CFGBrick");
00122   brickElem = 0;
00123   //lut_map = 0;
00124 }
00125 
00126 
00127 std::vector<unsigned int> * LutXml::getLutFast( uint32_t det_id ){
00128    /*
00129   if (lut_map){
00130     return &(*lut_map)[det_id];
00131   }
00132   else{
00133     std::cerr << "LUT not found, null pointer is returned" << std::endl;
00134     return 0;
00135   }
00136   */
00137    if (lut_map.find(det_id) != lut_map.end()) return &(lut_map)[det_id];
00138    std::cerr << "LUT not found, null pointer is returned" << std::endl;
00139    return 0;
00140 }
00141 
00142 //
00143 //_____ following removed as a xalan-c component_____________________
00144 //
00145 /*
00146 std::vector<unsigned int> LutXml::getLut( int lut_type, int crate, int slot, int topbottom, int fiber, int fiber_channel ){
00147   std::vector<unsigned int> _lut;
00148   //write();
00149 
00150   std::string _context = "/CFGBrickSet";
00151   char buf[1024];
00152   sprintf(buf,
00153           "CFGBrick[Parameter[@name='LUT_TYPE']=%d and Parameter[@name='CRATE']=%d and Parameter[@name='SLOT']=%d and Parameter[@name='TOPBOTTOM']=%d and Parameter[@name='FIBER']=%d and Parameter[@name='FIBERCHAN']=%d]/Data",
00154           lut_type, crate, slot, topbottom, fiber, fiber_channel);
00155   std::string _expression(buf);
00156 
00157   std::cout << _expression << std::endl;
00158 
00159   const XObjectPtr theResult = eval_xpath(_context,_expression);
00160 
00161   if(theResult.null() == false){
00162     std::cout << std::endl << theResult->str() << std::endl;
00163   }
00164 
00165   const XalanDOMString & _string = theResult->str();
00166   int _string_length = _string.length();
00167   XalanVector<char> _str;
00168   _string.transcode(_str);
00169   unsigned int _base = 16;
00170   unsigned int _item=0;
00171   for (int i=0; i!=_string_length; i++){
00172     bool _range;
00173     char ch_cur = _str[i];
00174     if (_base==16) _range = (ch_cur>='0' and ch_cur<='9') || (ch_cur>='a' and ch_cur<='f') || (ch_cur>='A' and ch_cur<='F');
00175     else if (_base==10) _range = (ch_cur>='0' and ch_cur<='9');
00176     if ( _range ){
00177       if ( ch_cur>='a' and ch_cur<='f' ) ch_cur += 10-'a';
00178       else if ( ch_cur>='A' and ch_cur<='F' ) ch_cur += 10-'A';
00179       else if ( ch_cur>='0' and ch_cur<='9' ) ch_cur += -'0';
00180       _item = _item*_base;
00181       _item += ch_cur;
00182       bool last_digit = false;
00183       if ( (i+1)==_string_length ) last_digit=true;
00184       else{
00185         char ch_next = _str[i+1];
00186         bool _range_next;
00187         if (_base==16) _range_next = (ch_next>='0' and ch_next<='9') || (ch_next>='a' and ch_next<='f') || (ch_next>='A' and ch_next<='F');
00188         else if (_base==10) _range_next = (ch_next>='0' and ch_next<='9');
00189         if ( !_range_next ) last_digit=true;
00190       }
00191       if (last_digit){
00192         _lut.push_back(_item);
00193         _item=0;
00194       }
00195     }
00196   }
00197 
00198   std::cout << "### ";
00199   for (std::vector<unsigned int>::const_iterator l=_lut.begin(); l!=_lut.end(); l++){
00200     std::cout << *l << " ";
00201   }
00202   std::cout << std::endl << std::endl;
00203 
00204   return _lut;
00205 }
00206 */
00207 
00208 
00209 // checksums_xml is 0 by default
00210 void LutXml::addLut( LutXml::Config & _config, XMLDOMBlock * checksums_xml )
00211 {
00212   DOMElement * rootElem = document -> getDocumentElement();
00213 
00214   brickElem = document->createElement( XMLProcessor::_toXMLCh("CFGBrick") );
00215   rootElem->appendChild(brickElem);
00216 
00217   addParameter( "IETA", "int", _config.ieta );
00218   addParameter( "IPHI", "int", _config.iphi );
00219   addParameter( "CRATE", "int", _config.crate );
00220   addParameter( "SLOT", "int", _config.slot );
00221   addParameter( "TOPBOTTOM", "int", _config.topbottom );
00222   addParameter( "LUT_TYPE", "int", _config.lut_type );
00223   addParameter( "CREATIONTAG", "string", _config.creationtag );
00224   addParameter( "CREATIONSTAMP", "string", _config.creationstamp );
00225   addParameter( "FORMATREVISION", "string", _config.formatrevision );
00226   addParameter( "TARGETFIRMWARE", "string", _config.targetfirmware );
00227   addParameter( "GENERALIZEDINDEX", "int", _config.generalizedindex );
00228   addParameter( "CHECKSUM", "string", get_checksum( _config.lut ) );
00229 
00230   if(_config.lut_type==1){ // linearizer LUT
00231     addParameter( "FIBER", "int", _config.fiber );
00232     addParameter( "FIBERCHAN", "int", _config.fiberchan );
00233     addParameter( "DEPTH", "int", _config.depth );
00234     addData( "128", "hex", _config.lut );
00235   }
00236   else if(_config.lut_type==2){ // compression LUT
00237   addParameter( "SLB", "int", _config.fiber );
00238   addParameter( "SLBCHAN", "int", _config.fiberchan );
00239     addData( "1024", "hex", _config.lut );
00240   }
00241   else{
00242     std::cout << "Unknown LUT type...produced XML will be incorrect" << std::endl;
00243   }
00244 
00245   // if the pointer to the checksums XML was given,
00246   // add the checksum to it
00247   // checksums_xml is 0 unless explicitely given
00248   if ( checksums_xml ){
00249     add_checksum( checksums_xml->getDocument(), _config );
00250   }
00251 }
00252 
00253 DOMElement * LutXml::addData( std::string _elements, std::string _encoding, std::vector<unsigned int> _lut )
00254 {
00255   DOMElement * child    = document -> createElement( XMLProcessor::_toXMLCh( "Data" ) );
00256   child -> setAttribute( XMLProcessor::_toXMLCh("elements"), XMLProcessor::_toXMLCh( _elements ) );
00257   child -> setAttribute( XMLProcessor::_toXMLCh("encoding"), XMLProcessor::_toXMLCh( _encoding ) );
00258 
00259   std::stringstream buf;
00260 
00261   for (std::vector<unsigned int>::const_iterator iter = _lut.begin();iter!=_lut.end();iter++){
00262     char buf2[8];
00263     sprintf(buf2,"%x",(*iter));
00264     buf << buf2 << " ";
00265     //buf << (*iter) << " ";
00266   }
00267 
00268   std::string _value = buf . str();
00269 
00270   DOMText * data_value = document -> createTextNode( XMLProcessor::_toXMLCh(_value));
00271   child -> appendChild( data_value );
00272 
00273   brickElem -> appendChild( child );
00274 
00275   return child;
00276 }
00277 
00278 
00279 
00280 DOMElement * LutXml::add_checksum( DOMDocument * parent, Config & config )
00281 {
00282   //template
00283   //   <Data crate='0' slot='2' fpga='1' fiber='1' fiberchan='0' luttype='1' elements='1' encoding='hex'>c6cf91b39e3bff21623fb7366efda1fd</Data>
00284   //
00285   DOMElement * child    = parent -> createElement( XMLProcessor::_toXMLCh( "Data" ) );
00286   child -> setAttribute( XMLProcessor::_toXMLCh("crate"),     XMLProcessor::_toXMLCh( config.crate ) );
00287   child -> setAttribute( XMLProcessor::_toXMLCh("slot"),      XMLProcessor::_toXMLCh( config.slot ) );
00288   child -> setAttribute( XMLProcessor::_toXMLCh("fpga"),      XMLProcessor::_toXMLCh( config.topbottom ) );
00289   child -> setAttribute( XMLProcessor::_toXMLCh("fiber"),     XMLProcessor::_toXMLCh( config.fiber ) );
00290   child -> setAttribute( XMLProcessor::_toXMLCh("fiberchan"), XMLProcessor::_toXMLCh( config.fiberchan ) );
00291   child -> setAttribute( XMLProcessor::_toXMLCh("luttype"),   XMLProcessor::_toXMLCh( config.lut_type ) );
00292   child -> setAttribute( XMLProcessor::_toXMLCh("elements"),  XMLProcessor::_toXMLCh( "1" ) );
00293   child -> setAttribute( XMLProcessor::_toXMLCh("encoding"),  XMLProcessor::_toXMLCh( "hex" ) );
00294   DOMText * checksum_value = parent -> createTextNode( XMLProcessor::_toXMLCh( get_checksum(config.lut) ));
00295   child -> appendChild( checksum_value );
00296 
00297   parent -> getDocumentElement() -> appendChild( child );
00298 
00299   return child;
00300 }
00301 
00302 
00303 
00304 DOMElement * LutXml::addParameter( std::string _name, std::string _type, std::string _value )
00305 {
00306   DOMElement * child    = document -> createElement( XMLProcessor::_toXMLCh( "Parameter" ) );
00307   child -> setAttribute( XMLProcessor::_toXMLCh("name"), XMLProcessor::_toXMLCh( _name ) );
00308   child -> setAttribute( XMLProcessor::_toXMLCh("type"), XMLProcessor::_toXMLCh( _type ) );
00309   DOMText * parameter_value = document -> createTextNode( XMLProcessor::_toXMLCh(_value));
00310   child -> appendChild( parameter_value );
00311 
00312   brickElem -> appendChild( child );
00313 
00314   return child;
00315 }
00316 
00317 
00318 
00319 DOMElement * LutXml::addParameter( std::string _name, std::string _type, int _value )
00320 {
00321   char buf[128];
00322   sprintf(buf, "%d", _value);
00323   std::string str_value = buf;
00324   return addParameter( _name, _type, str_value );
00325 }
00326 
00327 
00328 
00329 
00330 std::string & LutXml::getCurrentBrick( void )
00331 {
00332   return getString( brickElem );
00333 }
00334 
00335 
00336 
00337 // do MD5 checksum
00338 std::string LutXml::get_checksum( std::vector<unsigned int> & lut )
00339 {
00340   std::stringstream result;
00341   md5_state_t md5er;
00342   md5_byte_t digest[16];
00343   md5_init(&md5er);
00344   // linearizer LUT:
00345   if ( lut . size() == 128 ){
00346     unsigned char tool[2];
00347     for (int i=0; i<128; i++) {
00348       tool[0]=lut[i]&0xFF;
00349       tool[1]=(lut[i]>>8)&0xFF;
00350       md5_append(&md5er,tool,2);
00351     }
00352   }
00353   // compression LUT:
00354   else if ( lut . size() == 1024 ){
00355     unsigned char tool;
00356     for (int i=0; i<1024; i++) {
00357       tool=lut[i]&0xFF;
00358       md5_append(&md5er,&tool,1);
00359     }
00360   }
00361   else{
00362     std::cout << "ERROR: irregular LUT size, do not know how to compute checksum, exiting..." << std::endl;
00363     exit(-1);
00364   }
00365   md5_finish(&md5er,digest);
00366   for (int i=0; i<16; i++) result << std::hex << (((int)(digest[i]))&0xFF);
00367 
00368   //std::cout << "CHECKSUM: ";
00369   //std::cout << result . str();
00370   //std::cout << std::endl;
00371 
00372   return result . str();
00373 }
00374 
00375 
00376 int LutXml::test_access( std::string filename ){
00377   //create_lut_map();
00378   //std::cout << "Created map size: " << lut_map->size() << std::endl;
00379   std::cout << "Created map size: " << lut_map.size() << std::endl;
00380 
00381   struct timeval _t;
00382   gettimeofday( &_t, NULL );
00383   double _time =(double)(_t . tv_sec) + (double)(_t . tv_usec)/1000000.0;
00384 
00385   HcalEmap _emap("./backup/official_emap_v6.04_080905.txt");
00386   std::vector<HcalEmap::HcalEmapRow> & _map = _emap.get_map();
00387   std::cout << "HcalEmap contains " << _map . size() << " entries" << std::endl;
00388 
00389   int _counter=0;
00390   for (std::vector<HcalEmap::HcalEmapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++){
00391     if (row->subdet=="HB"){
00392       HcalDetId det_id(HcalBarrel,row->ieta,row->iphi,row->idepth);
00393       uint32_t raw_id = det_id.rawId();
00394       std::vector<unsigned int> * l = getLutFast(raw_id);
00395       if (l) _counter++;
00396     }
00397     if (row->subdet=="HE"){
00398       HcalDetId det_id(HcalEndcap,row->ieta,row->iphi,row->idepth);
00399       uint32_t raw_id = det_id.rawId();
00400       std::vector<unsigned int> * l = getLutFast(raw_id);
00401       if (l) _counter++;
00402     }
00403     if (row->subdet=="HF"){
00404       HcalDetId det_id(HcalForward,row->ieta,row->iphi,row->idepth);
00405       uint32_t raw_id = det_id.rawId();
00406       std::vector<unsigned int> * l = getLutFast(raw_id);
00407       if (l) _counter++;
00408     }
00409     if (row->subdet=="HO"){
00410       HcalDetId det_id(HcalOuter,row->ieta,row->iphi,row->idepth);
00411       uint32_t raw_id = det_id.rawId();
00412       std::vector<unsigned int> * l = getLutFast(raw_id);
00413       if (l) _counter++;
00414     }
00415   }
00416   gettimeofday( &_t, NULL );
00417   std::cout << "access to " << _counter << " HCAL channels took: " << (double)(_t . tv_sec) + (double)(_t . tv_usec)/1000000.0 - _time << "sec" << std::endl;
00418 
00419   //std::cout << std::endl;
00420   //for (std::vector<unsigned int>::const_iterator i=l->begin();i!=l->end();i++){
00421   //  std::cout << *i << " ";
00422   //}
00423   //std::cout << std::endl;
00424 
00425   return 0;
00426 }
00427 
00428 //
00429 //_____ following removed as a xalan-c component_____________________
00430 //
00431 /*
00432 int LutXml::test_xpath( std::string filename ){
00433   // http://svn.apache.org/repos/asf/xalan/c/tags/Xalan-C_1_10_0/samples/SimpleXPathAPI/SimpleXPathAPI.cpp
00434   
00435   XMLProcessor::getInstance();
00436 
00437   read_xml_file_xalan( filename );
00438 
00439   std::string _context = "/CFGBrickSet";
00440   //std::string _expression = "CFGBrick[Parameter[@name='IETA']=-1 and Parameter[@name='IPHI']=19]/Data";
00441   std::string _expression = "CFGBrick[Parameter[@name='IETA']=-1]/Data";
00442   std::cout << _expression << std::endl;
00443 
00444   const XObjectPtr theResult = eval_xpath(_context,_expression);
00445 
00446   if(theResult.null() == false){
00447     std::cout << "Number of nodes: " << theResult->nodeset().getLength() << std::endl;
00448     
00449     std::cout << "The std::string value of the result is:"
00450          << std::endl
00451          << theResult->str()
00452          << std::endl
00453          << std::endl;
00454   }
00455   return 0;
00456 }
00457 */
00458 
00459 HcalSubdetector LutXml::subdet_from_crate(int crate, int eta, int depth){
00460   HcalSubdetector result;
00461   // HBHE: 0,1,4,5,10,11,14,15,17
00462   // HF: 2,9,12
00463   // HO: 3,6,7,13
00464 
00465   if (crate==2 || crate==9 || crate==12) result=HcalForward;
00466   else if (crate==3 || crate==6 || crate==7 || crate==13) result=HcalOuter;
00467   else if (crate==0 || crate==1 || crate==4 || crate==5 || crate==10 || crate==11 || crate==14 || crate==15 || crate==17){
00468     if (eta<16) result=HcalBarrel;
00469     else if (eta>16) result=HcalEndcap;
00470     else if (eta==16 && depth!=3) result=HcalBarrel;
00471     else if (eta==16 && depth==3) result=HcalEndcap;
00472     else{
00473       std::cerr << "Impossible to determine HCAL subdetector!!!" << std::endl;
00474       exit(-1);
00475     }
00476   }
00477   else{
00478     std::cerr << "Impossible to determine HCAL subdetector!!!" << std::endl;
00479     exit(-1);
00480   }
00481 
00482   return result;
00483 }
00484 
00485 
00486 int LutXml::a_to_i(char * inbuf){
00487   int result;
00488   sscanf(inbuf,"%d",&result);
00489   return result;
00490 }
00491 
00492 // organize all LUTs in XML into a map for fast access
00493 //
00494 // FIXME: uses hardcoded CRATE-to-subdetector mapping
00495 // FIXME: it would be better to use some official map
00496 //
00497 int LutXml::create_lut_map( void ){
00498   //delete lut_map;
00499   lut_map.clear();
00500   //lut_map = new std::map<uint32_t,std::vector<unsigned int> >();
00501 
00502   if (document){
00503     //DOMElement * rootElem = 
00504     DOMNodeList * brick_list = document->getDocumentElement()->getElementsByTagName(brick);
00505     int n_of_bricks = brick_list->getLength();
00506     for(int i=0; i!=n_of_bricks; i++){
00507       DOMElement * aBrick = (DOMElement *)(brick_list->item(i));
00508       DOMNodeList * par_list = aBrick->getElementsByTagName(XMLString::transcode("Parameter"));
00509       int n_of_par = par_list->getLength();
00510       int ieta=-99;
00511       int iphi=-99;
00512       int depth=-99;
00513       int crate=-99;
00514       int lut_type=-99;
00515       HcalSubdetector subdet;
00516       for(int j=0; j!=n_of_par; j++){
00517         //std::cout << "DEBUG: i,j: " << i << ", " << j << std::endl;
00518         DOMElement * aPar = (DOMElement *)(par_list->item(j));
00519         char * aName = XMLString::transcode( aPar->getAttribute(XMLProcessor::_toXMLCh("name")) );
00520         if ( strcmp(aName, "IETA")==0 ) ieta=a_to_i(XMLString::transcode(aPar->getFirstChild()->getNodeValue()));
00521         if ( strcmp(aName, "IPHI")==0 ) iphi=a_to_i(XMLString::transcode(aPar->getFirstChild()->getNodeValue()));
00522         if ( strcmp(aName, "DEPTH")==0 ) depth=a_to_i(XMLString::transcode(aPar->getFirstChild()->getNodeValue()));
00523         if ( strcmp(aName, "CRATE")==0 ) crate=a_to_i(XMLString::transcode(aPar->getFirstChild()->getNodeValue()));
00524         if ( strcmp(aName, "LUT_TYPE")==0 ) lut_type=a_to_i(XMLString::transcode(aPar->getFirstChild()->getNodeValue()));
00525       }
00526       subdet=subdet_from_crate(crate,abs(ieta),depth);
00527       //std::cerr << "DEBUG: eta,phi,depth,crate,type,subdet: " << ieta << ", " << iphi << ", " << depth << ", " << crate << ", " << lut_type << ", " << subdet << std::endl;
00528       DOMElement * _data = (DOMElement *)(aBrick->getElementsByTagName(XMLString::transcode("Data"))->item(0));
00529       char * _str = XMLString::transcode(_data->getFirstChild()->getNodeValue());
00530       //std::cout << _str << std::endl;
00531       //
00532       // get the LUT vector
00533       int _string_length = strlen(_str);
00534       std::vector<unsigned int> _lut;
00535       unsigned int _base = 16;
00536       unsigned int _item=0;
00537       for (int i=0; i!=_string_length; i++){
00538         bool _range;
00539         char ch_cur = _str[i];
00540         if (_base==16) _range = (ch_cur>='0' and ch_cur<='9') || (ch_cur>='a' and ch_cur<='f') || (ch_cur>='A' and ch_cur<='F');
00541         else if (_base==10) _range = (ch_cur>='0' and ch_cur<='9');
00542         if ( _range ){
00543           if ( ch_cur>='a' and ch_cur<='f' ) ch_cur += 10-'a';
00544           else if ( ch_cur>='A' and ch_cur<='F' ) ch_cur += 10-'A';
00545           else if ( ch_cur>='0' and ch_cur<='9' ) ch_cur += -'0';
00546           _item = _item*_base;
00547           _item += ch_cur;
00548           bool last_digit = false;
00549           if ( (i+1)==_string_length ) last_digit=true;
00550           else{
00551             char ch_next = _str[i+1];
00552             bool _range_next;
00553             if (_base==16) _range_next = (ch_next>='0' and ch_next<='9') || (ch_next>='a' and ch_next<='f') || (ch_next>='A' and ch_next<='F');
00554             else if (_base==10) _range_next = (ch_next>='0' and ch_next<='9');
00555             if ( !_range_next ) last_digit=true;
00556           }
00557           if (last_digit){
00558             _lut.push_back(_item);
00559             _item=0;
00560           }
00561         }
00562       }
00564       //std::cout << _lut[127] << std::endl;
00565       // filling the map
00566       uint32_t _key = 0;
00567       if (lut_type==1){
00568         HcalDetId _id(subdet,ieta,iphi,depth);
00569         _key = _id.rawId();
00570       }
00571       else if (lut_type==2){
00572         HcalTrigTowerDetId _id(ieta,iphi);
00573         _key = _id.rawId();
00574       }
00575       //lut_map->insert(std::pair<uint32_t,std::vector<unsigned int> >(_key,_lut));
00576       lut_map.insert(std::pair<uint32_t,std::vector<unsigned int> >(_key,_lut));
00577     }
00578   }
00579   else{
00580     std::cerr << "XML file with LUTs is not loaded, cannot create map!" << std::endl;
00581   }
00582 
00583 
00584 
00585   return 0;
00586 }
00587 
00588 LutXml::const_iterator LutXml::begin() const{
00589    return lut_map.begin();
00590 }
00591 
00592 LutXml::const_iterator LutXml::end() const{
00593    return lut_map.end();
00594 }
00595 
00596 LutXml::const_iterator LutXml::find(uint32_t id) const{
00597    return lut_map.find(id);
00598 }