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 int lastValue = 0;
00224 for(int tpg = 0; tpg < 256 ; tpg++){
00225
00226 for(int i = 0; i < 1024 ; i++) {
00227
00228 if(tpg == (0xff & (lut_->at(i)))){
00229 tpgValue[tpg] = i;
00230 lastValue = i;
00231 break;
00232 }
00233 tpgValue[tpg] = lastValue;
00234 }
00235 }
00236 tpgValueMap[grpIt->first] = tpgValue;
00237 }
00238
00239
00240 std::vector < std::string > groupMap;
00241 groupMap.push_back("LOGIC_ID");
00242 groupMap.push_back("GROUP_ID");
00243
00244
00245
00246 l1t::OMDSReader::QueryResults grpMapResults =
00247 m_omdsReader.basicQuery( groupMap,
00248 "CMS_ECAL_CONF",
00249 "FE_CONFIG_LUT_DAT",
00250 "FE_CONFIG_LUT_DAT.LUT_CONF_ID",
00251 m_omdsReader.singleAttribute(objectKey)
00252 );
00253 if( grpMapResults.queryFailed()
00254 || (grpMapResults.numberRows()==0) )
00255 {
00256 edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale key. No fe_config_lut_dat info" ;
00257 return boost::shared_ptr< L1CaloEcalScale >() ;
00258 }
00259
00260 nEntries = grpMapResults.numberRows();
00261 for(int i = 0; i< nEntries; ++i){
00262 std::string ecid_name;
00263 int logic_id;
00264 grpMapResults.fillVariableFromRow("LOGIC_ID",i, logic_id);
00265 int group_id;
00266 grpMapResults.fillVariableFromRow("GROUP_ID",i, group_id);
00267
00268
00269 l1t::OMDSReader::QueryResults IDResults =
00270 m_omdsReader.basicQuery( IDStrings,
00271 "CMS_ECAL_COND",
00272 "CHANNELVIEW",
00273 "CHANNELVIEW.LOGIC_ID",
00274 m_omdsReader.singleAttribute(logic_id)
00275 );
00276 if( paramResults.queryFailed()
00277 || (paramResults.numberRows()==0) )
00278 {
00279 edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale key. Unable to find logic_id channel view" ;
00280 return boost::shared_ptr< L1CaloEcalScale >() ;
00281 }
00282 for(int j = 0; j < IDResults.numberRows(); j++){
00283
00284 std::string ecid_name, maps_to;
00285
00286 IDResults.fillVariableFromRow("NAME",j, ecid_name);
00287 IDResults.fillVariableFromRow("maps_to",j, maps_to);
00288 if(logic_id >= 2100001901 && logic_id <= 2100001916)
00289
00290 if(ecid_name != maps_to){
00291 continue;
00292 }
00293 if(ecid_name== "EB_trigger_tower" || ecid_name == "EE_trigger_tower") {
00294 int id1,id2;
00295 IDResults.fillVariableFromRow("ID1",j, id1);
00296 IDResults.fillVariableFromRow("ID2",j, id2);
00297
00298 if(ecid_name == "EB_trigger_tower")
00299 id1+=36;
00300 EcalTrigTowerDetId temp = theMapping_->getTrigTowerDetId(id1,id2);
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 lutGrpMap->setValue(temp, group_id);
00322 break;
00323 }
00324 }
00325 }
00326
00327 const EcalTPGGroups::EcalTPGGroupsMap & gMap = lutGrpMap->getMap();
00328
00329
00330
00331 for( unsigned short ieta = 1 ; ieta <= L1CaloEcalScale::nBinEta; ++ieta ){
00332 EcalSubdetector subdet = ( ieta <= 17 ) ? EcalBarrel : EcalEndcap ;
00333 double et_lsb = (ieta<=17) ? eb_lsb : ee_lsb;
00334 for(int pos = 0; pos <=1; pos++){
00335 int zside = (int) pow(-1,pos);
00336
00337
00338 for(int iphi = 1; iphi<=72; iphi++){
00339 if(!EcalTrigTowerDetId::validDetId(zside,subdet,ieta, iphi))
00340 continue;
00341 EcalTrigTowerDetId test(zside, subdet, ieta, iphi);
00342 EcalTPGGroups::EcalTPGGroupsMapItr itLut = gMap.find(test) ;
00343 if(itLut != gMap.end()) {
00344
00345 std::vector<int> tpgValue = tpgValueMap[itLut->second];
00346
00347 for( unsigned short irank = 0 ; irank < L1CaloEcalScale::nBinRank; ++irank )
00348 {
00349 ecalScale->setBin(irank, ieta, zside, et_lsb * tpgValue[irank]);
00350
00351
00352 }
00353
00354 break;
00355 }
00356 }
00357 }
00358 }
00359
00360
00361
00362
00363
00364
00365 return boost::shared_ptr< L1CaloEcalScale >( ecalScale );
00366 }
00367
00368 DEFINE_FWK_EVENTSETUP_MODULE(L1CaloEcalScaleConfigOnlineProd);