44 #ifdef CEXMC_USE_CUSTOM_FILTER
52 CexmcCustomFilterEval::CexmcCustomFilterEval(
const G4String & sourceFileName,
53 const CexmcEventFastSObject * evFastSObject,
54 const CexmcEventSObject * evSObject ) :
55 astEval( evFastSObject, evSObject )
58 std::ifstream sourceFile( sourceFileName );
63 bool commandIsPending(
false );
65 while ( ! sourceFile.eof() )
68 std::getline( sourceFile, line );
70 size_t commentStartPos( line.find_first_of(
'#' ) );
71 if ( commentStartPos != std::string::npos )
72 line.erase( commentStartPos );
75 line.find_first_not_of(
" \t" ) == std::string::npos )
77 if ( commandIsPending )
87 size_t length( command.length() );
89 if ( command[
length - 1 ] ==
'\\' )
91 command.erase(
length - 1 );
92 commandIsPending =
true;
96 CexmcCustomFilter::ParseResult curParseResult;
98 std::string::const_iterator begin( command.begin() );
99 std::string::const_iterator end( command.end() );
103 if ( ! CexmcCustomFilter::phrase_parse( begin, end, grammar,
104 CexmcCustomFilter::space, curParseResult ) ||
116 #ifdef CEXMC_DEBUG_CF
118 curParseResult.expression.Print();
121 switch ( curParseResult.action )
123 case CexmcCustomFilter::KeepTPT :
124 case CexmcCustomFilter::DeleteTPT :
125 parseResultTPT.push_back( curParseResult );
127 case CexmcCustomFilter::KeepEDT :
128 case CexmcCustomFilter::DeleteEDT :
129 parseResultEDT.push_back( curParseResult );
136 commandIsPending =
false;
141 if ( commandIsPending )
146 void CexmcCustomFilterEval::SetAddressedData(
147 const CexmcEventFastSObject * evFastSObject,
148 const CexmcEventSObject * evSObject )
150 astEval.SetAddressedData( evFastSObject, evSObject );
152 for ( ParseResultVector::iterator
k( parseResultTPT.begin() );
153 k != parseResultTPT.end(); ++
k )
155 if ( evFastSObject == NULL || evSObject == NULL )
156 astEval.ResetAddressBinding(
k->expression );
158 astEval.BindAddresses(
k->expression );
160 for ( ParseResultVector::iterator
k( parseResultEDT.begin() );
161 k != parseResultEDT.end(); ++
k )
163 if ( evFastSObject == NULL || evSObject == NULL )
164 astEval.ResetAddressBinding(
k->expression );
166 astEval.BindAddresses(
k->expression );
171 bool CexmcCustomFilterEval::EvalTPT(
void )
const
173 for ( ParseResultVector::const_iterator
k( parseResultTPT.begin() );
174 k != parseResultTPT.end(); ++
k )
176 if ( astEval(
k->expression ) )
177 return k->action == CexmcCustomFilter::KeepTPT;
184 bool CexmcCustomFilterEval::EvalEDT(
void )
const
186 for ( ParseResultVector::const_iterator
k( parseResultEDT.begin() );
187 k != parseResultEDT.end(); ++
k )
189 if ( astEval(
k->expression ) )
190 return k->action == CexmcCustomFilter::KeepEDT;