CMS 3D CMS Logo

FWItemValueGetter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWItemValueGetter
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Sun Nov 30 16:15:43 EST 2008
11 //
12 
13 // system include files
14 #include <sstream>
15 #include <cstdio>
16 #include "TMath.h"
19 
20 // user include files
22 
27 
29 
30 //==============================================================================
31 //==============================================================================
32 //==============================================================================
33 
35  : m_type(iType), m_titleWidth(0) {
36  if (!strcmp(iType.name().c_str(), "CaloTower")) {
37  if (iPurpose == "ECal")
38  addEntry("emEt", 1, "et", "GeV");
39  else if (iPurpose == "HCal")
40  addEntry("hadEt", 1, "et", "GeV");
41  else if (iPurpose == "HCal Outer")
42  addEntry("outerEt", 1, "et", "GeV");
43  } else if (strstr(iPurpose.c_str(), "Beam Spot")) {
44  addEntry("x0", 2, "x", "cm");
45  addEntry("y0", 2, "y", "cm");
46  addEntry("z0", 2, "z", "cm");
47  } else if (strstr(iPurpose.c_str(), "Vertices")) {
48  addEntry("x", 2, "x", "cm");
49  addEntry("y", 2, "y", "cm");
50  addEntry("z", 2, "z", "cm");
51  } else if (strstr(iPurpose.c_str(), "Conversion")) {
52  addEntry("pairMomentum().rho()", 1, "pt", "GeV");
53  addEntry("pairMomentum().eta()", 2, "eta");
54  addEntry("pairMomentum().phi()", 2, "phi");
55  } else if (strstr(iPurpose.c_str(), "Candidate") || strstr(iPurpose.c_str(), "GenParticle")) {
56  addEntry("pdgId()", 0, "pdg");
57  bool x = addEntry("pt", 1);
58  if (!x)
59  x = addEntry("et", 1);
60  if (!x)
61  addEntry("energy", 1);
62  } else if (iPurpose == "Jets") {
63  addEntry("et", 1);
64  } else if (iPurpose == "DT-segments") {
65  addEntry("chamberId().wheel()", 0, "wh");
66  addEntry("chamberId().station()", 0, "st");
67  addEntry("chamberId().sector()", 0, "sc");
68 
69  } else if (iPurpose == "CSC-segments") {
70  addEntry("cscDetId().endcap()", 0, "ec");
71  addEntry("cscDetId().station()", 0, "st");
72  addEntry("cscDetId().ring()", 0, "rn");
73  } else if (iPurpose == "HGCal Trigger Cell" || iPurpose == "HGCal Trigger Cluster") {
74  addEntry("detId", 0);
75  } else if (iPurpose == "CaloParticle") {
76  addEntry("energy", 3);
77  addEntry("pdgId()", 3, "pdgId");
78  addEntry("simClusters().size()", 3, "SimClSize");
79  } else if (iPurpose == "Trackster" || iPurpose == "Trackster hits" || iPurpose == "Trackster layers") {
80  addEntry("raw_energy", 3, "E", "GeV");
81  addEntry("barycenter().Eta()", 3, "eta");
82  addEntry("barycenter().Phi()", 3, "phi");
83  } else if (iPurpose == "HGCal MultiCluster") {
84  addEntry("energy", 3);
85  } else {
86  // by the default add pt, et, or energy
87  bool x = addEntry("pt", 1);
88  if (!x)
89  x = addEntry("et", 1);
90  if (!x)
91  addEntry("energy", 1);
92  }
93 
94  if (addEntry("eta", 2))
95  addEntry("phi", 2);
96 }
97 
98 bool FWItemValueGetter::addEntry(std::string iExpression, int iPrec, std::string iTitle, std::string iUnit) {
99  using namespace boost::spirit::classic;
100 
102  reco::parser::Grammar grammar(tmpPtr, m_type);
103 
104  if (m_type != edm::TypeWithDict() && !iExpression.empty()) {
105  using namespace fireworks::expression;
106 
107  //Backwards compatibility with old format
108  std::string temp = oldToNewFormat(iExpression);
109 
110  //now setup the parser
111  try {
112  if (parse(temp.c_str(), grammar.use_parser<1>() >> end_p, space_p).full) {
113  m_entries.push_back(Entry(tmpPtr, iExpression, iUnit, iTitle.empty() ? iExpression : iTitle, iPrec));
114  m_titleWidth = TMath::Max(m_titleWidth, (int)m_entries.back().m_title.size());
115  return true;
116  }
117  } catch (const reco::parser::BaseException& e) {
118  // std::cout <<"failed to parse "<<iExpression<<" because "<<reco::parser::baseExceptionWhat(e)<<std::endl;
119  }
120  }
121  return false;
122 }
123 
124 //______________________________________________________________________________
125 
126 double FWItemValueGetter::valueFor(const void* iObject, int idx) const {
127  // std::cout << " value for " << idx << "size " << m_entries.size() <<std::endl;
128  edm::ObjectWithDict o(m_type, const_cast<void*>(iObject));
129  return m_entries[idx].m_expr->value(o);
130 }
131 
132 UInt_t FWItemValueGetter::precision(int idx) const { return m_entries[idx].m_precision; }
133 
134 std::vector<std::string> FWItemValueGetter::getTitles() const {
135  std::vector<std::string> titles;
136  titles.reserve(m_entries.size());
137 
138  for (std::vector<Entry>::const_iterator i = m_entries.begin(); i != m_entries.end(); ++i)
139  titles.push_back((*i).m_title.empty() ? (*i).m_expression : (*i).m_title);
140 
141  return titles;
142 }
143 
144 int FWItemValueGetter::numValues() const { return static_cast<int>(m_entries.size()); }
145 //______________________________________________________________________________
146 
147 const std::string& FWItemValueGetter::getToolTip(const void* iObject) const {
148  static std::string buff(128, 0);
149  static std::string fs = "\n %*s = %.*f";
150 
151  edm::ObjectWithDict o(m_type, const_cast<void*>(iObject));
152 
153  int off = 0;
154  for (std::vector<Entry>::const_iterator i = m_entries.begin(); i != m_entries.end(); ++i) {
155  const Entry& e = *i;
156  off += snprintf(&buff[off],
157  127,
158  fs.c_str(),
159  m_titleWidth,
160  e.m_title.c_str(),
161  e.m_precision ? (e.m_precision + 1) : 0,
162  e.m_expr->value(o));
163  }
164 
165  // std::cout << buff;
166  return buff;
167 }
mps_fire.i
i
Definition: mps_fire.py:428
fireworks::expression::oldToNewFormat
std::string oldToNewFormat(const std::string &iExpression)
Definition: expressionFormatHelpers.cc:25
FWItemValueGetter.h
boost::spirit::classic
Definition: DDPartSelection.cc:10
BaseWithDict.h
edm::ObjectWithDict
Definition: ObjectWithDict.h:17
FWExpressionException.h
FWItemValueGetter::addEntry
bool addEntry(std::string iExpression, int iPrec=2, std::string iTitle="", std::string iUnit="")
Definition: FWItemValueGetter.cc:98
DDAxes::x
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:42
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
ObjectWithDict.h
FWItemValueGetter::m_titleWidth
int m_titleWidth
Definition: FWItemValueGetter.h:62
FWItemValueGetter::m_entries
Entries_t m_entries
Definition: FWItemValueGetter.h:59
FWItemValueGetter::FWItemValueGetter
FWItemValueGetter(const edm::TypeWithDict &, const std::string &iPurpose)
Definition: FWItemValueGetter.cc:34
Exception.h
expressionFormatHelpers.h
FWItemValueGetter::getToolTip
const std::string & getToolTip(const void *iObject) const
Definition: FWItemValueGetter.cc:147
fireworks::expression
Definition: expressionFormatHelpers.cc:24
FWItemValueGetter::m_type
edm::TypeWithDict m_type
Definition: FWItemValueGetter.h:60
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FWExpressionEvaluator.h
dumpparser.parse
def parse(path, config)
Definition: dumpparser.py:13
edm::TypeWithDict
Definition: TypeWithDict.h:38
reco::parser::BaseException
boost::spirit::classic::parser_error< reco::parser::SyntaxErrors > BaseException
Definition: Exception.h:33
FWItemValueGetter::getTitles
std::vector< std::string > getTitles() const
Definition: FWItemValueGetter.cc:134
FWItemValueGetter::precision
UInt_t precision(int idx) const
Definition: FWItemValueGetter.cc:132
Max
T Max(T a, T b)
Definition: MathUtil.h:44
reco::parser::ExpressionPtr
std::shared_ptr< ExpressionBase > ExpressionPtr
Definition: ExpressionBase.h:25
reco::parser::Grammar
Definition: Grammar.h:45
FWItemValueGetter::valueFor
double valueFor(const void *, int idx) const
Definition: FWItemValueGetter.cc:126
FWItemValueGetter::numValues
int numValues() const
Definition: FWItemValueGetter.cc:144
edm::TypeWithDict::name
std::string name() const
Definition: TypeWithDict.cc:456
FWItemValueGetter::Entry
Definition: FWItemValueGetter.h:43
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
Grammar.h