Iguana 0.0.0
Implementation Guardian of Analysis Algorithms
Loading...
Searching...
No Matches
iguana_ex_cpp_config_files.cc
Go to the documentation of this file.
1#include <cassert>
2#include <iguana/algorithms/clas12/ZVertexFilter/Algorithm.h>
3
21
23int main(int argc, char** argv)
24{
25
26 // parse arguments
27 std::string configDir;
28 if(argc > 1)
29 configDir = std::string(argv[1]);
30 else
32 fmt::print("Using top-level configuration directory {}\n", configDir);
33
34 // loop over multiple examples how to use configuration files and set options
35 for(int example = 1; example <= 6; example++) {
36 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 auto algo = std::make_unique<iguana::clas12::ZVertexFilter>();
40 algo->SetLogLevel("debug");
41
42 switch(example) {
43
44 case 1:
45 {
46 // Use the default configuration, from `../src/iguana/algorithms/clas12/ZVertexFilter.yaml`
47 algo->Start();
48 auto key = algo->PrepareEvent(4800); // sets the run number and loads the cuts
49 assert((algo->GetRunNum(key) == 4800)); // pass the key into the 'Get*' methods
50 assert((algo->GetElectronZcuts(key).at(0) == -13.0));
51 assert((algo->GetElectronZcuts(key).at(1) == 12.0));
52 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 algo->Start();
62 iguana::concurrent_key_t const key = 0; // need the same key in `SetElectronZcuts` and `GetElectronZcuts`
63 algo->SetElectronZcuts(-5.0, 3.0, key);
64 assert((algo->GetElectronZcuts(key).at(0) == -5.0));
65 assert((algo->GetElectronZcuts(key).at(1) == 3.0));
66 break;
67 }
68
69 case 3:
70 {
71 // Use a specific configuration file
72 algo->SetConfigFile(configDir + "/my_z_vertex_cuts.yaml");
73 algo->Start();
74 auto key = algo->PrepareEvent(5500);
75 assert((algo->GetElectronZcuts(key).at(0) == -0.8));
76 assert((algo->GetElectronZcuts(key).at(1) == 0.7));
77 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 algo->SetConfigDirectory(configDir);
85 algo->SetConfigFile("my_z_vertex_cuts.yaml");
86 algo->Start();
87 auto key = algo->PrepareEvent(0); // run number "0" means "no run number"
88 assert((algo->GetElectronZcuts(key).at(0) == -1.5));
89 assert((algo->GetElectronZcuts(key).at(1) == 1.3));
90 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 algo->SetConfigDirectory(configDir + "/my_config_directory");
100 algo->Start();
101 auto key = algo->PrepareEvent(0); // run number "0" means "no run number"
102 assert((algo->GetElectronZcuts(key).at(0) == -15.0));
103 assert((algo->GetElectronZcuts(key).at(1) == 15.0));
104 break;
105 }
106
107 case 6:
108 {
109 // Use a single, combined configuration file; each algorithm's options are in a separate section
110 algo->SetConfigDirectory(configDir);
111 algo->SetConfigFile("my_combined_config_file.yaml");
112 algo->Start();
113 auto key = algo->PrepareEvent(0); // run number "0" means "no run number"
114 assert((algo->GetElectronZcuts(key).at(0) == -33.0));
115 assert((algo->GetElectronZcuts(key).at(1) == 11.0));
116 break;
117 }
118
119 default:
120 {
121 fmt::print(stderr, "ERROR: unknown example number '{}'\n", example);
122 return 1;
123 }
124 }
125
126 algo->Stop();
127 }
128
129 return 0;
130}
static std::string GetConfigInstallationPrefix()
static std::string Header(std::string_view message, int const width=50)
int main(int argc, char **argv)
main function
std::size_t concurrent_key_t
concurrent hash key type