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.12.2.1 2013/04/09 00:51:49 amraktad Exp $
12 //
13 
14 // system include files
15 #include <sstream>
16 #include "TClass.h"
17 #include "Reflex/Object.h"
18 #include "Reflex/Type.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 
78  ROOT::Reflex::Type type= ROOT::Reflex::Type::ByName(iItem->modelType()->GetName());
79  assert(type != ROOT::Reflex::Type());
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  ROOT::Reflex::Object o(type, const_cast<void *>(iItem->modelData(index)));
103 
104  if((*selectorPtr)(o)) {
105  iItem->select(index);
106 
107  if (iColor > 0) {
109  props.setColor(iColor);
110  iItem->setDisplayProperties(index, props);
111  }
112  }
113  }
114 }
115 
116 //
117 // static member functions
118 //
type
Definition: HCALResponse.h:22
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
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
void select(FWEventItem *iItem, const std::string &iExpression, Color_t c=-1) const
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
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:251
const void * modelData(int iIndex) const
Definition: FWEventItem.cc:567
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:535