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.9 2009/04/27 16:53:29 dmytro 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 bool
74 FWModelExpressionSelector::select(FWEventItem* iItem, const std::string& iExpression) 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  bool succeeded=true;
89  try {
90  if(!parse(temp.c_str(), grammar.use_parser<0>() >> end_p, space_p).full) {
91  throw FWExpressionException("syntax error", -1);
92  //std::cout <<"failed to parse "<<iExpression<<" because of syntax error"<<std::endl;
93  succeeded=false;
94  }
95  } catch(const reco::parser::BaseException& e) {
96  //NOTE: need to calculate actual position before doing the regex
98  //std::cout <<"failed to parse "<<iExpression<<" because "<<reco::parser::baseExceptionWhat(e)<<std::endl;
99  succeeded=false;
100  }
101  if(!succeeded) { return false;}
102 
103 
104  FWChangeSentry sentry(*(iItem->changeManager()));
105  for( unsigned int index = 0; index < iItem->size(); ++index ) {
106  ROOT::Reflex::Object o(type, const_cast<void *>(iItem->modelData(index)));
107 
108  if((*selectorPtr)(o)) {
109  iItem->select(index);
110  }
111  }
112 
113  return true;
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)
FWModelChangeManager * changeManager() const
Definition: FWEventItem.h:130
boost::spirit::classic::parser_error< reco::parser::SyntaxErrors > BaseException
Definition: Exception.h:37
Evaluator * parse(const T &text)
bool select(FWEventItem *iItem, const std::string &iExpression) 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:549
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:261
const void * modelData(int iIndex) const
Definition: FWEventItem.cc:568