ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtUnpackTask.cxx
Go to the documentation of this file.
1 #include "AtUnpackTask.h"
2 
3 #include "AtRawEvent.h"
4 
5 #include <FairLogger.h>
6 #include <FairRootManager.h>
7 #include <FairTask.h>
8 
9 #include <TClonesArray.h>
10 #include <TObject.h>
11 
12 #include <utility>
13 
15 
17  : fRawEvent(new AtRawEvent()), fUnpacker(std::move(unpacker)), fOutputEventArray(TClonesArray("AtRawEvent", 1))
18 {
19 }
20 
21 InitStatus AtUnpackTask::Init()
22 {
23  if (FairRootManager::Instance() == nullptr) {
24  LOG(fatal) << "Cannot find RootManager!";
25  return kFATAL;
26  }
27 
28  fUnpacker->Init();
29 
30  FairRootManager::Instance()->Register(fOuputBranchName.data(), "AtTpc", &fOutputEventArray, fIsPersistent);
31 
32  return kSUCCESS;
33 }
34 
36 
37 void AtUnpackTask::Exec(Option_t *opt)
38 {
39  fOutputEventArray.Clear("C");
40  auto rawEvent = dynamic_cast<AtRawEvent *>(fOutputEventArray.ConstructedAt(0));
41 
42  LOG(debug) << "Unpacking event: " << fUnpacker->GetNextEventID();
43 
44  // Hacked solution to the fact that FinishEvent() is not normally called with how
45  // we unpack runs.
46  if (!fFinishedUnpacking) {
47  fUnpacker->FillRawEvent(*rawEvent);
48  } else {
49  LOG(warn) << "Hit last event at: " << fUnpacker->GetNextEventID();
50  fRawEvent->SetIsGood(false);
51  return;
52  }
53 
54  fFinishedUnpacking = fUnpacker->IsLastEvent();
55 }
56 
58 {
59  // Note this is only called if we are not running a "DummyRun"
60  // ie FairRoot thinks there is some sort of source. This is, in general
61  // not true so will never be called.
62  if (fUnpacker->IsLastEvent()) {
63  LOG(info) << "Unpacked last event. Terminating run.";
64  FairRootManager::Instance()->SetFinishRun();
65  }
66 }
AtUnpackTask::SetParContainers
virtual void SetParContainers() override
Definition: AtUnpackTask.cxx:35
AtRawEvent.h
AtUnpackTask
Definition: AtUnpackTask.h:28
AtUnpackTask::FinishEvent
virtual void FinishEvent() override
Definition: AtUnpackTask.cxx:57
AtUnpackTask::Exec
virtual void Exec(Option_t *opt) override
Definition: AtUnpackTask.cxx:37
AtBaseEvent::SetIsGood
void SetIsGood(Bool_t value)
Definition: AtBaseEvent.h:61
AtRawEvent
Definition: AtRawEvent.h:34
unpackerPtr
std::unique_ptr< AtUnpacker > unpackerPtr
Definition: AtUnpackTask.h:26
AtUnpackTask::AtUnpackTask
AtUnpackTask(unpackerPtr unpacker)
Definition: AtUnpackTask.cxx:16
AtUnpackTask::Init
virtual InitStatus Init() override
Definition: AtUnpackTask.cxx:21
ClassImp
ClassImp(AtUnpackTask)
AtUnpackTask.h