MUSIC unknown
Analysis for the MUSIC active-target ionization chamber
Loading...
Searching...
No Matches
main_calibrate_beam.cpp
Go to the documentation of this file.
1#include "CalibrateBeam.hpp"
2#include "Constants.hpp"
3#include <TString.h>
4#include <cstdlib>
5#include <iostream>
6
7// Resolve the epoch from the run number in a file label ("run100_8_c000") and
8// make it active for the run. Without this the tool would calibrate on the flat
9// DatasetConfig while the pipeline uses the epoch's hardware settings, and the
10// two would silently disagree.
11static Bool_t SetEpochFromLabel(const TString &file_label) {
12 if (Constants::cfg.EPOCHS.empty())
13 return kTRUE;
14 // A tagged label ("compass_run37_1") names its epoch outright. Run numbers
15 // repeat across acquisition systems, so the tag is the only thing that
16 // disambiguates them; fall back to the run number only for untagged eras.
17 for (Int_t e = 0; e < Int_t(Constants::cfg.EPOCHS.size()); e++) {
18 const RunEpoch &ep = Constants::cfg.EPOCHS[e];
19 if (ep.file_tag.Length() > 0 && file_label.BeginsWith(ep.file_tag + "_")) {
21 std::cout << "label '" << file_label << "' -> epoch " << ep.name
22 << std::endl;
23 return kTRUE;
24 }
25 }
26 Int_t start = file_label.Index("run");
27 if (start < 0)
28 return kFALSE;
29 Int_t i = start + 3, run = 0, ndig = 0;
30 while (i < file_label.Length() && isdigit(file_label[i])) {
31 run = run * 10 + (file_label[i] - '0');
32 i++;
33 ndig++;
34 }
35 if (ndig == 0)
36 return kFALSE;
37 const RunEpoch *ep = Constants::EpochForRun(run);
38 if (!ep) {
39 std::cerr << "run " << run << " belongs to no declared epoch" << std::endl;
40 return kFALSE;
41 }
43 std::cout << "run " << run << " -> epoch " << ep->name << std::endl;
44 return kTRUE;
45}
46
47int main(int argc, char **argv) {
48 TString file_label = (argc > 1) ? TString(argv[1]) : TString("");
49 if (!Constants::cfg.EPOCHS.empty() && file_label.Length() == 0) {
50 std::cerr << "this dataset declares epochs, so a file label is required "
51 "(e.g. run100_8_c000): the epoch cannot be resolved otherwise"
52 << std::endl;
53 return 1;
54 }
55 if (!SetEpochFromLabel(file_label)) {
56 std::cerr << "cannot resolve an epoch for '" << file_label << "'"
57 << std::endl;
58 return 1;
59 }
60 CalibrateBeam::Run(file_label);
62 return 0;
63}
The dataset configuration, and how it is layered.
static void Run(const TString &file_label="")
Calibrate every configured subfile, then aggregate per run.
int main()
const RunEpoch * EpochForRun(Int_t run)
The epoch owning a run number.
const DatasetConfig & cfg
The active dataset's configuration, flat block.
void SetActiveEpoch(const RunEpoch *epoch)
Set the epoch the Active*() accessors read from.
One acquisition period of a dataset.
Definition RunEpoch.hpp:37
TString name
Epoch name, used in logs and plot paths.
Definition RunEpoch.hpp:38
TString file_tag
Prefix for this epoch's output files and plot directories.
Definition RunEpoch.hpp:49