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 <FairParRootFileIo.h>
15#include <FairRootFileSink.h>
16#include <FairRunOnline.h>
17#include <FairRuntimeDb.h>
18#include <R3BEventHeader.h>
20#include <R3BLogger.h>
21#include <R3BLosMapped2Cal.h>
22#include <R3BLosProvideTStart.h>
23#include <R3BLosReader.h>
28#include <R3BProgramOptions.h>
29#include <R3BTrloiiTpatReader.h>
30#include <R3BUcesbSource.h>
31#include <R3BUcesbSource2.h>
32#include <R3BUnpackReader.h>
33#include <R3BWhiterabbitMasterReader.h>
34#include <TROOT.h>
35#include <TRandom3.h>
36#include <TStopwatch.h>
37#include <TSystem.h>
38#include <ext_h101_los.h>
39#include <ext_h101_tpat.h>
40#include <ext_h101_unpack.h>
41#include <ext_h101_wrmaster.h>
42
43#include <filesystem>
44#include <fmt/core.h>
45#include <iostream>
46#include <regex>
47#include <string_view>
48
49namespace fs = std::filesystem;
50
51struct EXT_STR_h101_t
52{
53 EXT_STR_h101_unpack_t unpack;
54 EXT_STR_h101_TPAT_t tpat;
55 EXT_STR_h101_raw_nnp_tamex_onion_t raw_nnp;
56 EXT_STR_h101_LOS_t los;
57 EXT_STR_h101_WRMASTER_t wrmaster;
58};
59
60constexpr int DEFAULT_PORT_NUM = 11000;
61constexpr int DEFAULT_REFRESH_RATE = 1;
62constexpr int DEFAULT_RUNID = 999;
63// constexpr int DEFAULT_OFFSPILL_POS = 14;
64constexpr auto DEFAULT_UNPACKER_PATH = "202205_s509/202205_s509";
65constexpr auto NEULAND_DEFAULT_DOUBLE_PLANE = 13;
66constexpr auto NEULAND_GLOBAL_TIME_OFFSET_NS = -400.;
67
68auto main(int argc, char** argv) -> int
69{
70 using namespace std::string_literals;
71 TStopwatch timer;
72 timer.Start();
73
74 //====================================================================================
75 // Program options:
76 auto programOptions = R3B::ProgramOptions("Online monitor for neuland data");
77 auto help = programOptions.create_option<bool>("help,h", "help message", false);
78 auto is_cal_disabled = programOptions.create_option<bool>("dis-cal", "disable cal level analysis", false);
79 auto is_hit_disabled = programOptions.create_option<bool>("dis-hit", "disable hit level analysis", false);
80 auto is_infinite_run = programOptions.create_option<bool>("infi", "set to infinite run", false);
81 auto input_fstream = programOptions.create_option<std::string>("inStream,i", "set the input data stream");
82 auto parameter_file =
83 programOptions.create_option<std::string>("par", "set the path of the parameter file (only one allowed)");
84 auto no_trig_neuland = programOptions.create_option<bool>("no-trig", "NeuLAND trigger times are disabled", false);
85 auto logLevel = programOptions.create_option<std::string>("logLevel,v", "set log level of fairlog", "info");
86 auto eventNum = programOptions.create_option<int>("eventNum,n", "set the event number", -1);
87 auto inputRunID = programOptions.create_option<int>("runID,r", "set the input runID", DEFAULT_RUNID);
88 auto neulandDP = programOptions.create_option<int>(
89 "dp", "set the number of double planes for neuland", NEULAND_DEFAULT_DOUBLE_PLANE);
90 auto wr_ID = programOptions.create_option<std::string>("wrID", "set the white rabbit id", "0x1000U");
91 auto unpacker_path = programOptions.create_option<std::string>(
92 "unpack", "set the path of unpacker executable relative to ${UCESB_DIR}/../unexps/", DEFAULT_UNPACKER_PATH);
93 auto port_number =
94 programOptions.create_option<int>("port,p", "set the port number of the output https server", DEFAULT_PORT_NUM);
95
96 if (!programOptions.verify(argc, argv))
97 {
98 return EXIT_FAILURE;
99 }
100
101 FairLogger::GetLogger()->SetLogScreenLevel(logLevel().c_str());
102
103 auto random_gen = TRandom3{};
104 random_gen.SetSeed(0);
105
106 const auto whiterabbit_id = std::stoi(wr_ID(), nullptr, 16);
107 const unsigned int planeNum = neulandDP() * 2;
108 const auto runID = inputRunID();
109 const auto ntuple_options = "RAW,time-stitch=4000"s;
110 // const auto ntuple_options = "RAW"s;
111 auto const* ucesb_dir = getenv("UCESB_DIR");
112 if (ucesb_dir == nullptr)
113 {
114 R3BLOG(error, "ucesb_dir is not defined!");
115 return 1;
116 }
117 const auto upexps_dir = std::string{ ucesb_dir } + "/../upexps"s;
118 const auto upexps_exe = fs::path{ upexps_dir } / unpacker_path();
119 const auto max_event_num = (eventNum() == 0) ? -1 : eventNum();
120
121 const auto lmd_file_path = input_fstream();
122 const auto parFile = parameter_file();
123
124 auto ucesb_command = upexps_exe.string() + " --allow-errors --input-buffer=150Mi"s;
125 ucesb_command = std::regex_replace(ucesb_command, std::regex("//"), "/");
126
127 auto ucesbStruct = EXT_STR_h101{};
128 auto source = std::make_unique<R3BUcesbSource2>(
129 lmd_file_path, ntuple_options, ucesb_command, &ucesbStruct, sizeof(ucesbStruct));
130 source->SetMaxEvents(max_event_num);
131 if (is_infinite_run.value())
132 {
133 source->SetInfiniteRun();
134 }
135
136 //====================================================================================
137 // Adding readers
138 source->AddReader(std::make_unique<R3BUnpackReader>(&ucesbStruct.unpack, offsetof(EXT_STR_h101, unpack)));
139 source->AddReader(std::make_unique<R3BTrloiiTpatReader>(&ucesbStruct.tpat, offsetof(EXT_STR_h101, tpat)));
140 auto* los_reader = source->AddReader(std::make_unique<R3BLosReader>(&ucesbStruct.los, offsetof(EXT_STR_h101, los)));
141 los_reader->SetOnline(true);
142 auto* neulandReader = source->AddReader(
143 std::make_unique<R3BNeulandTamexReader2>(&ucesbStruct.raw_nnp, offsetof(EXT_STR_h101, raw_nnp)));
144 neulandReader->AddExtraConditions(R3B::UcesbMap::array_fewer);
145 neulandReader->SetMaxNbPlanes(planeNum);
146 neulandReader->SetOnline(true);
147 if (no_trig_neuland())
148 {
149 R3BLOG(info, "Disable NeuLAND trigger times");
150 neulandReader->SetSkipTriggerTimes();
151 }
152 source->AddReader(std::make_unique<R3BWhiterabbitMasterReader>(
153 static_cast<EXT_STR_h101_WRMASTER*>(&ucesbStruct.wrmaster), offsetof(EXT_STR_h101, wrmaster), whiterabbit_id));
154
155 // FairRun:
156 auto* source_ptr = source.get();
157 auto run = FairRunOnline{ source.release() };
158 run.SetRunId(inputRunID());
159 run.ActivateHttpServer(DEFAULT_REFRESH_RATE, port_number());
160 auto EvntHeader = std::make_unique<R3BEventHeader>();
161 run.SetEventHeader(EvntHeader.release());
162 run.SetRunId(runID);
163
164 //=====================================================================================
165 // set parameter files:
166 auto fileio = std::make_unique<FairParRootFileIo>(false);
167 fileio->open(parFile.c_str());
168 run.GetRuntimeDb()->setFirstInput(fileio.release());
169
170 //=====================================================================================
171 // add tasks
172 if (not is_cal_disabled.value())
173 {
174 auto losMapped2Cal = std::make_unique<R3BLosMapped2Cal>("LosTCalPar", 1);
175 constexpr auto LOS_MODULE_NUM = 8;
176 losMapped2Cal->SetNofModules(1, LOS_MODULE_NUM);
177 losMapped2Cal->SetTrigger(1);
178 losMapped2Cal->SetOnline(true);
179 run.AddTask(losMapped2Cal.release());
180
181 auto map2Cal = std::make_unique<R3BNeulandMapped2Cal2>();
182 map2Cal->SetTrigger(R3B::Neuland::CalTrigger::allspill);
183 map2Cal->SetDisableHist();
184 run.AddTask(map2Cal.release());
185 }
186
187 if (not is_hit_disabled.value())
188 {
189 run.AddTask(std::make_unique<R3BLosProvideTStart>().release());
190 auto cal2hit = std::make_unique<R3B::Neuland::Cal2HitTask>();
191 cal2hit->SetTrigger(R3B::Neuland::CalTrigger::allspill);
192 cal2hit->SetGlobalTimeOffset(NEULAND_GLOBAL_TIME_OFFSET_NS);
193 cal2hit->SetDisableHist();
194 run.AddTask(cal2hit.release());
195 }
196
197 auto online_spectra = std::make_unique<R3B::Neuland::OnlineSpectra>();
198 online_spectra->SetRandomGenerator(&random_gen);
199 online_spectra->SetUcesbSource(source_ptr);
200 online_spectra->AddCanvas<R3B::Neuland::EventHeaderCanvas>("EventHeader");
201 online_spectra->AddCanvas<R3B::Neuland::MappedCanvas>("NeulandMapped");
202
203 if (not is_cal_disabled.value())
204 {
205 online_spectra->AddCanvas<R3B::Neuland::CalCanvas>("NeulandCal", R3B::Neuland::CalTrigger::allspill);
206 online_spectra->AddCanvas<R3B::Neuland::TJumpCanvas>("NeulandJumps");
207 }
208
209 if (not is_hit_disabled.value())
210 {
211 online_spectra->AddCanvas<R3B::Neuland::CountRateCanvas>("NeulandCountRate", R3B::Neuland::CalTrigger::all);
212 online_spectra->AddCanvas<R3B::Neuland::HitCanvas>("NeulandHit", R3B::Neuland::CalTrigger::onspill);
213 online_spectra->AddCanvas<R3B::Neuland::HitXYCanvas>("NeulandPlaneXY", R3B::Neuland::CalTrigger::onspill);
214 online_spectra->AddCanvas<R3B::Neuland::HitCosmicCanvas>("NeulandHitCosmics",
216 online_spectra->AddCanvas<R3B::Neuland::TimingCanvas>("NeulandTiming", R3B::Neuland::CalTrigger::onspill);
217 }
218 run.AddTask(online_spectra.release());
219
220 try
221 {
222 run.Init();
223 run.Run(-1, eventNum());
224 }
225 catch (R3B::runtime_error& ex)
226 {
227 std::cout << "A runtime error has occured: \n";
228 std::cerr << ex.what();
229 std::cout << "\n\n";
230 return 0;
231 }
232 catch (R3B::logic_error& ex)
233 {
234 std::cout << "A logic error has occured: \n";
235 std::cerr << ex.what();
236 std::cout << "\n\n";
237 return 0;
238 }
239
240 return 0;
241}
#define R3BLOG(severity, x)
Definition R3BLogger.h:35
struct EXT_STR_h101_t EXT_STR_h101
auto main() -> int
Definition ex_test.cxx:109
constexpr auto NEULAND_GLOBAL_TIME_OFFSET_NS
constexpr auto DEFAULT_UNPACKER_PATH
constexpr auto NEULAND_DEFAULT_DOUBLE_PLANE
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