52auto main(
int argc,
char** argv) ->
int
54 using namespace std::string_literals;
55 auto const* ucesb_dir = getenv(
"UCESB_DIR");
62 auto help = programOptions.create_option<
bool>(
"help,h",
"help message",
false);
63 auto logLevel = programOptions.create_option<std::string>(
"logLevel,v",
"set log level of fairlog",
"info");
64 auto no_trig_neuland = programOptions.create_option<
bool>(
"no-trig",
"auto detect trigID",
false);
65 auto input_par = programOptions.create_option<std::string>(
"in-par,p",
"set the input parameter");
66 auto eventNum = programOptions.create_option<
int>(
"eventNum,n",
"set the event number",
DEFAULT_EVENT_NUM);
67 auto input_files = programOptions.create_option<std::string>(
"in,i",
"set the input files");
68 auto output_file = programOptions.create_option<std::string>(
"out,o",
"set the output file");
69 auto inputRunID = programOptions.create_option<
int>(
"runID,r",
"set the input runID",
DEFAULT_RUN_ID);
71 programOptions.create_option<
int>(
"time-stitch,t",
"set time stitch for ucesb",
DEFAULT_TIME_STITCH);
74 auto unpacker_path = programOptions.create_option<std::string>(
76 if (!programOptions.verify(argc, argv))
83 FairLogger::GetLogger()->SetLogScreenLevel(logLevel().c_str());
88 const auto runID = inputRunID.value();
89 const auto outputfile_path = fs::path{ output_file.value() };
92 outputDir / fmt::format(
"{}.par{}", outputfile_path.stem().string(), outputfile_path.extension().string());
94 if (ucesb_dir ==
nullptr)
96 R3BLOG(error,
"ucesb_dir is not defined!");
100 const auto upexps_exe = fs::path{ unpacker_path.value() };
101 const auto ntuple_options =
102 (time_stich.value() > 0) ? fmt::format(
"RAW,time-stitch={}", time_stich.value()) : fmt::format(
"RAW");
103 const auto max_event_num = (eventNum.value() < 0) ? -1 : eventNum.value();
105 auto ucesb_command = upexps_exe.string() +
" --allow-errors --input-buffer=600Mi"s;
107 ucesb_command = std::regex_replace(ucesb_command, std::regex(
"//"),
"/");
110 auto source = std::make_unique<R3BUcesbSource2>(
111 input_files(), ntuple_options, ucesb_command, &ucesbStruct,
sizeof(ucesbStruct));
112 source->SetMaxEvents(max_event_num);
117 source->AddReader<R3BTrloiiTpatReader>(&ucesbStruct.tpat, offsetof(
EXT_STR_h101, tpat));
119 auto* neulandReader =
122 neulandReader->SetMaxNbPlanes(planeNum);
123 if (no_trig_neuland())
125 R3BLOG(info,
"Disable NeuLAND trigger times");
126 neulandReader->SetSkipTriggerTimes();
134 auto run = std::make_unique<FairRunOnline>();
135 run->SetSource(source.release());
136 auto EvntHeader = std::make_unique<R3BEventHeader>();
137 run->SetEventHeader(EvntHeader.release());
138 run->SetRunId(runID);
139 run->SetSink(std::make_unique<FairRootFileSink>(output_file().c_str()));
143 auto* rtdb = run->GetRuntimeDb();
144 auto parIn = std::make_unique<FairParRootFileIo>(
false);
145 auto parOut = std::make_unique<FairParRootFileIo>(
true);
146 parIn->open(input_par().c_str());
147 parOut->open(parfile.c_str());
148 rtdb->setFirstInput(parIn.release());
149 rtdb->setOutput(parOut.release());
154 auto calPar = std::make_unique<R3B::Neuland::Map2CalParTask>();
157 calPar->SetTrigEnabled(not no_trig_neuland.value());
158 calPar->SetErrorMethod(R3B::Neuland::Map2CalParTask::ErrorMethod::approx);
160 calPar->SetTrigIDMapAutoFind(
false);
161 calPar->SetTrigIDMapDir(outputDir.string());
163 run->AddTask(calPar.release());
170 run->Run(-1, eventNum());
171 std::cout <<
"Analysis finished succesfully.\n";
172 std::cout <<
"Output file is " << output_file() <<
"\n";
175 const double rtime = timer.RealTime();
176 const double ctime = timer.CpuTime();
177 std::cout <<
"Real time " << rtime <<
" s, CPU time " << ctime <<
" s\n";
179 catch (fair::FatalException& ex)
181 std::cerr << ex.What();
184 catch (std::runtime_error& ex)
186 std::cout <<
"A runtime error has occured: \n";
187 std::cerr << ex.what();
190 catch (std::logic_error& ex)
192 std::cout <<
"A logic error has occured: \n";
193 std::cerr << ex.what();
198 std::cout <<
"A unrecognised error has occured! \n";
202 auto* sinkfile = run->GetSink();
203 if (sinkfile !=
nullptr)