43auto main(
int argc,
char** argv) ->
int
45 auto timer = TStopwatch{};
49 auto help = programOptions.create_option<
bool>(
"help,h",
"help message",
false);
50 auto enable_mille = programOptions.create_option<
bool>(
"mille",
"enable millepede",
false);
51 auto logLevel = programOptions.create_option<std::string>(
"logLevel,v",
"set log level of fairlog",
"info");
52 auto input_file = programOptions.create_option<std::string>(
"in,i",
"set the input files (regex)");
53 auto input_par = programOptions.create_option<std::string>(
"in-par,p",
"set the input parameter");
54 auto output_file = programOptions.create_option<std::string>(
"out,o",
"set the output file");
55 auto event_num = programOptions.create_option<
int>(
"eventNum,n",
"set the event number",
DEFAULT_EVENT_NUM);
57 programOptions.create_option<
int>(
"min-stat,m",
"set minimun statistics for calibration",
DEFAULT_MIN_STAT);
58 auto run_num = programOptions.create_option<
int>(
"runNum,r",
"set the number of runs", 1);
61 auto disable_task = programOptions.create_option<
bool>(
"no-map2cal",
"disable MapToCal task",
false);
63 if (!programOptions.verify(argc, argv))
68 FairLogger::GetLogger()->SetLogScreenLevel(logLevel().c_str());
71 const auto outputfile_path = fs::path{ output_file() };
72 const auto outputParFileName =
73 outputDir / fmt::format(
"{}.par{}", outputfile_path.stem().string(), outputfile_path.extension().string());
76 R3BLOG(debug, fmt::format(
"input data file: {}", fmt::join(input_filenames,
";")).c_str());
77 R3BLOG(debug, fmt::format(
"input data par file: {}", input_par()).c_str());
78 R3BLOG(debug, fmt::format(
"output data file: {}", output_file()).c_str());
79 R3BLOG(debug, fmt::format(
"output data par file: {}", outputParFileName).c_str());
81 auto source = std::make_unique<R3BFileSource2>();
82 for (
const auto& filename : input_filenames)
84 source->AddFile(filename);
88 auto sink = std::make_unique<FairRootFileSink>(sinkFile.release());
90 auto run = std::make_unique<FairRunAna>();
92 FairRootManager::SetTreeName(
"evt");
96 auto EvntHeader = std::make_unique<R3BEventHeader>();
97 run->SetEventHeader(EvntHeader.release());
98 run->SetSource(source.release());
99 run->SetSink(sink.release());
103 if (not disable_task.value())
105 auto runIdTask = std::make_unique<R3BEventHeaderPropagator>();
106 run->AddTask(runIdTask.release());
107 auto map2Cal = std::make_unique<R3B::Neuland::Map2CalTask>();
109 run->AddTask(map2Cal.release());
112 auto cal2hit_method =
114 auto cal2hitParTask = std::make_unique<R3B::Neuland::Cal2HitParTask>(cal2hit_method);
115 auto* cal2hitParTaskPtr = cal2hitParTask.get();
117 cal2hitParTaskPtr->SetMinStat(min_stat.value());
118 run->AddTask(cal2hitParTask.release());
121 auto* rtdb = run->GetRuntimeDb();
123 auto fileio = std::make_unique<FairParRootFileIo>();
124 fileio->open(input_par().c_str());
125 auto parOut = std::make_unique<FairParRootFileIo>(
true);
126 parOut->open(outputParFileName.c_str());
127 rtdb->setFirstInput(fileio.release());
128 rtdb->setOutput(parOut.release());
138 run->Run(0, event_num.value() <= 0 ? 0 : event_num.value());
142 std::cout <<
"Cal level data written to file " << outputfile_path <<
"\n";
143 std::cout <<
"Cal level parameter written to file " << outputParFileName <<
"\n";
144 std::cout <<
"Macro finished successfully." << std::endl;
145 std::cout <<
"Real time: " << timer.RealTime() <<
"s, CPU time: " << timer.CpuTime() <<
"s" << std::endl;
149 std::cout <<
"A runtime error has occured: \n";
150 std::cerr << ex.what();
155 std::cout <<
"A logic error has occured: \n";
156 std::cerr << ex.what();
159 catch (std::exception& ex)
161 std::cout <<
"A error has occured: \n";
162 std::cerr << ex.what();
167 std::cout <<
"An unrecognized error has occured: \n";
171 auto* sinkfile = run->GetSink();
172 if (sinkfile !=
nullptr)
176 run->GetRuntimeDb()->writeContainers();