From 2c9ba543a1deaff8e12cad9beae97179d2eb5c17 Mon Sep 17 00:00:00 2001 From: Jordi Duarte Campderros Date: Thu, 30 Sep 2021 21:21:21 +0200 Subject: [PATCH 1/5] Implement multiple run processing for EUDAQ loader --- src/modules/EventLoaderEUDAQ/CMakeLists.txt | 1 + .../EventLoaderEUDAQ/EventLoaderEUDAQ.cpp | 25 +++++---- .../EventLoaderEUDAQ/EventLoaderEUDAQ.h | 23 ++++---- .../EventLoaderEUDAQ/SequentialReader.cpp | 37 +++++++++++++ .../EventLoaderEUDAQ/SequentialReader.h | 53 +++++++++++++++++++ 5 files changed, 119 insertions(+), 20 deletions(-) create mode 100644 src/modules/EventLoaderEUDAQ/SequentialReader.cpp create mode 100644 src/modules/EventLoaderEUDAQ/SequentialReader.h diff --git a/src/modules/EventLoaderEUDAQ/CMakeLists.txt b/src/modules/EventLoaderEUDAQ/CMakeLists.txt index 001a1cd5..a19ca83a 100644 --- a/src/modules/EventLoaderEUDAQ/CMakeLists.txt +++ b/src/modules/EventLoaderEUDAQ/CMakeLists.txt @@ -14,6 +14,7 @@ INCLUDE_DIRECTORIES(SYSTEM ${EUDAQ_INCLUDE_DIR}) # Add source files to library CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME} EventLoaderEUDAQ.cpp + SequentialReader.cpp ) # Add EUDAQ libraries diff --git a/src/modules/EventLoaderEUDAQ/EventLoaderEUDAQ.cpp b/src/modules/EventLoaderEUDAQ/EventLoaderEUDAQ.cpp index 7d3a6a29..41cbb23e 100644 --- a/src/modules/EventLoaderEUDAQ/EventLoaderEUDAQ.cpp +++ b/src/modules/EventLoaderEUDAQ/EventLoaderEUDAQ.cpp @@ -8,10 +8,14 @@ * Intergovernmental Organization or submit itself to any jurisdiction. */ +#include + +#include "TDirectory.h" +#include "TH2F.h" + #include "EventLoaderEUDAQ.h" -#include "eudaq/PluginManager.hh" -#include +#include "eudaq/PluginManager.hh" using namespace corryvreckan; using namespace std; @@ -21,17 +25,20 @@ EventLoaderEUDAQ::EventLoaderEUDAQ(Configuration& config, std::vector("long_detector_id", true); - m_filename = config_.getPath("file_name", true); + m_filenames = config_.getPathArray("file_names", true); m_longID = config_.get("long_detector_id"); } void EventLoaderEUDAQ::initialize() { - // Create new file reader: - try { - reader = new eudaq::FileReader(m_filename, ""); - } catch(...) { - throw ModuleError("Unable to read input file \"" + m_filename + "\""); + // Create files reader: + reader = std::make_unique(); + for(const auto& file : m_filenames) { + try { + reader->addFile(file); + } catch(...) { + throw ModuleError("Unable to read input file \"" + file + "\""); + } } // Loop over all planes @@ -65,7 +72,7 @@ void EventLoaderEUDAQ::initialize() { StatusCode EventLoaderEUDAQ::run(const std::shared_ptr& clipboard) { // Read next event from EUDAQ reader: - const eudaq::DetectorEvent& evt = reader->Event(); + const eudaq::DetectorEvent& evt = reader->GetDetectorEvent(); LOG(TRACE) << evt; // Convert timestamp to nanoseconds, using diff --git a/src/modules/EventLoaderEUDAQ/EventLoaderEUDAQ.h b/src/modules/EventLoaderEUDAQ/EventLoaderEUDAQ.h index 806ee471..60af3cf1 100644 --- a/src/modules/EventLoaderEUDAQ/EventLoaderEUDAQ.h +++ b/src/modules/EventLoaderEUDAQ/EventLoaderEUDAQ.h @@ -11,15 +11,16 @@ #ifndef EventLoaderEUDAQ_H #define EventLoaderEUDAQ_H 1 -#include -#include -#include -#include +#include +#include +#include +#include + #include "core/module/Module.hpp" -#include "eudaq/FileReader.hh" -#include "objects/Cluster.hpp" -#include "objects/Pixel.hpp" -#include "objects/Track.hpp" + +#include "SequentialReader.h" + +class TH2F; namespace corryvreckan { /** @ingroup Modules @@ -35,11 +36,11 @@ namespace corryvreckan { void initialize() override; StatusCode run(const std::shared_ptr& clipboard) override; - // EUDAQ file reader instance: - eudaq::FileReader* reader; + // EUDAQ-based file reader instance: + std::unique_ptr reader; // Member variables - std::string m_filename{}; + std::vector m_filenames{}; bool m_longID; std::map hitmap; diff --git a/src/modules/EventLoaderEUDAQ/SequentialReader.cpp b/src/modules/EventLoaderEUDAQ/SequentialReader.cpp new file mode 100644 index 00000000..2f4950fd --- /dev/null +++ b/src/modules/EventLoaderEUDAQ/SequentialReader.cpp @@ -0,0 +1,37 @@ +/** + * @file + * @brief EUDAQ event-based reader to allow sequential reading of multiple runs + * + * @copyright Copyright (c) 2017-2020 CERN and the Corryvreckan authors. + * This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md". + * In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an + * Intergovernmental Organization or submit itself to any jurisdiction. + */ + +#include "SequentialReader.h" + +using namespace corryvreckan; + +void SequentialReader::addFile(const std::string& filename) { + // Files are read sequentially, and FIFO + file_readers_.emplace(std::make_unique(filename, "")); +} + +bool SequentialReader::NextEvent() { + if(!file_readers_.front()->NextEvent()) { + // Remove the all one, assign the event, and ask again + // if still are readers + file_readers_.pop(); + if(file_readers_.size() == 0) { + return false; + }; + // and call it again + NextEvent(); + } + + return true; +} + +const eudaq::DetectorEvent& SequentialReader::GetDetectorEvent() const { + return file_readers_.front()->GetDetectorEvent(); +} diff --git a/src/modules/EventLoaderEUDAQ/SequentialReader.h b/src/modules/EventLoaderEUDAQ/SequentialReader.h new file mode 100644 index 00000000..f70bb6eb --- /dev/null +++ b/src/modules/EventLoaderEUDAQ/SequentialReader.h @@ -0,0 +1,53 @@ +/** + * @file + * @brief EUDAQ event-based reader to allow sequential reading of multiple runs + * + * @copyright Copyright (c) 2017-2020 CERN and the Corryvreckan authors. + * This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md". + * In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an + * Intergovernmental Organization or submit itself to any jurisdiction. + */ + +#ifndef SequentialREADER_H__ +#define SequentialREADER_H__ + +#include "eudaq/DetectorEvent.hh" +#include "eudaq/Event.hh" +#include "eudaq/FileReader.hh" + +#include +#include +#include + +namespace corryvreckan { + + class SequentialReader { + + public: + /* + * @brief Constructor and destructor + */ + SequentialReader() = default; + ~SequentialReader() = default; + + /* + * @brief Add a file to read + * @param filename: the name of the raw file + */ + void addFile(const std::string& filename); + + /* + * @brief Process the next event + */ + bool NextEvent(); + /* + * @brief Get the current detector event + */ + const eudaq::DetectorEvent& GetDetectorEvent() const; + + private: + // the container of all file readers + std::queue> file_readers_; + }; +} // namespace corryvreckan +#endif // SequentialREADER_H__ -- GitLab From 74a45b261d85c4859c6cb494215f770284709fea Mon Sep 17 00:00:00 2001 From: Jordi Duarte Campderros Date: Thu, 30 Sep 2021 21:53:57 +0200 Subject: [PATCH 2/5] Include info in readme --- src/modules/EventLoaderEUDAQ/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/EventLoaderEUDAQ/README.md b/src/modules/EventLoaderEUDAQ/README.md index 382ddc0e..6bf3e0a0 100644 --- a/src/modules/EventLoaderEUDAQ/README.md +++ b/src/modules/EventLoaderEUDAQ/README.md @@ -8,6 +8,8 @@ This module allows data recorded by EUDAQ and stored in the EUDAQ-native raw for The detector IDs are taken from the plane name and IDs, two possible naming options for Corryvreckan are available: When setting `long_detector_id = true`, the name of the sensor plane and the ID are used in the form `_`, while only the ID is used otherwise as `plane`. Only detectors listed in the Corryvreckan geometry are decoded and stored, data from other detectors available in the same EUDAQ event are ignored. +This module is able to process multiple runs sequentially. + ### Requirements This module requires an installation of [EUDAQ 1.x](https://github.com/eudaq/eudaq). The installation path should be set as environment variable via ```bash @@ -16,13 +18,13 @@ export EUDAQPATH=/path/to/eudaq for CMake to find the library link against and headers to include. ### Parameters -* `file_name`: File name of the EUDAQ raw data file. This parameter is mandatory. +* `file_names`: File name(s) of the EUDAQ raw data file(s). At least one file is mandatory. * `long_detector_id`: Boolean switch to configure using the long or short detector ID in Corryvreckan, defaults to `true`. ### Usage ```toml [EUDAQEventLoader] -file_name = "rawdata/eudaq/run020808.raw" +file_names = "rawdata/eudaq/run020808.raw","rawdata/eudaq/run020810.raw" long_detector_id = true ``` -- GitLab From e9b49ac6c1c186d8b5048220a7f8f9bd9e3019c5 Mon Sep 17 00:00:00 2001 From: Jordi Duarte Campderros Date: Tue, 2 Nov 2021 20:08:28 +0100 Subject: [PATCH 3/5] Revert back to to keep backwards compatibility --- src/modules/EventLoaderEUDAQ/EventLoaderEUDAQ.cpp | 2 +- src/modules/EventLoaderEUDAQ/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/EventLoaderEUDAQ/EventLoaderEUDAQ.cpp b/src/modules/EventLoaderEUDAQ/EventLoaderEUDAQ.cpp index 41cbb23e..99d74215 100644 --- a/src/modules/EventLoaderEUDAQ/EventLoaderEUDAQ.cpp +++ b/src/modules/EventLoaderEUDAQ/EventLoaderEUDAQ.cpp @@ -25,7 +25,7 @@ EventLoaderEUDAQ::EventLoaderEUDAQ(Configuration& config, std::vector("long_detector_id", true); - m_filenames = config_.getPathArray("file_names", true); + m_filenames = config_.getPathArray("file_name", true); m_longID = config_.get("long_detector_id"); } diff --git a/src/modules/EventLoaderEUDAQ/README.md b/src/modules/EventLoaderEUDAQ/README.md index 6bf3e0a0..1f24fcd2 100644 --- a/src/modules/EventLoaderEUDAQ/README.md +++ b/src/modules/EventLoaderEUDAQ/README.md @@ -18,7 +18,7 @@ export EUDAQPATH=/path/to/eudaq for CMake to find the library link against and headers to include. ### Parameters -* `file_names`: File name(s) of the EUDAQ raw data file(s). At least one file is mandatory. +* `file_name`: File name(s) of the EUDAQ raw data file(s). At least one file is mandatory. * `long_detector_id`: Boolean switch to configure using the long or short detector ID in Corryvreckan, defaults to `true`. ### Usage -- GitLab From ea5f5e112c87ac59b47fcd28abe1d3ab01f3bb62 Mon Sep 17 00:00:00 2001 From: Jordi Duarte Campderros Date: Tue, 2 Nov 2021 20:31:27 +0100 Subject: [PATCH 4/5] Add warning from multiple files processing usage --- src/modules/EventLoaderEUDAQ/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/modules/EventLoaderEUDAQ/README.md b/src/modules/EventLoaderEUDAQ/README.md index 1f24fcd2..24d8ab2c 100644 --- a/src/modules/EventLoaderEUDAQ/README.md +++ b/src/modules/EventLoaderEUDAQ/README.md @@ -8,7 +8,7 @@ This module allows data recorded by EUDAQ and stored in the EUDAQ-native raw for The detector IDs are taken from the plane name and IDs, two possible naming options for Corryvreckan are available: When setting `long_detector_id = true`, the name of the sensor plane and the ID are used in the form `_`, while only the ID is used otherwise as `plane`. Only detectors listed in the Corryvreckan geometry are decoded and stored, data from other detectors available in the same EUDAQ event are ignored. -This module is able to process multiple runs sequentially. +This module is able to process multiple runs sequentially if all the devices were integrated with EUDAQ in the data-taking. This is an important limitation preventing to add data from other devices via different event loaders, as the event building algorithm of Corryvreckan will add the data into the Event if it matches either the timestamps or trigger IDs. However, EUDAQv1.x support stopped some years ago, and this module is a bit outdated: right now is defining the Corryvreckan Event using hardcoded timestamps in the [code](https://gitlab.cern.ch/corryvreckan/corryvreckan/-/blob/master/src/modules/EventLoaderEUDAQ/EventLoaderEUDAQ.cpp#L140-143) and therefore, it is impossible to include any device from a different event loader. ### Requirements This module requires an installation of [EUDAQ 1.x](https://github.com/eudaq/eudaq). The installation path should be set as environment variable via @@ -24,6 +24,12 @@ for CMake to find the library link against and headers to include. ### Usage ```toml [EUDAQEventLoader] +file_names = "rawdata/eudaq/run020808.raw" +long_detector_id = true +``` +If all the devices were integrated in EUDAQ: you can process multiple files at once: +```toml +[EUDAQEventLoader] file_names = "rawdata/eudaq/run020808.raw","rawdata/eudaq/run020810.raw" long_detector_id = true ``` -- GitLab From 6ea9ffd4a1fdfc73466c2035a056745dd8f288a9 Mon Sep 17 00:00:00 2001 From: Jordi Duarte Campderros Date: Wed, 3 Nov 2021 19:00:38 +0100 Subject: [PATCH 5/5] Add myself in the list of contributors (as requested) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e43c363f..992403e8 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ The following authors, in alphabetical order, have contributed to Corryvreckan: * Carsten Daniel Burgard, DESY, @cburgard * Manuel Colocci, CERN, @mcolocci * Jens Dopke, STFC RAL, @jdopke +* Jordi Duarte-Campderros, IFCA, @duarte * Nicolò Jacazio, CERN, @njacazio * Chun Cheng, DESY, @chengc * Dominik Dannheim, CERN, @dannheim -- GitLab