From 956a2ca80a99be55f7b0d3e6f5aa01c7b3c84386 Mon Sep 17 00:00:00 2001
From: "s.zharko@gsi.de" <s.zharko@gsi.de>
Date: Fri, 6 May 2022 20:04:01 +0200
Subject: [PATCH] L1Algo: added documentation to L1AlgoInputData class

---
 reco/L1/CbmL1ReadEvent.cxx  |  16 ++----
 reco/L1/L1AlgoInputData.cxx |  27 +++++++++-
 reco/L1/L1AlgoInputData.h   | 102 +++++++++++++++++++++++-------------
 3 files changed, 95 insertions(+), 50 deletions(-)

diff --git a/reco/L1/CbmL1ReadEvent.cxx b/reco/L1/CbmL1ReadEvent.cxx
index 9cf9dbb9df..1f37ac3eac 100644
--- a/reco/L1/CbmL1ReadEvent.cxx
+++ b/reco/L1/CbmL1ReadEvent.cxx
@@ -1061,7 +1061,10 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, float& TsStart, float& TsLength,
 
   if (fVerbose >= 10) { cout << "ReadEvent: strips are read." << endl; }
 
-  // -- save hits --
+  /*
+   * Fill and then save vStsHits, vHitStore and vHitMCRef vectors as well as fData->vStsHits
+   */
+
   int nEffHits = 0;
 
   SortedIndex.reset(maxHitIndex + 1);
@@ -1072,14 +1075,7 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, float& TsStart, float& TsLength,
   vHitStore.reserve(nHits);
   vHitMCRef.reserve(nHits);
 
-  /*
-   * In this section the vStsHits, vHitStore and vHitMCRef vectors as well as fData->vStsHits are
-   * filled. 
-   */
   
-  L1_SHOW(vStsHits.size());
-  L1_SHOW(vHitStore.size());
-  L1_SHOW(vHitMCRef.size());
   for (int i = 0; i < nHits; i++) {
     TmpHit& th = tmpHits[i];
 
@@ -1147,10 +1143,6 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, float& TsStart, float& TsLength,
     vHitStore.push_back(s);
     vHitMCRef.push_back(th.iMC);
   }
-  L1_SHOW(&vStsHits);
-  L1_SHOW(vStsHits.size());
-  L1_SHOW(&(fData_->vStsHits));
-  L1_SHOW((fData_->vStsHits).size());
 
   for (int i = 0; i < NStation; i++) {
     if (fData_->StsHitsStartIndex[i] == static_cast<L1HitIndex_t>(-1)) {
diff --git a/reco/L1/L1AlgoInputData.cxx b/reco/L1/L1AlgoInputData.cxx
index 6b9e035a8e..d6471fc1cc 100644
--- a/reco/L1/L1AlgoInputData.cxx
+++ b/reco/L1/L1AlgoInputData.cxx
@@ -53,6 +53,25 @@ void L1AlgoInputData::SetData( const vector< L1Hit >      & StsHits_,
 
 */
 
+/****************************************************************************************************************/
+
+void L1AlgoInputData::Clear() 
+{
+  vStsHits.clear();
+  NStsStrips = 0;
+  fStripFlag.clear();
+  {
+    for (int i = 0; i < kMaxNStations + 1; ++i) {
+      StsHitsStartIndex[i] = 0;
+    }
+    for (int i = 0; i < kMaxNStations + 1; ++i) {
+      StsHitsStopIndex[i] = 0;
+    }
+  }
+}
+
+/****************************************************************************************************************/
+
 istream& L1AlgoInputData::eatwhite(istream& is)  // skip spaces
 {
   char c;
@@ -65,6 +84,8 @@ istream& L1AlgoInputData::eatwhite(istream& is)  // skip spaces
   return is;
 }
 
+/****************************************************************************************************************/
+
 bool L1AlgoInputData::ReadHitsFromFile(const char work_dir[100], const int maxNEvent, const int iVerbose)
 {
   static int nEvent = 1;
@@ -142,7 +163,7 @@ bool L1AlgoInputData::ReadHitsFromFile(const char work_dir[100], const int maxNE
     for (int i = 0; i < n; i++) {
       int tmp;
       fadata >> tmp;
-      if (MaxNStations + 1 > i) StsHitsStartIndex[i] = tmp;
+      if (kMaxNStations + 1 > i) StsHitsStartIndex[i] = tmp;
       //   cout << " StsHitsStartIndex[i]"<< StsHitsStartIndex[i] << endl;
 
       //    cout << tmp<<  " tmp"<<endl;
@@ -150,7 +171,7 @@ bool L1AlgoInputData::ReadHitsFromFile(const char work_dir[100], const int maxNE
     for (int i = 0; i < n; i++) {
       int tmp;
       fadata >> tmp;
-      if (MaxNStations + 1 > i) StsHitsStopIndex[i] = tmp;
+      if (kMaxNStations + 1 > i) StsHitsStopIndex[i] = tmp;
       //   cout << " StsHitsStopIndex[i]"<< StsHitsStopIndex[i] << endl;
       //   cout << tmp<<  " tmp"<<endl;
     }
@@ -165,6 +186,8 @@ bool L1AlgoInputData::ReadHitsFromFile(const char work_dir[100], const int maxNE
   return 1;
 }  // void L1AlgoInputData::ReadStAPAlgoData()
 
+/****************************************************************************************************************/
+
 /*
 void L1AlgoInputData::PrintHits()
 {
diff --git a/reco/L1/L1AlgoInputData.h b/reco/L1/L1AlgoInputData.h
index 0de3900188..5af39afaf6 100644
--- a/reco/L1/L1AlgoInputData.h
+++ b/reco/L1/L1AlgoInputData.h
@@ -12,67 +12,97 @@
 #include "L1Hit.h"
 #include "L1Vector.h"
 
-class L1AlgoInputData {
-
-public:
+///
+/// Class L1AlgoInputData implements a container for keeping a vector of L1Algo internal hit structures (the 
+/// L1Hit objects), used for track reconstruction procedure.
+///
+struct L1AlgoInputData {
+  /*
+   *  Funcitons
+   */
+
+  static constexpr int kMaxNStations {25};  ///> max number of stations to be passed to the L1AlgoInputData object
+  // TODO: Why is it different to the value used in L1Algo (L1Parameters::kMaxNstations)? (S.Zharko)
+
+  /// Default constructor
   L1AlgoInputData()  = default;
+  /// Default destructor
   ~L1AlgoInputData() = default;
 
-  L1Vector<L1Hit>& GetStsHits() { return vStsHits; }
+  /// Resets the object
+  /// For all the vectors the clear method is called, all other fields are set to zero
+  void Clear();
+  /// Gets number of the station strips
   int GetNStsStrips() const { return NStsStrips; }
+  /// Gives an access to the underlying vector of L1Hit objects
+  L1Vector<L1Hit>& GetStsHits() { return vStsHits; }
+  /// Gives an access to the vector of the strip flags
   L1Vector<unsigned char>& GetSFlag() { return fStripFlag; }
+  /// Gets an access of the start indexes for different stations 
+  /// \return pointer to the first element of the array over the stations
   const L1HitIndex_t* GetStsHitsStartIndex() const { return StsHitsStartIndex; }
+  /// Gets an access of the stop indexes for different stations 
+  /// \return pointer to the first element of the array over the stations
   const L1HitIndex_t* GetStsHitsStopIndex() const { return StsHitsStopIndex; }
 
-
+  /// Reads a vector of L1Hit object from file
+  /// The input text file must have the exactly "data_algo.txt" basename
+  /// \param  work_dir  path to the file data_algo.txt file, containing the L1Hit objects for different events
+  /// \param  maxNEvent max number of events to be read from the data_algo.txt file
+  /// \param  iVerbose  verbosity level
+  /// \return success flag: 
+  ///    true  - data was read and stored into this object
+  ///    false - data was not read for some reason
   bool ReadHitsFromFile(const char work_dir[100], const int maxNEvent, const int iVerbose);
+  // TODO: Is there any reason to pass string as an array of chars? It is dangerous, because if one can pass a 
+  //       string containing more then 100 symbols and thus cast a segmentation violation. So, I'd change it
+  //       to const char*, if there are no any specific reasons to keep the current signature. (S.Zharko)
+
   //  void PrintHits();
 
-  /// redefine new\delete for use alignment memmory
+  //
+  // Redefinitions of the new\delete operators for using the alignment memmory
+  //
+  /// Placement new operator for single element
   void* operator new(size_t size, void* ptr) { return ::operator new(size, ptr); }
+  /// Placement new operator for multiple elements
   void* operator new[](size_t size, void* ptr) { return ::operator new(size, ptr); }
+  /// New operator for single element
   void* operator new(size_t size) { return _mm_malloc(size, 16); }
+  /// New operator for multiple elements
   void* operator new[](size_t size) { return _mm_malloc(size, 16); }
+  /// Delete operator for single element
   void operator delete(void* ptr, size_t) { _mm_free(ptr); }
+  /// Delete operator for multiple elements 
   void operator delete[](void* ptr, size_t) { _mm_free(ptr); }
 
+  // TODO: Where are the definitions? (S.Zharko)
+  /// Copy constructor
   L1AlgoInputData(const L1AlgoInputData& a);
+  /// Copy assignment operator
   const L1AlgoInputData& operator=(const L1AlgoInputData& a);
 
-
-  void Clear()
-  {
-
-    vStsHits.clear();
-    NStsStrips = 0;
-    fStripFlag.clear();
-
-    {
-      for (int i = 0; i < MaxNStations + 1; ++i)
-        StsHitsStartIndex[i] = 0;
-      for (int i = 0; i < MaxNStations + 1; ++i)
-        StsHitsStopIndex[i] = 0;
-    }
-  }
-
-
   // private:
+  //
   // functionality
+  //
+  /// Skips spaces in the input stream (TODO: is it used somewhere? (S.Zharko))
   static std::istream& eatwhite(std::istream& is);  // skip spaces
                                                     /// read data from data_algo.txt
-  // data
-  enum
-  {
-    MaxNStations = 25
-  };
-  L1Vector<L1Hit> vStsHits {"L1AlgoInputData::vStsHits"};  // hits as a combination of front-, backstrips and z-position
-  int NStsStrips {0};                                      // Number of strips in sts
-
-  L1Vector<unsigned char> fStripFlag {
-    "L1AlgoInputData::fStripFlag"};  // information of hits station & used hits in tracks;
-
-  L1HitIndex_t StsHitsStartIndex[MaxNStations + 1] {0};  // station-bounders in vStsHits array
-  L1HitIndex_t StsHitsStopIndex[MaxNStations + 1] {0};   // station-bounders in vStsHits array
+  /*
+   *  Data fields (public)
+   */
+  /// hits as a combination of front-, backstrips and z-position
+  L1Vector<L1Hit> vStsHits {"L1AlgoInputData::vStsHits"};  
+
+  int NStsStrips {0};  ///> Number of strips in the station
+  /// information of hits station & used hits in tracks;
+  L1Vector<unsigned char> fStripFlag {"L1AlgoInputData::fStripFlag"};
+
+  /// Start indeces for a given station
+  L1HitIndex_t StsHitsStartIndex[kMaxNStations + 1] {0};
+  /// Stop indeces for a given station
+  L1HitIndex_t StsHitsStopIndex[kMaxNStations + 1] {0}; 
 
 } _fvecalignment;
 
-- 
GitLab