Skip to content
Snippets Groups Projects
Archive.h 1.70 KiB
/* Copyright (C) 2023 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main
   SPDX-License-Identifier: GPL-3.0-only
   Authors: Felix Weiglhofer [committer] */
#ifndef CBM_ALGO_GLOBAL_ARCHIVE_H
#define CBM_ALGO_GLOBAL_ARCHIVE_H

#include "CbmDigiEvent.h"

#include "MicrosliceDescriptor.hpp"

#include <boost/serialization/access.hpp>
#include <boost/serialization/version.hpp>

#include <optional>
#include <vector>

#include "ArchiveDescriptor.h"
#include "compat/Filesystem.h"

namespace cbm::algo
{
  class Archive {
  public:
    /**
     * @brief Read Archive object from file.
    */
    Archive(fs::path file);

    /**
     * @brief Construct empty archive.
    */
    Archive(ArchiveDescriptor descriptor) : fDescriptor(descriptor) {}
    ~Archive() = default;

    /**
     * @brief Store Archive object to file.
    */
    void Store(fs::path file, std::optional<size_t> tsId = {}) const;

    const ArchiveDescriptor& Descriptor() const { return fDescriptor; }

    std::vector<CbmDigiEvent>& TimesliceResults() { return fTimesliceResults; }
    const std::vector<CbmDigiEvent>& TimesliceResults() const { return fTimesliceResults; }

  private:
    ArchiveDescriptor fDescriptor;
    // TODO: Need a better storage class here, that can also store Hits, ...
    // Will be changed with the rework of storage
    std::vector<CbmDigiEvent> fTimesliceResults;

    friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive& ar, const unsigned int /*version*/)
    {
      ar& fDescriptor;
      ar& fTimesliceResults;
    }

    fs::path makeFileName(fs::path file, std::optional<size_t> tsId) const;
  };
}  // namespace cbm::algo

BOOST_CLASS_VERSION(cbm::algo::Archive, 1)

#endif