PandaRoot
TestTasks.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 #include "FairTask.h"
14 #include "FairTimeStamp.h"
15 
16 #include "PndConstContainer.h"
17 #include "PndMutableContainer.h"
18 // #include "PndPersistencyTask.h" // for PndPersistencyTask
19 #include "PndSTDMutableContainer.h"
20 #include "PndTCAMutableContainer.h"
21 
22 #include "gtest/gtest.h" // for AssertHelper, EXPECT_EQ, EXPECT_TRUE
23 
24 //______________________________________________________________________________
25 class TestInTask : public FairTask {
27  Int_t fgNumber{111};
28  TString fBranchName;
29 
30  public:
31  TestInTask(const TString &t_branch = "TestBranch") : FairTask(), fBranchName(t_branch){};
32  virtual ~TestInTask(){};
33 
40  PndTCAConstContainer<FairTimeStamp> *GetTCA(const TString &t_branchname)
41  {
42  PndTCAConstContainer<FairTimeStamp> *container{nullptr};
43 
44  if (FairRootManager::Instance()->CheckBranch(t_branchname) ==
45  0) { // This test is required here, as you get a segmentation violation if you try to access a not existing branch t_branchname via std
46  return container;
47  }
48  container = new PndTCAConstContainer<FairTimeStamp>{};
49  container->SetBranchName(t_branchname);
50  container->SetTCA(dynamic_cast<TClonesArray *>(FairRootManager::Instance()->GetObject(t_branchname)));
51  return container;
52  }
53 
60  PndSTDConstContainer<FairTimeStamp> *GetSTD(const TString &t_branchname)
61  {
62  PndSTDConstContainer<FairTimeStamp> *container{nullptr};
63  if (FairRootManager::Instance()->CheckBranch(t_branchname) ==
64  0) { // This test is required here, as you get a segmentation violation if you try to access a not existing branch t_branchname via std
65  return container;
66  }
67  std::vector<FairTimeStamp> const *data = FairRootManager::Instance()->InitObjectAs<std::vector<FairTimeStamp> const *>(t_branchname);
68  if (data != nullptr) {
69  container = new PndSTDConstContainer<FairTimeStamp>{};
70  container->SetBranchName(t_branchname);
71  container->SetData(data);
72  }
73 
74  return container;
75  }
76 
77  virtual InitStatus Init() /*override*/ final
78  {
79  fInCont.SetBranchName(fBranchName);
80  PndConstContainerI<FairTimeStamp> *container = GetTCA(fBranchName);
81  if (container != nullptr) {
82  fInCont.SetConstContainer(container);
83  return kSUCCESS;
84  }
85  container = GetSTD(fBranchName);
86  if (container != nullptr) {
87  fInCont.SetConstContainer(container);
88  return kSUCCESS;
89  }
90  return kFATAL;
91  };
92 
93  virtual void Exec(Option_t * /*option*/) /*override*/
94  {
95  ASSERT_EQ(fInCont.GetSize(), 1);
96  EXPECT_EQ(fInCont.GetConstElementPtr(0)->GetTimeStamp(), fgNumber--);
97  };
98 
99  private:
100  // ClassDef(TestInTask, 1);
101 };
102 
103 //______________________________________________________________________________
104 class TestOutTask : public FairTask {
106  Int_t fgNumber{111};
107  TString fBranchName;
108 
109  public:
110  TestOutTask(const TString &t_branch = "TestBranch") : FairTask(), fBranchName(t_branch) {}
111  virtual ~TestOutTask() {}
112 
113  virtual InitStatus Init() /*override*/ final
114  {
115  fOutCont.SetBranchName(fBranchName);
116  fOutCont.SetTCA(dynamic_cast<TClonesArray *>(FairRootManager::Instance()->Register(fBranchName, "FairTimeStamp", "Test", kTRUE)));
117  return kSUCCESS;
118  }
119 
120  virtual void Exec(Option_t * /*option*/) /*override*/
121  {
122  fOutCont.Reset();
123  FairTimeStamp stamp;
124  stamp.SetTimeStamp(fgNumber--);
125  fOutCont.CreateCopy(stamp);
126  }
127  // ClassDef(TestOutTask, 1);
128 };
129 
130 //______________________________________________________________________________
131 class TestOutWithSTDTask : public FairTask {
133  Int_t fgNumber{111};
134  TString fBranchName;
135 
136  public:
137  TestOutWithSTDTask(const TString &t_branch = "TestBranch") : FairTask(), fBranchName(t_branch) {}
138  virtual ~TestOutWithSTDTask() {}
139 
140  virtual InitStatus Init() /*override*/ final
141  {
142  fOutCont.SetBranchName(fBranchName);
143  auto *data = new std::vector<FairTimeStamp>{};
144  FairRootManager::Instance()->RegisterAny(fBranchName, data, kTRUE);
145  fOutCont.SetData(data);
146 
147  return kSUCCESS;
148  }
149 
150  virtual void Exec(Option_t * /*option*/) /*override*/
151  {
152  fOutCont.Reset();
153  FairTimeStamp stamp;
154  stamp.SetTimeStamp(fgNumber--);
155  fOutCont.CreateCopy(stamp);
156  }
157  // ClassDef(TestOutWithSTDTask, 1);
158 };
159 
160 //______________________________________________________________________________
161 class TestOutWithTCATask : public FairTask {
163  Int_t fgNumber{111};
164  TString fBranchName;
165 
166  public:
167  TestOutWithTCATask(const TString &t_branch = "TestBranch") : FairTask(), fBranchName(t_branch) {}
168 
169  virtual ~TestOutWithTCATask() {}
170 
171  virtual InitStatus Init() /*override*/ final
172  {
173  fOutCont.SetBranchName(fBranchName);
174  fOutCont.SetTCA(dynamic_cast<TClonesArray *>(FairRootManager::Instance()->Register(fBranchName, "FairTimeStamp", "Test", kTRUE)));
175 
176  return kSUCCESS;
177  }
178 
179  virtual void Exec(Option_t * /*option*/) /*override*/
180  {
181  fOutCont.Reset();
182  FairTimeStamp stamp;
183  stamp.SetTimeStamp(fgNumber--);
184  fOutCont.CreateCopy(stamp);
185  }
186  // ClassDef(TestOutWithTCATask, 1);
187 };
virtual ~TestOutWithTCATask()
Definition: TestTasks.h:169
PndSTDConstContainer implementation of PndConstContainerI<T> for FairRootManager and std::vector<T> ...
virtual T * CreateCopy(const T &t_element)
Create a Copy object of t_element and return pointer to copy.
virtual void Exec(Option_t *)
Definition: TestTasks.h:120
virtual T const * GetConstElementPtr(Int_t t_index) const
Get the Element object at t_index.
virtual InitStatus Init() final
Definition: TestTasks.h:77
void SetData(std::vector< T > *t_container)
Set the Data.
virtual void Reset() final
"Delete" all elements
TestOutTask(const TString &t_branch="TestBranch")
Definition: TestTasks.h:110
PndSTDConstContainer< FairTimeStamp > * GetSTD(const TString &t_branchname)
Tries to find a registered const std::vector<T>* with name t_branchname. Returns kTRUE on success...
Definition: TestTasks.h:60
TestOutWithTCATask(const TString &t_branch="TestBranch")
Definition: TestTasks.h:167
Input and Output Container implementation of PndMutableContainerI using an underlying TClonesArray...
virtual ~TestOutTask()
Definition: TestTasks.h:111
Container to wrap PndTCA/STDMutableContainer (not needed anymore)
void SetTCA(TClonesArray *t_tca)
Set the TClonesArray address.
virtual ~TestInTask()
Definition: TestTasks.h:32
virtual void Exec(Option_t *)
Definition: TestTasks.h:150
virtual void Reset() final
Delete all elements.
TestInTask(const TString &t_branch="TestBranch")
Definition: TestTasks.h:31
void SetConstContainer(PndConstContainerI< T > *t_container)
Set the Input Container object.
TestOutWithSTDTask(const TString &t_branch="TestBranch")
Definition: TestTasks.h:137
Input and Output Container implementation of PndMutableContainerI using an underlying std::vector<T> ...
virtual void Exec(Option_t *)
Definition: TestTasks.h:179
void SetBranchName(const TString &t_branchname)
Set the Branch Name.
virtual InitStatus Init() final
Definition: TestTasks.h:113
virtual void Exec(Option_t *)
Definition: TestTasks.h:93
PndTCAConstContainer< FairTimeStamp > * GetTCA(const TString &t_branchname)
Tries to find a registered TClonesArray with name t_branchname. Returns kTRUE on success.
Definition: TestTasks.h:40
PndTCAConstContainer implementation of PndConstContainerI<T> for FairRootManager and TClonesArray...
virtual ~TestOutWithSTDTask()
Definition: TestTasks.h:138
virtual ssize_t GetSize() const final
Get the number of members in internal data.
Container to wrap PndTCA/STDConstContainer (not needed anymore)
virtual InitStatus Init() final
Definition: TestTasks.h:171
virtual T * CreateCopy(const T &t_element)
Create a copy of t_element in the TClonesArray and return a pointer to it.
virtual InitStatus Init() final
Definition: TestTasks.h:140