Line | Branch | Exec | Source |
---|---|---|---|
1 | #include <cassert> | ||
2 | #include <iguana/algorithms/clas12/ZVertexFilter/Algorithm.h> | ||
3 | |||
4 | /// @begin_doc_example{cpp} | ||
5 | /// @file iguana_ex_cpp_config_files.cc | ||
6 | /// @brief Example showing how to control algorithm configuration. | ||
7 | /// | ||
8 | /// Examples include: | ||
9 | /// - hard-coding a configuration setting override | ||
10 | /// - using a configuration file | ||
11 | /// - using a directory of configuration files | ||
12 | /// | ||
13 | /// @par Usage | ||
14 | /// ```bash | ||
15 | /// iguana_ex_cpp_config_files [CONFIG_FILE_DIRECTORY] | ||
16 | /// | ||
17 | /// CONFIG_FILE_DIRECTORY a custom directory with config files | ||
18 | /// (default = an example directory) | ||
19 | /// ``` | ||
20 | /// @end_doc_example | ||
21 | |||
22 | /// main function | ||
23 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | int main(int argc, char** argv) |
24 | { | ||
25 | |||
26 | // parse arguments | ||
27 | std::string configDir; | ||
28 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if(argc > 1) |
29 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
2 | configDir = std::string(argv[1]); |
30 | else | ||
31 | ✗ | configDir = iguana::ConfigFileReader::GetConfigInstallationPrefix() + "/examples"; | |
32 | 1 | fmt::print("Using top-level configuration directory {}\n", configDir); | |
33 | |||
34 | // loop over multiple examples how to use configuration files and set options | ||
35 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
|
7 | for(int example = 1; example <= 6; example++) { |
36 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
12 | fmt::print("\n" + iguana::Logger::Header(fmt::format("CONFIG EXAMPLE {}", example)) + "\n"); |
37 | |||
38 | // start the algorithm; it will be destroyed at the end of each `example` iteration | ||
39 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | auto algo = std::make_unique<iguana::clas12::ZVertexFilter>(); |
40 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | algo->SetLogLevel("debug"); |
41 | |||
42 |
6/6✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
|
6 | switch(example) { |
43 | |||
44 | case 1: | ||
45 | { | ||
46 | // Use the default configuration, from `../src/iguana/algorithms/clas12/ZVertexFilter.yaml` | ||
47 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | algo->Start(); |
48 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | auto key = algo->PrepareEvent(4800); // sets the run number and loads the cuts |
49 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | assert((algo->GetRunNum(key) == 4800)); // pass the key into the 'Get*' methods |
50 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -13.0)); |
51 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(1) == 12.0)); |
52 | 1 | break; | |
53 | } | ||
54 | |||
55 | case 2: | ||
56 | { | ||
57 | // Use `SetElectronZcuts` to set the cuts | ||
58 | // - note that this will OVERRIDE any value used in any configuration file | ||
59 | // - only use `SetElectronZcuts` if for any reason you want to hard-code a specific value; usage | ||
60 | // of configuration files is preferred in general | ||
61 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | algo->Start(); |
62 | iguana::concurrent_key_t const key = 0; // need the same key in `SetElectronZcuts` and `GetElectronZcuts` | ||
63 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | algo->SetElectronZcuts(-5.0, 3.0, key); |
64 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -5.0)); |
65 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(1) == 3.0)); |
66 | 1 | break; | |
67 | } | ||
68 | |||
69 | case 3: | ||
70 | { | ||
71 | // Use a specific configuration file | ||
72 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | algo->SetConfigFile(configDir + "/my_z_vertex_cuts.yaml"); |
73 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | algo->Start(); |
74 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | auto key = algo->PrepareEvent(5500); |
75 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -0.8)); |
76 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(1) == 0.7)); |
77 | 1 | break; | |
78 | } | ||
79 | |||
80 | case 4: | ||
81 | { | ||
82 | // Use the same specific configuration file, but don't set a run number; | ||
83 | // note also the usage of `SetConfigDirectory`, as another example how to set a specific configuration file | ||
84 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | algo->SetConfigDirectory(configDir); |
85 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | algo->SetConfigFile("my_z_vertex_cuts.yaml"); |
86 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | algo->Start(); |
87 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | auto key = algo->PrepareEvent(0); // run number "0" means "no run number" |
88 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -1.5)); |
89 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(1) == 1.3)); |
90 | 1 | break; | |
91 | } | ||
92 | |||
93 | case 5: | ||
94 | { | ||
95 | // Use a custom directory of configuration files; if a configuration file within | ||
96 | // has the same path and name as the default (`ZVertexFilter.yaml`), it will be used instead of the default. | ||
97 | // This is designed such that if you copy the full installed configuration directory to a new location, you | ||
98 | // may use that directory instead of the default, and modify any configuration file within. | ||
99 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | algo->SetConfigDirectory(configDir + "/my_config_directory"); |
100 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | algo->Start(); |
101 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | auto key = algo->PrepareEvent(0); // run number "0" means "no run number" |
102 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -15.0)); |
103 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(1) == 15.0)); |
104 | 1 | break; | |
105 | } | ||
106 | |||
107 | case 6: | ||
108 | { | ||
109 | // Use a single, combined configuration file; each algorithm's options are in a separate section | ||
110 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | algo->SetConfigDirectory(configDir); |
111 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | algo->SetConfigFile("my_combined_config_file.yaml"); |
112 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | algo->Start(); |
113 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | auto key = algo->PrepareEvent(0); // run number "0" means "no run number" |
114 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -33.0)); |
115 |
3/8✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
1 | assert((algo->GetElectronZcuts(key).at(1) == 11.0)); |
116 | 1 | break; | |
117 | } | ||
118 | |||
119 | default: | ||
120 | { | ||
121 | fmt::print(stderr, "ERROR: unknown example number '{}'\n", example); | ||
122 | return 1; | ||
123 | } | ||
124 | } | ||
125 | |||
126 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | algo->Stop(); |
127 | } | ||
128 | |||
129 | return 0; | ||
130 | } | ||
131 |