CMS 3D CMS Logo

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