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