Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-05 22:48:10

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWModelExpressionSelector
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Wed Jan 23 10:37:22 EST 2008
0011 //
0012 
0013 // system include files
0014 #include <sstream>
0015 #include "TClass.h"
0016 #include "FWCore/Reflection/interface/ObjectWithDict.h"
0017 #include "FWCore/Reflection/interface/TypeWithDict.h"
0018 
0019 #include "CommonTools/Utils/interface/Grammar.h"
0020 #include "CommonTools/Utils/interface/Exception.h"
0021 
0022 // user include files
0023 #include "Fireworks/Core/interface/FWModelExpressionSelector.h"
0024 #include "Fireworks/Core/interface/FWEventItem.h"
0025 #include "Fireworks/Core/interface/FWModelChangeManager.h"
0026 #include "Fireworks/Core/interface/FWExpressionException.h"
0027 #include "Fireworks/Core/src/expressionFormatHelpers.h"
0028 //
0029 // constants, enums and typedefs
0030 //
0031 
0032 //
0033 // static data member definitions
0034 //
0035 
0036 //
0037 // constructors and destructor
0038 //
0039 /*
0040    FWModelExpressionSelector::FWModelExpressionSelector()
0041    {
0042    }
0043  */
0044 // FWModelExpressionSelector::FWModelExpressionSelector(const FWModelExpressionSelector& rhs)
0045 // {
0046 //    // do actual copying here;
0047 // }
0048 
0049 /*FWModelExpressionSelector::~FWModelExpressionSelector()
0050    {
0051    }
0052  */
0053 //
0054 // assignment operators
0055 //
0056 // const FWModelExpressionSelector& FWModelExpressionSelector::operator=(const FWModelExpressionSelector& rhs)
0057 // {
0058 //   //An exception safe implementation is
0059 //   FWModelExpressionSelector temp(rhs);
0060 //   swap(rhs);
0061 //
0062 //   return *this;
0063 // }
0064 
0065 //
0066 // member functions
0067 //
0068 
0069 //
0070 // const member functions
0071 //
0072 void FWModelExpressionSelector::select(FWEventItem* iItem, const std::string& iExpression, Color_t iColor) const {
0073   using namespace fireworks::expression;
0074 
0075   edm::TypeWithDict type(edm::TypeWithDict::byName(iItem->modelType()->GetName()));
0076   assert(type != edm::TypeWithDict());
0077 
0078   //Backwards compatibility with old format
0079   std::string temp = oldToNewFormat(iExpression);
0080 
0081   //now setup the parser
0082   using namespace boost::spirit::classic;
0083   reco::parser::SelectorPtr selectorPtr;
0084   reco::parser::Grammar grammar(selectorPtr, type);
0085   try {
0086     if (!parse(temp.c_str(), grammar.use_parser<0>() >> end_p, space_p).full) {
0087       throw FWExpressionException("syntax error", -1);
0088       //std::cout <<"failed to parse "<<iExpression<<" because of syntax error"<<std::endl;
0089     }
0090   } catch (const reco::parser::BaseException& e) {
0091     //NOTE: need to calculate actual position before doing the regex
0092     throw FWExpressionException(reco::parser::baseExceptionWhat(e),
0093                                 indexFromNewFormatToOldFormat(temp, e.where - temp.c_str(), iExpression));
0094     //std::cout <<"failed to parse "<<iExpression<<" because "<<reco::parser::baseExceptionWhat(e)<<std::endl;
0095   }
0096 
0097   FWChangeSentry sentry(*(iItem->changeManager()));
0098   for (unsigned int index = 0; index < iItem->size(); ++index) {
0099     edm::ObjectWithDict o(type, const_cast<void*>(iItem->modelData(index)));
0100     if ((*selectorPtr)(o)) {
0101       iItem->select(index);
0102       if (iColor > 0) {
0103         FWDisplayProperties props = iItem->modelInfo(index).displayProperties();
0104         props.setColor(iColor);
0105         iItem->setDisplayProperties(index, props);
0106       }
0107     }
0108   }
0109 }
0110 
0111 //
0112 // static member functions
0113 //