00001
00002
00003
00004
00005
00006 #include "cafe/EventMultiSplitter.hpp"
00007 #include "cafe/Config.hpp"
00008 #include "cafe/Stat.hpp"
00009 #include "cafe/PermuterBase.hpp"
00010
00011 #include <stdexcept>
00012
00013 #include "TClass.h"
00014 #include "TMethodCall.h"
00015 #include "TROOT.h"
00016
00017 ClassImp(cafe::EventMultiSplitter)
00018
00019 using namespace std;
00020
00021 namespace cafe {
00027 EventMultiSplitter::EventMultiSplitter (const char *name)
00028 : Controller (name), _perm(0), _local_stat(0)
00029 {
00030 Config cfg (name);
00031
00035
00036 std::string permClassName (cfg.get("PermuterObject", "bogus"));
00037 std::string permName (cfg.get("PermuterName", "bogus"));
00038
00039 if (permClassName == "bogus") {
00040 throw runtime_error ("EventMultiSplitter's parameter permClassName wasn't set!");
00041 }
00042
00043 if(TClass *cl = gROOT->GetClass (permClassName.c_str())) {
00044 if(cl->GetMethodWithPrototype(permClassName.c_str(),"const char *") != 0) {
00045 TMethodCall call;
00046 call.InitWithPrototype(cl, permClassName.c_str(), "const char *");
00047 call.ResetParam();
00048 call.SetParam((Long_t )permName.c_str());
00049 Long_t ret (0);
00050 call.Execute(ret);
00051 _perm = reinterpret_cast<PermuterBase*> (ret);
00052 } else {
00053 throw runtime_error ("Class " + permClassName + " doesn't have a ctor with a string argument!");
00054 }
00055 } else {
00056 throw runtime_error ("ROOT doesn't know about class " + permClassName + "! EventMultiSplitter can't make it!");
00057 }
00058
00062
00063 _local_stat = new Stat (name, true);
00064 _local_stat->begin();
00065 }
00066
00072 EventMultiSplitter::~EventMultiSplitter (void)
00073 {
00074 delete _perm;
00075 delete _local_stat;
00076 }
00077
00083 bool EventMultiSplitter::processEvent (Event &event)
00084 {
00088
00089 _local_stat->chain();
00090
00094
00095 EventMultiSplitter::callback cb (*this, event);
00096 _perm->permuteEvent (cb);
00097
00101
00102 _local_stat->unchain();
00103
00104 return true;
00105 }
00106
00112 void EventMultiSplitter::finish(void)
00113 {
00114 _local_stat->finish();
00115 Controller::finish();
00116 }
00117
00123 void EventMultiSplitter::processPermutation (double weight, Event &event)
00124 {
00128
00129 event.clear ("StatPointer");
00130 _local_stat->processEvent (event);
00131 _local_stat->inheritWeights();
00132
00136
00137 _local_stat->applyWeight (name(), weight);
00138
00142
00143 Controller::processEvent (event);
00144
00148
00149 _local_stat->eventEnd();
00150 }
00151
00153
00159 EventMultiSplitter::callback::callback (EventMultiSplitter &splitter, Event &event)
00160 : _event (event), _splitter (splitter)
00161 {
00162 }
00163
00169 void EventMultiSplitter::callback::operator () (double weight)
00170 {
00171 _splitter.processPermutation (weight, _event);
00172 }
00173 }