Skip to content
Snippets Groups Projects
Select Git revision
  • f2ff3b27eec5a93fecffd3ac55a828029115028a
  • master default protected
  • jul25_patches
  • nightly_master
  • online_mvd_readconf_cleanup protected
  • online_much_readconf_cleanup protected
  • 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
  • RC2_jul25
  • dev_2025_46
  • 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
38 results

L1ObjectInitController.h

Blame
  • L1ObjectInitController.h 3.74 KiB
    /* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
       SPDX-License-Identifier: GPL-3.0-only
       Authors: Sergey Gorbunov, Sergei Zharko [committer] */
    
    #ifndef L1ObjectInitController_h
    #define L1ObjectInitController_h 1
    
    /// @file   L1ObjectInitController.h
    /// @author Sergei Zharko
    /// @date   22.02.2022
    
    #include "FairLogger.h"
    
    #include <bitset>
    #include <cassert>
    #include <iomanip>
    #include <iostream>
    #include <sstream>
    #include <string>
    
    /// L1ObjectInitController is a class, which provides flags system
    /// and functionality needed for L1 algorithm objects initialization
    ///
    // TODO: Possible improvement: introduce another template parameter, which represents a local enum class...
    template<int NumberOfFlags, class InitKeyEnum>
    class L1ObjectInitController {
    public:
      /// Gets an initialization status of the flag placed at bitIndex
      /// \param bitIndex    index of bit
      bool GetFlag(InitKeyEnum bitKey) const;
      /// Checks, if the object is finalized, i.e. all its fields were set up
      bool IsFinalized() const { return fInitFlags.size() == fInitFlags.count(); }
      /// Sets an initialization status of the flag placed at bitIndex
      /// \param bitIndex    index of bit
      /// \param newStatus   flag value (true is default)
      void SetFlag(InitKeyEnum bitKey, bool newStatus = true);
      /// String representation of initialization flags contents
      /// \param indentLevel   number of indent charachets int output
      std::string ToString(int indentLevel = 0) const;
    
    private:
      std::bitset<NumberOfFlags> fInitFlags {};  ///< object of flags sets
    };
    
    //
    //------------------------------------------------------------------------------------------------------------------------
    //
    template<int NumberOfFlags, class InitKeyEnum>
    bool L1ObjectInitController<NumberOfFlags, InitKeyEnum>::GetFlag(InitKeyEnum bitKey) const
    {
    #ifndef FAST_CODE
      int bitIndex = static_cast<int>(bitKey);
      if (bitIndex >= NumberOfFlags || bitIndex < 0) {
        LOG(fatal) << "L1OnjectInitController::GetFlagStatus: attempt of flag access with index = " << bitIndex
                   << " outside the range [0, " << NumberOfFlags << ']';
        //assert((!(bitIndex >= NumberOfFlags || bitIndex < 0)));
      }
    #endif  // FAST_CODE
      return fInitFlags[static_cast<int>(bitKey)];
    }
    //
    //------------------------------------------------------------------------------------------------------------------------
    //
    template<int NumberOfFlags, class InitKeyEnum>
    void L1ObjectInitController<NumberOfFlags, InitKeyEnum>::SetFlag(InitKeyEnum bitKey, bool newStatus)
    {
    #ifndef FAST_CODE
      int bitIndex = static_cast<int>(bitKey);
      if (bitIndex >= NumberOfFlags || bitIndex < 0) {
        LOG(fatal) << "L1OnjectInitController::GetFlagStatus: attempt of flag access with index = " << bitIndex
                   << " outside the range [0, " << NumberOfFlags << ']';
        //assert((!(bitIndex >= NumberOfFlags || bitIndex < 0)));
      }
    #endif  // FAST_CODE
      fInitFlags[static_cast<int>(bitKey)] = newStatus;
    }
    //
    //------------------------------------------------------------------------------------------------------------------------
    //
    template<int NumberOfFlags, class InitKeyEnum>
    std::string L1ObjectInitController<NumberOfFlags, InitKeyEnum>::ToString(int indentLevel) const
    {
      std::stringstream aStream {};
      constexpr char indentChar = '\t';
      std::string indent(indentLevel, indentChar);
      aStream << indent << "L1ObjectInitController: flag values";
      aStream << '\n' << indent << "index: ";
      for (int idx = 0; idx < NumberOfFlags; ++idx) {
        aStream << std::setw(3) << std::setfill(' ') << idx << ' ';
      }
      aStream << '\n' << indent << "value: ";
      for (int idx = 0; idx < NumberOfFlags; ++idx) {
        aStream << "  " << static_cast<int>(fInitFlags[idx]) << ' ';
      }
      return aStream.str();
    }
    
    #endif  // L1ObjectInitController_h