ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtDataReductionTask.cxx
Go to the documentation of this file.
1 #include "AtDataReductionTask.h"
2 
3 #include "AtBaseEvent.h"
4 
5 #include <FairLogger.h>
6 #include <FairRootManager.h>
7 #include <FairRunAna.h>
8 #include <FairTask.h>
9 
10 #include <TClonesArray.h>
11 #include <TObject.h>
12 
14 
15 void AtDataReductionTask::SetReductionFunction(std::function<bool(AtBaseEvent *)> func)
16 {
17  // Bind the reduction function to the passed function, having it call that function with the current
18  // AtRawEvent in the pointer this->fRawEvent.
19  fReductionFunc = [this, func]() { return func(fEvent); };
20 }
21 
23 {
24  FairRootManager *ioMan = FairRootManager::Instance();
25  if (ioMan == nullptr) {
26  LOG(fatal) << "Cannot find RootManager!";
27  return kFATAL;
28  }
29 
30  fInputEventArray = dynamic_cast<TClonesArray *>(ioMan->GetObject(fInputBranchName));
31  if (fInputEventArray == nullptr) {
32  LOG(fatal) << "Cannot find TClonesArray in branch " << fInputBranchName << "!";
33  return kFATAL;
34  }
35 
36  return kSUCCESS;
37 }
38 
39 void AtDataReductionTask::Exec(Option_t *opt)
40 {
41  // Get raw event
42  if (fInputEventArray->GetEntriesFast() == 0)
43  return;
44  fEvent = dynamic_cast<AtBaseEvent *>(fInputEventArray->At(0));
45 
46  // If we should skip this event mark bad and don't fill tree
47  if (fReductionFunc())
48  LOG(info) << "Keeping event " << fEvent->GetEventID() << " at " << FairRootManager::Instance()->GetEntryNr();
49  else {
50 
51  LOG(info) << "Skipping event " << fEvent->GetEventID() << " at " << FairRootManager::Instance()->GetEntryNr();
52 
53  FairRootManager *ioMan = FairRootManager::Instance();
54  for (auto name : fOutputBranchs) {
55  auto b = dynamic_cast<TClonesArray *>(ioMan->GetObject(name));
56  if (fInputEventArray == nullptr)
57  LOG(fatal) << "Cannot find branch " << name << "!";
58 
59  auto e = dynamic_cast<AtBaseEvent *>(b->At(0));
60  if (e == nullptr) {
61  LOG(error) << "Not setting " << name;
62  continue;
63  }
64  e->SetIsGood(false);
65  }
66  FairRunAna::Instance()->MarkFill(false);
67  }
68 }
AtBaseEvent.h
AtBaseEvent::SetIsGood
void SetIsGood(Bool_t value)
Definition: AtBaseEvent.h:61
AtDataReductionTask.h
AtDataReductionTask::Exec
virtual void Exec(Option_t *opt) override
Definition: AtDataReductionTask.cxx:39
AtDataReductionTask
Definition: AtDataReductionTask.h:27
AtDataReductionTask::Init
virtual InitStatus Init() override
Definition: AtDataReductionTask.cxx:22
AtDataReductionTask::SetReductionFunction
void SetReductionFunction(ReductionFunction func)
Definition: AtDataReductionTask.h:42
AtBaseEvent
Base class for all event types in ATTPCROOT.
Definition: AtBaseEvent.h:20
ClassImp
ClassImp(AtDataReductionTask)
AtBaseEvent::GetEventID
ULong_t GetEventID() const
Definition: AtBaseEvent.h:67