Skip to content
Snippets Groups Projects
Commit 57f13396 authored by Sergei Zharko's avatar Sergei Zharko Committed by Sergei Zharko
Browse files

CA: moving L1InputData and L1IODataManager: applying documentation

parent e5a94754
No related branches found
No related tags found
1 merge request!1364CA: Moving L1IODataManager and L1InputData into the CaCore library
Pipeline #24551 passed
......@@ -75,14 +75,14 @@ void DataManager::ReadInputData(const std::string& fileName)
// ---------------------------------------------------------------------------------------------------------------------
//
void DataManager::ResetInputData(ca::HitIndex_t nHits) noexcept
void DataManager::ResetInputData(HitIndex_t nHits) noexcept
{
InputData tmp;
fInputData.Swap(tmp);
fLastStreamId = -1;
fInputData.fStreamStartIndices.reserve(2000); // TODO: What are these numbers? Please, put them into constants.h
fInputData.fStreamStopIndices.reserve(2000);
fInputData.fHits.reserve(nHits);
fInputData.fvStreamStartIndices.reserve(2000); // TODO: What are these numbers? Please, put them into constants.h
fInputData.fvStreamStopIndices.reserve(2000);
fInputData.fvHits.reserve(nHits);
}
// ---------------------------------------------------------------------------------------------------------------------
......@@ -90,20 +90,17 @@ void DataManager::ResetInputData(ca::HitIndex_t nHits) noexcept
void DataManager::InitData()
{
// set the end pointers to data streams
//std::cout << "N data streams: " << fInputData.fStreamStartIndices.size() << std::endl;
// TODO: SZh 14.08.2023: Move the max allowed number of streams to the constants.h
if (fInputData.fStreamStartIndices.size() > 3000) {
LOG(warning) << "L1: unexpected order of input data: too many data streams!!! ";
fInputData.fStreamStartIndices.reduce(3000);
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.fStreamStartIndices.size();
fInputData.fStreamStopIndices.reset(nStreams);
int nStreams = fInputData.fvStreamStartIndices.size();
fInputData.fvStreamStopIndices.reset(nStreams);
for (int i = 0; i < nStreams - 1; i++) {
fInputData.fStreamStopIndices[i] = fInputData.fStreamStartIndices[i + 1];
fInputData.fvStreamStopIndices[i] = fInputData.fvStreamStartIndices[i + 1];
}
if (nStreams > 0) { fInputData.fStreamStopIndices[nStreams - 1] = fInputData.fHits.size(); }
if (nStreams > 0) { fInputData.fvStreamStopIndices[nStreams - 1] = fInputData.fvHits.size(); }
}
// ---------------------------------------------------------------------------------------------------------------------
......@@ -112,14 +109,16 @@ void DataManager::WriteInputData(const std::string& fileName) const
{
// Check current data object for consistency
if (!CheckInputData<constants::control::InputDataQaLevel>()) {
LOG(error) << "L1: input data writer: attempt to write invalid input data object to file \"" << fileName << "\"";
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) << "L1: input data writer: failed opening file \"" << fileName << " for writing input data\"";
LOG(error) << "ca::DataManager: input data writer: failed opening file \"" << fileName
<< " for writing input data\"";
return;
}
......
......@@ -20,82 +20,76 @@ namespace cbm::algo::ca
///
class alignas(constants::misc::Alignment) DataManager {
public:
// ***************************
// ** Member functions list **
// ***************************
// ** Constructors and destructor **
/// Default constructor
/// \brief Default constructor
DataManager() = default;
/// Destructor
/// \brief Destructor
~DataManager() = default;
/// Copy constructor
/// \brief Copy constructor
DataManager(const DataManager& other) = delete;
/// Move constructor
/// \brief Move constructor
DataManager(DataManager&& other) = delete;
/// Copy assignment operator
/// \brief Copy assignment operator
DataManager& operator=(const DataManager& other) = delete;
/// Move assignment operator
/// \brief Move assignment operator
DataManager& operator=(DataManager&& other) = delete;
/// @brief Gets number of hits stored
/// @return Number of hits
int GetNofHits() { return fInputData.fHits.size(); }
/// \brief Gets number of hits stored
/// \return Number of hits
int GetNofHits() { return fInputData.fvHits.size(); }
/// Reads input data object from boost-serialized binary file
/// \brief Reads input data object from boost-serialized binary file
/// \param fileName Name of input file
void ReadInputData(const std::string& fileName);
/// Reserve number of hits
/// \brief Reserve number of hits
/// \param nHits Number of hits to be stored
/// \note If one does not call this method, the underlying vector of hits will be filled with the time penalty
void ReserveNhits(ca::HitIndex_t nHits) { fInputData.fHits.reserve(nHits); }
void ReserveNhits(HitIndex_t nHits) { fInputData.fvHits.reserve(nHits); }
/// @brief Resets the input data block
/// @param nHits Number of hits to reserve
void ResetInputData(ca::HitIndex_t nHits = 0) noexcept;
/// \brief Resets the input data block
/// \param nHits Number of hits to reserve
void ResetInputData(HitIndex_t nHits = 0) noexcept;
/// Pushes back a hit
/// \brief Pushes back a hit
/// \param hit An ca::Hit object
void PushBackHit(const ca::Hit& hit, int64_t streamId)
void PushBackHit(const Hit& hit, int64_t streamId)
{
if (fInputData.fStreamStartIndices.size() == 0 || fLastStreamId != streamId) { // new data stream
if (fInputData.fvStreamStartIndices.size() == 0 || fLastStreamId != streamId) { // new data stream
fLastStreamId = streamId;
fInputData.fStreamStartIndices.push_back(fInputData.fHits.size());
fInputData.fvStreamStartIndices.push_back(fInputData.fvHits.size());
// for a case.. it is fixed later in InitData()
fInputData.fStreamStopIndices.push_back(fInputData.fHits.size());
fInputData.fvStreamStopIndices.push_back(fInputData.fvHits.size());
}
fInputData.fHits.push_back(hit);
fInputData.fvHits.push_back(hit);
}
/// Sets the number of hit keys
/// \brief Sets the number of hit keys
/// \param nKeys Number of hit keys
void SetNhitKeys(int nKeys) { fInputData.fNhitKeys = nKeys; }
/// @brief Sets number of active stations
/// @param nStations Number of stations
/// \brief Sets number of active stations
/// \param nStations Number of stations
void SetNofActiveStations(int nStations) { fNofActiveStations = nStations; }
/// @brief Sends (moves) input data to an object (alternative method of data sending)
/// @param destination Destination object of input data
/// \brief Sends (moves) input data to an object (alternative method of data sending)
/// \param destination Destination object of input data
bool SendInputData(InputData& destination);
/// \brief Takes (moves) the instance of the input data object
InputData&& TakeInputData();
/// Writes input data object to boost-serialized binary file
/// \brief Writes input data object to boost-serialized binary file
/// \param fileName Name of input file
void WriteInputData(const std::string& fileName) const;
private:
/// @brief Initializes data object
/// \brief Initializes data object
///
/// Sorts hits by stations (complexity O(n)) and defines bordering hit index for station
void InitData();
......@@ -136,7 +130,7 @@ namespace cbm::algo::ca
if constexpr (Level == 0) { return true; } // Level = 0 -> do nothing
else if constexpr (Level > 0) { // Level = 1 and higher
// ----- Check if the hits container is not empty ----------------------------------------------------------------
if (fInputData.fHits.size() == 0) {
if (fInputData.fvHits.size() == 0) {
LOG(warn) << "DataManager [check input]: Sample contains empty hits, tracking will not be executed";
return false;
}
......
......@@ -18,9 +18,9 @@ InputData::InputData() {}
// ---------------------------------------------------------------------------------------------------------------------
//
InputData::InputData(const InputData& other)
: fHits(other.fHits)
, fStreamStartIndices(other.fStreamStartIndices)
, fStreamStopIndices(other.fStreamStopIndices)
: fvHits(other.fvHits)
, fvStreamStartIndices(other.fvStreamStartIndices)
, fvStreamStopIndices(other.fvStreamStopIndices)
, fNhitKeys(other.fNhitKeys)
{
}
......
......@@ -24,86 +24,73 @@ namespace cbm::algo::ca
///
class alignas(constants::misc::Alignment) InputData {
public:
// **************************
// ** Friend classes list **
// **************************
friend class DataManager; ///< Class which fills the InputData object for each event or time slice
friend class boost::serialization::access;
// ***************************
// ** Member functions list **
// ***************************
// ** Constructors and destructor **
/// Default constructor
/// \brief Default constructor
InputData();
/// Destructor
/// \brief Destructor
~InputData() = default;
/// Copy constructor
/// \brief Copy constructor
InputData(const InputData& other);
/// Move constructor
/// \brief Move constructor
InputData(InputData&&) noexcept;
/// Copy assignment operator
/// \brief Copy assignment operator
InputData& operator=(const InputData& other);
/// Move assignment operator
/// \brief Move assignment operator
InputData& operator=(InputData&& other) noexcept;
/// Gets hits sample size
ca::HitIndex_t GetSampleSize() const { return fHits.size(); }
// ** Accessors **
/// \brief Gets hits sample size
HitIndex_t GetSampleSize() const { return fvHits.size(); }
/// Gets number of data streams
int GetNdataStreams() const { return fStreamStartIndices.size(); }
/// \brief Gets number of data streams
int GetNdataStreams() const { return fvStreamStartIndices.size(); }
/// Gets reference to hit by its index
/// \brief Gets reference to hit by its index
/// \param index Index of hit in the hits sample
const ca::Hit& GetHit(ca::HitIndex_t index) const { return fHits[index]; }
const Hit& GetHit(HitIndex_t index) const { return fvHits[index]; }
/// Gets reference to hits vector
const Vector<ca::Hit>& GetHits() const { return fHits; }
/// \brief Gets reference to hits vector
const Vector<Hit>& GetHits() const { return fvHits; }
/// Gets number of hits in the hits vector
ca::HitIndex_t GetNhits() const { return fHits.size(); }
/// \brief Gets number of hits in the hits vector
HitIndex_t GetNhits() const { return fvHits.size(); }
/// Gets total number of stored keys
/// \brief Gets total number of stored keys
int GetNhitKeys() const { return fNhitKeys; }
/// Gets index of the first hit in the sorted hits vector
/// \brief Gets index of the first hit in the sorted hits vector
/// \param iStream Index of the data stream
ca::HitIndex_t GetStreamStartIndex(int iStream) const { return fStreamStartIndices[iStream]; }
HitIndex_t GetStreamStartIndex(int iStream) const { return fvStreamStartIndices[iStream]; }
/// Gets index of (the last + 1) hit in the sorted hits vector
/// \brief Gets index of (the last + 1) hit in the sorted hits vector
/// \param iStream Index of the data stream
ca::HitIndex_t GetStreamStopIndex(int iStream) const { return fStreamStopIndices[iStream]; }
HitIndex_t GetStreamStopIndex(int iStream) const { return fvStreamStopIndices[iStream]; }
/// Gets n hits for the data stream
/// \brief Gets n hits for the data stream
/// \param iStream Index of the data stream
ca::HitIndex_t GetStreamNhits(int iStream) const
HitIndex_t GetStreamNhits(int iStream) const
{
return fStreamStopIndices[iStream] - fStreamStartIndices[iStream];
return fvStreamStopIndices[iStream] - fvStreamStartIndices[iStream];
}
private:
/// Swap method
/// \brief Swap method
void Swap(InputData& other) noexcept;
/// Data serialization method
/// \brief Data serialization method
template<class Archive>
void serialize(Archive& ar, const unsigned int /*versino*/)
{
ar& fHits;
ar& fStreamStartIndices;
ar& fStreamStopIndices;
ar& fvHits;
ar& fvStreamStartIndices;
ar& fvStreamStopIndices;
ar& fNhitKeys;
}
......@@ -111,14 +98,14 @@ namespace cbm::algo::ca
// ** Member variables list **
// ***************************
/// @brief Sample of input hits
Vector<ca::Hit> fHits {"InputData::fHits"};
/// \brief Sample of input hits
Vector<Hit> fvHits {"InputData::fHits"};
/// @brief Index of the first hit in the sorted hits vector for a given data stream
Vector<ca::HitIndex_t> fStreamStartIndices {"InputData::fStreamStartIndices"};
Vector<ca::HitIndex_t> fStreamStopIndices {"InputData::fStreamStopIndices"};
/// \brief Index of the first hit in the sorted hits vector for a given data stream
Vector<HitIndex_t> fvStreamStartIndices {"InputData::fStreamStartIndices"};
Vector<HitIndex_t> fvStreamStopIndices {"InputData::fStreamStopIndices"};
/// @brief Number of hit keys used for rejecting fake STS hits
/// \brief Number of hit keys used for rejecting fake STS hits
int fNhitKeys = -1;
};
......@@ -131,9 +118,9 @@ namespace cbm::algo::ca
//
[[gnu::always_inline]] inline void InputData::Swap(InputData& other) noexcept
{
std::swap(fHits, other.fHits);
std::swap(fStreamStartIndices, other.fStreamStartIndices);
std::swap(fStreamStopIndices, other.fStreamStopIndices);
std::swap(fvHits, other.fvHits);
std::swap(fvStreamStartIndices, other.fvStreamStartIndices);
std::swap(fvStreamStopIndices, other.fvStreamStopIndices);
std::swap(fNhitKeys, other.fNhitKeys);
}
......
......@@ -295,8 +295,7 @@ namespace cbm::algo::ca
FieldFunction_t fFieldFunction {[](const double (&)[3], double (&)[3]) {}};
// NOTE: Stations of the detectors which are not assigned as active, are not included in the tracking!
[[deprecated]] int fCAIterationsNumberCrosscheck {
-1}; ///< Number of iterations to be passed (must be used for cross-checks)
int fCAIterationsNumberCrosscheck {-1}; ///< Number of iterations to be passed (must be used for cross-checks)
Parameters fParameters {}; ///< CA parameters object
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment