Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-02 08:28:13

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 
0027 // Class template for accumulable arrays handled by Geant4 analysis
0028 //
0029 // Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 18/07/2024
0030 
0031 #ifndef G4AccArray_h
0032 #define G4AccArray_h 1
0033 
0034 #include "G4VAccumulable.hh"
0035 #include "G4MergeMode.hh"
0036 
0037 #include "globals.hh"
0038 
0039 #include <array>
0040 
0041 template <class T,  std::size_t N>
0042 class G4AccArray : public G4VAccumulable
0043 {
0044   public:
0045     // Default constructor (1)
0046     // Constructs the container with the default init value
0047     G4AccArray(const G4String& name = "",
0048                const T& value = 0,
0049                G4MergeMode mergeMode = G4MergeMode::kAddition);
0050 
0051     // Constructor (2)
0052     // Constructs the container with the provided initializer list
0053     // and defaults for all other members
0054     template <typename... Args>
0055     G4AccArray(Args&&... args);
0056 
0057     // // Constructor (3)
0058     // // Constructs the container with the provided name and initializer list
0059     // // and defaults for the other members
0060     template <typename First, typename... Args>
0061     G4AccArray(const First& firstArg, Args&&... args);
0062 
0063     // Copy constructor
0064     G4AccArray(const G4AccArray& rhs) = default;
0065     // Move constructor
0066     G4AccArray(G4AccArray&& rhs) = default;
0067 
0068     // Destructor
0069     ~G4AccArray() override = default;
0070 
0071     // operators
0072     inline T& operator[](typename std::array<T,N>::size_type i) { return fArray[i]; }
0073 
0074     // Methods
0075     void Merge(const G4VAccumulable& other) final;
0076     void Reset() final;
0077     void Print(G4PrintOptions options = G4PrintOptions()) const final;
0078     void SetMergeMode(G4MergeMode value) final;
0079 
0080     // Get methods
0081     G4AccType GetType() const final { return G4AccType::kArray; }
0082     std::array<T,N>& GetArray();
0083     const std::array<T,N>& GetArray() const;
0084 
0085   private:
0086     // Data members
0087     std::array<T,N> fArray {};
0088     T fInitValue = 0;
0089     G4MergeFunction<T> fMergeFunction;
0090 };
0091 
0092 // inline functions
0093 
0094 #include "G4AccArray.icc"
0095 
0096 #endif