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 (2→3) taken 1 times.
✗ Branch 1 (2→11) not taken.
|
1 | int main(int argc, char** argv) |
24 | { | ||
25 | |||
26 | // parse arguments | ||
27 | std::string configDir; | ||
28 |
1/2✓ Branch 0 (2→3) taken 1 times.
✗ Branch 1 (2→11) not taken.
|
1 | if(argc > 1) |
29 |
1/2✓ Branch 0 (3→4) taken 1 times.
✗ Branch 1 (3→315) 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 (202→30) taken 6 times.
✓ Branch 1 (202→203) taken 1 times.
|
7 | for(int example = 1; example <= 6; example++) { |
36 |
3/8✗ Branch 0 (31→32) not taken.
✓ Branch 1 (31→33) taken 6 times.
✓ Branch 2 (33→34) taken 6 times.
✗ Branch 3 (33→233) not taken.
✗ Branch 4 (41→42) not taken.
✓ Branch 5 (41→44) taken 6 times.
✗ Branch 6 (315→316) not taken.
✗ Branch 7 (315→318) 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 (61→62) taken 6 times.
✗ Branch 1 (61→315) not taken.
|
6 | auto algo = std::make_unique<iguana::clas12::ZVertexFilter>(); |
40 |
1/2✓ Branch 0 (62→63) taken 6 times.
✗ Branch 1 (62→311) not taken.
|
6 | algo->SetLogLevel("debug"); |
41 | |||
42 |
6/6✓ Branch 0 (63→64) taken 1 times.
✓ Branch 1 (63→84) taken 1 times.
✓ Branch 2 (63→101) taken 1 times.
✓ Branch 3 (63→125) taken 1 times.
✓ Branch 4 (63→150) taken 1 times.
✓ Branch 5 (63→174) 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 (64→65) taken 1 times.
✗ Branch 1 (64→311) not taken.
|
1 | algo->Start(); |
48 |
1/2✓ Branch 0 (65→66) taken 1 times.
✗ Branch 1 (65→311) not taken.
|
1 | auto key = algo->PrepareEvent(4800); // sets the run number and loads the cuts |
49 |
2/4✓ Branch 0 (66→67) taken 1 times.
✗ Branch 1 (66→311) not taken.
✗ Branch 2 (67→68) not taken.
✓ Branch 3 (67→69) taken 1 times.
|
1 | assert((algo->GetRunNum(key) == 4800)); // pass the key into the 'Get*' methods |
50 |
3/6✓ Branch 0 (69→70) taken 1 times.
✗ Branch 1 (69→311) not taken.
✓ Branch 2 (70→71) taken 1 times.
✗ Branch 3 (70→239) not taken.
✗ Branch 4 (71→72) not taken.
✓ Branch 5 (71→73) taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -13.0)); |
51 |
3/6✓ Branch 0 (76→77) taken 1 times.
✗ Branch 1 (76→311) not taken.
✓ Branch 2 (77→78) taken 1 times.
✗ Branch 3 (77→243) not taken.
✗ Branch 4 (78→79) not taken.
✓ Branch 5 (78→80) 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 (84→85) taken 1 times.
✗ Branch 1 (84→311) 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 (85→86) taken 1 times.
✗ Branch 1 (85→311) not taken.
|
1 | algo->SetElectronZcuts(-5.0, 3.0, key); |
64 |
3/6✓ Branch 0 (86→87) taken 1 times.
✗ Branch 1 (86→311) not taken.
✓ Branch 2 (87→88) taken 1 times.
✗ Branch 3 (87→247) not taken.
✗ Branch 4 (88→89) not taken.
✓ Branch 5 (88→90) taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -5.0)); |
65 |
3/6✓ Branch 0 (93→94) taken 1 times.
✗ Branch 1 (93→311) not taken.
✓ Branch 2 (94→95) taken 1 times.
✗ Branch 3 (94→251) not taken.
✗ Branch 4 (95→96) not taken.
✓ Branch 5 (95→97) 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 (101→102) taken 1 times.
✗ Branch 1 (101→311) not taken.
✓ Branch 2 (102→103) taken 1 times.
✗ Branch 3 (102→255) not taken.
|
1 | algo->SetConfigFile(configDir + "/my_z_vertex_cuts.yaml"); |
73 |
1/2✓ Branch 0 (108→109) taken 1 times.
✗ Branch 1 (108→311) not taken.
|
1 | algo->Start(); |
74 |
1/2✓ Branch 0 (109→110) taken 1 times.
✗ Branch 1 (109→311) not taken.
|
1 | auto key = algo->PrepareEvent(5500); |
75 |
3/6✓ Branch 0 (110→111) taken 1 times.
✗ Branch 1 (110→311) not taken.
✓ Branch 2 (111→112) taken 1 times.
✗ Branch 3 (111→261) not taken.
✗ Branch 4 (112→113) not taken.
✓ Branch 5 (112→114) taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -0.8)); |
76 |
3/6✓ Branch 0 (117→118) taken 1 times.
✗ Branch 1 (117→311) not taken.
✓ Branch 2 (118→119) taken 1 times.
✗ Branch 3 (118→265) not taken.
✗ Branch 4 (119→120) not taken.
✓ Branch 5 (119→121) 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 (125→126) taken 1 times.
✗ Branch 1 (125→311) not taken.
|
1 | algo->SetConfigDirectory(configDir); |
85 |
2/4✓ Branch 0 (126→127) taken 1 times.
✗ Branch 1 (126→311) not taken.
✓ Branch 2 (127→128) taken 1 times.
✗ Branch 3 (127→269) not taken.
|
1 | algo->SetConfigFile("my_z_vertex_cuts.yaml"); |
86 |
1/2✓ Branch 0 (133→134) taken 1 times.
✗ Branch 1 (133→311) not taken.
|
1 | algo->Start(); |
87 |
1/2✓ Branch 0 (134→135) taken 1 times.
✗ Branch 1 (134→311) not taken.
|
1 | auto key = algo->PrepareEvent(0); // run number "0" means "no run number" |
88 |
3/6✓ Branch 0 (135→136) taken 1 times.
✗ Branch 1 (135→311) not taken.
✓ Branch 2 (136→137) taken 1 times.
✗ Branch 3 (136→275) not taken.
✗ Branch 4 (137→138) not taken.
✓ Branch 5 (137→139) taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -1.5)); |
89 |
3/6✓ Branch 0 (142→143) taken 1 times.
✗ Branch 1 (142→311) not taken.
✓ Branch 2 (143→144) taken 1 times.
✗ Branch 3 (143→279) not taken.
✗ Branch 4 (144→145) not taken.
✓ Branch 5 (144→146) 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 (150→151) taken 1 times.
✗ Branch 1 (150→311) not taken.
✓ Branch 2 (151→152) taken 1 times.
✗ Branch 3 (151→283) not taken.
|
1 | algo->SetConfigDirectory(configDir + "/my_config_directory"); |
100 |
1/2✓ Branch 0 (157→158) taken 1 times.
✗ Branch 1 (157→311) not taken.
|
1 | algo->Start(); |
101 |
1/2✓ Branch 0 (158→159) taken 1 times.
✗ Branch 1 (158→311) not taken.
|
1 | auto key = algo->PrepareEvent(0); // run number "0" means "no run number" |
102 |
3/6✓ Branch 0 (159→160) taken 1 times.
✗ Branch 1 (159→311) not taken.
✓ Branch 2 (160→161) taken 1 times.
✗ Branch 3 (160→289) not taken.
✗ Branch 4 (161→162) not taken.
✓ Branch 5 (161→163) taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -15.0)); |
103 |
3/6✓ Branch 0 (166→167) taken 1 times.
✗ Branch 1 (166→311) not taken.
✓ Branch 2 (167→168) taken 1 times.
✗ Branch 3 (167→293) not taken.
✗ Branch 4 (168→169) not taken.
✓ Branch 5 (168→170) 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 (174→175) taken 1 times.
✗ Branch 1 (174→311) not taken.
|
1 | algo->SetConfigDirectory(configDir); |
111 |
2/4✓ Branch 0 (175→176) taken 1 times.
✗ Branch 1 (175→311) not taken.
✓ Branch 2 (176→177) taken 1 times.
✗ Branch 3 (176→297) not taken.
|
1 | algo->SetConfigFile("my_combined_config_file.yaml"); |
112 |
1/2✓ Branch 0 (182→183) taken 1 times.
✗ Branch 1 (182→311) not taken.
|
1 | algo->Start(); |
113 |
1/2✓ Branch 0 (183→184) taken 1 times.
✗ Branch 1 (183→311) not taken.
|
1 | auto key = algo->PrepareEvent(0); // run number "0" means "no run number" |
114 |
3/6✓ Branch 0 (184→185) taken 1 times.
✗ Branch 1 (184→311) not taken.
✓ Branch 2 (185→186) taken 1 times.
✗ Branch 3 (185→303) not taken.
✗ Branch 4 (186→187) not taken.
✓ Branch 5 (186→188) taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -33.0)); |
115 |
3/8✓ Branch 0 (191→192) taken 1 times.
✗ Branch 1 (191→311) not taken.
✓ Branch 2 (192→193) taken 1 times.
✗ Branch 3 (192→307) not taken.
✗ Branch 4 (193→194) not taken.
✓ Branch 5 (193→195) taken 1 times.
✗ Branch 6 (311→312) not taken.
✗ Branch 7 (311→314) 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 (199→200) taken 6 times.
✗ Branch 1 (199→311) not taken.
|
6 | algo->Stop(); |
127 | } | ||
128 | |||
129 | return 0; | ||
130 | } | ||
131 |