Iguana 1.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 // Use the default configuration, from `../src/iguana/algorithms/clas12/ZVertexFilter.yaml`
46 algo->Start();
47 auto key = algo->PrepareEvent(4800); // sets the run number and loads the cuts
48 assert((algo->GetRunNum(key) == 4800)); // pass the key into the 'Get*' methods
49 fmt::println("Z-vertex cuts: {} to {}", algo->GetElectronZcuts(key).at(0), algo->GetElectronZcuts(key).at(1));
50 break;
51 }
52
53 case 2: {
54 // Use `SetElectronZcuts` to set the cuts
55 // - note that this will OVERRIDE any value used in any configuration file
56 // - only use `SetElectronZcuts` if for any reason you want to hard-code a specific value; usage
57 // of configuration files is preferred in general
58 algo->Start();
59 iguana::concurrent_key_t const key = 0; // need the same key in `SetElectronZcuts` and `GetElectronZcuts`
60 algo->SetElectronZcuts(-5.0, 3.0, key);
61 assert((algo->GetElectronZcuts(key).at(0) == -5.0));
62 assert((algo->GetElectronZcuts(key).at(1) == 3.0));
63 break;
64 }
65
66 case 3: {
67 // Use a specific configuration file
68 algo->SetConfigFile(configDir + "/my_z_vertex_cuts.yaml");
69 algo->Start();
70 auto key = algo->PrepareEvent(5500);
71 assert((algo->GetElectronZcuts(key).at(0) == -0.8));
72 assert((algo->GetElectronZcuts(key).at(1) == 0.7));
73 break;
74 }
75
76 case 4: {
77 // Use the same specific configuration file, but don't set a run number;
78 // note also the usage of `SetConfigDirectory`, as another example how to set a specific configuration file
79 algo->SetConfigDirectory(configDir);
80 algo->SetConfigFile("my_z_vertex_cuts.yaml");
81 algo->Start();
82 auto key = algo->PrepareEvent(0); // run number "0" means "no run number"
83 assert((algo->GetElectronZcuts(key).at(0) == -1.5));
84 assert((algo->GetElectronZcuts(key).at(1) == 1.3));
85 break;
86 }
87
88 case 5: {
89 // Use a custom directory of configuration files; if a configuration file within
90 // has the same path and name as the default (`ZVertexFilter.yaml`), it will be used instead of the default.
91 // This is designed such that if you copy the full installed configuration directory to a new location, you
92 // may use that directory instead of the default, and modify any configuration file within.
93 algo->SetConfigDirectory(configDir + "/my_config_directory");
94 algo->Start();
95 auto key = algo->PrepareEvent(0); // run number "0" means "no run number"
96 assert((algo->GetElectronZcuts(key).at(0) == -15.0));
97 assert((algo->GetElectronZcuts(key).at(1) == 15.0));
98 break;
99 }
100
101 case 6: {
102 // Use a single, combined configuration file; each algorithm's options are in a separate section
103 algo->SetConfigDirectory(configDir);
104 algo->SetConfigFile("my_combined_config_file.yaml");
105 algo->Start();
106 auto key = algo->PrepareEvent(0); // run number "0" means "no run number"
107 assert((algo->GetElectronZcuts(key).at(0) == -33.0));
108 assert((algo->GetElectronZcuts(key).at(1) == 11.0));
109 break;
110 }
111
112 default: {
113 fmt::print(stderr, "ERROR: unknown example number '{}'\n", example);
114 return 1;
115 }
116 }
117
118 algo->Stop();
119 }
120
121 return 0;
122}
static std::string GetConfigInstallationPrefix()
static std::string Header(std::string_view message, int const width=50)
int main(int argc, char **argv)
main function