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→312) 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 (199→30) taken 6 times.
✓ Branch 1 (199→200) 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→230) not taken.
✗ Branch 4 (41→42) not taken.
✓ Branch 5 (41→44) taken 6 times.
✗ Branch 6 (312→313) not taken.
✗ Branch 7 (312→315) 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→312) not taken.
|
6 | auto algo = std::make_unique<iguana::clas12::ZVertexFilter>(); |
40 |
1/2✓ Branch 0 (62→63) taken 6 times.
✗ Branch 1 (62→308) not taken.
|
6 | algo->SetLogLevel("debug"); |
41 | |||
42 |
6/6✓ Branch 0 (63→64) taken 1 times.
✓ Branch 1 (63→81) taken 1 times.
✓ Branch 2 (63→98) taken 1 times.
✓ Branch 3 (63→122) taken 1 times.
✓ Branch 4 (63→147) taken 1 times.
✓ Branch 5 (63→171) 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→308) not taken.
|
1 | algo->Start(); |
48 |
1/2✓ Branch 0 (65→66) taken 1 times.
✗ Branch 1 (65→308) 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→308) 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 |
7/18✓ Branch 0 (69→70) taken 1 times.
✗ Branch 1 (69→308) not taken.
✓ Branch 2 (70→71) taken 1 times.
✗ Branch 3 (70→240) not taken.
✓ Branch 4 (71→72) taken 1 times.
✗ Branch 5 (71→240) not taken.
✓ Branch 6 (72→73) taken 1 times.
✗ Branch 7 (72→236) not taken.
✓ Branch 8 (73→74) taken 1 times.
✗ Branch 9 (73→236) not taken.
✓ Branch 10 (74→75) taken 1 times.
✗ Branch 11 (74→77) not taken.
✓ Branch 12 (77→78) taken 1 times.
✗ Branch 13 (77→80) not taken.
✗ Branch 14 (236→237) not taken.
✗ Branch 15 (236→239) not taken.
✗ Branch 16 (240→241) not taken.
✗ Branch 17 (240→243) not taken.
|
2 | fmt::println("Z-vertex cuts: {} to {}", algo->GetElectronZcuts(key).at(0), algo->GetElectronZcuts(key).at(1)); |
51 | 1 | break; | |
52 | } | ||
53 | |||
54 | case 2: | ||
55 | { | ||
56 | // Use `SetElectronZcuts` to set the cuts | ||
57 | // - note that this will OVERRIDE any value used in any configuration file | ||
58 | // - only use `SetElectronZcuts` if for any reason you want to hard-code a specific value; usage | ||
59 | // of configuration files is preferred in general | ||
60 |
1/2✓ Branch 0 (81→82) taken 1 times.
✗ Branch 1 (81→308) not taken.
|
1 | algo->Start(); |
61 | iguana::concurrent_key_t const key = 0; // need the same key in `SetElectronZcuts` and `GetElectronZcuts` | ||
62 |
1/2✓ Branch 0 (82→83) taken 1 times.
✗ Branch 1 (82→308) not taken.
|
1 | algo->SetElectronZcuts(-5.0, 3.0, key); |
63 |
3/6✓ Branch 0 (83→84) taken 1 times.
✗ Branch 1 (83→308) not taken.
✓ Branch 2 (84→85) taken 1 times.
✗ Branch 3 (84→244) not taken.
✗ Branch 4 (85→86) not taken.
✓ Branch 5 (85→87) taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -5.0)); |
64 |
3/6✓ Branch 0 (90→91) taken 1 times.
✗ Branch 1 (90→308) not taken.
✓ Branch 2 (91→92) taken 1 times.
✗ Branch 3 (91→248) not taken.
✗ Branch 4 (92→93) not taken.
✓ Branch 5 (92→94) taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(1) == 3.0)); |
65 | 1 | break; | |
66 | } | ||
67 | |||
68 | case 3: | ||
69 | { | ||
70 | // Use a specific configuration file | ||
71 |
2/4✓ Branch 0 (98→99) taken 1 times.
✗ Branch 1 (98→308) not taken.
✓ Branch 2 (99→100) taken 1 times.
✗ Branch 3 (99→252) not taken.
|
1 | algo->SetConfigFile(configDir + "/my_z_vertex_cuts.yaml"); |
72 |
1/2✓ Branch 0 (105→106) taken 1 times.
✗ Branch 1 (105→308) not taken.
|
1 | algo->Start(); |
73 |
1/2✓ Branch 0 (106→107) taken 1 times.
✗ Branch 1 (106→308) not taken.
|
1 | auto key = algo->PrepareEvent(5500); |
74 |
3/6✓ Branch 0 (107→108) taken 1 times.
✗ Branch 1 (107→308) not taken.
✓ Branch 2 (108→109) taken 1 times.
✗ Branch 3 (108→258) not taken.
✗ Branch 4 (109→110) not taken.
✓ Branch 5 (109→111) taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -0.8)); |
75 |
3/6✓ Branch 0 (114→115) taken 1 times.
✗ Branch 1 (114→308) not taken.
✓ Branch 2 (115→116) taken 1 times.
✗ Branch 3 (115→262) not taken.
✗ Branch 4 (116→117) not taken.
✓ Branch 5 (116→118) taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(1) == 0.7)); |
76 | 1 | break; | |
77 | } | ||
78 | |||
79 | case 4: | ||
80 | { | ||
81 | // Use the same specific configuration file, but don't set a run number; | ||
82 | // note also the usage of `SetConfigDirectory`, as another example how to set a specific configuration file | ||
83 |
1/2✓ Branch 0 (122→123) taken 1 times.
✗ Branch 1 (122→308) not taken.
|
1 | algo->SetConfigDirectory(configDir); |
84 |
2/4✓ Branch 0 (123→124) taken 1 times.
✗ Branch 1 (123→308) not taken.
✓ Branch 2 (124→125) taken 1 times.
✗ Branch 3 (124→266) not taken.
|
1 | algo->SetConfigFile("my_z_vertex_cuts.yaml"); |
85 |
1/2✓ Branch 0 (130→131) taken 1 times.
✗ Branch 1 (130→308) not taken.
|
1 | algo->Start(); |
86 |
1/2✓ Branch 0 (131→132) taken 1 times.
✗ Branch 1 (131→308) not taken.
|
1 | auto key = algo->PrepareEvent(0); // run number "0" means "no run number" |
87 |
3/6✓ Branch 0 (132→133) taken 1 times.
✗ Branch 1 (132→308) not taken.
✓ Branch 2 (133→134) taken 1 times.
✗ Branch 3 (133→272) not taken.
✗ Branch 4 (134→135) not taken.
✓ Branch 5 (134→136) taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -1.5)); |
88 |
3/6✓ Branch 0 (139→140) taken 1 times.
✗ Branch 1 (139→308) not taken.
✓ Branch 2 (140→141) taken 1 times.
✗ Branch 3 (140→276) not taken.
✗ Branch 4 (141→142) not taken.
✓ Branch 5 (141→143) taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(1) == 1.3)); |
89 | 1 | break; | |
90 | } | ||
91 | |||
92 | case 5: | ||
93 | { | ||
94 | // Use a custom directory of configuration files; if a configuration file within | ||
95 | // has the same path and name as the default (`ZVertexFilter.yaml`), it will be used instead of the default. | ||
96 | // This is designed such that if you copy the full installed configuration directory to a new location, you | ||
97 | // may use that directory instead of the default, and modify any configuration file within. | ||
98 |
2/4✓ Branch 0 (147→148) taken 1 times.
✗ Branch 1 (147→308) not taken.
✓ Branch 2 (148→149) taken 1 times.
✗ Branch 3 (148→280) not taken.
|
1 | algo->SetConfigDirectory(configDir + "/my_config_directory"); |
99 |
1/2✓ Branch 0 (154→155) taken 1 times.
✗ Branch 1 (154→308) not taken.
|
1 | algo->Start(); |
100 |
1/2✓ Branch 0 (155→156) taken 1 times.
✗ Branch 1 (155→308) not taken.
|
1 | auto key = algo->PrepareEvent(0); // run number "0" means "no run number" |
101 |
3/6✓ Branch 0 (156→157) taken 1 times.
✗ Branch 1 (156→308) not taken.
✓ Branch 2 (157→158) taken 1 times.
✗ Branch 3 (157→286) not taken.
✗ Branch 4 (158→159) not taken.
✓ Branch 5 (158→160) taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -15.0)); |
102 |
3/6✓ Branch 0 (163→164) taken 1 times.
✗ Branch 1 (163→308) not taken.
✓ Branch 2 (164→165) taken 1 times.
✗ Branch 3 (164→290) not taken.
✗ Branch 4 (165→166) not taken.
✓ Branch 5 (165→167) taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(1) == 15.0)); |
103 | 1 | break; | |
104 | } | ||
105 | |||
106 | case 6: | ||
107 | { | ||
108 | // Use a single, combined configuration file; each algorithm's options are in a separate section | ||
109 |
1/2✓ Branch 0 (171→172) taken 1 times.
✗ Branch 1 (171→308) not taken.
|
1 | algo->SetConfigDirectory(configDir); |
110 |
2/4✓ Branch 0 (172→173) taken 1 times.
✗ Branch 1 (172→308) not taken.
✓ Branch 2 (173→174) taken 1 times.
✗ Branch 3 (173→294) not taken.
|
1 | algo->SetConfigFile("my_combined_config_file.yaml"); |
111 |
1/2✓ Branch 0 (179→180) taken 1 times.
✗ Branch 1 (179→308) not taken.
|
1 | algo->Start(); |
112 |
1/2✓ Branch 0 (180→181) taken 1 times.
✗ Branch 1 (180→308) not taken.
|
1 | auto key = algo->PrepareEvent(0); // run number "0" means "no run number" |
113 |
3/6✓ Branch 0 (181→182) taken 1 times.
✗ Branch 1 (181→308) not taken.
✓ Branch 2 (182→183) taken 1 times.
✗ Branch 3 (182→300) not taken.
✗ Branch 4 (183→184) not taken.
✓ Branch 5 (183→185) taken 1 times.
|
1 | assert((algo->GetElectronZcuts(key).at(0) == -33.0)); |
114 |
3/8✓ Branch 0 (188→189) taken 1 times.
✗ Branch 1 (188→308) not taken.
✓ Branch 2 (189→190) taken 1 times.
✗ Branch 3 (189→304) not taken.
✗ Branch 4 (190→191) not taken.
✓ Branch 5 (190→192) taken 1 times.
✗ Branch 6 (308→309) not taken.
✗ Branch 7 (308→311) not taken.
|
1 | assert((algo->GetElectronZcuts(key).at(1) == 11.0)); |
115 | 1 | break; | |
116 | } | ||
117 | |||
118 | default: | ||
119 | { | ||
120 | fmt::print(stderr, "ERROR: unknown example number '{}'\n", example); | ||
121 | return 1; | ||
122 | } | ||
123 | } | ||
124 | |||
125 |
1/2✓ Branch 0 (196→197) taken 6 times.
✗ Branch 1 (196→308) not taken.
|
6 | algo->Stop(); |
126 | } | ||
127 | |||
128 | return 0; | ||
129 | } | ||
130 |