00001
00002
00003 #include "cafe/If.hpp"
00004 #include "cafe/ParseRun.hpp"
00005 #include "cafe/Config.hpp"
00006 #include "cafe/Event.hpp"
00007
00008 #include "TFile.h"
00009 #include "TTreeFormula.h"
00010
00011 #include <iostream>
00012 #include <vector>
00013
00014 namespace cafe {
00015
00016 If::If(const char *name)
00017 : Controller(name, std::list<Processor*>()),
00018 Formula(this)
00019 {
00020 using namespace std;
00021
00022 Config config(name);
00023
00024
00025 std::string expr = config.get("Select", "1");
00026 setFormula(expr);
00027
00028
00029 ParseRun parser;
00030 add(new Controller((string(name) + "_Then").c_str(), parser.parse(config.get("Then", ""))));
00031 add(new Controller((string(name) + "_Else").c_str(), parser.parse(config.get("Else", ""))));
00032
00033
00034 if(config.get("Run","") != "") {
00035 err() << "If[" << name << "]: .Run not used in If[]. .Use 'Then:' and '.Else:' instead" << endl;
00036 }
00037 }
00038
00039 If::~If() {}
00040
00041 void If::inputFileOpened(TFile *file)
00042 {
00043 Formula::inputFileOpened(file);
00044 Controller::inputFileOpened(file);
00045 }
00046
00047
00048 bool If::processEvent(Event& event)
00049 {
00050 event.untag(_untag.begin(), _untag.end());
00051 event.tag(_tag.begin(), _tag.end());
00052 TTreeFormula *formula = getFormula();
00053
00054 if(_processors.size() > 0) {
00055 std::list<Processor*>::iterator it = _processors.begin();
00056
00057 int ndata = formula->GetNdata();
00058 for(int i = 0; i < ndata; i++) {
00059 if(formula->EvalInstance(i) > 0.0) {
00060
00061 (*it)->incEventCount();
00062 return (*it)->processEvent(event) ;
00063 }
00064 }
00065
00066
00067 ++it;
00068 while(it != _processors.end()) {
00069 (*it)->incEventCount();
00070 if(!(*it)->processEvent(event)) return false;
00071 ++it;
00072 }
00073
00074 }
00075 return true;
00076 }
00077 }
00078
00079 ClassImp(cafe::If);
00080