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 // Set boundary hit indexes
25 InitData();
26
27 // Check data before input
29 destination = std::move(fInputData);
30 assert(this->GetNofHits() == 0);
31 return true;
32 }
33 LOG(error) << "L1: Attempt to set up inconsistent input data";
34 return false;
35}
36
37// ---------------------------------------------------------------------------------------------------------------------
38//
40{
41 // Init the input data
42 InitData();
43
44 // Check the input data
45 // TODO: Provide assertion
46 // if (CheckInputData<constants::control::InputDataQaLevel>()) {
47 // pAlgo->ReceiveInputData(std::move(fInputData));
48 //
49 // }
50
51 return std::move(fInputData);
52}
53
54// ---------------------------------------------------------------------------------------------------------------------
55//
56void DataManager::ReadInputData(const std::string& fileName)
57{
58 // Reset input data object
60 LOG(info) << "L1: Input data will be read from file \"" << fileName << "\"";
61
62 // Open input binary file
63 std::ifstream ifs(fileName, std::ios::binary);
64 if (!ifs) {
65 LOG(fatal) << "L1: input data reader: data file \"" << fileName << "\" was not found";
66 }
67
68 // Get InputData object
69 try {
70 boost::archive::binary_iarchive ia(ifs);
71 ia >> fInputData;
72 }
73 catch (const std::exception&) {
74 LOG(fatal) << "L1: input data reader: data file \"" << fileName << "\" has incorrect data format or was corrupted";
75 }
76}
77
78// ---------------------------------------------------------------------------------------------------------------------
79//
81{
82 InputData tmp;
83 fInputData.Swap(tmp);
84 fLastStreamId = -1;
85 fInputData.fvStreamStartIndices.reserve(2000); // TODO: What are these numbers? Please, put them into constants.h
86 fInputData.fvStreamStopIndices.reserve(2000);
87 fInputData.fvHits.reserve(nHits);
88}
89
90// ---------------------------------------------------------------------------------------------------------------------
91//
93{
94 // set the end pointers to data streams
95 // TODO: SZh 14.08.2023: Move the max allowed number of streams to the constants.h
96 if (fInputData.fvStreamStartIndices.size() > 3000) {
97 LOG(warning) << "ca::DataManager: unexpected order of input data: too many data streams!!! ";
99 }
100 int nStreams = fInputData.fvStreamStartIndices.size();
102 for (int i = 0; i < nStreams - 1; i++) {
104 }
105 if (nStreams > 0) {
106 fInputData.fvStreamStopIndices[nStreams - 1] = fInputData.fvHits.size();
107 }
108}
109
110// ---------------------------------------------------------------------------------------------------------------------
111//
112void DataManager::WriteInputData(const std::string& fileName) const
113{
114 // Check current data object for consistency
116 LOG(error) << "ca::DataManager: input data writer: attempt to write invalid input data object to file \""
117 << fileName << "\"";
118 return;
119 }
120
121 // Open output binary file
122 std::ofstream ofs(fileName, std::ios::binary);
123 if (!ofs) {
124 LOG(error) << "ca::DataManager: input data writer: failed opening file \"" << fileName
125 << " for writing input data\"";
126 return;
127 }
128
129 // Serialize InputData object and write
130 boost::archive::binary_oarchive oa(ofs);
131 oa << fInputData;
132}
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.
int GetNofHits()
Gets number of hits stored.
bool SendInputData(InputData &destination)
Sends (moves) input data to an object (alternative method of data sending)
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 reset(std::size_t count, Tinput... value)
Clears vector and resizes it to the selected size with selected values.
Definition CaVector.h:121
unsigned int HitIndex_t
Index of ca::Hit.
Definition CaHit.h:27