![]() |
![]() |
#include <CaloOnlineTools/HcalOnlineDb/interface/HcalLutManager.h>
Public Member Functions | |
HcalLutSet | getLutSetFromFile (string _filename) |
std::string & | getLutXml (std::vector< unsigned int > &_lut) |
std::string | getLutXmlFromAsciiMaster (string _filename, string _tag, int _crate, bool split_by_crate=true) |
HcalLutManager () | |
void | init (void) |
~HcalLutManager () | |
Static Public Member Functions | |
static HcalSubdetector | get_subdetector (string _subdet) |
static string | get_time_stamp (time_t _time) |
static int | getInt (string number) |
Protected Attributes | |
LutXml * | lut_xml |
Definition at line 31 of file HcalLutManager.h.
HcalLutManager::HcalLutManager | ( | void | ) |
HcalLutManager::~HcalLutManager | ( | void | ) |
HcalSubdetector HcalLutManager::get_subdetector | ( | string | _subdet | ) | [static] |
Definition at line 65 of file HcalLutManager.cc.
References HcalBarrel, HcalEndcap, HcalForward, HcalOther, HcalOuter, and HLT_VtxMuL3::result.
Referenced by getLutXmlFromAsciiMaster().
00066 { 00067 HcalSubdetector result; 00068 if ( _det.find("HB") != string::npos ) result = HcalBarrel; 00069 else if ( _det.find("HE") != string::npos ) result = HcalEndcap; 00070 else if ( _det.find("HF") != string::npos ) result = HcalForward; 00071 else if ( _det.find("HO") != string::npos ) result = HcalOuter; 00072 else result = HcalOther; 00073 00074 return result; 00075 }
string HcalLutManager::get_time_stamp | ( | time_t | _time | ) | [static] |
Definition at line 284 of file HcalLutManager.cc.
Referenced by getLutXmlFromAsciiMaster().
00285 { 00286 char timebuf[50]; 00287 //strftime( timebuf, 50, "%c", gmtime( &_time ) ); 00288 strftime( timebuf, 50, "%Y-%m-%d %H:%M:%S", gmtime( &_time ) ); 00289 string creationstamp = timebuf; 00290 00291 return creationstamp; 00292 }
int HcalLutManager::getInt | ( | string | number | ) | [static] |
Definition at line 58 of file HcalLutManager.cc.
References HLT_VtxMuL3::result.
Referenced by getLutSetFromFile().
00059 { 00060 int result; 00061 sscanf(number.c_str(), "%d", &result); 00062 return result; 00063 }
HcalLutSet HcalLutManager::getLutSetFromFile | ( | string | _filename | ) |
Definition at line 107 of file HcalLutManager.cc.
References GenMuonPlsPt100GeV_cfg::cout, HcalLutSet::depth_max, HcalLutSet::depth_min, lat::endl(), HcalLutSet::eta_max, HcalLutSet::eta_min, getInt(), i, TreeToEdges::infile, iter, label, lut, HcalLutSet::lut, HcalLutSet::phi_max, HcalLutSet::phi_min, and HcalQIEManager::splitString().
Referenced by getLutXmlFromAsciiMaster().
00108 { 00109 HcalLutSet _lutset; 00110 00111 ifstream infile( _filename . c_str() ); 00112 string buf; 00113 00114 if ( infile . is_open() ){ 00115 cout << "File " << _filename << " is open..." << endl; 00116 cout << "Reading LUTs and their eta/phi/depth/subdet ranges..."; 00117 00118 // get label 00119 getline( infile, _lutset . label ); 00120 00121 //get subdetectors 00122 getline( infile, buf ); 00123 _lutset . subdet = HcalQIEManager::splitString( buf ); 00124 00125 //get min etas 00126 vector<string> buf_vec; 00127 getline( infile, buf ); 00128 buf_vec = HcalQIEManager::splitString( buf ); 00129 for (vector<string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){ 00130 _lutset.eta_min.push_back(HcalLutManager::getInt(*iter)); 00131 } 00132 00133 //get max etas 00134 getline( infile, buf ); 00135 buf_vec = HcalQIEManager::splitString( buf ); 00136 for (vector<string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){ 00137 _lutset.eta_max.push_back(HcalLutManager::getInt(*iter)); 00138 } 00139 00140 //get min phis 00141 getline( infile, buf ); 00142 buf_vec = HcalQIEManager::splitString( buf ); 00143 for (vector<string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){ 00144 _lutset.phi_min.push_back(HcalLutManager::getInt(*iter)); 00145 } 00146 00147 //get max phis 00148 getline( infile, buf ); 00149 buf_vec = HcalQIEManager::splitString( buf ); 00150 for (vector<string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){ 00151 _lutset.phi_max.push_back(HcalLutManager::getInt(*iter)); 00152 } 00153 00154 //get min depths 00155 getline( infile, buf ); 00156 buf_vec = HcalQIEManager::splitString( buf ); 00157 for (vector<string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){ 00158 _lutset.depth_min.push_back(HcalLutManager::getInt(*iter)); 00159 } 00160 00161 //get max depths 00162 getline( infile, buf ); 00163 buf_vec = HcalQIEManager::splitString( buf ); 00164 for (vector<string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){ 00165 _lutset.depth_max.push_back(HcalLutManager::getInt(*iter)); 00166 } 00167 00168 bool first_lut_entry = true; 00169 while ( getline( infile, buf ) > 0 ){ 00170 buf_vec = HcalQIEManager::splitString( buf ); 00171 for (unsigned int i = 0; i < buf_vec.size(); i++){ 00172 if (first_lut_entry){ 00173 vector<unsigned int> _l; 00174 _lutset.lut.push_back(_l); 00175 } 00176 _lutset . lut[i] . push_back(HcalLutManager::getInt(buf_vec[i])); 00177 } 00178 first_lut_entry = false; 00179 } 00180 } 00181 00182 cout << "done." << endl; 00183 00184 return _lutset; 00185 }
std::string & HcalLutManager::getLutXml | ( | std::vector< unsigned int > & | _lut | ) |
Definition at line 39 of file HcalLutManager.cc.
References LutXml::getCurrentBrick(), LutXml::_Config::lut, and lut_xml.
00040 { 00041 00042 if (lut_xml) delete lut_xml; 00043 00044 lut_xml = new LutXml(); 00045 00046 LutXml::Config _config; 00047 _config.lut = _lut; 00048 lut_xml -> addLut( _config ); 00049 lut_xml -> addLut( _config ); 00050 lut_xml -> addLut( _config ); 00051 00052 //return lut_xml->getString(); 00053 return lut_xml->getCurrentBrick(); 00054 00055 }
std::string HcalLutManager::getLutXmlFromAsciiMaster | ( | string | _filename, | |
string | _tag, | |||
int | _crate, | |||
bool | split_by_crate = true | |||
) |
Definition at line 187 of file HcalLutManager.cc.
References GenMuonPlsPt100GeV_cfg::cout, LutXml::_Config::crate, LutXml::_Config::creationstamp, LutXml::_Config::creationtag, LutXml::_Config::depth, HcalLutSet::depth_max, HcalLutSet::depth_min, lat::endl(), HcalLutSet::eta_max, HcalLutSet::eta_min, LutXml::_Config::fiber, LutXml::_Config::fiberchan, find(), LutXml::_Config::formatrevision, LutXml::_Config::generalizedindex, LMap::get_map(), get_subdetector(), get_time_stamp(), getLutSetFromFile(), i, LutXml::_Config::ieta, if(), LutXml::_Config::iphi, LutXml::_Config::lut, HcalLutSet::lut, LutXml::_Config::lut_type, HcalLutSet::phi_max, HcalLutSet::phi_min, SiStripLorentzAngle_cfi::read, HLT_VtxMuL3::result, row, size, LutXml::_Config::slot, HcalLutSet::subdet, LutXml::_Config::targetfirmware, and LutXml::_Config::topbottom.
00188 { 00189 //shared_ptr<LutXml> _xml( new LutXml() ); 00190 map<int, shared_ptr<LutXml> > _xml; // index - crate number 00191 00192 LMap _lmap; 00193 _lmap . read( "HCALmapHBEF.txt", "HBEF" ); 00194 _lmap . read( "HCALmapHO.txt", "HO" ); 00195 map<int,LMapRow> & _map = _lmap.get_map(); 00196 cout << "LMap contains " << _map . size() << " channels" << endl; 00197 00198 // read LUTs and their eta/phi/depth/subdet ranges 00199 HcalLutSet _set = getLutSetFromFile( _filename ); 00200 int lut_set_size = _set.lut.size(); // number of different luts 00201 00202 //loop over all HCAL channels 00203 for( map<int,LMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){ 00204 LutXml::Config _cfg; 00205 00206 // search for the correct LUT for a given channel, 00207 // higher LUT numbers have priority in case of overlapping 00208 int lut_index=-1; 00209 for ( int i=0; i<lut_set_size; i++ ){ 00210 if ( (row->second.crate == _crate || _crate == -1) && // -1 stands for all crates 00211 _set.eta_min[i] <= row->second.side*row->second.eta && 00212 _set.eta_max[i] >= row->second.side*row->second.eta && 00213 _set.phi_min[i] <= row->second.phi && 00214 _set.phi_max[i] >= row->second.phi && 00215 _set.depth_min[i] <= row->second.depth && 00216 _set.depth_max[i] >= row->second.depth && 00217 get_subdetector(_set.subdet[i]) == row->second.det ){ 00218 lut_index=i; 00219 } 00220 } 00221 if ( lut_index >= 0 ){ 00222 if ( _xml.count(row->second.crate) == 0 && split_by_crate ){ 00223 _xml.insert( pair<int,shared_ptr<LutXml> >(row->second.crate,shared_ptr<LutXml>(new LutXml())) ); 00224 } 00225 else if ( _xml.count(0) == 0 ){ 00226 _xml.insert( pair<int,shared_ptr<LutXml> >(0,shared_ptr<LutXml>(new LutXml())) ); 00227 } 00228 _cfg.ieta = row->second.side*row->second.eta; 00229 _cfg.iphi = row->second.phi; 00230 _cfg.depth = row->second.depth; 00231 _cfg.crate = row->second.crate; 00232 _cfg.slot = row->second.htr; 00233 if (row->second.fpga . find("top") != string::npos) _cfg.topbottom = 1; 00234 else if (row->second.fpga . find("bot") != string::npos) _cfg.topbottom = 0; 00235 else cout << "Warning! fpga out of range..." << endl; 00236 _cfg.fiber = row->second.rm_fi; 00237 _cfg.fiberchan = row->second.fi_ch; 00238 if (_set.lut[lut_index].size() == 128) _cfg.lut_type = 1; 00239 else _cfg.lut_type = 2; 00240 _cfg.creationtag = _tag; 00241 _cfg.creationstamp = get_time_stamp( time(0) ); 00242 _cfg.targetfirmware = "1.0.0"; 00243 _cfg.formatrevision = "1"; //??? 00244 _cfg.generalizedindex = 00245 _cfg.iphi*10000+_cfg.depth*1000+ 00246 (row->second.side>0)*100+row->second.eta; 00247 _cfg.lut = _set.lut[lut_index]; 00248 if (split_by_crate ){ 00249 _xml[row->second.crate]->addLut( _cfg ); 00250 } 00251 else{ 00252 _xml[0]->addLut( _cfg ); 00253 } 00254 } 00255 } 00256 00257 /* 00258 string result = _xml->getString(); 00259 stringstream output_file_name; 00260 if (_crate<0) output_file_name << _tag << "_all" << ".xml"; 00261 else output_file_name << _tag << "_" << _crate << ".xml"; 00262 //_xml -> write("LUT_GR0T_v1.0.xml"); 00263 _xml -> write( output_file_name.str().c_str() ); 00264 */ 00265 00266 string result; 00267 for (map<int,shared_ptr<LutXml> >::const_iterator cr = _xml.begin(); cr != _xml.end(); cr++){ 00268 result = cr->second->getString(); 00269 stringstream output_file_name; 00270 if ( split_by_crate ){ 00271 output_file_name << _tag << "_" << cr->first << ".xml"; 00272 } 00273 else{ 00274 output_file_name << _tag << ".xml"; 00275 } 00276 cr->second->write( output_file_name.str().c_str() ); 00277 } 00278 00279 return result; 00280 }
LutXml* HcalLutManager::lut_xml [protected] |
Definition at line 48 of file HcalLutManager.h.
Referenced by getLutXml(), init(), and ~HcalLutManager().