CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWModelExpressionSelector.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWModelExpressionSelector
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Wed Jan 23 10:37:22 EST 2008
11 //
12 
13 // system include files
14 #include <sstream>
15 #include "TClass.h"
18 
21 
22 // user include files
28 //
29 // constants, enums and typedefs
30 //
31 
32 //
33 // static data member definitions
34 //
35 
36 //
37 // constructors and destructor
38 //
39 /*
40  FWModelExpressionSelector::FWModelExpressionSelector()
41  {
42  }
43  */
44 // FWModelExpressionSelector::FWModelExpressionSelector(const FWModelExpressionSelector& rhs)
45 // {
46 // // do actual copying here;
47 // }
48 
49 /*FWModelExpressionSelector::~FWModelExpressionSelector()
50  {
51  }
52  */
53 //
54 // assignment operators
55 //
56 // const FWModelExpressionSelector& FWModelExpressionSelector::operator=(const FWModelExpressionSelector& rhs)
57 // {
58 // //An exception safe implementation is
59 // FWModelExpressionSelector temp(rhs);
60 // swap(rhs);
61 //
62 // return *this;
63 // }
64 
65 //
66 // member functions
67 //
68 
69 //
70 // const member functions
71 //
72 void
73 FWModelExpressionSelector::select(FWEventItem* iItem, const std::string& iExpression, Color_t iColor) const
74 {
75  using namespace fireworks::expression;
76 
78  assert(type != edm::TypeWithDict());
79 
80  //Backwards compatibility with old format
81  std::string temp = oldToNewFormat(iExpression);
82 
83  //now setup the parser
84  using namespace boost::spirit::classic;
85  reco::parser::SelectorPtr selectorPtr;
86  reco::parser::Grammar grammar(selectorPtr,type);
87  try {
88  if(!parse(temp.c_str(), grammar.use_parser<0>() >> end_p, space_p).full) {
89  throw FWExpressionException("syntax error", -1);
90  //std::cout <<"failed to parse "<<iExpression<<" because of syntax error"<<std::endl;
91  }
92  } catch(const reco::parser::BaseException& e) {
93  //NOTE: need to calculate actual position before doing the regex
95  //std::cout <<"failed to parse "<<iExpression<<" because "<<reco::parser::baseExceptionWhat(e)<<std::endl;
96  }
97 
98 
99  FWChangeSentry sentry(*(iItem->changeManager()));
100  for( unsigned int index = 0; index < iItem->size(); ++index ) {
101  edm::ObjectWithDict o(type, const_cast<void *>(iItem->modelData(index)));
102  if((*selectorPtr)(o)) {
103  iItem->select(index);
104  if (iColor > 0) {
106  props.setColor(iColor);
107  iItem->setDisplayProperties(index, props);
108  }
109  }
110  }
111 }
112 
113 //
114 // static member functions
115 //
type
Definition: HCALResponse.h:21
long indexFromNewFormatToOldFormat(const std::string &iNewFormat, long iNewFormatIndex, const std::string &iOldFormat)
void setColor(Color_t iColor)
FWModelChangeManager * changeManager() const
Definition: FWEventItem.h:130
const FWDisplayProperties & displayProperties() const
Definition: FWEventItem.h:67
boost::spirit::classic::parser_error< reco::parser::SyntaxErrors > BaseException
Definition: Exception.h:37
Evaluator * parse(const T &text)
assert(m_qm.get())
void setDisplayProperties(int iIndex, const FWDisplayProperties &) const
Definition: FWEventItem.cc:276
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:60
const char * baseExceptionWhat(const BaseException &e)
returns the appropriate &#39;what&#39; message for the exception
Definition: Exception.h:40
size_t size() const
Definition: FWEventItem.cc:548
void select(FWEventItem *iItem, const std::string &iExpression, Color_t iColor=-1) const
boost::shared_ptr< SelectorBase > SelectorPtr
Definition: SelectorPtr.h:17
std::string oldToNewFormat(const std::string &iExpression)
const TClass * modelType() const
Definition: FWEventItem.cc:561
void select(int iIndex) const
Definition: FWEventItem.cc:250
const void * modelData(int iIndex) const
Definition: FWEventItem.cc:567
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:535