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 // $Id: FWModelExpressionSelector.cc,v 1.14 2013/04/05 05:24:58 amraktad Exp $
12 //
13 
14 // system include files
15 #include <sstream>
16 #include "TClass.h"
19 
22 
23 // user include files
29 //
30 // constants, enums and typedefs
31 //
32 
33 //
34 // static data member definitions
35 //
36 
37 //
38 // constructors and destructor
39 //
40 /*
41  FWModelExpressionSelector::FWModelExpressionSelector()
42  {
43  }
44  */
45 // FWModelExpressionSelector::FWModelExpressionSelector(const FWModelExpressionSelector& rhs)
46 // {
47 // // do actual copying here;
48 // }
49 
50 /*FWModelExpressionSelector::~FWModelExpressionSelector()
51  {
52  }
53  */
54 //
55 // assignment operators
56 //
57 // const FWModelExpressionSelector& FWModelExpressionSelector::operator=(const FWModelExpressionSelector& rhs)
58 // {
59 // //An exception safe implementation is
60 // FWModelExpressionSelector temp(rhs);
61 // swap(rhs);
62 //
63 // return *this;
64 // }
65 
66 //
67 // member functions
68 //
69 
70 //
71 // const member functions
72 //
73 void
74 FWModelExpressionSelector::select(FWEventItem* iItem, const std::string& iExpression, Color_t iColor) const
75 {
76  using namespace fireworks::expression;
77 
79  assert(type != edm::TypeWithDict());
80 
81  //Backwards compatibility with old format
82  std::string temp = oldToNewFormat(iExpression);
83 
84  //now setup the parser
85  using namespace boost::spirit::classic;
86  reco::parser::SelectorPtr selectorPtr;
87  reco::parser::Grammar grammar(selectorPtr,type);
88  try {
89  if(!parse(temp.c_str(), grammar.use_parser<0>() >> end_p, space_p).full) {
90  throw FWExpressionException("syntax error", -1);
91  //std::cout <<"failed to parse "<<iExpression<<" because of syntax error"<<std::endl;
92  }
93  } catch(const reco::parser::BaseException& e) {
94  //NOTE: need to calculate actual position before doing the regex
96  //std::cout <<"failed to parse "<<iExpression<<" because "<<reco::parser::baseExceptionWhat(e)<<std::endl;
97  }
98 
99 
100  FWChangeSentry sentry(*(iItem->changeManager()));
101  for( unsigned int index = 0; index < iItem->size(); ++index ) {
102  edm::ObjectWithDict o(type, const_cast<void *>(iItem->modelData(index)));
103  if((*selectorPtr)(o)) {
104  iItem->select(index);
105  if (iColor > 0) {
107  props.setColor(iColor);
108  iItem->setDisplayProperties(index, props);
109  }
110  }
111  }
112 }
113 
114 //
115 // static member functions
116 //
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:131
const FWDisplayProperties & displayProperties() const
Definition: FWEventItem.h:68
static TypeWithDict byName(std::string const &className)
boost::spirit::classic::parser_error< reco::parser::SyntaxErrors > BaseException
Definition: Exception.h:37
Evaluator * parse(const T &text)
void setDisplayProperties(int iIndex, const FWDisplayProperties &) const
Definition: FWEventItem.cc:277
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:549
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:562
void select(int iIndex) const
Definition: FWEventItem.cc:251
const void * modelData(int iIndex) const
Definition: FWEventItem.cc:568
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:536