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.2 2009/10/23 14:47:00 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 >
94 L1CaloEcalScaleConfigOnlineProd::newObject( const std::string& objectKey )
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  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  break;
230  }
231  }
232  }
233  tpgValueMap[grpIt->first] = tpgValue;
234  }
235 
236 
237  std::vector < std::string > groupMap;
238  groupMap.push_back("LOGIC_ID");
239  groupMap.push_back("GROUP_ID");
240 
241 
242 
243  l1t::OMDSReader::QueryResults grpMapResults =
244  m_omdsReader.basicQuery( groupMap,
245  "CMS_ECAL_CONF",
246  "FE_CONFIG_LUT_DAT",
247  "FE_CONFIG_LUT_DAT.LUT_CONF_ID",
248  m_omdsReader.singleAttribute(objectKey)
249  );
250  if( grpMapResults.queryFailed()
251  || (grpMapResults.numberRows()==0) ) // check query successful
252  {
253  edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale key. No fe_config_lut_dat info" ;
254  return boost::shared_ptr< L1CaloEcalScale >() ;
255  }
256 
257  nEntries = grpMapResults.numberRows();
258  for(int i = 0; i< nEntries; ++i){
259  std::string ecid_name;
260  int logic_id;
261  grpMapResults.fillVariableFromRow("LOGIC_ID",i, logic_id);
262  int group_id;
263  grpMapResults.fillVariableFromRow("GROUP_ID",i, group_id);
264  // if(logic_id >= 2100001901 && logic_id <= 2100001916)
265  // std::cout<< "missing logic id found " <<logic_id <<std::endl;
267  m_omdsReader.basicQuery( IDStrings,
268  "CMS_ECAL_COND",
269  "CHANNELVIEW",
270  "CHANNELVIEW.LOGIC_ID",
271  m_omdsReader.singleAttribute(logic_id)
272  );
273  if( paramResults.queryFailed()
274  || (paramResults.numberRows()==0) ) // check query successful
275  {
276  edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale key. Unable to find logic_id channel view" ;
277  return boost::shared_ptr< L1CaloEcalScale >() ;
278  }
279  for(int j = 0; j < IDResults.numberRows(); j++){
280 
281  std::string ecid_name, maps_to;
282 
283  IDResults.fillVariableFromRow("NAME",j, ecid_name);
284  IDResults.fillVariableFromRow("maps_to",j, maps_to);
285  if(logic_id >= 2100001901 && logic_id <= 2100001916)
286  // std::cout << " name " << ecid_name << " maps to " << maps_to <<std::endl;
287  if(ecid_name != maps_to){
288  continue; // make sure they match
289  }
290  if(ecid_name== "EB_trigger_tower" || ecid_name == "EE_trigger_tower") {
291  int id1,id2;
292  IDResults.fillVariableFromRow("ID1",j, id1);
293  IDResults.fillVariableFromRow("ID2",j, id2);
294 
295  if(ecid_name == "EB_trigger_tower")
296  id1+=36; //lowest TCC for barrel 37
298  /* if(ecid_name == "EE_trigger_tower"){
299  int testID = theMapping_->TCCid(temp);
300 
301  if( testID != id1 ){
302  std::cout << " unmatched mapping testID " <<testID <<std::endl;
303  std::cout << "id1 " << id1 << " id2 " <<id2<< " iphi " << temp.iphi() <<" ieta " << temp.ieta() <<std::endl;
304  }
305  }
306  if(ecid_name == "EB_trigger_tower"){
307  int testID = theMapping_->TCCid(temp);
308  if( testID != id1 ){
309  std::cout << " unmatched mapping testID " <<testID <<std::endl;
310  std::cout << "id1 " << id1 << " id2 " <<id2<< " iphi " << temp.iphi() <<" ieta " << temp.ieta() <<std::endl;
311  }
312  }
313  */
314  // if(temp.ieta() == -18 || temp.ietaAbs() == 28)
315  // if(logic_id >= 2100001901 && logic_id <= 2100001916)
316 
317 
318  lutGrpMap->setValue(temp, group_id); // assume ee has less than 68 tt
319  break;
320  }
321  }
322  }
323 
325 
326 
327 
328  for( unsigned short ieta = 1 ; ieta <= L1CaloEcalScale::nBinEta; ++ieta ){
329  EcalSubdetector subdet = ( ieta <= 17 ) ? EcalBarrel : EcalEndcap ;
330  double et_lsb = (ieta<=17) ? eb_lsb : ee_lsb;
331  for(int pos = 0; pos <=1; pos++){
332  int zside = (int) pow(-1,pos);
333 
334  // std::cout << "ieta " <<zside*ieta ;
335  for(int iphi = 1; iphi<=72; iphi++){
336  if(!EcalTrigTowerDetId::validDetId(zside,subdet,ieta, iphi))
337  continue;
338  EcalTrigTowerDetId test(zside, subdet, ieta, iphi);
339  EcalTPGGroups::EcalTPGGroupsMapItr itLut = gMap.find(test) ;
340  if(itLut != gMap.end()) {
341  // std::cout << " non mapped section iphi " << iphi << " ieta " <<ieta << " tccid " << theMapping_->TCCid(test) << " iTT " << theMapping_->iTT(test)<< std::endl;
342  std::vector<int> tpgValue = tpgValueMap[itLut->second];
343 
344  for( unsigned short irank = 0 ; irank < L1CaloEcalScale::nBinRank; ++irank )
345  {
346  ecalScale->setBin(irank, ieta, zside, et_lsb * tpgValue[irank]);
347 
348  // std::cout << " irank " << irank << " etValue " << et_lsb*tpgValue[irank] << std::endl;
349  }
350 
351  break;
352  }
353  }
354  }
355  }
356 
357 
358 
359 
360 
361 // ------------ method called to produce the data ------------
362  return boost::shared_ptr< L1CaloEcalScale >( ecalScale );
363 }
364 //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:48
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:41
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