CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/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.10 2010/06/18 10:17:16 yana Exp $
00012 //
00013 
00014 // system include files
00015 #include <sstream>
00016 #include "TClass.h"
00017 #include "Reflex/Object.h"
00018 #include "Reflex/Type.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 bool
00074 FWModelExpressionSelector::select(FWEventItem* iItem, const std::string& iExpression) const
00075 {
00076    using namespace fireworks::expression;
00077 
00078    ROOT::Reflex::Type type= ROOT::Reflex::Type::ByName(iItem->modelType()->GetName());
00079    assert(type != ROOT::Reflex::Type());
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    bool succeeded=true;
00089    try {
00090       if(!parse(temp.c_str(), grammar.use_parser<0>() >> end_p, space_p).full) {
00091          throw FWExpressionException("syntax error", -1);
00092          //std::cout <<"failed to parse "<<iExpression<<" because of syntax error"<<std::endl;
00093          succeeded=false;
00094       }
00095    } catch(const reco::parser::BaseException& e) {
00096       //NOTE: need to calculate actual position before doing the regex
00097       throw FWExpressionException(reco::parser::baseExceptionWhat(e), indexFromNewFormatToOldFormat(temp,e.where-temp.c_str(),iExpression));
00098       //std::cout <<"failed to parse "<<iExpression<<" because "<<reco::parser::baseExceptionWhat(e)<<std::endl;
00099       succeeded=false;
00100    }
00101    if(!succeeded) { return false;}
00102 
00103 
00104    FWChangeSentry sentry(*(iItem->changeManager()));
00105    for( unsigned int index = 0; index < iItem->size(); ++index ) {
00106       ROOT::Reflex::Object o(type, const_cast<void *>(iItem->modelData(index)));
00107 
00108       if((*selectorPtr)(o)) {
00109          iItem->select(index);
00110       }
00111    }
00112 
00113    return true;
00114 }
00115 
00116 //
00117 // static member functions
00118 //