44auto main(
int argc,
char** argv) ->
int
46 using namespace std::string_literals;
47 auto const* ucesb_dir = getenv(
"UCESB_DIR");
54 auto help = programOptions.create_option<
bool>(
"help,h",
"help message",
false);
55 auto logLevel = programOptions.create_option<std::string>(
"logLevel,v",
"set log level of fairlog",
"info");
56 auto no_trig_neuland = programOptions.create_option<
bool>(
"no-trig",
"auto detect trigID",
false);
57 auto input_par = programOptions.create_option<std::string>(
"in-par,p",
"set the input parameter");
58 auto eventNum = programOptions.create_option<
int>(
"eventNum,n",
"set the event number",
DEFAULT_EVENT_NUM);
59 auto input_files = programOptions.create_option<std::string>(
"in,i",
"set the input files");
60 auto output_file = programOptions.create_option<std::string>(
"out,o",
"set the output file");
61 auto inputRunID = programOptions.create_option<
int>(
"runID,r",
"set the input runID",
DEFAULT_RUN_ID);
63 programOptions.create_option<
int>(
"time-stitch,t",
"set time stitch for ucesb",
DEFAULT_TIME_STITCH);
66 auto unpacker_path = programOptions.create_option<std::string>(
68 if (!programOptions.verify(argc, argv))
75 FairLogger::GetLogger()->SetLogScreenLevel(logLevel().c_str());
80 const auto runID = inputRunID.value();
81 const auto outputfile_path = fs::path{ output_file.value() };
84 outputDir / fmt::format(
"{}.par{}", outputfile_path.stem().string(), outputfile_path.extension().string());
86 if (ucesb_dir ==
nullptr)
88 R3BLOG(error,
"ucesb_dir is not defined!");
91 const auto upexps_dir = std::string{ ucesb_dir } +
"/../upexps"s;
92 const auto upexps_exe = fs::path{ unpacker_path.value() };
93 const auto ntuple_options =
94 (time_stich.value() > 0) ? fmt::format(
"RAW,time-stitch={}", time_stich.value()) : fmt::format(
"RAW");
95 const auto max_event_num = (eventNum.value() < 0) ? -1 : eventNum.value();
97 auto ucesb_command = upexps_exe.string() +
" --allow-errors --input-buffer=600Mi"s;
99 ucesb_command = std::regex_replace(ucesb_command, std::regex(
"//"),
"/");
102 auto source = std::make_unique<R3BUcesbSource2>(
103 input_files(), ntuple_options, ucesb_command, &ucesbStruct,
sizeof(ucesbStruct));
104 source->SetMaxEvents(max_event_num);
109 source->AddReader<R3BTrloiiTpatReader>(&ucesbStruct.tpat, offsetof(
EXT_STR_h101, tpat));
111 auto* neulandReader =
114 neulandReader->SetMaxNbPlanes(planeNum);
115 if (no_trig_neuland())
117 R3BLOG(info,
"Disable NeuLAND trigger times");
118 neulandReader->SetSkipTriggerTimes();
126 auto run = std::make_unique<FairRunOnline>();
127 run->SetSource(source.release());
128 auto EvntHeader = std::make_unique<R3BEventHeader>();
129 run->SetEventHeader(EvntHeader.release());
130 run->SetRunId(runID);
131 run->SetSink(std::make_unique<FairRootFileSink>(output_file().c_str()));
135 auto* rtdb = run->GetRuntimeDb();
136 auto parIn = std::make_unique<FairParRootFileIo>(
false);
137 auto parOut = std::make_unique<FairParRootFileIo>(
true);
138 parIn->open(input_par().c_str());
139 parOut->open(parfile.c_str());
140 rtdb->setFirstInput(parIn.release());
141 rtdb->setOutput(parOut.release());
146 auto calPar = std::make_unique<R3B::Neuland::Map2CalParTask>();
149 calPar->SetTrigEnabled(not no_trig_neuland.value());
150 calPar->SetErrorMethod(R3B::Neuland::Map2CalParTask::ErrorMethod::approx);
152 calPar->SetTrigIDMapAutoFind(
false);
153 calPar->SetTrigIDMapDir(outputDir.string());
155 run->AddTask(calPar.release());
162 run->Run(-1, eventNum());
163 std::cout <<
"Analysis finished succesfully." << std::endl;
164 std::cout <<
"Output file is " << output_file() << std::endl;
167 const double rtime = timer.RealTime();
168 const double ctime = timer.CpuTime();
169 std::cout <<
"Real time " << rtime <<
" s, CPU time " << ctime <<
" s" << std::endl;
171 catch (fair::FatalException& ex)
173 std::cerr << ex.What();
176 catch (std::runtime_error& ex)
178 std::cout <<
"A runtime error has occured: \n";
179 std::cerr << ex.what();
182 catch (std::logic_error& ex)
184 std::cout <<
"A logic error has occured: \n";
185 std::cerr << ex.what();
190 std::cout <<
"A unrecognised error has occured! \n";
194 auto* sinkfile = run->GetSink();
195 if (sinkfile !=
nullptr)