CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes
FWItemValueGetter Class Reference

#include <Fireworks/Core/interface/FWItemValueGetter.h>

Classes

struct  Entry
 

Public Member Functions

 FWItemValueGetter (const edm::TypeWithDict &, const std::string &iPurpose)
 
std::vector< std::string > getTitles () const
 
const std::string & getToolTip (const void *iObject) const
 
int numValues () const
 
UInt_t precision (int idx) const
 
double valueFor (const void *, int idx) const
 

Private Types

typedef std::vector< EntryEntries_t
 

Private Member Functions

bool addEntry (std::string iExpression, int iPrec=2, std::string iTitle="", std::string iUnit="")
 

Private Attributes

Entries_t::const_iterator Entries_i
 
Entries_t m_entries
 
int m_titleWidth
 
edm::TypeWithDict m_type
 

Detailed Description

Description: Retrieves a particular value from an item

Usage: <usage>

Definition at line 32 of file FWItemValueGetter.h.

Member Typedef Documentation

typedef std::vector<Entry> FWItemValueGetter::Entries_t
private

Definition at line 56 of file FWItemValueGetter.h.

Constructor & Destructor Documentation

FWItemValueGetter::FWItemValueGetter ( const edm::TypeWithDict iType,
const std::string &  iPurpose 
)

Definition at line 34 of file FWItemValueGetter.cc.

References addEntry(), edm::TypeWithDict::name(), and x.

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 }
bool addEntry(std::string iExpression, int iPrec=2, std::string iTitle="", std::string iUnit="")
std::string name() const
edm::TypeWithDict m_type

Member Function Documentation

bool FWItemValueGetter::addEntry ( std::string  iExpression,
int  iPrec = 2,
std::string  iTitle = "",
std::string  iUnit = "" 
)
private

Definition at line 98 of file FWItemValueGetter.cc.

References alignCSCRings::e, m_entries, m_titleWidth, m_type, Max(), fireworks::expression::oldToNewFormat(), dumpparser::parse(), AlCaHLTBitMon_QueryRunRegistry::string, and groupFilesInBlocks::temp.

Referenced by FWItemValueGetter().

98  {
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 }
boost::spirit::classic::parser_error< reco::parser::SyntaxErrors > BaseException
Definition: Exception.h:33
std::shared_ptr< ExpressionBase > ExpressionPtr
edm::TypeWithDict m_type
T Max(T a, T b)
Definition: MathUtil.h:44
std::string oldToNewFormat(const std::string &iExpression)
std::vector< std::string > FWItemValueGetter::getTitles ( ) const

Definition at line 134 of file FWItemValueGetter.cc.

References mps_fire::i, and m_entries.

Referenced by FWCollectionSummaryTableManager::getTitles().

134  {
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 }
const std::string & FWItemValueGetter::getToolTip ( const void *  iObject) const

Definition at line 147 of file FWItemValueGetter.cc.

References alignCSCRings::e, mps_fire::i, m_entries, FWItemValueGetter::Entry::m_expr, FWItemValueGetter::Entry::m_precision, FWItemValueGetter::Entry::m_title, m_titleWidth, m_type, class-composition::o, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by FWEventItem::modelInterestingValueAsString().

147  {
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 }
edm::TypeWithDict m_type
int FWItemValueGetter::numValues ( ) const

Definition at line 144 of file FWItemValueGetter.cc.

References m_entries.

Referenced by FWCollectionSummaryTableManager::cellRenderer(), and FWCollectionSummaryTableManager::numberOfColumns().

144 { return static_cast<int>(m_entries.size()); }
UInt_t FWItemValueGetter::precision ( int  idx) const

Definition at line 132 of file FWItemValueGetter.cc.

References m_entries.

Referenced by FWCollectionSummaryTableManager::cellRenderer().

132 { return m_entries[idx].m_precision; }
double FWItemValueGetter::valueFor ( const void *  iObject,
int  idx 
) const

Definition at line 126 of file FWItemValueGetter.cc.

References m_entries, m_type, and class-composition::o.

Referenced by FWCollectionSummaryTableManager::cellRenderer(), and FWViewContextMenuHandlerGL::select().

126  {
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 }
edm::TypeWithDict m_type

Member Data Documentation

Entries_t::const_iterator FWItemValueGetter::Entries_i
private

Definition at line 57 of file FWItemValueGetter.h.

Entries_t FWItemValueGetter::m_entries
private

Definition at line 59 of file FWItemValueGetter.h.

Referenced by addEntry(), getTitles(), getToolTip(), numValues(), precision(), and valueFor().

int FWItemValueGetter::m_titleWidth
private

Definition at line 62 of file FWItemValueGetter.h.

Referenced by addEntry(), and getToolTip().

edm::TypeWithDict FWItemValueGetter::m_type
private

Definition at line 60 of file FWItemValueGetter.h.

Referenced by addEntry(), getToolTip(), and valueFor().