83auto main(
int argc,
char** argv) ->
int
85 using namespace std::string_literals;
92 auto help = programOptions.create_option<
bool>(
"help,h",
"help message",
false);
93 auto is_cal_disabled = programOptions.create_option<
bool>(
"dis-cal",
"disable cal level analysis",
false);
94 auto is_hit_disabled = programOptions.create_option<
bool>(
"dis-hit",
"disable hit level analysis",
false);
95 auto is_infinite_run = programOptions.create_option<
bool>(
"infi",
"set to infinite run",
false);
96 auto input_fstream = programOptions.create_option<std::string>(
"inStream,i",
"set the input data stream");
98 programOptions.create_option<std::string>(
"par",
"set the path of the parameter file (only one allowed)");
99 auto no_trig_neuland = programOptions.create_option<
bool>(
"no-trig",
"NeuLAND trigger times are disabled",
false);
100 auto logLevel = programOptions.create_option<std::string>(
"logLevel,v",
"set log level of fairlog",
"info");
101 auto eventNum = programOptions.create_option<
int>(
"eventNum,n",
"set the event number", -1);
102 auto inputRunID = programOptions.create_option<
int>(
"runID,r",
"set the input runID",
DEFAULT_RUNID);
103 auto neulandDP = programOptions.create_option<
int>(
105 auto wr_ID = programOptions.create_option<std::string>(
"wrID",
"set the white rabbit id",
"0x1000U");
106 auto unpacker_path = programOptions.create_option<std::string>(
107 "unpack",
"set the path of unpacker executable relative to ${UCESB_DIR}/../unexps/",
DEFAULT_UNPACKER_PATH);
109 programOptions.create_option<
int>(
"port,p",
"set the port number of the output https server",
DEFAULT_PORT_NUM);
111 if (!programOptions.verify(argc, argv))
116 FairLogger::GetLogger()->SetLogScreenLevel(logLevel().c_str());
118 auto random_gen = TRandom3{};
119 random_gen.SetSeed(0);
121 const auto whiterabbit_id = std::stoi(wr_ID(),
nullptr, 16);
122 const int planeNum = neulandDP() * 2;
123 const auto runID = inputRunID();
124 const auto ntuple_options =
"RAW,time-stitch=4000"s;
126 auto const* ucesb_dir = getenv(
"UCESB_DIR");
127 if (ucesb_dir ==
nullptr)
129 R3BLOG(error,
"ucesb_dir is not defined!");
132 const auto upexps_dir = std::string{ ucesb_dir } +
"/../upexps"s;
133 const auto upexps_exe = fs::path{ upexps_dir } / unpacker_path();
134 const auto max_event_num = (eventNum() == 0) ? -1 : eventNum();
136 const auto lmd_file_path = input_fstream();
137 const auto parFile = parameter_file();
139 auto ucesb_command = upexps_exe.string() +
" --allow-errors --input-buffer=150Mi"s;
140 ucesb_command = std::regex_replace(ucesb_command, std::regex(
"//"),
"/");
143 auto source = std::make_unique<R3BUcesbSource2>(
144 lmd_file_path, ntuple_options, ucesb_command, &ucesbStruct,
sizeof(ucesbStruct));
145 source->SetMaxEvents(max_event_num);
146 if (is_infinite_run.value())
148 source->SetInfiniteRun();
153 source->AddReader(std::make_unique<R3BUnpackReader>(&ucesbStruct.unpack, offsetof(
EXT_STR_h101, unpack)));
154 source->AddReader(std::make_unique<R3BTrloiiTpatReader>(&ucesbStruct.tpat, offsetof(
EXT_STR_h101, tpat)));
155 auto* los_reader = source->AddReader(std::make_unique<R3BLosReader>(&ucesbStruct.los, offsetof(
EXT_STR_h101, los)));
156 los_reader->SetOnline(
true);
157 auto* neulandReader = source->AddReader(
158 std::make_unique<R3BNeulandTamexReader2>(&ucesbStruct.raw_nnp, offsetof(
EXT_STR_h101, raw_nnp)));
160 neulandReader->SetMaxNbPlanes(planeNum);
161 neulandReader->SetOnline(
true);
162 if (no_trig_neuland())
164 R3BLOG(info,
"Disable NeuLAND trigger times");
165 neulandReader->SetSkipTriggerTimes();
167 source->AddReader(std::make_unique<R3BWhiterabbitMasterReader>(
168 static_cast<EXT_STR_h101_WRMASTER*
>(&ucesbStruct.wrmaster), offsetof(
EXT_STR_h101, wrmaster), whiterabbit_id));
171 auto* source_ptr = source.get();
172 auto run = FairRunOnline{ source.release() };
173 run.SetRunId(inputRunID());
175 auto EvntHeader = std::make_unique<R3BEventHeader>();
176 run.SetEventHeader(std::move(EvntHeader));
181 auto fileio = std::make_unique<FairParRootFileIo>(
false);
182 fileio->open(parFile.c_str());
183 run.GetRuntimeDb()->setFirstInput(fileio.release());
187 if (not is_cal_disabled.value())
189 auto losMapped2Cal = std::make_unique<R3BLosMapped2Cal>(
"LosTCalPar", 1);
190 constexpr auto LOS_MODULE_NUM = 8;
191 losMapped2Cal->SetNofModules(1, LOS_MODULE_NUM);
192 losMapped2Cal->SetTrigger(1);
193 losMapped2Cal->SetOnline(
true);
194 run.AddTask(losMapped2Cal.release());
196 auto map2Cal = std::make_unique<R3BNeulandMapped2Cal2>();
198 map2Cal->SetDisableHist();
199 run.AddTask(map2Cal.release());
202 if (not is_hit_disabled.value())
204 run.AddTask(std::make_unique<R3BLosProvideTStart>().release());
205 auto cal2hit = std::make_unique<R3B::Neuland::Cal2HitTask>();
208 cal2hit->SetDisableHist();
209 run.AddTask(cal2hit.release());
212 auto online_spectra = std::make_unique<R3B::Neuland::OnlineSpectra>();
213 online_spectra->SetRandomGenerator(&random_gen);
214 online_spectra->SetUcesbSource(source_ptr);
218 if (not is_cal_disabled.value())
224 if (not is_hit_disabled.value())
233 run.AddTask(online_spectra.release());
238 run.Run(-1, eventNum());
242 std::cout <<
"A runtime error has occured: \n";
243 std::cerr << ex.what();
249 std::cout <<
"A logic error has occured: \n";
250 std::cerr << ex.what();