CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1CaloEcalScaleConfigOnlineProd.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1EmEtScaleOnlineProd
4 // Class: L1EmEtScaleOnlineProd
5 //
13 //
14 // Original Author: Werner Man-Li Sun
15 // Created: Tue Sep 16 22:43:22 CEST 2008
16 //
17 //
18 
19 
20 // system include files
21 
22 // user include files
33 
34 //
35 // class declaration
36 //
37 
39  public L1ConfigOnlineProdBase< L1CaloEcalScaleRcd, L1CaloEcalScale > {
40  public:
43 
44  virtual boost::shared_ptr< L1CaloEcalScale > newObject(
45  const std::string& objectKey ) override ;
46 
47 
48  private:
50  std::map<int, std::vector<int>* > groupInfo;
53  // ----------member data ---------------------------
54 };
55 
56 //
57 // constants, enums and typedefs
58 //
59 
60 //
61 // static data member definitions
62 //
63 
64 //
65 // constructors and destructor
66 //
68  const edm::ParameterSet& iConfig)
70 {
71  ecalScale = new L1CaloEcalScale(0);
73  lutGrpMap = new EcalTPGGroups();
74 
75 }
76 
77 
79 {
80 
81  // do anything here that needs to be done at desctruction time
82  // (e.g. close files, deallocate resources etc.)
83  delete theMapping_;
84 
85  // delete ecalScale;
86  // delete lutGrpMap;
87  groupInfo.clear();
88 
89 
90 }
91 
92 boost::shared_ptr< L1CaloEcalScale >
94 {
95  using namespace edm::es;
96 
97  std:: cout << "object Key " << objectKey <<std::endl;
98 
99  if(objectKey == "NULL" || objectKey == "") // return default blank ecal scale
100  return boost::shared_ptr< L1CaloEcalScale >( ecalScale );
101  if(objectKey == "IDENTITY"){ // return identity ecal scale
102  ecalScale = 0;
103  ecalScale = new L1CaloEcalScale(1);
104  return boost::shared_ptr< L1CaloEcalScale >( ecalScale);
105  }
106 
107 
108  double ee_lsb = 0.;
109  double eb_lsb = 0.;
110 
111  std::vector < std::string > mainStrings;
112 
113  // ~~~~~~~~~ Cut values ~~~~~~~~~
114 
115 
116  std::vector< std::string > paramStrings ;
117  paramStrings.push_back("LOGIC_ID"); // EB/EE
118  paramStrings.push_back("ETSAT"); //Only object needed
119 
120 
121  std::vector< std::string> IDStrings;
122  IDStrings.push_back("NAME");
123  IDStrings.push_back("ID1");
124  IDStrings.push_back("ID2");
125  IDStrings.push_back("maps_to");
126 
127  l1t::OMDSReader::QueryResults paramResults =
128  m_omdsReader.basicQuery( paramStrings,
129  "CMS_ECAL_CONF",
130  "FE_CONFIG_LUTPARAM_DAT",
131  "FE_CONFIG_LUTPARAM_DAT.LUT_CONF_ID",
132  m_omdsReader.singleAttribute(objectKey)
133  );
134 
135  if( paramResults.queryFailed()
136  || (paramResults.numberRows()==0) ) // check query successful
137  {
138  edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale key. Unable to find lutparam dat table" ;
139  return boost::shared_ptr< L1CaloEcalScale >() ;
140  }
141 
142 
143 
144  for(int i = 0; i < paramResults.numberRows() ; i++){
145 
146  //EcalTPGPhysicsConst::Item item;
147  float etSat;
148  paramResults.fillVariableFromRow("ETSAT",i,etSat);
149 
150  std::string ecid_name;
151  int logic_id;
152  paramResults.fillVariableFromRow("LOGIC_ID",i, logic_id);
153 
154 
156  m_omdsReader.basicQuery(IDStrings,
157  "CMS_ECAL_COND",
158  "CHANNELVIEW",
159  "CHANNELVIEW.LOGIC_ID",
160  m_omdsReader.singleAttribute(logic_id)
161  );
162 
163  logicID.fillVariable("NAME",ecid_name);
164 
165  if(ecid_name =="EB")
166  eb_lsb = etSat/1024;
167  else if("EE" == ecid_name)
168  ee_lsb = etSat/1024;
169  else {
170  edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale LOGIC_ID. unable to find channel view with appropiate logic id" ;
171  return boost::shared_ptr< L1CaloEcalScale >() ;
172  }
173 
174  }
175  // std::cout << " eb lsb " << eb_lsb << " ee_lsb " << ee_lsb << std::endl;
176 
177  std::vector< std::string > grpLUT;
178  grpLUT.push_back("GROUP_ID");
179  grpLUT.push_back("LUT_ID");
180  grpLUT.push_back("LUT_VALUE");
181 
182  l1t::OMDSReader::QueryResults lutGrpResults =
183  m_omdsReader.basicQuery( grpLUT,
184  "CMS_ECAL_CONF",
185  "FE_LUT_PER_GROUP_DAT",
186  "FE_LUT_PER_GROUP_DAT.LUT_CONF_ID",
187  m_omdsReader.singleAttribute(objectKey)
188  );
189 
190  if( lutGrpResults.queryFailed()
191  || (lutGrpResults.numberRows()%1024 !=0) ) // check query successful
192  {
193  edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale key. No group info" ;
194  return boost::shared_ptr< L1CaloEcalScale >() ;
195  }
196 
197 
198  int nEntries = lutGrpResults.numberRows();
199  for(int i = 0; i < nEntries; i++) {
200  int group, lutID;
201  float lutValue;
202 
203  lutGrpResults.fillVariableFromRow("GROUP_ID",i,group);
204  if(groupInfo.find(group) == groupInfo.end()){
205  groupInfo[group] = new std::vector<int>;
206  (groupInfo[group])->resize(1024);
207  }
208 
209  lutGrpResults.fillVariableFromRow("LUT_ID",i,lutID);
210  lutGrpResults.fillVariableFromRow("LUT_VALUE",i,lutValue);
211  groupInfo[group]->at(lutID) = (int) lutValue;
212  }
213 
214  std::map<int, std::vector<int> > tpgValueMap;
215 
216  std::map<int, std::vector<int>* >::iterator grpIt;
217  for ( grpIt = groupInfo.begin(); grpIt != groupInfo.end() ; ++grpIt){
218  const std::vector<int> * lut_ = grpIt->second;
219 
220  std::vector<int> tpgValue;
221  tpgValue.resize(256);
222  int lastValue = 0;
223  for(int tpg = 0; tpg < 256 ; tpg++){
224 
225  for(int i = 0; i < 1024 ; i++) {
226 
227  if(tpg == (0xff & (lut_->at(i)))){
228  tpgValue[tpg] = i;
229  lastValue = i;
230  break;
231  }
232  tpgValue[tpg] = lastValue;
233  }
234  }
235  tpgValueMap[grpIt->first] = tpgValue;
236  }
237 
238 
239  std::vector < std::string > groupMap;
240  groupMap.push_back("LOGIC_ID");
241  groupMap.push_back("GROUP_ID");
242 
243 
244 
245  l1t::OMDSReader::QueryResults grpMapResults =
246  m_omdsReader.basicQuery( groupMap,
247  "CMS_ECAL_CONF",
248  "FE_CONFIG_LUT_DAT",
249  "FE_CONFIG_LUT_DAT.LUT_CONF_ID",
250  m_omdsReader.singleAttribute(objectKey)
251  );
252  if( grpMapResults.queryFailed()
253  || (grpMapResults.numberRows()==0) ) // check query successful
254  {
255  edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale key. No fe_config_lut_dat info" ;
256  return boost::shared_ptr< L1CaloEcalScale >() ;
257  }
258 
259  nEntries = grpMapResults.numberRows();
260  for(int i = 0; i< nEntries; ++i){
261  std::string ecid_name;
262  int logic_id;
263  grpMapResults.fillVariableFromRow("LOGIC_ID",i, logic_id);
264  int group_id;
265  grpMapResults.fillVariableFromRow("GROUP_ID",i, group_id);
266  // if(logic_id >= 2100001901 && logic_id <= 2100001916)
267  // std::cout<< "missing logic id found " <<logic_id <<std::endl;
269  m_omdsReader.basicQuery( IDStrings,
270  "CMS_ECAL_COND",
271  "CHANNELVIEW",
272  "CHANNELVIEW.LOGIC_ID",
273  m_omdsReader.singleAttribute(logic_id)
274  );
275  if( paramResults.queryFailed()
276  || (paramResults.numberRows()==0) ) // check query successful
277  {
278  edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale key. Unable to find logic_id channel view" ;
279  return boost::shared_ptr< L1CaloEcalScale >() ;
280  }
281  for(int j = 0; j < IDResults.numberRows(); j++){
282 
283  std::string ecid_name, maps_to;
284 
285  IDResults.fillVariableFromRow("NAME",j, ecid_name);
286  IDResults.fillVariableFromRow("maps_to",j, maps_to);
287  if(logic_id >= 2100001901 && logic_id <= 2100001916)
288  // std::cout << " name " << ecid_name << " maps to " << maps_to <<std::endl;
289  if(ecid_name != maps_to){
290  continue; // make sure they match
291  }
292  if(ecid_name== "EB_trigger_tower" || ecid_name == "EE_trigger_tower") {
293  int id1,id2;
294  IDResults.fillVariableFromRow("ID1",j, id1);
295  IDResults.fillVariableFromRow("ID2",j, id2);
296 
297  if(ecid_name == "EB_trigger_tower")
298  id1+=36; //lowest TCC for barrel 37
300  /* if(ecid_name == "EE_trigger_tower"){
301  int testID = theMapping_->TCCid(temp);
302 
303  if( testID != id1 ){
304  std::cout << " unmatched mapping testID " <<testID <<std::endl;
305  std::cout << "id1 " << id1 << " id2 " <<id2<< " iphi " << temp.iphi() <<" ieta " << temp.ieta() <<std::endl;
306  }
307  }
308  if(ecid_name == "EB_trigger_tower"){
309  int testID = theMapping_->TCCid(temp);
310  if( testID != id1 ){
311  std::cout << " unmatched mapping testID " <<testID <<std::endl;
312  std::cout << "id1 " << id1 << " id2 " <<id2<< " iphi " << temp.iphi() <<" ieta " << temp.ieta() <<std::endl;
313  }
314  }
315  */
316  // if(temp.ieta() == -18 || temp.ietaAbs() == 28)
317  // if(logic_id >= 2100001901 && logic_id <= 2100001916)
318 
319 
320  lutGrpMap->setValue(temp, group_id); // assume ee has less than 68 tt
321  break;
322  }
323  }
324  }
325 
327 
328 
329 
330  for( unsigned short ieta = 1 ; ieta <= L1CaloEcalScale::nBinEta; ++ieta ){
331  EcalSubdetector subdet = ( ieta <= 17 ) ? EcalBarrel : EcalEndcap ;
332  double et_lsb = (ieta<=17) ? eb_lsb : ee_lsb;
333  for(int pos = 0; pos <=1; pos++){
334  int zside = (int) pow(-1,pos);
335 
336  // std::cout << "ieta " <<zside*ieta ;
337  for(int iphi = 1; iphi<=72; iphi++){
338  if(!EcalTrigTowerDetId::validDetId(zside,subdet,ieta, iphi))
339  continue;
340  EcalTrigTowerDetId test(zside, subdet, ieta, iphi);
341  EcalTPGGroups::EcalTPGGroupsMapItr itLut = gMap.find(test) ;
342  if(itLut != gMap.end()) {
343  // std::cout << " non mapped section iphi " << iphi << " ieta " <<ieta << " tccid " << theMapping_->TCCid(test) << " iTT " << theMapping_->iTT(test)<< std::endl;
344  std::vector<int> tpgValue = tpgValueMap[itLut->second];
345 
346  for( unsigned short irank = 0 ; irank < L1CaloEcalScale::nBinRank; ++irank )
347  {
348  ecalScale->setBin(irank, ieta, zside, et_lsb * tpgValue[irank]);
349 
350  // std::cout << " irank " << irank << " etValue " << et_lsb*tpgValue[irank] << std::endl;
351  }
352 
353  break;
354  }
355  }
356  }
357  }
358 
359 
360  // ecalScale->print(std::cout);
361 
362 
363 // ------------ method called to produce the data ------------
364  return boost::shared_ptr< L1CaloEcalScale >( ecalScale );
365 }
366 //define this as a plug-in
int i
Definition: DBlmapReader.cc:9
const EcalTPGGroupsMap & getMap() const
Definition: EcalTPGGroups.h:28
bool fillVariable(const std::string &columnName, T &outputVariable) const
Definition: OMDSReader.h:311
const QueryResults singleAttribute(const T &data) const
Definition: OMDSReader.h:295
std::map< uint32_t, uint32_t >::const_iterator EcalTPGGroupsMapItr
Definition: EcalTPGGroups.h:23
std::map< int, std::vector< int > * > groupInfo
EcalTrigTowerDetId getTrigTowerDetId(int TCCid, int iTT) const
Builds a EcalTrigTowerDetID from the TCCid &amp; TriggerTower index in TCC.
void setBin(unsigned short rank, unsigned short eta, short etaSign, double et)
set scale element; use this to create non-linear scales
int zside(DetId const &)
bool fillVariableFromRow(const std::string &columnName, int rowNumber, T &outputVariable) const
Definition: OMDSReader.h:319
const QueryResults basicQuery(const std::vector< std::string > &columnNames, const std::string &schemaName, const std::string &tableName, const std::string &conditionLHS="", const QueryResults conditionRHS=QueryResults(), const std::string &conditionRHSName="") const
Definition: OMDSReader.cc:87
L1CaloEcalScaleConfigOnlineProd(const edm::ParameterSet &)
int j
Definition: DBlmapReader.cc:9
void setValue(const uint32_t &rawId, const uint32_t &ObjectId)
Definition: EcalTPGGroups.cc:9
const EcalElectronicsMapping * theMapping_
tuple group
Definition: watchdog.py:82
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
static bool validDetId(int iz, EcalSubdetector sd, int i, int j)
check if a valid index combination
static const unsigned short nBinRank
virtual boost::shared_ptr< L1CaloEcalScale > newObject(const std::string &objectKey) override
static const unsigned short nBinEta
tuple cout
Definition: gather_cfg.py:121
EcalSubdetector
std::map< uint32_t, uint32_t > EcalTPGGroupsMap
Definition: EcalTPGGroups.h:22
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40