R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
neuland_online_monitor.cxx
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2023 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
14#include "R3BException.h"
15#include "R3BNeulandCalCanvas.h"
18#include "R3BNeulandHitCanvas.h"
25#include "R3BUcesbMappingFlag.h"
26#include "ext_h101_raw_nnp_tamex.h"
27#include <FairLogger.h>
28#include <FairParRootFileIo.h>
29#include <FairRunOnline.h>
30#include <FairRuntimeDb.h>
31#include <R3BEventHeader.h>
32#include <R3BLogger.h>
33#include <R3BLosMapped2Cal.h>
34#include <R3BLosProvideTStart.h>
35#include <R3BLosReader.h>
40#include <R3BProgramOptions.h>
41#include <R3BTrloiiTpatReader.h>
42#include <R3BUcesbSource.h>
43#include <R3BUcesbSource2.h>
44#include <R3BUnpackReader.h>
45#include <R3BWhiterabbitMasterReader.h>
46#include <TRandom3.h>
47#include <TStopwatch.h>
48#include <bits/basic_string.h>
49#include <cstddef>
50#include <cstdlib>
51#include <ext_h101_los.h>
52#include <ext_h101_tpat.h>
53#include <ext_h101_unpack.h>
54#include <ext_h101_wrmaster.h>
55
56#include <filesystem>
57#include <iostream>
58#include <memory>
59#include <regex>
60#include <string>
61#include <string_view>
62#include <utility>
63
64namespace fs = std::filesystem;
65
66struct EXT_STR_h101_t
67{
68 EXT_STR_h101_unpack_t unpack;
69 EXT_STR_h101_TPAT_t tpat;
70 EXT_STR_h101_raw_nnp_tamex_onion_t raw_nnp;
71 EXT_STR_h101_LOS_t los;
72 EXT_STR_h101_WRMASTER_t wrmaster;
73};
74
75constexpr int DEFAULT_PORT_NUM = 11000;
76constexpr int DEFAULT_REFRESH_RATE = 1;
77constexpr int DEFAULT_RUNID = 999;
78// constexpr int DEFAULT_OFFSPILL_POS = 14;
79constexpr auto DEFAULT_UNPACKER_PATH = "202205_s509/202205_s509";
80constexpr auto NEULAND_DEFAULT_DOUBLE_PLANE = 13;
81constexpr auto NEULAND_GLOBAL_TIME_OFFSET_NS = -400.;
82
83auto main(int argc, char** argv) -> int
84{
85 using namespace std::string_literals;
86 TStopwatch timer;
87 timer.Start();
88
89 //====================================================================================
90 // Program options:
91 auto programOptions = R3B::ProgramOptions("Online monitor for neuland data");
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");
97 auto parameter_file =
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>(
104 "dp", "set the number of double planes for neuland", NEULAND_DEFAULT_DOUBLE_PLANE);
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);
108 auto port_number =
109 programOptions.create_option<int>("port,p", "set the port number of the output https server", DEFAULT_PORT_NUM);
110
111 if (!programOptions.verify(argc, argv))
112 {
113 return EXIT_FAILURE;
114 }
115
116 FairLogger::GetLogger()->SetLogScreenLevel(logLevel().c_str());
117
118 auto random_gen = TRandom3{};
119 random_gen.SetSeed(0);
120
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;
125 // const auto ntuple_options = "RAW"s;
126 auto const* ucesb_dir = getenv("UCESB_DIR");
127 if (ucesb_dir == nullptr)
128 {
129 R3BLOG(error, "ucesb_dir is not defined!");
130 return 1;
131 }
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();
135
136 const auto lmd_file_path = input_fstream();
137 const auto parFile = parameter_file();
138
139 auto ucesb_command = upexps_exe.string() + " --allow-errors --input-buffer=150Mi"s;
140 ucesb_command = std::regex_replace(ucesb_command, std::regex("//"), "/");
141
142 auto ucesbStruct = EXT_STR_h101{};
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())
147 {
148 source->SetInfiniteRun();
149 }
150
151 //====================================================================================
152 // Adding readers
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)));
159 neulandReader->AddExtraConditions(R3B::UcesbMap::array_fewer);
160 neulandReader->SetMaxNbPlanes(planeNum);
161 neulandReader->SetOnline(true);
162 if (no_trig_neuland())
163 {
164 R3BLOG(info, "Disable NeuLAND trigger times");
165 neulandReader->SetSkipTriggerTimes();
166 }
167 source->AddReader(std::make_unique<R3BWhiterabbitMasterReader>(
168 static_cast<EXT_STR_h101_WRMASTER*>(&ucesbStruct.wrmaster), offsetof(EXT_STR_h101, wrmaster), whiterabbit_id));
169
170 // FairRun:
171 auto* source_ptr = source.get();
172 auto run = FairRunOnline{ source.release() };
173 run.SetRunId(inputRunID());
174 run.ActivateHttpServer(DEFAULT_REFRESH_RATE, port_number());
175 auto EvntHeader = std::make_unique<R3BEventHeader>();
176 run.SetEventHeader(std::move(EvntHeader));
177 run.SetRunId(runID);
178
179 //=====================================================================================
180 // set parameter files:
181 auto fileio = std::make_unique<FairParRootFileIo>(false);
182 fileio->open(parFile.c_str());
183 run.GetRuntimeDb()->setFirstInput(fileio.release());
184
185 //=====================================================================================
186 // add tasks
187 if (not is_cal_disabled.value())
188 {
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());
195
196 auto map2Cal = std::make_unique<R3BNeulandMapped2Cal2>();
197 map2Cal->SetTrigger(R3B::Neuland::CalTrigger::allspill);
198 map2Cal->SetDisableHist();
199 run.AddTask(map2Cal.release());
200 }
201
202 if (not is_hit_disabled.value())
203 {
204 run.AddTask(std::make_unique<R3BLosProvideTStart>().release());
205 auto cal2hit = std::make_unique<R3B::Neuland::Cal2HitTask>();
206 cal2hit->SetTrigger(R3B::Neuland::CalTrigger::allspill);
207 cal2hit->SetGlobalTimeOffset(NEULAND_GLOBAL_TIME_OFFSET_NS);
208 cal2hit->SetDisableHist();
209 run.AddTask(cal2hit.release());
210 }
211
212 auto online_spectra = std::make_unique<R3B::Neuland::OnlineSpectra>();
213 online_spectra->SetRandomGenerator(&random_gen);
214 online_spectra->SetUcesbSource(source_ptr);
215 online_spectra->AddCanvas<R3B::Neuland::EventHeaderCanvas>("EventHeader");
216 online_spectra->AddCanvas<R3B::Neuland::MappedCanvas>("NeulandMapped");
217
218 if (not is_cal_disabled.value())
219 {
220 online_spectra->AddCanvas<R3B::Neuland::CalCanvas>("NeulandCal", R3B::Neuland::CalTrigger::allspill);
221 online_spectra->AddCanvas<R3B::Neuland::TJumpCanvas>("NeulandJumps");
222 }
223
224 if (not is_hit_disabled.value())
225 {
226 online_spectra->AddCanvas<R3B::Neuland::CountRateCanvas>("NeulandCountRate", R3B::Neuland::CalTrigger::all);
227 online_spectra->AddCanvas<R3B::Neuland::HitCanvas>("NeulandHit", R3B::Neuland::CalTrigger::onspill);
228 online_spectra->AddCanvas<R3B::Neuland::HitXYCanvas>("NeulandPlaneXY", R3B::Neuland::CalTrigger::onspill);
229 online_spectra->AddCanvas<R3B::Neuland::HitCosmicCanvas>("NeulandHitCosmics",
231 online_spectra->AddCanvas<R3B::Neuland::TimingCanvas>("NeulandTiming", R3B::Neuland::CalTrigger::onspill);
232 }
233 run.AddTask(online_spectra.release());
234
235 try
236 {
237 run.Init();
238 run.Run(-1, eventNum());
239 }
240 catch (R3B::runtime_error& ex)
241 {
242 std::cout << "A runtime error has occured: \n";
243 std::cerr << ex.what();
244 std::cout << "\n\n";
245 return 0;
246 }
247 catch (R3B::logic_error& ex)
248 {
249 std::cout << "A logic error has occured: \n";
250 std::cerr << ex.what();
251 std::cout << "\n\n";
252 return 0;
253 }
254
255 return 0;
256}
#define R3BLOG(severity, x)
Definition R3BLogger.h:32
struct EXT_STR_h101_t EXT_STR_h101
constexpr auto NEULAND_GLOBAL_TIME_OFFSET_NS
constexpr auto DEFAULT_UNPACKER_PATH
constexpr auto NEULAND_DEFAULT_DOUBLE_PLANE
auto main(int argc, char **argv) -> int
constexpr int DEFAULT_PORT_NUM
constexpr int DEFAULT_RUNID
constexpr int DEFAULT_REFRESH_RATE
EXT_STR_h101_TPAT_t tpat
EXT_STR_h101_WRMASTER_t wrmaster
EXT_STR_h101_raw_nnp_tamex_onion_t raw_nnp
EXT_STR_h101_LOS_t los
EXT_STR_h101_unpack_t unpack