Skip to content
Snippets Groups Projects
Select Git revision
  • 1036dc23776d5a4178bb231231346e7408c3e230
  • master default protected
  • nightly_master
  • online_mvd_readconf_cleanup protected
  • online_much_readconf_cleanup protected
  • jul25_patches
  • cleanup_rich_v25a
  • jul24_patches
  • nov23_patches
  • DC_2404
  • nighly_master
  • DC_Jan24
  • DC_Nov23
  • DC_Oct23
  • feb23_patches
  • L1Algo-dev9
  • dec21_patches protected
  • apr21_patches protected
  • dev_2025_45
  • dev_2025_44
  • dev_2025_43
  • dev_2025_42
  • dev_2025_41
  • dev_2025_40
  • dev_2025_39
  • dev_2025_38
  • dev_2025_37
  • dev_2025_36
  • dev_2025_35
  • dev_2025_34
  • dev_2025_33
  • dev_2025_32
  • dev_2025_31
  • dev_2025_30
  • RC_jul25
  • dev_2025_29
  • dev_2025_28
  • dev_2025_27
38 results

CaDataManager.cxx

  • CaDataManager.cxx 4.25 KiB
    /* Copyright (C) 2022-2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
       SPDX-License-Identifier: GPL-3.0-only
       Authors: Sergey Gorbunov, Sergei Zharko [committer] */
    
    /// \file   CaDataManager.h
    /// \brief  Input-output data manager for L1 tracking algorithm
    /// \since  08.08.2022
    /// \author S.Zharko <s.zharko@gsi.de>
    
    #include "CaDataManager.h"
    
    #include <boost/archive/binary_iarchive.hpp>
    #include <boost/archive/binary_oarchive.hpp>
    
    #include <fstream>
    
    using cbm::algo::ca::DataManager;
    using cbm::algo::ca::InputData;
    
    // ---------------------------------------------------------------------------------------------------------------------
    //
    bool DataManager::SendInputData(InputData& destination)
    {
      // Set boundary hit indexes
      InitData();
    
      // Check data before input
      if (CheckInputData<constants::control::InputDataQaLevel>()) {
        destination = std::move(fInputData);
        assert(this->GetNofHits() == 0);
        return true;
      }
      LOG(error) << "L1: Attempt to set up inconsistent input data";
      return false;
    }
    
    // ---------------------------------------------------------------------------------------------------------------------
    //
    InputData&& DataManager::TakeInputData()
    {
      // Init the input data
      InitData();
    
      // Check the input data
      // TODO: Provide assertion
      // if (CheckInputData<constants::control::InputDataQaLevel>()) {
      //   pAlgo->ReceiveInputData(std::move(fInputData));
      //
      // }
    
      return std::move(fInputData);
    }
    
    // ---------------------------------------------------------------------------------------------------------------------
    //
    void DataManager::ReadInputData(const std::string& fileName)
    {
      // Reset input data object
      ResetInputData();
      LOG(info) << "L1: Input data will be read from file \"" << fileName << "\"";
    
      // Open input binary file
      std::ifstream ifs(fileName, std::ios::binary);
      if (!ifs) {
        LOG(fatal) << "L1: input data reader: data file \"" << fileName << "\" was not found";
      }
    
      // Get InputData object
      try {
        boost::archive::binary_iarchive ia(ifs);
        ia >> fInputData;
      }
      catch (const std::exception&) {
        LOG(fatal) << "L1: input data reader: data file \"" << fileName << "\" has incorrect data format or was corrupted";
      }
    }
    
    // ---------------------------------------------------------------------------------------------------------------------
    //
    void DataManager::ResetInputData(HitIndex_t nHits) noexcept
    {
      InputData tmp;
      fInputData.Swap(tmp);
      fLastStreamId = -1;
      fInputData.fvStreamStartIndices.reserve(2000);  // TODO: What are these numbers? Please, put them into constants.h
      fInputData.fvStreamStopIndices.reserve(2000);
      fInputData.fvHits.reserve(nHits);
    }
    
    // ---------------------------------------------------------------------------------------------------------------------
    //
    void DataManager::InitData()
    {
      // set the end pointers to data streams
      // TODO: SZh 14.08.2023: Move the max allowed number of streams to the constants.h
      if (fInputData.fvStreamStartIndices.size() > 3000) {
        LOG(warning) << "ca::DataManager: unexpected order of input data: too many data streams!!! ";
        fInputData.fvStreamStartIndices.reduce(3000);
      }
      int nStreams = fInputData.fvStreamStartIndices.size();
      fInputData.fvStreamStopIndices.reset(nStreams);
      for (int i = 0; i < nStreams - 1; i++) {
        fInputData.fvStreamStopIndices[i] = fInputData.fvStreamStartIndices[i + 1];
      }
      if (nStreams > 0) {
        fInputData.fvStreamStopIndices[nStreams - 1] = fInputData.fvHits.size();
      }
    }
    
    // ---------------------------------------------------------------------------------------------------------------------
    //
    void DataManager::WriteInputData(const std::string& fileName) const
    {
      // Check current data object for consistency
      if (!CheckInputData<constants::control::InputDataQaLevel>()) {
        LOG(error) << "ca::DataManager: input data writer: attempt to write invalid input data object to file \""
                   << fileName << "\"";
        return;
      }
    
      // Open output binary file
      std::ofstream ofs(fileName, std::ios::binary);
      if (!ofs) {
        LOG(error) << "ca::DataManager: input data writer: failed opening file \"" << fileName
                   << " for writing input data\"";
        return;
      }
    
      // Serialize InputData object and write
      boost::archive::binary_oarchive oa(ofs);
      oa << fInputData;
    }