00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "CondTools/L1Trigger/interface/L1ConfigOnlineProdBase.h"
00025 #include "CondFormats/L1TObjects/interface/L1CaloEcalScale.h"
00026 #include "CondFormats/DataRecord/interface/L1CaloEcalScaleRcd.h"
00027 #include "CondFormats/EcalObjects/interface/EcalTPGLutIdMap.h"
00028 #include "CondFormats/EcalObjects/interface/EcalTPGLutGroup.h"
00029 #include "CondFormats/EcalObjects/interface/EcalTPGPhysicsConst.h"
00030 #include "DataFormats/EcalDigi/interface/EcalTriggerPrimitiveDigi.h"
00031 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
00032 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
00033 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
00034
00035
00036
00037
00038
00039 class L1CaloEcalScaleConfigOnlineProd :
00040 public L1ConfigOnlineProdBase< L1CaloEcalScaleRcd, L1CaloEcalScale > {
00041 public:
00042 L1CaloEcalScaleConfigOnlineProd(const edm::ParameterSet&);
00043 ~L1CaloEcalScaleConfigOnlineProd();
00044
00045 virtual boost::shared_ptr< L1CaloEcalScale > newObject(
00046 const std::string& objectKey ) ;
00047
00048
00049 private:
00050 const EcalElectronicsMapping * theMapping_ ;
00051 std::map<int, std::vector<int>* > groupInfo;
00052 EcalTPGGroups* lutGrpMap;
00053 L1CaloEcalScale* ecalScale;
00054
00055 };
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 L1CaloEcalScaleConfigOnlineProd::L1CaloEcalScaleConfigOnlineProd(
00069 const edm::ParameterSet& iConfig)
00070 : L1ConfigOnlineProdBase< L1CaloEcalScaleRcd, L1CaloEcalScale >( iConfig )
00071 {
00072 ecalScale = new L1CaloEcalScale(0);
00073 theMapping_ = new EcalElectronicsMapping();
00074 lutGrpMap = new EcalTPGGroups();
00075
00076 }
00077
00078
00079 L1CaloEcalScaleConfigOnlineProd::~L1CaloEcalScaleConfigOnlineProd()
00080 {
00081
00082
00083
00084 delete theMapping_;
00085
00086
00087
00088 groupInfo.clear();
00089
00090
00091 }
00092
00093 boost::shared_ptr< L1CaloEcalScale >
00094 L1CaloEcalScaleConfigOnlineProd::newObject( const std::string& objectKey )
00095 {
00096 using namespace edm::es;
00097
00098 std:: cout << "object Key " << objectKey <<std::endl;
00099
00100 if(objectKey == "NULL" || objectKey == "")
00101 return boost::shared_ptr< L1CaloEcalScale >( ecalScale );
00102 if(objectKey == "IDENTITY"){
00103 ecalScale = 0;
00104 ecalScale = new L1CaloEcalScale(1);
00105 return boost::shared_ptr< L1CaloEcalScale >( ecalScale);
00106 }
00107
00108
00109 double ee_lsb = 0.;
00110 double eb_lsb = 0.;
00111
00112 std::vector < std::string > mainStrings;
00113
00114
00115
00116
00117 std::vector< std::string > paramStrings ;
00118 paramStrings.push_back("LOGIC_ID");
00119 paramStrings.push_back("ETSAT");
00120
00121
00122 std::vector< std::string> IDStrings;
00123 IDStrings.push_back("NAME");
00124 IDStrings.push_back("ID1");
00125 IDStrings.push_back("ID2");
00126 IDStrings.push_back("maps_to");
00127
00128 l1t::OMDSReader::QueryResults paramResults =
00129 m_omdsReader.basicQuery( paramStrings,
00130 "CMS_ECAL_CONF",
00131 "FE_CONFIG_LUTPARAM_DAT",
00132 "FE_CONFIG_LUTPARAM_DAT.LUT_CONF_ID",
00133 m_omdsReader.singleAttribute(objectKey)
00134 );
00135
00136 if( paramResults.queryFailed()
00137 || (paramResults.numberRows()==0) )
00138 {
00139 edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale key. Unable to find lutparam dat table" ;
00140 return boost::shared_ptr< L1CaloEcalScale >() ;
00141 }
00142
00143
00144
00145 for(int i = 0; i < paramResults.numberRows() ; i++){
00146
00147
00148 float etSat;
00149 paramResults.fillVariableFromRow("ETSAT",i,etSat);
00150
00151 std::string ecid_name;
00152 int logic_id;
00153 paramResults.fillVariableFromRow("LOGIC_ID",i, logic_id);
00154
00155
00156 l1t::OMDSReader::QueryResults logicID =
00157 m_omdsReader.basicQuery(IDStrings,
00158 "CMS_ECAL_COND",
00159 "CHANNELVIEW",
00160 "CHANNELVIEW.LOGIC_ID",
00161 m_omdsReader.singleAttribute(logic_id)
00162 );
00163
00164 logicID.fillVariable("NAME",ecid_name);
00165
00166 if(ecid_name =="EB")
00167 eb_lsb = etSat/1024;
00168 else if("EE" == ecid_name)
00169 ee_lsb = etSat/1024;
00170 else {
00171 edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale LOGIC_ID. unable to find channel view with appropiate logic id" ;
00172 return boost::shared_ptr< L1CaloEcalScale >() ;
00173 }
00174
00175 }
00176
00177
00178 std::vector< std::string > grpLUT;
00179 grpLUT.push_back("GROUP_ID");
00180 grpLUT.push_back("LUT_ID");
00181 grpLUT.push_back("LUT_VALUE");
00182
00183 l1t::OMDSReader::QueryResults lutGrpResults =
00184 m_omdsReader.basicQuery( grpLUT,
00185 "CMS_ECAL_CONF",
00186 "FE_LUT_PER_GROUP_DAT",
00187 "FE_LUT_PER_GROUP_DAT.LUT_CONF_ID",
00188 m_omdsReader.singleAttribute(objectKey)
00189 );
00190
00191 if( lutGrpResults.queryFailed()
00192 || (lutGrpResults.numberRows()%1024 !=0) )
00193 {
00194 edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale key. No group info" ;
00195 return boost::shared_ptr< L1CaloEcalScale >() ;
00196 }
00197
00198
00199 int nEntries = lutGrpResults.numberRows();
00200 for(int i = 0; i < nEntries; i++) {
00201 int group, lutID;
00202 float lutValue;
00203
00204 lutGrpResults.fillVariableFromRow("GROUP_ID",i,group);
00205 if(groupInfo.find(group) == groupInfo.end()){
00206 groupInfo[group] = new std::vector<int>;
00207 (groupInfo[group])->resize(1024);
00208 }
00209
00210 lutGrpResults.fillVariableFromRow("LUT_ID",i,lutID);
00211 lutGrpResults.fillVariableFromRow("LUT_VALUE",i,lutValue);
00212 groupInfo[group]->at(lutID) = (int) lutValue;
00213 }
00214
00215 std::map<int, std::vector<int> > tpgValueMap;
00216
00217 std::map<int, std::vector<int>* >::iterator grpIt;
00218 for ( grpIt = groupInfo.begin(); grpIt != groupInfo.end() ; ++grpIt){
00219 const std::vector<int> * lut_ = grpIt->second;
00220
00221 std::vector<int> tpgValue;
00222 tpgValue.resize(256);
00223 for(int tpg = 0; tpg < 256 ; tpg++){
00224
00225 for(int i = 0; i < 1024 ; i++) {
00226
00227 if(tpg == (0xff & (lut_->at(i)))){
00228 tpgValue[tpg] = i;
00229 break;
00230 }
00231 }
00232 }
00233 tpgValueMap[grpIt->first] = tpgValue;
00234 }
00235
00236
00237 std::vector < std::string > groupMap;
00238 groupMap.push_back("LOGIC_ID");
00239 groupMap.push_back("GROUP_ID");
00240
00241
00242
00243 l1t::OMDSReader::QueryResults grpMapResults =
00244 m_omdsReader.basicQuery( groupMap,
00245 "CMS_ECAL_CONF",
00246 "FE_CONFIG_LUT_DAT",
00247 "FE_CONFIG_LUT_DAT.LUT_CONF_ID",
00248 m_omdsReader.singleAttribute(objectKey)
00249 );
00250 if( grpMapResults.queryFailed()
00251 || (grpMapResults.numberRows()==0) )
00252 {
00253 edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale key. No fe_config_lut_dat info" ;
00254 return boost::shared_ptr< L1CaloEcalScale >() ;
00255 }
00256
00257 nEntries = grpMapResults.numberRows();
00258 for(int i = 0; i< nEntries; ++i){
00259 std::string ecid_name;
00260 int logic_id;
00261 grpMapResults.fillVariableFromRow("LOGIC_ID",i, logic_id);
00262 int group_id;
00263 grpMapResults.fillVariableFromRow("GROUP_ID",i, group_id);
00264
00265
00266 l1t::OMDSReader::QueryResults IDResults =
00267 m_omdsReader.basicQuery( IDStrings,
00268 "CMS_ECAL_COND",
00269 "CHANNELVIEW",
00270 "CHANNELVIEW.LOGIC_ID",
00271 m_omdsReader.singleAttribute(logic_id)
00272 );
00273 if( paramResults.queryFailed()
00274 || (paramResults.numberRows()==0) )
00275 {
00276 edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale key. Unable to find logic_id channel view" ;
00277 return boost::shared_ptr< L1CaloEcalScale >() ;
00278 }
00279 for(int j = 0; j < IDResults.numberRows(); j++){
00280
00281 std::string ecid_name, maps_to;
00282
00283 IDResults.fillVariableFromRow("NAME",j, ecid_name);
00284 IDResults.fillVariableFromRow("maps_to",j, maps_to);
00285 if(logic_id >= 2100001901 && logic_id <= 2100001916)
00286
00287 if(ecid_name != maps_to){
00288 continue;
00289 }
00290 if(ecid_name== "EB_trigger_tower" || ecid_name == "EE_trigger_tower") {
00291 int id1,id2;
00292 IDResults.fillVariableFromRow("ID1",j, id1);
00293 IDResults.fillVariableFromRow("ID2",j, id2);
00294
00295 if(ecid_name == "EB_trigger_tower")
00296 id1+=36;
00297 EcalTrigTowerDetId temp = theMapping_->getTrigTowerDetId(id1,id2);
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318 lutGrpMap->setValue(temp, group_id);
00319 break;
00320 }
00321 }
00322 }
00323
00324 const EcalTPGGroups::EcalTPGGroupsMap & gMap = lutGrpMap->getMap();
00325
00326
00327
00328 for( unsigned short ieta = 1 ; ieta <= L1CaloEcalScale::nBinEta; ++ieta ){
00329 EcalSubdetector subdet = ( ieta <= 17 ) ? EcalBarrel : EcalEndcap ;
00330 double et_lsb = (ieta<=17) ? eb_lsb : ee_lsb;
00331 for(int pos = 0; pos <=1; pos++){
00332 int zside = (int) pow(-1,pos);
00333
00334
00335 for(int iphi = 1; iphi<=72; iphi++){
00336 if(!EcalTrigTowerDetId::validDetId(zside,subdet,ieta, iphi))
00337 continue;
00338 EcalTrigTowerDetId test(zside, subdet, ieta, iphi);
00339 EcalTPGGroups::EcalTPGGroupsMapItr itLut = gMap.find(test) ;
00340 if(itLut != gMap.end()) {
00341
00342 std::vector<int> tpgValue = tpgValueMap[itLut->second];
00343
00344 for( unsigned short irank = 0 ; irank < L1CaloEcalScale::nBinRank; ++irank )
00345 {
00346 ecalScale->setBin(irank, ieta, zside, et_lsb * tpgValue[irank]);
00347
00348
00349 }
00350
00351 break;
00352 }
00353 }
00354 }
00355 }
00356
00357
00358
00359
00360
00361
00362 return boost::shared_ptr< L1CaloEcalScale >( ecalScale );
00363 }
00364
00365 DEFINE_FWK_EVENTSETUP_MODULE(L1CaloEcalScaleConfigOnlineProd);