CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 Reflex::Type &, 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
 
Reflex::Type m_type
 

Detailed Description

Description: Retrieves a particular value from an item

Usage: <usage>

Definition at line 35 of file FWItemValueGetter.h.

Member Typedef Documentation

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

Definition at line 61 of file FWItemValueGetter.h.

Constructor & Destructor Documentation

FWItemValueGetter::FWItemValueGetter ( const Reflex::Type &  iType,
const std::string &  iPurpose 
)

Definition at line 37 of file FWItemValueGetter.cc.

References addEntry(), and x.

37  :
38  m_type(iType),
39  m_titleWidth(0)
40 {
41  if ( iType.Name() == "CaloTower" )
42  {
43  if ( iPurpose == "ECal" )
44  addEntry("emEt", 1, "et", "GeV");
45  else if ( iPurpose == "HCal" )
46  addEntry("hadEt", 1, "et", "GeV");
47  else if (iPurpose == "HCal Outer")
48  addEntry("outerEt", 1, "et", "GeV");
49  }
50  else if (strstr(iPurpose.c_str(), "Beam Spot") )
51  {
52  addEntry("x0", 2, "x", "cm");
53  addEntry("y0", 2, "y", "cm");
54  addEntry("z0", 2, "z", "cm");
55  }
56  else if (strstr(iPurpose.c_str(), "Vertices") )
57  {
58  addEntry("x", 2, "x", "cm");
59  addEntry("y", 2, "y", "cm");
60  addEntry("z", 2, "z", "cm");
61  }
62  else if (strstr(iPurpose.c_str(), "Conversion") )
63  {
64  addEntry("pairMomentum().rho()", 1, "pt", "GeV" );
65  addEntry("pairMomentum().eta()", 2, "eta");
66  addEntry("pairMomentum().phi()", 2, "phi");
67  }
68  else if (strstr(iPurpose.c_str(), "Candidate") || strstr(iPurpose.c_str(), "GenParticle"))
69  {
70  addEntry("pdgId()", 0, "pdg");
71  bool x = addEntry("pt", 1);
72  if (!x) x = addEntry("et", 1);
73  if (!x) addEntry("energy", 1);
74  }
75  else if (iPurpose == "Jets" )
76  {
77  addEntry("et", 1);
78  }
79  else {
80  // by the default add pt, et, or energy
81  bool x = addEntry("pt", 1);
82  if (!x) x = addEntry("et", 1);
83  if (!x) addEntry("energy", 1);
84  }
85 
86  if (addEntry("eta", 2))
87  addEntry("phi", 2);
88 }
bool addEntry(std::string iExpression, int iPrec=2, std::string iTitle="", std::string iUnit="")
Definition: DDAxes.h:10

Member Function Documentation

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

Definition at line 92 of file FWItemValueGetter.cc.

References alignCSCRings::e, m_entries, m_titleWidth, m_type, siStripFEDMonitor_P5_cff::Max, fireworks::expression::oldToNewFormat(), triggerExpression::parse(), and groupFilesInBlocks::temp.

Referenced by FWItemValueGetter().

93 {
94  using namespace boost::spirit::classic;
95 
97  reco::parser::Grammar grammar(tmpPtr, m_type);
98 
99  if(m_type != Reflex::Type() && iExpression.size())
100  {
101  using namespace fireworks::expression;
102 
103  //Backwards compatibility with old format
104  std::string temp = oldToNewFormat(iExpression);
105 
106  //now setup the parser
107  try
108  {
109  if(parse(temp.c_str(), grammar.use_parser<1>() >> end_p, space_p).full)
110  {
111  m_entries.push_back(Entry(tmpPtr, iExpression, iUnit, iTitle.empty() ? iExpression :iTitle , iPrec));
112  m_titleWidth = TMath::Max(m_titleWidth, (int) m_entries.back().m_title.size());
113  return true;
114  }
115  }
116  catch(const reco::parser::BaseException& e)
117  {
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:37
Evaluator * parse(const T &text)
Definition: Entry.h:18
boost::shared_ptr< ExpressionBase > ExpressionPtr
std::string oldToNewFormat(const std::string &iExpression)
std::vector< std::string > FWItemValueGetter::getTitles ( ) const

Definition at line 142 of file FWItemValueGetter.cc.

References i, and m_entries.

Referenced by FWCollectionSummaryTableManager::getTitles().

143 {
144  std::vector<std::string> titles;
145  titles.reserve(m_entries.size());
146 
147  for (std::vector<Entry >::const_iterator i = m_entries.begin() ; i != m_entries.end(); ++i)
148  titles.push_back((*i).m_title.empty() ? (*i).m_expression : (*i).m_title );
149 
150  return titles;
151 }
int i
Definition: DBlmapReader.cc:9
const std::string & FWItemValueGetter::getToolTip ( const void *  iObject) const

Definition at line 161 of file FWItemValueGetter.cc.

References alignCSCRings::e, i, m_entries, FWItemValueGetter::Entry::m_expr, FWItemValueGetter::Entry::m_precision, FWItemValueGetter::Entry::m_title, m_titleWidth, m_type, and python.connectstrParser::o.

Referenced by FWEventItem::modelInterestingValueAsString().

162 {
163  static std::string buff(128, 0);
164  static std::string fs = "\n %*s = %.*f";
165 
166  Reflex::Object o(m_type, const_cast<void *>(iObject));
167 
168  int off = 0;
169  for ( std::vector<Entry >::const_iterator i = m_entries.begin() ; i != m_entries.end(); ++i) {
170  const Entry& e = *i;
171  off += snprintf(&buff[off], 127, fs.c_str(), m_titleWidth, e.m_title.c_str(), e.m_precision ? (e.m_precision+1) : 0, e.m_expr->value(o));
172  }
173 
174  // std::cout << buff;
175  return buff;
176 }
int i
Definition: DBlmapReader.cc:9
Definition: Entry.h:18
ALIdouble value() const
Definition: Entry.h:55
int FWItemValueGetter::numValues ( ) const

Definition at line 154 of file FWItemValueGetter.cc.

References m_entries.

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

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

Definition at line 136 of file FWItemValueGetter.cc.

References m_entries.

Referenced by FWCollectionSummaryTableManager::cellRenderer().

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

Definition at line 128 of file FWItemValueGetter.cc.

References m_entries, m_type, and python.connectstrParser::o.

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

129 {
130  // std::cout << " value for " << idx << "size " << m_entries.size() <<std::endl;
131  Reflex::Object o(m_type, const_cast<void *>(iObject));
132  return m_entries[idx].m_expr->value(o);
133 }

Member Data Documentation

Entries_t::const_iterator FWItemValueGetter::Entries_i
private

Definition at line 62 of file FWItemValueGetter.h.

Entries_t FWItemValueGetter::m_entries
private

Definition at line 64 of file FWItemValueGetter.h.

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

int FWItemValueGetter::m_titleWidth
private

Definition at line 67 of file FWItemValueGetter.h.

Referenced by addEntry(), and getToolTip().

Reflex::Type FWItemValueGetter::m_type
private

Definition at line 65 of file FWItemValueGetter.h.

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