Iguana 0.9.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 fmt::println("Z-vertex cuts: {} to {}", algo->GetElectronZcuts(key).at(0), algo->GetElectronZcuts(key).at(1));
51 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 algo->Start();
61 iguana::concurrent_key_t const key = 0; // need the same key in `SetElectronZcuts` and `GetElectronZcuts`
62 algo->SetElectronZcuts(-5.0, 3.0, key);
63 assert((algo->GetElectronZcuts(key).at(0) == -5.0));
64 assert((algo->GetElectronZcuts(key).at(1) == 3.0));
65 break;
66 }
67
68 case 3:
69 {
70 // Use a specific configuration file
71 algo->SetConfigFile(configDir + "/my_z_vertex_cuts.yaml");
72 algo->Start();
73 auto key = algo->PrepareEvent(5500);
74 assert((algo->GetElectronZcuts(key).at(0) == -0.8));
75 assert((algo->GetElectronZcuts(key).at(1) == 0.7));
76 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 algo->SetConfigDirectory(configDir);
84 algo->SetConfigFile("my_z_vertex_cuts.yaml");
85 algo->Start();
86 auto key = algo->PrepareEvent(0); // run number "0" means "no run number"
87 assert((algo->GetElectronZcuts(key).at(0) == -1.5));
88 assert((algo->GetElectronZcuts(key).at(1) == 1.3));
89 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 algo->SetConfigDirectory(configDir + "/my_config_directory");
99 algo->Start();
100 auto key = algo->PrepareEvent(0); // run number "0" means "no run number"
101 assert((algo->GetElectronZcuts(key).at(0) == -15.0));
102 assert((algo->GetElectronZcuts(key).at(1) == 15.0));
103 break;
104 }
105
106 case 6:
107 {
108 // Use a single, combined configuration file; each algorithm's options are in a separate section
109 algo->SetConfigDirectory(configDir);
110 algo->SetConfigFile("my_combined_config_file.yaml");
111 algo->Start();
112 auto key = algo->PrepareEvent(0); // run number "0" means "no run number"
113 assert((algo->GetElectronZcuts(key).at(0) == -33.0));
114 assert((algo->GetElectronZcuts(key).at(1) == 11.0));
115 break;
116 }
117
118 default:
119 {
120 fmt::print(stderr, "ERROR: unknown example number '{}'\n", example);
121 return 1;
122 }
123 }
124
125 algo->Stop();
126 }
127
128 return 0;
129}
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