DAS  3.0
Das Analysis System
SelfAwareBranch.cc File Reference
#include <boost/test/included/unit_test.hpp>
#include <boost/exception/all.hpp>
#include <filesystem>
#include "Flow.h"
#include "Jet.h"
#include "SelfAwareBranch.h"
+ Include dependency graph for SelfAwareBranch.cc:

Macros

#define BOOST_TEST_MODULE   SelfAwareBranch
 

Functions

 BOOST_AUTO_TEST_CASE (plain_type)
 
 BOOST_AUTO_TEST_CASE (vector_type)
 
 BOOST_AUTO_TEST_CASE (polymorphism)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   SelfAwareBranch

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/3]

BOOST_AUTO_TEST_CASE ( plain_type  )
24  {
25  BOOST_TEST_MESSAGE( "Filling the tree" );
26  {
27  Flow flow(verbose);
28  auto tOut = flow.GetOutputTree("self_aware_branch.root");
29  SelfAwarePlainBranch<int, int> br1(flow, "branch1", [](int v) -> int { return v;});
30  br1.Fill(42);
31  SelfAwarePlainBranch<int> br2(flow, "branch2", []() -> int { return 43;});
32  br2.Fill();
33  tOut->Fill();
34  br1.Clear();
35  br1.Fill(43);
36  tOut->Fill();
37  }
38 
39  BOOST_TEST_MESSAGE( "Testing output values" );
40  {
41  Flow flow(verbose, {"self_aware_branch.root"});
42  auto tIn = flow.GetInputTree();
43  auto br1 = flow.GetBranchReadOnly<int>("branch1"),
44  br2 = flow.GetBranchReadOnly<int>("branch2");
45  tIn->Scan();
46  tIn->GetEntry(0);
47  BOOST_TEST( *br1 == 42 );
48  BOOST_TEST( *br2 == 43 );
49  tIn->GetEntry(1);
50  BOOST_TEST( *br1 == 43 );
51  BOOST_TEST( *br2 == 43 );
52  }
53 
54  fs::remove("self_aware_branch.root");
55  }

◆ BOOST_AUTO_TEST_CASE() [2/3]

BOOST_AUTO_TEST_CASE ( polymorphism  )
97  {
98  BOOST_TEST_MESSAGE( "Filling the tree" );
99  {
100  Flow flow(verbose);
101  auto tOut = flow.GetOutputTree("self_aware_branch.root");
102  auto fill = [](int v) -> int { return v;};
103 
104  SelfAwareBranch<int> * plain_branch = new SelfAwarePlainBranch <int, int>(flow, "plain_branch" , fill);
105  SelfAwareBranch<int> * vector_branch = new SelfAwareVectorBranch<int, int>(flow, "vector_branch", fill);
106  for (auto&& branch: {plain_branch, vector_branch})
107  branch->Fill(42);
108  tOut->Fill();
109  for (auto&& branch: {plain_branch, vector_branch})
110  delete branch;
111  }
112 
113  BOOST_TEST_MESSAGE( "Testing output values" );
114  {
115  Flow flow(verbose, {"self_aware_branch.root"});
116  auto tIn = flow.GetInputTree();
117  auto plain_branch = flow.GetBranchReadOnly<int> ("plain_branch");
118  auto vector_branch = flow.GetBranchReadOnly<vector<int>>("vector_branch");
119  tIn->GetEntry(0);
120  tIn->Scan();
121  BOOST_TEST( *plain_branch == 42 );
122  BOOST_TEST( vector_branch->at(0) == 42 );
123  }
124 
125  fs::remove("self_aware_branch.root");
126  }

◆ BOOST_AUTO_TEST_CASE() [3/3]

BOOST_AUTO_TEST_CASE ( vector_type  )
58  {
59  BOOST_TEST_MESSAGE( "Filling the tree" );
60  {
61  Flow flow(verbose);
62  auto tOut = flow.GetOutputTree("self_aware_branch.root");
63  SelfAwareVectorBranch<int, int> br1(flow, "branch1", [](int v) -> int { return v;});
64  br1.Fill(42);
65  br1.Fill(44);
66  SelfAwareVectorBranch<int> br2(flow, "branch2", []() -> int { return 43;});
67  br2.Fill();
68  br2.Fill();
69  tOut->Fill();
70  br1.Clear();
71  br2.Clear();
72  br1.Fill(24);
73  tOut->Fill();
74  }
75 
76  BOOST_TEST_MESSAGE( "Testing output values" );
77  {
78  Flow flow(verbose, {"self_aware_branch.root"});
79  auto tIn = flow.GetInputTree();
80  auto br1 = flow.GetBranchReadOnly<vector<int>>("branch1"),
81  br2 = flow.GetBranchReadOnly<vector<int>>("branch2");
82  tIn->Scan();
83  tIn->GetEntry(0);
84  BOOST_TEST( br1->at(0) == 42 );
85  BOOST_TEST( br2->at(0) == 43 );
86  BOOST_TEST( br1->at(1) == 44 );
87  BOOST_TEST( br2->at(1) == 43 );
88  tIn->GetEntry(1);
89  BOOST_TEST( br1->at(0) == 24 );
90  BOOST_TEST( br2->size() == 0 );
91  }
92 
93  fs::remove("self_aware_branch.root");
94  }
Darwin::Tools::fill
@ fill
activate -f to fill the tree
Definition: Options.h:32
Darwin::Tools::Flow
User-friendly handling of input and output n-tuples.
Definition: Flow.h:80
Step::verbose
static bool verbose
Definition: Step.h:40
BOOST_TEST
BOOST_TEST(gendijet.Rapidity()==1.3573785791881385)
Darwin::Tools::SelfAwareVectorBranch::Fill
void Fill(Args... args) override
Definition: SelfAwareBranch.h:83
Darwin::Tools::SelfAwarePlainBranch::Fill
void Fill(Args... args) override
Definition: SelfAwareBranch.h:53
Darwin::Tools::SelfAwarePlainBranch
Type for a plain-type branch that knows how to fill itself.
Definition: SelfAwareBranch.h:44
Darwin::Tools::SelfAwareVectorBranch
Type for a vector branch that knows how to fill itself.
Definition: SelfAwareBranch.h:74
Darwin::Tools::Flow::GetInputTree
ChainSlice * GetInputTree(const Slice, const std::string &="events")
Load chain from a list of files with non-empty trees.
Definition: Flow.cc:67
Darwin::Tools::ChainSlice::GetEntry
Int_t GetEntry(Long64_t entry, Int_t getall=0) override
Get entry from the chain to memory.
Definition: FriendUtils.h:135
Darwin::Tools::SelfAwareBranch
Abstract type for a branch that knows how to fill itself.
Definition: SelfAwareBranch.h:22