CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/Fireworks/Core/src/FWModelExpressionSelector.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWModelExpressionSelector
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Wed Jan 23 10:37:22 EST 2008
00011 // $Id: FWModelExpressionSelector.cc,v 1.13 2012/08/03 18:20:28 wmtan Exp $
00012 //
00013 
00014 // system include files
00015 #include <sstream>
00016 #include "TClass.h"
00017 #include "FWCore/Utilities/interface/ObjectWithDict.h"
00018 #include "FWCore/Utilities/interface/TypeWithDict.h"
00019 
00020 #include "CommonTools/Utils/src/Grammar.h"
00021 #include "CommonTools/Utils/interface/Exception.h"
00022 
00023 // user include files
00024 #include "Fireworks/Core/interface/FWModelExpressionSelector.h"
00025 #include "Fireworks/Core/interface/FWEventItem.h"
00026 #include "Fireworks/Core/interface/FWModelChangeManager.h"
00027 #include "Fireworks/Core/interface/FWExpressionException.h"
00028 #include "Fireworks/Core/src/expressionFormatHelpers.h"
00029 //
00030 // constants, enums and typedefs
00031 //
00032 
00033 //
00034 // static data member definitions
00035 //
00036 
00037 //
00038 // constructors and destructor
00039 //
00040 /*
00041    FWModelExpressionSelector::FWModelExpressionSelector()
00042    {
00043    }
00044  */
00045 // FWModelExpressionSelector::FWModelExpressionSelector(const FWModelExpressionSelector& rhs)
00046 // {
00047 //    // do actual copying here;
00048 // }
00049 
00050 /*FWModelExpressionSelector::~FWModelExpressionSelector()
00051    {
00052    }
00053  */
00054 //
00055 // assignment operators
00056 //
00057 // const FWModelExpressionSelector& FWModelExpressionSelector::operator=(const FWModelExpressionSelector& rhs)
00058 // {
00059 //   //An exception safe implementation is
00060 //   FWModelExpressionSelector temp(rhs);
00061 //   swap(rhs);
00062 //
00063 //   return *this;
00064 // }
00065 
00066 //
00067 // member functions
00068 //
00069 
00070 //
00071 // const member functions
00072 //
00073 void
00074 FWModelExpressionSelector::select(FWEventItem* iItem, const std::string& iExpression) const
00075 {
00076    using namespace fireworks::expression;
00077 
00078    edm::TypeWithDict type(edm::TypeWithDict::byName(iItem->modelType()->GetName()));
00079    assert(type != edm::TypeWithDict());
00080 
00081    //Backwards compatibility with old format
00082    std::string temp = oldToNewFormat(iExpression);
00083 
00084    //now setup the parser
00085    using namespace boost::spirit::classic;
00086    reco::parser::SelectorPtr selectorPtr;
00087    reco::parser::Grammar grammar(selectorPtr,type);
00088    try {
00089       if(!parse(temp.c_str(), grammar.use_parser<0>() >> end_p, space_p).full) {
00090          throw FWExpressionException("syntax error", -1);
00091          //std::cout <<"failed to parse "<<iExpression<<" because of syntax error"<<std::endl;
00092       }
00093    } catch(const reco::parser::BaseException& e) {
00094       //NOTE: need to calculate actual position before doing the regex
00095       throw FWExpressionException(reco::parser::baseExceptionWhat(e), indexFromNewFormatToOldFormat(temp,e.where-temp.c_str(),iExpression));
00096       //std::cout <<"failed to parse "<<iExpression<<" because "<<reco::parser::baseExceptionWhat(e)<<std::endl;
00097    }
00098 
00099 
00100    FWChangeSentry sentry(*(iItem->changeManager()));
00101    for( unsigned int index = 0; index < iItem->size(); ++index ) {
00102       edm::ObjectWithDict o(type, const_cast<void *>(iItem->modelData(index)));
00103 
00104       if((*selectorPtr)(o)) {
00105          iItem->select(index);
00106       }
00107    }
00108 }
00109 
00110 //
00111 // static member functions
00112 //