1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
// -*- C++ -*-
//
// Package: Core
// Class : FWModelExpressionSelector
//
// Implementation:
// <Notes on implementation>
//
// Original Author: Chris Jones
// Created: Wed Jan 23 10:37:22 EST 2008
//
// system include files
#include <sstream>
#include "TClass.h"
#include "FWCore/Reflection/interface/ObjectWithDict.h"
#include "FWCore/Reflection/interface/TypeWithDict.h"
#include "CommonTools/Utils/interface/parser/Grammar.h"
#include "CommonTools/Utils/interface/parser/Exception.h"
// user include files
#include "Fireworks/Core/interface/FWModelExpressionSelector.h"
#include "Fireworks/Core/interface/FWEventItem.h"
#include "Fireworks/Core/interface/FWModelChangeManager.h"
#include "Fireworks/Core/interface/FWExpressionException.h"
#include "Fireworks/Core/src/expressionFormatHelpers.h"
//
// constants, enums and typedefs
//
//
// static data member definitions
//
//
// constructors and destructor
//
/*
FWModelExpressionSelector::FWModelExpressionSelector()
{
}
*/
// FWModelExpressionSelector::FWModelExpressionSelector(const FWModelExpressionSelector& rhs)
// {
// // do actual copying here;
// }
/*FWModelExpressionSelector::~FWModelExpressionSelector()
{
}
*/
//
// assignment operators
//
// const FWModelExpressionSelector& FWModelExpressionSelector::operator=(const FWModelExpressionSelector& rhs)
// {
// //An exception safe implementation is
// FWModelExpressionSelector temp(rhs);
// swap(rhs);
//
// return *this;
// }
//
// member functions
//
//
// const member functions
//
void FWModelExpressionSelector::select(FWEventItem* iItem, const std::string& iExpression, Color_t iColor) const {
using namespace fireworks::expression;
edm::TypeWithDict type(edm::TypeWithDict::byName(iItem->modelType()->GetName()));
assert(type != edm::TypeWithDict());
//Backwards compatibility with old format
std::string temp = oldToNewFormat(iExpression);
//now setup the parser
using namespace boost::spirit::classic;
reco::parser::SelectorPtr selectorPtr;
reco::parser::Grammar grammar(selectorPtr, type);
try {
if (!parse(temp.c_str(), grammar.use_parser<0>() >> end_p, space_p).full) {
throw FWExpressionException("syntax error", -1);
//std::cout <<"failed to parse "<<iExpression<<" because of syntax error"<<std::endl;
}
} catch (const reco::parser::BaseException& e) {
//NOTE: need to calculate actual position before doing the regex
throw FWExpressionException(reco::parser::baseExceptionWhat(e),
indexFromNewFormatToOldFormat(temp, e.where - temp.c_str(), iExpression));
//std::cout <<"failed to parse "<<iExpression<<" because "<<reco::parser::baseExceptionWhat(e)<<std::endl;
}
FWChangeSentry sentry(*(iItem->changeManager()));
for (unsigned int index = 0; index < iItem->size(); ++index) {
edm::ObjectWithDict o(type, const_cast<void*>(iItem->modelData(index)));
if ((*selectorPtr)(o)) {
iItem->select(index);
if (iColor > 0) {
FWDisplayProperties props = iItem->modelInfo(index).displayProperties();
props.setColor(iColor);
iItem->setDisplayProperties(index, props);
}
}
}
}
//
// static member functions
//
|