diff --git a/services/CMakeLists.txt b/services/CMakeLists.txt index 824b7748ebeec61dfcd62fa16b14233f54f2b115..39051bcf6107518fefd780eca1abd81b55ff515f 100644 --- a/services/CMakeLists.txt +++ b/services/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(archive_explorer) add_subdirectory(histserv) add_subdirectory(online_par_dump) +add_subdirectory(tsa_dump) diff --git a/services/tsa_dump/Application.cxx b/services/tsa_dump/Application.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ecc2c581e5fed087dc69b78d7991c8886ac0759d --- /dev/null +++ b/services/tsa_dump/Application.cxx @@ -0,0 +1,45 @@ +/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt + SPDX-License-Identifier: GPL-3.0-only + Authors: Pierre-Alain Loizeau [committer] */ + +#include "Application.h" + +#include "CbmFormatTsPrintout.h" + +#include <StorableTimeslice.hpp> +#include <TimesliceAutoSource.hpp> + +#include <Logger.h> + +#include <iomanip> +#include <ios> +#include <iostream> +#include <sstream> + +void Application::Run() +{ + LOG(info) << "Calling string constructor with "; + LOG(info) << fOpts.sFullFilename; + fles::TimesliceAutoSource* fTsSource = new fles::TimesliceAutoSource(fOpts.sFullFilename); + + std::unique_ptr<fles::Timeslice> ts; + ts = fTsSource->get(); + uint64_t uTsNb = 0; + while (ts) { + // Use << operator defined in <cbmroot_src>core/base/utils/flestools/CbmFormatTsPrintout.h + std::stringstream ss; + ss << (*(ts.get())); + LOG(info) << "=====================================\n" << ss.str(); + uTsNb++; + if (fOpts.uNbTimeslices == uTsNb) { + break; + } + ts = fTsSource->get(); + } + if (fOpts.uNbTimeslices == uTsNb) { + LOG(info) << "Requested number of TS reached; stopping there. Dumped " << uTsNb << " TS"; + } + else { + LOG(info) << "End of archive reached; stopping there. Dumped " << uTsNb << " TS"; + } +} diff --git a/services/tsa_dump/Application.h b/services/tsa_dump/Application.h new file mode 100644 index 0000000000000000000000000000000000000000..6732607ba469488f8b5ca452892397b0ac965000 --- /dev/null +++ b/services/tsa_dump/Application.h @@ -0,0 +1,18 @@ +/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt + SPDX-License-Identifier: GPL-3.0-only + Authors: Pierre-Alain Loizeau [committer] */ + +#pragma once + +#include "ProgramOptions.h" + +class Application { + + public: + Application(ProgramOptions opts) : fOpts(opts) {} + + void Run(); + + private: + ProgramOptions fOpts; +}; diff --git a/services/tsa_dump/CMakeLists.txt b/services/tsa_dump/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..994461aca9e8d41a29d86ab385f769f52274ecd9 --- /dev/null +++ b/services/tsa_dump/CMakeLists.txt @@ -0,0 +1,38 @@ +# Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt +# SPDX-License-Identifier: GPL-3.0-only +# Authors: Pierre-Alain Loizeau [committer] + +set(APP tsadump) + +set(INCLUDE_DIRECTORIES + ${INCLUDE_DIRECTORIES} + ${CMAKE_CURRENT_SOURCE_DIR} + ${CBMROOT_SOURCE_DIR} + ) + +set(SRCS + Application.cxx + ProgramOptions.cxx + main.cxx + ) + +set(HEADERS + Application.h + ProgramOptions.h + ) + +add_executable(${APP} ${SRCS} ${HEADERS}) +target_link_libraries(${APP} + PUBLIC + CbmFlibFlesTools + FairLogger::FairLogger + external::fles_ipc + libzmq + cppzmq + PRIVATE + Boost::program_options + external::fles_logging # Needed for TimesliceSource in CbmSourceTsArchive, not sure of conflicts with FairLogger + ) + + +install(TARGETS ${APP} DESTINATION bin) diff --git a/services/tsa_dump/ProgramOptions.cxx b/services/tsa_dump/ProgramOptions.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e0c384674930674a0dd979e05edf4db150d68868 --- /dev/null +++ b/services/tsa_dump/ProgramOptions.cxx @@ -0,0 +1,62 @@ +/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt + SPDX-License-Identifier: GPL-3.0-only + Authors: Pierre-Alain Loizeau [committer] */ + +#include "ProgramOptions.h" + +#include <boost/program_options.hpp> + +#include <iostream> + +namespace po = boost::program_options; + +ProgramOptions::ProgramOptions(int argc, char** argv) +{ + po::options_description required("Required options"); + // clang-format off + required.add_options() + ("filename,f", po::value(&sFullFilename)->value_name("<outputDir>")->required(), + "Full path to TSA file") + ; + // clang-format on + + po::options_description optional{"Other options"}; + // clang-format off + optional.add_options() + ("timeslices,n", po::value(&uNbTimeslices), + "number of timeslices") + ("help,h", "Print help message") + ; + // clang-format on + + + po::options_description cmdline_options; + cmdline_options.add(required).add(optional); + + po::variables_map vm; + po::command_line_parser parser{argc, argv}; + parser.options(cmdline_options); + try { + auto result = parser.run(); + po::store(result, vm); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + std::cerr << "Use '-h' to display all valid options." << std::endl; + std::exit(EXIT_FAILURE); + } + + if (vm.count("help") > 0) { + std::cout << cmdline_options << std::endl; + std::exit(EXIT_SUCCESS); + } + + try { + po::notify(vm); + } + catch (const po::required_option& e) { + std::cerr << "Error: " << e.what() << std::endl; + std::cerr << "Use '-h' to display all valid options." << std::endl; + std::exit(EXIT_FAILURE); + } +} diff --git a/services/tsa_dump/ProgramOptions.h b/services/tsa_dump/ProgramOptions.h new file mode 100644 index 0000000000000000000000000000000000000000..6edd3bacf4b83a8c2c0623e44cd0cbffadccde5c --- /dev/null +++ b/services/tsa_dump/ProgramOptions.h @@ -0,0 +1,14 @@ +/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt + SPDX-License-Identifier: GPL-3.0-only + Authors: Pierre-Alain Loizeau [committer] */ + +#pragma once + +#include <string> + +struct ProgramOptions { + ProgramOptions(int argc, char** argv); + + uint64_t uNbTimeslices = 0; + std::string sFullFilename; +}; diff --git a/services/tsa_dump/main.cxx b/services/tsa_dump/main.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6f64705d0b4a195a23778d648018e092272e240b --- /dev/null +++ b/services/tsa_dump/main.cxx @@ -0,0 +1,13 @@ +/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt + SPDX-License-Identifier: GPL-3.0-only + Authors: Pierre-Alain Loizeau [committer] */ + +#include "Application.h" + +int main(int argc, char** argv) +{ + ProgramOptions opts{argc, argv}; + Application app{opts}; + app.Run(); + return 0; +}