#include <CalibCalorimetry/HcalTPGAlgos/interface/LutXml.h>
Classes | |
struct | _Config |
Public Types | |
typedef struct LutXml::_Config | Config |
typedef std::map< uint32_t, std::vector< unsigned int > >::const_iterator | const_iterator |
Public Member Functions | |
int | a_to_i (char *inbuf) |
void | addLut (Config &_config, XMLDOMBlock *checksums_xml=0) |
const_iterator | begin () const |
int | create_lut_map (void) |
const_iterator | end () const |
const_iterator | find (uint32_t) const |
std::string & | getCurrentBrick (void) |
std::vector< unsigned int > * | getLutFast (uint32_t det_id) |
void | init (void) |
LutXml () | |
LutXml (std::string filename) | |
LutXml (InputSource &_source) | |
HcalSubdetector | subdet_from_crate (int crate, int eta, int depth) |
int | test_access (std::string filename) |
virtual | ~LutXml () |
Static Public Member Functions | |
static std::string | get_checksum (std::vector< unsigned int > &lut) |
Protected Member Functions | |
DOMElement * | add_checksum (DOMDocument *parent, Config &config) |
DOMElement * | addData (std::string _elements, std::string _encoding, std::vector< unsigned int > _lut) |
DOMElement * | addParameter (std::string _name, std::string _type, std::string _value) |
DOMElement * | addParameter (std::string _name, std::string _type, int _value) |
Protected Attributes | |
XMLCh * | brick |
DOMElement * | brickElem |
std::map< uint32_t, std::vector< unsigned int > > | lut_map |
XMLCh * | root |
Description: <one line="" class="" summary>="">
Usage: <usage>
typedef struct LutXml::_Config LutXml::Config |
typedef std::map<uint32_t,std::vector<unsigned int> >::const_iterator LutXml::const_iterator |
LutXml::LutXml | ( | ) |
Definition at line 91 of file LutXml.cc.
References init().
: XMLDOMBlock( "CFGBrickSet", 1 ) { init(); }
LutXml::LutXml | ( | InputSource & | _source | ) |
LutXml::LutXml | ( | std::string | filename | ) |
LutXml::~LutXml | ( | ) | [virtual] |
Definition at line 109 of file LutXml.cc.
References brick, cmsPerfSuiteHarvest::release, and root.
{ //delete brickElem; // belongs to document that belongs to parser??? XMLString::release(&root); XMLString::release(&brick); //delete lut_map; }
int LutXml::a_to_i | ( | char * | inbuf | ) |
DOMElement * LutXml::add_checksum | ( | DOMDocument * | parent, |
Config & | config | ||
) | [protected] |
Definition at line 280 of file LutXml.cc.
References XMLProcessor::_toXMLCh(), LutXml::_Config::crate, LutXml::_Config::fiber, LutXml::_Config::fiberchan, get_checksum(), LutXml::_Config::lut, LutXml::_Config::lut_type, LutXml::_Config::slot, and LutXml::_Config::topbottom.
Referenced by addLut().
{ //template // <Data crate='0' slot='2' fpga='1' fiber='1' fiberchan='0' luttype='1' elements='1' encoding='hex'>c6cf91b39e3bff21623fb7366efda1fd</Data> // DOMElement * child = parent -> createElement( XMLProcessor::_toXMLCh( "Data" ) ); child -> setAttribute( XMLProcessor::_toXMLCh("crate"), XMLProcessor::_toXMLCh( config.crate ) ); child -> setAttribute( XMLProcessor::_toXMLCh("slot"), XMLProcessor::_toXMLCh( config.slot ) ); child -> setAttribute( XMLProcessor::_toXMLCh("fpga"), XMLProcessor::_toXMLCh( config.topbottom ) ); child -> setAttribute( XMLProcessor::_toXMLCh("fiber"), XMLProcessor::_toXMLCh( config.fiber ) ); child -> setAttribute( XMLProcessor::_toXMLCh("fiberchan"), XMLProcessor::_toXMLCh( config.fiberchan ) ); child -> setAttribute( XMLProcessor::_toXMLCh("luttype"), XMLProcessor::_toXMLCh( config.lut_type ) ); child -> setAttribute( XMLProcessor::_toXMLCh("elements"), XMLProcessor::_toXMLCh( "1" ) ); child -> setAttribute( XMLProcessor::_toXMLCh("encoding"), XMLProcessor::_toXMLCh( "hex" ) ); DOMText * checksum_value = parent -> createTextNode( XMLProcessor::_toXMLCh( get_checksum(config.lut) )); child -> appendChild( checksum_value ); parent -> getDocumentElement() -> appendChild( child ); return child; }
DOMElement * LutXml::addData | ( | std::string | _elements, |
std::string | _encoding, | ||
std::vector< unsigned int > | _lut | ||
) | [protected] |
Definition at line 253 of file LutXml.cc.
References XMLProcessor::_toXMLCh(), brickElem, and XMLDOMBlock::document.
Referenced by addLut().
{ DOMElement * child = document -> createElement( XMLProcessor::_toXMLCh( "Data" ) ); child -> setAttribute( XMLProcessor::_toXMLCh("elements"), XMLProcessor::_toXMLCh( _elements ) ); child -> setAttribute( XMLProcessor::_toXMLCh("encoding"), XMLProcessor::_toXMLCh( _encoding ) ); std::stringstream buf; for (std::vector<unsigned int>::const_iterator iter = _lut.begin();iter!=_lut.end();iter++){ char buf2[8]; sprintf(buf2,"%x",(*iter)); buf << buf2 << " "; //buf << (*iter) << " "; } std::string _value = buf . str(); DOMText * data_value = document -> createTextNode( XMLProcessor::_toXMLCh(_value)); child -> appendChild( data_value ); brickElem -> appendChild( child ); return child; }
void LutXml::addLut | ( | LutXml::Config & | _config, |
XMLDOMBlock * | checksums_xml = 0 |
||
) |
Definition at line 210 of file LutXml.cc.
References XMLProcessor::_toXMLCh(), add_checksum(), addData(), addParameter(), brickElem, gather_cfg::cout, LutXml::_Config::crate, LutXml::_Config::creationstamp, LutXml::_Config::creationtag, LutXml::_Config::depth, XMLDOMBlock::document, LutXml::_Config::fiber, LutXml::_Config::fiberchan, LutXml::_Config::formatrevision, LutXml::_Config::generalizedindex, get_checksum(), XMLDOMBlock::getDocument(), LutXml::_Config::ieta, LutXml::_Config::iphi, LutXml::_Config::lut, LutXml::_Config::lut_type, LutXml::_Config::slot, LutXml::_Config::targetfirmware, and LutXml::_Config::topbottom.
{ DOMElement * rootElem = document -> getDocumentElement(); brickElem = document->createElement( XMLProcessor::_toXMLCh("CFGBrick") ); rootElem->appendChild(brickElem); addParameter( "IETA", "int", _config.ieta ); addParameter( "IPHI", "int", _config.iphi ); addParameter( "CRATE", "int", _config.crate ); addParameter( "SLOT", "int", _config.slot ); addParameter( "TOPBOTTOM", "int", _config.topbottom ); addParameter( "LUT_TYPE", "int", _config.lut_type ); addParameter( "CREATIONTAG", "string", _config.creationtag ); addParameter( "CREATIONSTAMP", "string", _config.creationstamp ); addParameter( "FORMATREVISION", "string", _config.formatrevision ); addParameter( "TARGETFIRMWARE", "string", _config.targetfirmware ); addParameter( "GENERALIZEDINDEX", "int", _config.generalizedindex ); addParameter( "CHECKSUM", "string", get_checksum( _config.lut ) ); if(_config.lut_type==1){ // linearizer LUT addParameter( "FIBER", "int", _config.fiber ); addParameter( "FIBERCHAN", "int", _config.fiberchan ); addParameter( "DEPTH", "int", _config.depth ); addData( "128", "hex", _config.lut ); } else if(_config.lut_type==2){ // compression LUT addParameter( "SLB", "int", _config.fiber ); addParameter( "SLBCHAN", "int", _config.fiberchan ); addData( "1024", "hex", _config.lut ); } else{ std::cout << "Unknown LUT type...produced XML will be incorrect" << std::endl; } // if the pointer to the checksums XML was given, // add the checksum to it // checksums_xml is 0 unless explicitely given if ( checksums_xml ){ add_checksum( checksums_xml->getDocument(), _config ); } }
DOMElement * LutXml::addParameter | ( | std::string | _name, |
std::string | _type, | ||
std::string | _value | ||
) | [protected] |
Definition at line 304 of file LutXml.cc.
References XMLProcessor::_toXMLCh(), brickElem, and XMLDOMBlock::document.
Referenced by addLut(), and addParameter().
{ DOMElement * child = document -> createElement( XMLProcessor::_toXMLCh( "Parameter" ) ); child -> setAttribute( XMLProcessor::_toXMLCh("name"), XMLProcessor::_toXMLCh( _name ) ); child -> setAttribute( XMLProcessor::_toXMLCh("type"), XMLProcessor::_toXMLCh( _type ) ); DOMText * parameter_value = document -> createTextNode( XMLProcessor::_toXMLCh(_value)); child -> appendChild( parameter_value ); brickElem -> appendChild( child ); return child; }
DOMElement * LutXml::addParameter | ( | std::string | _name, |
std::string | _type, | ||
int | _value | ||
) | [protected] |
Definition at line 319 of file LutXml.cc.
References addParameter().
{ char buf[128]; sprintf(buf, "%d", _value); std::string str_value = buf; return addParameter( _name, _type, str_value ); }
LutXml::const_iterator LutXml::begin | ( | ) | const |
int LutXml::create_lut_map | ( | void | ) |
Definition at line 497 of file LutXml.cc.
References XMLProcessor::_toXMLCh(), a_to_i(), abs, brick, benchmark_cfg::cerr, XMLDOMBlock::document, i, j, lut_map, DetId::rawId(), and subdet_from_crate().
Referenced by HcaluLUTTPGCoder::updateXML().
{ //delete lut_map; lut_map.clear(); //lut_map = new std::map<uint32_t,std::vector<unsigned int> >(); if (document){ //DOMElement * rootElem = DOMNodeList * brick_list = document->getDocumentElement()->getElementsByTagName(brick); int n_of_bricks = brick_list->getLength(); for(int i=0; i!=n_of_bricks; i++){ DOMElement * aBrick = (DOMElement *)(brick_list->item(i)); DOMNodeList * par_list = aBrick->getElementsByTagName(XMLString::transcode("Parameter")); int n_of_par = par_list->getLength(); int ieta=-99; int iphi=-99; int depth=-99; int crate=-99; int lut_type=-99; HcalSubdetector subdet; for(int j=0; j!=n_of_par; j++){ //std::cout << "DEBUG: i,j: " << i << ", " << j << std::endl; DOMElement * aPar = (DOMElement *)(par_list->item(j)); char * aName = XMLString::transcode( aPar->getAttribute(XMLProcessor::_toXMLCh("name")) ); if ( strcmp(aName, "IETA")==0 ) ieta=a_to_i(XMLString::transcode(aPar->getFirstChild()->getNodeValue())); if ( strcmp(aName, "IPHI")==0 ) iphi=a_to_i(XMLString::transcode(aPar->getFirstChild()->getNodeValue())); if ( strcmp(aName, "DEPTH")==0 ) depth=a_to_i(XMLString::transcode(aPar->getFirstChild()->getNodeValue())); if ( strcmp(aName, "CRATE")==0 ) crate=a_to_i(XMLString::transcode(aPar->getFirstChild()->getNodeValue())); if ( strcmp(aName, "LUT_TYPE")==0 ) lut_type=a_to_i(XMLString::transcode(aPar->getFirstChild()->getNodeValue())); } subdet=subdet_from_crate(crate,abs(ieta),depth); //std::cerr << "DEBUG: eta,phi,depth,crate,type,subdet: " << ieta << ", " << iphi << ", " << depth << ", " << crate << ", " << lut_type << ", " << subdet << std::endl; DOMElement * _data = (DOMElement *)(aBrick->getElementsByTagName(XMLString::transcode("Data"))->item(0)); char * _str = XMLString::transcode(_data->getFirstChild()->getNodeValue()); //std::cout << _str << std::endl; // // get the LUT vector int _string_length = strlen(_str); std::vector<unsigned int> _lut; unsigned int _base = 16; unsigned int _item=0; for (int i=0; i!=_string_length; i++){ bool _range; char ch_cur = _str[i]; 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'); else if (_base==10) _range = (ch_cur>='0' and ch_cur<='9'); if ( _range ){ if ( ch_cur>='a' and ch_cur<='f' ) ch_cur += 10-'a'; else if ( ch_cur>='A' and ch_cur<='F' ) ch_cur += 10-'A'; else if ( ch_cur>='0' and ch_cur<='9' ) ch_cur += -'0'; _item = _item*_base; _item += ch_cur; bool last_digit = false; if ( (i+1)==_string_length ) last_digit=true; else{ char ch_next = _str[i+1]; bool _range_next; 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'); else if (_base==10) _range_next = (ch_next>='0' and ch_next<='9'); if ( !_range_next ) last_digit=true; } if (last_digit){ _lut.push_back(_item); _item=0; } } } //std::cout << _lut[127] << std::endl; // filling the map uint32_t _key = 0; if (lut_type==1){ HcalDetId _id(subdet,ieta,iphi,depth); _key = _id.rawId(); } else if (lut_type==2){ HcalTrigTowerDetId _id(ieta,iphi); _key = _id.rawId(); } //lut_map->insert(std::pair<uint32_t,std::vector<unsigned int> >(_key,_lut)); lut_map.insert(std::pair<uint32_t,std::vector<unsigned int> >(_key,_lut)); } } else{ std::cerr << "XML file with LUTs is not loaded, cannot create map!" << std::endl; } return 0; }
LutXml::const_iterator LutXml::end | ( | ) | const |
LutXml::const_iterator LutXml::find | ( | uint32_t | id | ) | const |
std::string LutXml::get_checksum | ( | std::vector< unsigned int > & | lut | ) | [static] |
Definition at line 338 of file LutXml.cc.
References gather_cfg::cout, cmsRelvalreport::exit, i, md5_append(), md5_finish(), md5_init(), query::result, and findQualityFiles::size.
Referenced by add_checksum(), and addLut().
{ std::stringstream result; md5_state_t md5er; md5_byte_t digest[16]; md5_init(&md5er); // linearizer LUT: if ( lut . size() == 128 ){ unsigned char tool[2]; for (int i=0; i<128; i++) { tool[0]=lut[i]&0xFF; tool[1]=(lut[i]>>8)&0xFF; md5_append(&md5er,tool,2); } } // compression LUT: else if ( lut . size() == 1024 ){ unsigned char tool; for (int i=0; i<1024; i++) { tool=lut[i]&0xFF; md5_append(&md5er,&tool,1); } } else{ std::cout << "ERROR: irregular LUT size, do not know how to compute checksum, exiting..." << std::endl; exit(-1); } md5_finish(&md5er,digest); for (int i=0; i<16; i++) result << std::hex << (((int)(digest[i]))&0xFF); //std::cout << "CHECKSUM: "; //std::cout << result . str(); //std::cout << std::endl; return result . str(); }
std::string & LutXml::getCurrentBrick | ( | void | ) |
std::vector< unsigned int > * LutXml::getLutFast | ( | uint32_t | det_id | ) |
Definition at line 127 of file LutXml.cc.
References benchmark_cfg::cerr, and lut_map.
Referenced by test_access(), and HcaluLUTTPGCoder::updateXML().
void LutXml::init | ( | void | ) |
HcalSubdetector LutXml::subdet_from_crate | ( | int | crate, |
int | eta, | ||
int | depth | ||
) |
Definition at line 459 of file LutXml.cc.
References benchmark_cfg::cerr, cmsRelvalreport::exit, HcalBarrel, HcalEndcap, HcalForward, HcalOuter, and query::result.
Referenced by create_lut_map().
{ HcalSubdetector result; // HBHE: 0,1,4,5,10,11,14,15,17 // HF: 2,9,12 // HO: 3,6,7,13 if (crate==2 || crate==9 || crate==12) result=HcalForward; else if (crate==3 || crate==6 || crate==7 || crate==13) result=HcalOuter; else if (crate==0 || crate==1 || crate==4 || crate==5 || crate==10 || crate==11 || crate==14 || crate==15 || crate==17){ if (eta<16) result=HcalBarrel; else if (eta>16) result=HcalEndcap; else if (eta==16 && depth!=3) result=HcalBarrel; else if (eta==16 && depth==3) result=HcalEndcap; else{ std::cerr << "Impossible to determine HCAL subdetector!!!" << std::endl; exit(-1); } } else{ std::cerr << "Impossible to determine HCAL subdetector!!!" << std::endl; exit(-1); } return result; }
int LutXml::test_access | ( | std::string | filename | ) |
Definition at line 376 of file LutXml.cc.
References gather_cfg::cout, HcalEmap::get_map(), getLutFast(), HcalBarrel, HcalEndcap, HcalForward, HcalOuter, prof2calltree::l, lut_map, NULL, DetId::rawId(), and findQualityFiles::size.
{ //create_lut_map(); //std::cout << "Created map size: " << lut_map->size() << std::endl; std::cout << "Created map size: " << lut_map.size() << std::endl; struct timeval _t; gettimeofday( &_t, NULL ); double _time =(double)(_t . tv_sec) + (double)(_t . tv_usec)/1000000.0; HcalEmap _emap("./backup/official_emap_v6.04_080905.txt"); std::vector<HcalEmap::HcalEmapRow> & _map = _emap.get_map(); std::cout << "HcalEmap contains " << _map . size() << " entries" << std::endl; int _counter=0; for (std::vector<HcalEmap::HcalEmapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++){ if (row->subdet=="HB"){ HcalDetId det_id(HcalBarrel,row->ieta,row->iphi,row->idepth); uint32_t raw_id = det_id.rawId(); std::vector<unsigned int> * l = getLutFast(raw_id); if (l) _counter++; } if (row->subdet=="HE"){ HcalDetId det_id(HcalEndcap,row->ieta,row->iphi,row->idepth); uint32_t raw_id = det_id.rawId(); std::vector<unsigned int> * l = getLutFast(raw_id); if (l) _counter++; } if (row->subdet=="HF"){ HcalDetId det_id(HcalForward,row->ieta,row->iphi,row->idepth); uint32_t raw_id = det_id.rawId(); std::vector<unsigned int> * l = getLutFast(raw_id); if (l) _counter++; } if (row->subdet=="HO"){ HcalDetId det_id(HcalOuter,row->ieta,row->iphi,row->idepth); uint32_t raw_id = det_id.rawId(); std::vector<unsigned int> * l = getLutFast(raw_id); if (l) _counter++; } } gettimeofday( &_t, NULL ); std::cout << "access to " << _counter << " HCAL channels took: " << (double)(_t . tv_sec) + (double)(_t . tv_usec)/1000000.0 - _time << "sec" << std::endl; //std::cout << std::endl; //for (std::vector<unsigned int>::const_iterator i=l->begin();i!=l->end();i++){ // std::cout << *i << " "; //} //std::cout << std::endl; return 0; }
XMLCh* LutXml::brick [protected] |
Definition at line 83 of file LutXml.h.
Referenced by create_lut_map(), init(), and ~LutXml().
DOMElement* LutXml::brickElem [protected] |
Definition at line 90 of file LutXml.h.
Referenced by addData(), addLut(), addParameter(), getCurrentBrick(), and init().
std::map<uint32_t,std::vector<unsigned int> > LutXml::lut_map [protected] |
Definition at line 93 of file LutXml.h.
Referenced by begin(), create_lut_map(), end(), find(), getLutFast(), and test_access().
XMLCh* LutXml::root [protected] |