45auto main(
int argc,
char** argv) ->
int
47 auto timer = TStopwatch{};
51 auto help = programOptions.create_option<
bool>(
"help,h",
"help message",
false);
52 auto enable_mille = programOptions.create_option<
bool>(
"mille",
"enable millepede",
false);
53 auto logLevel = programOptions.create_option<std::string>(
"logLevel,v",
"set log level of fairlog",
"info");
54 auto input_file = programOptions.create_option<std::string>(
"in,i",
"set the input files (regex)");
55 auto input_par = programOptions.create_option<std::string>(
"in-par,p",
"set the input parameter");
56 auto output_file = programOptions.create_option<std::string>(
"out,o",
"set the output file");
57 auto event_num = programOptions.create_option<
int>(
"eventNum,n",
"set the event number",
DEFAULT_EVENT_NUM);
59 programOptions.create_option<
int>(
"min-stat,m",
"set minimun statistics for calibration",
DEFAULT_MIN_STAT);
60 auto run_num = programOptions.create_option<
int>(
"runNum,r",
"set the number of runs", 1);
63 auto disable_task = programOptions.create_option<
bool>(
"no-map2cal",
"disable MapToCal task",
false);
65 if (!programOptions.verify(argc, argv))
70 FairLogger::GetLogger()->SetLogScreenLevel(logLevel().c_str());
73 const auto outputfile_path = fs::path{ output_file() };
74 const auto outputParFileName =
75 outputDir / fmt::format(
"{}.par{}", outputfile_path.stem().string(), outputfile_path.extension().string());
78 R3BLOG(debug, fmt::format(
"input data file: {}", fmt::join(input_filenames,
";")).c_str());
79 R3BLOG(debug, fmt::format(
"input data par file: {}", input_par()).c_str());
80 R3BLOG(debug, fmt::format(
"output data file: {}", output_file()).c_str());
81 R3BLOG(debug, fmt::format(
"output data par file: {}", outputParFileName).c_str());
83 auto source = std::make_unique<R3BFileSource2>();
84 for (
const auto& filename : input_filenames)
86 source->AddFile(filename);
90 auto sink = std::make_unique<FairRootFileSink>(sinkFile.release());
92 auto run = std::make_unique<FairRunAna>();
94 FairRootManager::SetTreeName(
"evt");
98 auto EvntHeader = std::make_unique<R3BEventHeader>();
99 run->SetEventHeader(EvntHeader.release());
100 run->SetSource(source.release());
101 run->SetSink(sink.release());
105 if (not disable_task.value())
107 auto runIdTask = std::make_unique<R3BEventHeaderPropagator>();
108 run->AddTask(runIdTask.release());
109 auto map2Cal = std::make_unique<R3B::Neuland::Map2CalTask>();
111 run->AddTask(map2Cal.release());
114 auto cal2hit_method =
116 auto cal2hitParTask = std::make_unique<R3B::Neuland::Cal2HitParTask>(cal2hit_method);
117 auto* cal2hitParTaskPtr = cal2hitParTask.get();
119 cal2hitParTaskPtr->SetMinStat(min_stat.value());
120 run->AddTask(cal2hitParTask.release());
123 auto* rtdb = run->GetRuntimeDb();
125 auto fileio = std::make_unique<FairParRootFileIo>();
126 fileio->open(input_par().c_str());
127 auto parOut = std::make_unique<FairParRootFileIo>(
true);
128 parOut->open(outputParFileName.c_str());
129 rtdb->setFirstInput(fileio.release());
130 rtdb->setOutput(parOut.release());
140 run->Run(0, event_num.value() <= 0 ? 0 : event_num.value());
144 std::cout <<
"Cal level data written to file " << outputfile_path <<
"\n";
145 std::cout <<
"Cal level parameter written to file " << outputParFileName <<
"\n";
146 std::cout <<
"Macro finished successfully.\n";
147 std::cout <<
"Real time: " << timer.RealTime() <<
"s, CPU time: " << timer.CpuTime() <<
"s\n";
151 std::cout <<
"A runtime error has occured: \n";
152 std::cerr << ex.what();
157 std::cout <<
"A logic error has occured: \n";
158 std::cerr << ex.what();
161 catch (std::exception& ex)
163 std::cout <<
"A error has occured: \n";
164 std::cerr << ex.what();
169 std::cout <<
"An unrecognized error has occured: \n";
173 auto* sinkfile = run->GetSink();
174 if (sinkfile !=
nullptr)
178 run->GetRuntimeDb()->writeContainers();