Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:21

0001 #ifndef MICROMEGAS_MICROMEGASBCOMATCHINGINFORMATION_V1_H
0002 #define MICROMEGAS_MICROMEGASBCOMATCHINGINFORMATION_V1_H
0003 
0004 /*!
0005  * \file MicromegasBcoMatchingInformation_v1.h
0006  * \author Hugo Pereira Da Costa <hugo.pereira-da-costa@cea.fr>
0007  * \brief handles matching between GTM and FEE BCO clock
0008  */
0009 
0010 #include <cstdint>
0011 #include <list>
0012 #include <optional>
0013 #include <set>
0014 #include <utility>
0015 
0016 class Packet;
0017 
0018 class MicromegasBcoMatchingInformation_v1
0019 {
0020  public:
0021   //! constructor
0022   MicromegasBcoMatchingInformation_v1() = default;
0023 
0024   //!@name accessor
0025   //@{
0026 
0027   //! verbosity
0028   int verbosity() const
0029   {
0030     return m_verbosity;
0031   }
0032 
0033   //! true if matching information is verified
0034   /**
0035    * matching information is verified if at least one match
0036    * between gtm_bco and fee_bco is found
0037    */
0038   bool is_verified() const
0039   {
0040     return m_verified_from_modebits || m_verified_from_data;
0041   }
0042 
0043   //! get predicted fee_bco from gtm_bco
0044   std::optional<uint32_t> get_predicted_fee_bco(uint64_t) const;
0045 
0046   //! multiplier
0047   static double get_gtm_clock_multiplier()
0048   {
0049     return m_multiplier;
0050   }
0051 
0052   //! get adjusted multiplier
0053   double get_adjusted_multiplier() const;
0054 
0055   //! print gtm bco information
0056   void print_gtm_bco_information() const;
0057 
0058   //@}
0059 
0060   //!@name modifiers
0061   //@{
0062 
0063   //! verbosity
0064   void set_verbosity(int value)
0065   {
0066     m_verbosity = value;
0067   }
0068 
0069   /// set gtm clock multiplier
0070   static void set_gtm_clock_multiplier(double value)
0071   {
0072     m_multiplier = value;
0073   }
0074 
0075   //! find reference from modebits
0076   bool find_reference_from_modebits(Packet*);
0077 
0078   //! find reference from data
0079   bool find_reference_from_data(Packet*);
0080 
0081   //! save all GTM BCO clocks from packet data
0082   void save_gtm_bco_information(Packet*);
0083 
0084   //! find gtm bco matching a given fee
0085   std::optional<uint64_t> find_gtm_bco(uint32_t /*fee_gtm*/);
0086 
0087   //! cleanup
0088   void cleanup();
0089 
0090   //! cleanup
0091   void cleanup(uint64_t /*ref_bco*/);
0092 
0093   //@}
0094 
0095  private:
0096 
0097   //! update multiplier adjustment
0098   void update_multiplier_adjustment(uint64_t /* gtm_bco */, uint32_t /* fee_bco */);
0099 
0100   //! verbosity
0101   unsigned int m_verbosity = 0;
0102 
0103   //! verified
0104   bool m_verified_from_modebits = false;
0105 
0106   bool m_verified_from_data = false;
0107 
0108   //! first lvl1 bco (40 bits)
0109   uint64_t m_gtm_bco_first = 0;
0110 
0111   //! first fee bco (20 bits)
0112   uint32_t m_fee_bco_first = 0;
0113 
0114   //! list of available bco
0115   std::list<uint64_t> m_gtm_bco_list;
0116 
0117   //! matching between fee bco and lvl1 bco
0118   using m_bco_matching_pair_t = std::pair<unsigned int, uint64_t>;
0119   std::list<m_bco_matching_pair_t> m_bco_matching_list;
0120 
0121   //! keep track or  fee_bco for which no gtm_bco is found
0122   std::set<uint32_t> m_orphans;
0123 
0124   //! gtm clock multiplier
0125   static double m_multiplier;
0126 
0127   //! adjustment to multiplier
0128   double m_multiplier_adjustment = 0;
0129 
0130   //! running numerator for multiplier adjustment
0131   double m_multiplier_adjustment_numerator = 0;
0132 
0133   //! running denominator for multiplier adjustment
0134   double m_multiplier_adjustment_denominator = 0;
0135 
0136   //! running count for multiplier adjustment
0137   unsigned int m_multiplier_adjustment_count = 0;
0138 };
0139 
0140 #endif