CbmRoot
Loading...
Searching...
No Matches
CaDataManager.cxx
Go to the documentation of this file.
1/* Copyright (C) 2022-2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergey Gorbunov, Sergei Zharko [committer] */
4
9
10#include "CaDataManager.h"
11
12#include <boost/archive/binary_iarchive.hpp>
13#include <boost/archive/binary_oarchive.hpp>
14
15#include <fstream>
16
19
20// ---------------------------------------------------------------------------------------------------------------------
21//
23{
24 // Init the input data
25 InitData();
26
27 // Check the input data
28 // TODO: Provide assertion
29 // if (CheckInputData<constants::control::InputDataQaLevel>()) {
30 // pAlgo->ReceiveInputData(std::move(fInputData));
31 //
32 // }
33
34 return std::move(fInputData);
35}
36
37// ---------------------------------------------------------------------------------------------------------------------
38//
39void DataManager::ReadInputData(const std::string& fileName)
40{
41 // Reset input data object
43 LOG(info) << "L1: Input data will be read from file \"" << fileName << "\"";
44
45 // Open input binary file
46 std::ifstream ifs(fileName, std::ios::binary);
47 if (!ifs) {
48 LOG(fatal) << "L1: input data reader: data file \"" << fileName << "\" was not found";
49 }
50
51 // Get InputData object
52 try {
53 boost::archive::binary_iarchive ia(ifs);
54 ia >> fInputData;
55 }
56 catch (const std::exception&) {
57 LOG(fatal) << "L1: input data reader: data file \"" << fileName << "\" has incorrect data format or was corrupted";
58 }
59}
60
61// ---------------------------------------------------------------------------------------------------------------------
62//
64{
65 InputData tmp;
66 fInputData.Swap(tmp);
67 fLastStreamId = -1;
68 fInputData.fvStreamStartIndices.reserve(2000); // TODO: What are these numbers? Please, put them into constants.h
69 fInputData.fvStreamStopIndices.reserve(2000);
70 fInputData.fvHits.reserve(nHits);
71}
72
73// ---------------------------------------------------------------------------------------------------------------------
74//
76{
77 // set the end pointers to data streams
78 // TODO: SZh 14.08.2023: Move the max allowed number of streams to the constants.h
79
80 int nStreams = fInputData.fvStreamStartIndices.size();
81 if (!nStreams) { // No data streams provided
84 }
85 else {
86 if (nStreams > 3000) {
87 LOG(warning) << "ca::DataManager: unexpected order of input data: too many data streams!!! ";
89 }
91 for (int i = 0; i < nStreams - 1; i++) {
93 }
94 fInputData.fvStreamStopIndices[nStreams - 1] = fInputData.fvHits.size();
95 }
96}
97
98// ---------------------------------------------------------------------------------------------------------------------
99//
100void DataManager::WriteInputData(const std::string& fileName) const
101{
102 // Check current data object for consistency
103 if constexpr (constants::control::InputDataQaLevel > 0) {
105 LOG(error) << "ca::DataManager: input data writer: attempt to write invalid input data object to file \""
106 << fileName << "\"";
107 return;
108 }
109 }
110
111 // Open output binary file
112 std::ofstream ofs(fileName, std::ios::binary);
113 if (!ofs) {
114 LOG(error) << "ca::DataManager: input data writer: failed opening file \"" << fileName
115 << " for writing input data\"";
116 return;
117 }
118
119 // Serialize InputData object and write
120 boost::archive::binary_oarchive oa(ofs);
121 oa << fInputData;
122}
Input-output data manager for L1 tracking algorithm.
A manager for the input-output data of the CA tracking algorithm.
void ReadInputData(const std::string &fileName)
Reads input data object from boost-serialized binary file.
void WriteInputData(const std::string &fileName) const
Writes input data object to boost-serialized binary file.
InputData && TakeInputData()
Takes (moves) the instance of the input data object.
InputData fInputData
Object of input data.
void InitData()
Initializes data object.
void ResetInputData(HitIndex_t nHits=0) noexcept
Resets the input data block.
void Swap(InputData &other) noexcept
Swap method.
Vector< HitIndex_t > fvStreamStopIndices
Vector< Hit > fvHits
Sample of input hits.
Vector< HitIndex_t > fvStreamStartIndices
Index of the first hit in the sorted hits vector for a given data stream.
void shrink(std::size_t count)
Reduces the vector to a given size.
Definition CaVector.h:150
void push_back(Tinput value)
Pushes back a value to the vector.
Definition CaVector.h:176
void reset(std::size_t count, Tinput... value)
Clears vector and resizes it to the selected size with selected values.
Definition CaVector.h:121
constexpr int InputDataQaLevel
Flag: input data QA level.
Definition CaDefs.h:66
unsigned int HitIndex_t
Index of ca::Hit.
Definition CaHit.h:27