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

Macros

#define BOOST_TEST_MODULE   testOptions
 
#define DARWIN_EXAMPLE   DARWIN "/test/example.info"
 

Functions

 BOOST_AUTO_TEST_CASE (test_default)
 
 BOOST_AUTO_TEST_CASE (test_steering_parameters)
 
 BOOST_AUTO_TEST_CASE (test_example_config)
 
 BOOST_AUTO_TEST_CASE (test_splitting)
 
 BOOST_AUTO_TEST_CASE (test_parse_env_var)
 
 BOOST_AUTO_TEST_CASE (test_config)
 
 BOOST_AUTO_TEST_CASE (test_args)
 
 BOOST_AUTO_TEST_CASE (test_stages)
 
 BOOST_AUTO_TEST_CASE (slicing)
 
 BOOST_AUTO_TEST_CASE (multiple_inputs)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   testOptions

◆ DARWIN_EXAMPLE

#define DARWIN_EXAMPLE   DARWIN "/test/example.info"

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/10]

BOOST_AUTO_TEST_CASE ( multiple_inputs  )
226  {
227  for (int i = 0; i < 3; ++i)
228  TFile::Open(Form("input%d.root", i), "RECREATE")->Close();
229 
230  {
231  Options options("Test");
232  vector<fs::path> inputs;
233  BOOST_REQUIRE_NO_THROW( options.inputs("inputs", &inputs, "input ROOT files") );
234 
235  system("ls input*.root");
236  auto const args = tokenize("exec input*.root");
237  BOOST_REQUIRE_NO_THROW( options(args.size(), args.data()) );
238  BOOST_TEST( inputs.size() == 3ul );
239  for (auto const& input: inputs)
240  cout << input << ' ';
241  cout << endl;
242  }
243 
244  {
245  Options options("Test");
246  vector<fs::path> inputs;
247  fs::path output;
248  BOOST_REQUIRE_NO_THROW( options.inputs("inputs", &inputs, "input ROOT files") );
249  options.output("output", &output, "output ROOT file");
250 
251  auto const args = tokenize("exec input*.root output.root");
252  BOOST_REQUIRE_NO_THROW( options(args.size(), args.data()) );
253  BOOST_TEST( inputs.size() == 3ul );
254  for (auto const& input: inputs)
255  cout << input << ' ';
256  cout << endl;
257  BOOST_TEST( output == "output.root" );
258  }
259 
260  for (int i = 0; i < 3; ++i)
261  fs::remove(Form("input%d.root", i));
262  fs::remove("output.root");
263 
264  {
265  Options options("Test");
266  vector<fs::path> inputs;
267  options.inputs("inputs", &inputs, "input ROOT files");
268  auto const args = tokenize("exec input*.root"); // no such file exists
269  BOOST_REQUIRE_THROW( options(args.size(), args.data()), boost::wrapexcept<fs::filesystem_error> );
270  }
271  }

◆ BOOST_AUTO_TEST_CASE() [2/10]

BOOST_AUTO_TEST_CASE ( slicing  )
214  {
215  Options options("test", split);
216  auto const args = tokenize("exec -j 0");
217  BOOST_REQUIRE_THROW( options(args.size(), args.data()),
218  boost::wrapexcept<invalid_argument> );
219 
220  auto const args2 = tokenize("exec -j 1 -k 2");
221  BOOST_REQUIRE_THROW( options(args2.size(), args2.data()),
222  boost::wrapexcept<invalid_argument> );
223  }

◆ BOOST_AUTO_TEST_CASE() [3/10]

BOOST_AUTO_TEST_CASE ( test_args  )
188  {
189  Options options("Test");
190 
191  TFile::Open("input.root", "RECREATE")->Close();
192 
193  fs::path input, output;
194  options.input("input", &input, "input")
195  .args("labels", "labels", "labels");
196  BOOST_REQUIRE_THROW( options.output("output", &output, "output"), runtime_error );
197 
198  fs::remove("input.root");
199  }

◆ BOOST_AUTO_TEST_CASE() [4/10]

BOOST_AUTO_TEST_CASE ( test_config  )
149  {
150  BOOST_REQUIRE_NO_THROW( Options("Test", config) );
151  Options options("Test", config);
152 
153  TFile::Open("input.root", "RECREATE")->Close();
154 
155  fs::path input, output;
156  BOOST_REQUIRE_NO_THROW( options.input("input", &input, "input ROOT file") );
157  BOOST_REQUIRE_NO_THROW( options.output("output", &output, "output ROOT file") );
158 
159  // testing normal commands
160  auto const args = tokenize("exec input.root output.root -c " DARWIN_EXAMPLE);
161  BOOST_REQUIRE_NO_THROW( Options::parse_env_var("${DARWIN_TABLES}") ); // is used in `example.info`
162  BOOST_REQUIRE_NO_THROW( options(args.size(), args.data()) );
163  auto const& config = options(args.size(), args.data());
164  BOOST_TEST( !config.empty() );
165  for (auto it: config)
166  cout << it.first << endl;
167  BOOST_TEST( config.count("flags") );
168  BOOST_TEST( config.count("corrections") );
169 
170  auto const flags = config.get_child("flags");
171  BOOST_TEST( flags.count("isMC") );
172  BOOST_TEST( flags.count("year") );
173  BOOST_TEST( flags.count("R") );
174 
175  auto const corrections = config.get_child("corrections");
176  BOOST_TEST( corrections.count("filters") );
177  BOOST_TEST( corrections.count("lumi") );
178  BOOST_TEST( corrections.count("xsecs") );
179  BOOST_TEST( corrections.count("JES") );
180  BOOST_TEST( corrections.count("triggers") );
181  BOOST_TEST( corrections.count("PUstaub") );
182 
183  fs::remove("input.root");
184  fs::remove("output.root");
185  }

◆ BOOST_AUTO_TEST_CASE() [5/10]

BOOST_AUTO_TEST_CASE ( test_default  )
29  {
30  BOOST_REQUIRE_NO_THROW( Options("Test") );
31 
32  Options options("Test"); // no config, no splitting by default
33  BOOST_TEST( options.full_cmd.empty() );
34 
35  // check that we have a commit SHA
36  BOOST_TEST( options.commit().size() == 40 );
37 
38  TFile::Open("input.root", "RECREATE")->Close();
39 
40  fs::path input, output;
41  BOOST_REQUIRE_NO_THROW( options.input("input", &input, "input ROOT file") );
42  BOOST_REQUIRE_NO_THROW( options.output("output", &output, "output ROOT file") );
43 
44  {
45  // testing normal commands
46  auto const args = tokenize("exec input.root output.root --unknown");
47  BOOST_REQUIRE_THROW( options(args.size(), args.data()), boost::wrapexcept<po::error> );
48  }
49 
50  {
51  // testing normal commands
52  auto const args = tokenize("exec input.root output.root");
53  BOOST_REQUIRE_NO_THROW( options(args.size(), args.data()) );
54  BOOST_TEST( input == "input.root" );
55  BOOST_TEST( output == "output.root" );
56  cout << options.full_cmd << endl;
57  BOOST_TEST( !options.full_cmd.empty() );
58  }
59 
60  fs::remove("output.root");
61 
62  {
63  // testing bad input
64  auto const args = tokenize("exec inpu.root output.root");
65  BOOST_REQUIRE_THROW( options(args.size(),args.data()), boost::wrapexcept<fs::filesystem_error> );
66  }
67 
68  {
69  // testing bad output
70  auto const args = tokenize("exec input.root .");
71  BOOST_REQUIRE_THROW( options(args.size(),args.data()), boost::wrapexcept<fs::filesystem_error> );
72  }
73 
74  {
75  // testing non-readable input
76  fs::permissions("input.root", fs::perms::owner_read, fs::perm_options::remove);
77  auto const args = tokenize("exec input.root output.root");
78  BOOST_REQUIRE_THROW( options(args.size(),args.data()), boost::wrapexcept<fs::filesystem_error> );
79  fs::permissions("input.root", fs::perms::owner_read, fs::perm_options::add);
80  }
81 
82  TFile::Open("output.root", "RECREATE")->Close();
83 
84  {
85  // testing non-writable output
86  fs::permissions("output.root", fs::perms::owner_write, fs::perm_options::remove);
87  auto const args = tokenize("exec input.root output.root");
88  BOOST_REQUIRE_THROW( options(args.size(),args.data()), boost::wrapexcept<fs::filesystem_error> );
89  fs::permissions("output.root", fs::perms::owner_write, fs::perm_options::add);
90  }
91 
92  fs::remove("input.root");
93  fs::remove("output.root");
94  }

◆ BOOST_AUTO_TEST_CASE() [6/10]

BOOST_AUTO_TEST_CASE ( test_example_config  )
113  {
114  Options options("Test", config);
115  options.arg<fs::path>("blah", "foo.bar", "this must fail bc this path does not exist in the example config");
116  auto const args = tokenize("exec -e");
117  BOOST_REQUIRE_THROW( options(args.size(), args.data()), boost::wrapexcept<pt::ptree_bad_path> );
118  }

◆ BOOST_AUTO_TEST_CASE() [7/10]

BOOST_AUTO_TEST_CASE ( test_parse_env_var  )
143  {
144  BOOST_REQUIRE_NO_THROW( Options::parse_env_var("${HOME}") );
145  BOOST_REQUIRE_THROW( Options::parse_env_var("${THISVARDOESNOTEXIST}"), boost::wrapexcept<std::runtime_error> );
146  }

◆ BOOST_AUTO_TEST_CASE() [8/10]

BOOST_AUTO_TEST_CASE ( test_splitting  )
121  {
122  BOOST_REQUIRE_NO_THROW( Options("Test", split) );
123  Options options("Test", split);
124 
125  TFile::Open("input.root", "RECREATE")->Close();
126 
127  fs::path input, output;
128  BOOST_REQUIRE_NO_THROW( options.input("input", &input, "input ROOT file") );
129  BOOST_REQUIRE_NO_THROW( options.output("output", &output, "output ROOT file") );
130 
131  // testing normal commands
132  auto const args = tokenize("exec input.root output.root -j 42 -k 24");
133  BOOST_REQUIRE_NO_THROW( options(args.size(), args.data()) );
134  auto const slice = options.slice();
135  BOOST_TEST( slice.first == 42u );
136  BOOST_TEST( slice.second == 24u );
137 
138  fs::remove("input.root");
139  fs::remove("output.root");
140  }

◆ BOOST_AUTO_TEST_CASE() [9/10]

BOOST_AUTO_TEST_CASE ( test_stages  )
202  {
203  Options options("Test");
204 
205  TFile::Open("input.root", "RECREATE")->Close();
206  fs::path output, input;
207  options.output("output", &output, "output");
208  BOOST_REQUIRE_NO_THROW( options.arg<int>("R", "R", "R") );
209  BOOST_REQUIRE_THROW( options.input("input", &input, "input"), runtime_error );
210  fs::remove("input.root");
211  }

◆ BOOST_AUTO_TEST_CASE() [10/10]

BOOST_AUTO_TEST_CASE ( test_steering_parameters  )
97  {
98  namespace DT = Darwin::Tools;
99  vector<pair<string,int>> in_out {
100  {"exec -v", DT::verbose},
101  {"exec -f", DT::fill},
102  {"exec -F", DT::Friend | DT::fill},
103  };
104  for (auto [In, Out]: in_out) {
105  Options options("Test", DT::Friend);
106  auto const args = tokenize(In.c_str());
107  options(args.size(), args.data());
108  BOOST_TEST( options.steering() == Out );
109  }
110  }
Darwin::Tools::fill
@ fill
activate -f to fill the tree
Definition: Options.h:27
DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.options
options
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:41
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
Ntupliser_cfg.args
args
Definition: Ntupliser_cfg.py:11
BOOST_TEST
BOOST_TEST(gendijet.Rapidity()==1.3573785791881385)
Darwin::Tools::split
@ split
activate -k and -j to define slice
Definition: Options.h:26
Ntupliser_cfg.config
config
Definition: Ntupliser_cfg.py:264
DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.input
input
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:35
Darwin::Tools::Options
Common class to interpret the command line, based on Boost Program Options.
Definition: Options.h:58
DARWIN_EXAMPLE
#define DARWIN_EXAMPLE
Definition: Options.cc:16
Darwin::Tools
Classes and functions related to the framework.
Definition: Dict_rdict.cxx:990
jercExample.inputs
def inputs
Definition: jercExample.py:118
DAS::Options
Darwin::Tools::Options Options(const char *, int=Darwin::Tools::none)
Constructs Darwin options with the correct commit information.
Definition: DASOptions.cc:14
Darwin::Tools::tokenize
std::vector< const char * > tokenize(const char *str)
Definition: test.h:15
Ntupliser_cfg.flags
dictionary flags
Definition: Ntupliser_cfg.py:27