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

Classes

struct  EventBoom
 

Macros

#define BOOST_TEST_MODULE   Flow
 

Functions

 BOOST_AUTO_TEST_CASE (write_only)
 
 BOOST_AUTO_TEST_CASE (read_only_getter)
 
 BOOST_AUTO_TEST_CASE (read_only_applier)
 
 BOOST_AUTO_TEST_CASE (read_write)
 
 BOOST_AUTO_TEST_CASE (hists)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   Flow

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/5]

BOOST_AUTO_TEST_CASE ( hists  )
160  {
161  {
162  auto f = make_unique<TFile>("flow_hist.root", "RECREATE");
163  auto h = make_unique<TH1D>("h", "", 1, 0, 1);
164  h->SetBinContent(1, 42);
165  h->Write("h1");
166  h->Write("h2");
167  }
168 
169  Flow flow(verbose, {"flow_hist.root"});
170  const char * h1s = "h1";
171  string h2s = "h2";
172  auto [h1, h2] = flow.GetInputHists(h1s, h2s);
173  BOOST_TEST( h1->GetBinContent(1) == 42 );
174  BOOST_TEST( h2->GetBinContent(1) == 42 );
175  }

◆ BOOST_AUTO_TEST_CASE() [2/5]

BOOST_AUTO_TEST_CASE ( read_only_applier  )
92  {
93  Flow flow(verbose | Friend, {"flow.root"});
94  auto tIn = flow.GetInputTree();
95  tIn->GetEntry(0);
96  BOOST_TEST( tIn->GetTree()->GetTitle() == "Flow"s );
97 
98  BOOST_TEST_MESSAGE( "Forcing same command for input and output tree" );
99  auto tOut = flow.GetOutputTree("flow2.root");
100 
101  BOOST_TEST_MESSAGE( "Trying to access the same branch once in read-only mode and once in write-only" );
102  DP::RecEvent * ev = nullptr,
103  * ev2 = nullptr;
104  BOOST_REQUIRE_NO_THROW( ev = flow.GetBranchReadOnly<DP::RecEvent>("recEvent") );
105  BOOST_REQUIRE_NO_THROW( ev2 = flow.GetBranchWriteOnly<DP::RecEvent>("recEvent") );
106  BOOST_TEST( ev == ev2 );
107 
108  ev2->fill = 1235;
109  ev2->runNo = 424243;
110  ev2->lumi = 123456790;
111  BOOST_TEST( tOut->Fill() > 0 );
112  tOut->Show(0);
113  }

◆ BOOST_AUTO_TEST_CASE() [3/5]

BOOST_AUTO_TEST_CASE ( read_only_getter  )
61  {
62  Flow flow(verbose, {"flow.root"});
63 
64  BOOST_TEST_MESSAGE( "Trying to get the input tree before it has been set up" );
65  BOOST_REQUIRE_THROW( flow.GetBranchReadOnly<DP::RecEvent>("recEvent"), wrapexcept<invalid_argument> );
66  BOOST_REQUIRE_THROW( flow.GetInputTree({0, 0}), wrapexcept<invalid_argument> );
67  BOOST_REQUIRE_THROW( flow.GetInputTree({0, 1}), wrapexcept<invalid_argument> );
68 
69  auto tIn = flow.GetInputTree();
70  BOOST_TEST( tIn->GetEntries() > 0 );
71  tIn->Show(0);
72 
73  BOOST_TEST_MESSAGE( "Trying to read an existing branch with the correct type" );
74  BOOST_REQUIRE_NO_THROW( flow.GetBranchReadOnly<DP::RecEvent>("recEvent") );
75 
76  BOOST_TEST_MESSAGE( "Trying to read inexisting branch" );
77  BOOST_REQUIRE_THROW( flow.GetBranchReadOnly<DP::RecEvent>("recEvent2"), wrapexcept<DE::BadInput> );
78 
79  BOOST_TEST_MESSAGE( "Trying to read an existing branch assuming a wrong type" );
80  BOOST_REQUIRE_THROW( flow.GetBranchReadOnly<DP::GenEvent>("recEvent"), wrapexcept<bad_any_cast> );
81 
82  BOOST_TEST_MESSAGE( "Trying to get output file when it has not been set" );
83  BOOST_TEST( flow.GetOutputFile() == nullptr );
84 
85  BOOST_TEST_MESSAGE( "Setting custom output file" );
86  auto fOut = make_shared<TFile>("flow2.root", "RECREATE");
87  BOOST_REQUIRE_NO_THROW( flow.SetOutputFile(fOut) );
88  BOOST_TEST( flow.GetOutputFile() != nullptr );
89  }

◆ BOOST_AUTO_TEST_CASE() [4/5]

BOOST_AUTO_TEST_CASE ( read_write  )
116  {
117  int steering1 = verbose,
118  steering2 = verbose | Friend;
119  for (int steering: {steering1, steering2}) {
120  Flow flow(steering, {"flow2.root"});
121 
122  BOOST_TEST_MESSAGE( "Trying to get a branch before the input has been set up" );
123  BOOST_REQUIRE_THROW( flow.GetBranchReadWrite<DP::RecEvent>("recEvent"), wrapexcept<invalid_argument> );
124  auto tIn = flow.GetInputTree();
125  tIn->Show(0);
126 
127  BOOST_TEST_MESSAGE( "Trying to get a branch before the output has been set up" );
128  BOOST_REQUIRE_THROW( flow.GetBranchReadWrite<DP::RecEvent>("recEvent"), wrapexcept<invalid_argument> );
129 
130  BOOST_TEST_MESSAGE( "Testing default name in case of friends" );
131  tIn->GetTree()->SetTitle("");
132  auto t1 = flow.GetOutputTree();
133 
134  BOOST_TEST_MESSAGE( "Trying to read an existant branch with the correct type" );
135  BOOST_REQUIRE_NO_THROW( flow.GetBranchReadWrite<DP::RecEvent>("recEvent") );
136 
137  BOOST_TEST_MESSAGE( "Trying to read an inexistant branch" );
138  BOOST_REQUIRE_THROW( flow.GetBranchReadWrite<DP::RecEvent>("recEvent2"), wrapexcept<DE::BadInput> );
139  BOOST_TEST( flow.GetBranchReadWrite<DP::RecEvent>("recEvent2", facultative) == nullptr );
140 
141  BOOST_TEST_MESSAGE( "Trying to write to an existing branch assuming a wrong type" );
142  BOOST_REQUIRE_THROW( flow.GetBranchReadWrite<DP::GenEvent>("recEvent"), wrapexcept<bad_any_cast> );
143 
144  BOOST_TEST_MESSAGE( "Trying to write to a branch with a missing dictionary." );
145  BOOST_REQUIRE_THROW( flow.GetBranchReadWrite<EventBoom>("recEventBOOM"), wrapexcept<DE::BadInput> );
146 
147  BOOST_TEST_MESSAGE( "Trying to write twice to the same branch." );
148  DP::RecEvent * ev = nullptr,
149  * ev2 = nullptr;
150  BOOST_REQUIRE_NO_THROW( ev = flow.GetBranchReadWrite<DP::RecEvent>("recEvent") );
151  BOOST_REQUIRE_NO_THROW( ev2 = flow.GetBranchReadWrite<DP::RecEvent>("recEvent") );
152  BOOST_TEST( ev == ev2 );
153 
154  t1->GetEntry(0);
155  BOOST_TEST( ev == ev2 );
156  }
157  }

◆ BOOST_AUTO_TEST_CASE() [5/5]

BOOST_AUTO_TEST_CASE ( write_only  )
32  {
34 
35  BOOST_TEST_MESSAGE( "Trying to get a branch before the input tree has been set up" );
36  BOOST_REQUIRE_THROW( flow.GetBranchWriteOnly<DP::RecEvent>("recEvent"), wrapexcept<invalid_argument> );
37 
38  BOOST_TEST_MESSAGE( "Testing the unicity of the output tree" );
39  auto tOut1 = flow.GetOutputTree("flow.root"),
40  tOut2 = flow.GetOutputTree();
41  BOOST_TEST( tOut1 == tOut2 );
42 
43  BOOST_TEST_MESSAGE( "Trying to write twice to the same branch." );
44  DP::RecEvent * ev = nullptr,
45  * ev2 = nullptr;
46  BOOST_REQUIRE_NO_THROW( ev = flow.GetBranchWriteOnly<DP::RecEvent>("recEvent") );
47  BOOST_REQUIRE_NO_THROW( ev2 = flow.GetBranchWriteOnly<DP::RecEvent>("recEvent") );
48  BOOST_TEST( ev == ev2 );
49 
50  BOOST_TEST_MESSAGE( "Trying to write to a branch with a missing dictionary." );
51  BOOST_REQUIRE_THROW( flow.GetBranchWriteOnly<EventBoom>("recEventBOOM"), wrapexcept<DE::BadInput> );
52 
53  ev->fill = 1234;
54  ev->runNo = 424242;
55  ev->lumi = 123456789;
56  tOut1->Fill();
57  BOOST_TEST( tOut1->GetEntries() > 0 );
58  }
Darwin::Tools::fill
@ fill
activate -f to fill the tree
Definition: Options.h:27
Darwin::Tools::Flow
User-friendly handling of input and output n-tuples.
Definition: Flow.h:69
Step::verbose
static bool verbose
Definition: Step.h:40
Darwin::Tools::Friend
@ Friend
activate -F to only fill the new branches
Definition: Options.h:28
BOOST_TEST
BOOST_TEST(gendijet.Rapidity()==1.3573785791881385)
Ntupliser_cfg.f
f
Definition: Ntupliser_cfg.py:256
Darwin::Physics::RecEvent::runNo
int runNo
at LHC, typically a 6-digit run number
Definition: Event.h:72
Darwin::Tools::Flow::GetInputHists
std::array< std::unique_ptr< THX >, N > GetInputHists(const std::array< std::string, N > &names={})
Load ROOT histograms from a list of files.
Definition: Flow.h:153
Darwin::Physics::GenEvent
Generic generator-level event.
Definition: Event.h:43
Darwin::Physics::RecEvent
Generic detector-level event.
Definition: Event.h:64
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::Flow::GetInputTree
ChainSlice * GetInputTree(std::vector< std::filesystem::path >, const Slice={1, 0}, const std::string &="events")
Load chain from a list of files.
Definition: Flow.cc:46
Darwin::Physics::RecEvent::fill
int fill
at LHC, typically a 4-digit number
Definition: Event.h:71
Darwin::Physics::RecEvent::lumi
int lumi
lumi section (shortest unit time in LHC jargon)
Definition: Event.h:73
EventBoom
Definition: Flow.cc:25
Darwin::Tools::facultative
@ facultative
mounting branch is facultative
Definition: Flow.h:31