Back to home page

EIC code displayed by LXR

 
 

    


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

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 vectors handled by Geant4 analysis
0028 //
0029 // Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 12/07/2024
0030 
0031 #ifndef G4AccVector_h
0032 #define G4AccVector_h 1
0033 
0034 #include "G4VAccumulable.hh"
0035 #include "G4MergeMode.hh"
0036 
0037 #include "globals.hh"
0038 
0039 #include <vector>
0040 
0041 // using vector_std::size_t = std::vector::std::size_t;
0042 
0043 template <class T, class Allocator = std::allocator<T>>
0044 class G4AccVector : public G4VAccumulable
0045 {
0046   public:
0047     // ctors to be supported
0048     // (https://en.cppreference.com/w/cpp/container/vector/vector)
0049     // 1) Default constructor. Constructs an empty container with a default-constructed allocator.
0050     // vector() noexcept(noexcept(Allocator()));
0051     // 3) Constructs the container with count copies of elements with value value.
0052     // vector( std::size_t count,
0053     //         const T& value,
0054     //         const Allocator& alloc = Allocator() );
0055     // 4) Constructs the container with count default-inserted instances of T. No copies are made.
0056     // vector( std::size_t count,
0057     //         const Allocator& alloc = Allocator() );
0058     // 6) Copy constructor. Constructs the container with the copy of the contents of other.
0059     // vector( const vector& other );
0060     // 8) Move constructor. Constructs the container with the contents of other using move semantics.
0061     // vector( vector&& other );
0062     // 10) Constructs the container with the contents of the initializer list init.
0063     // vector( std::initializer_list<T> init,
0064     //    const Allocator& alloc = Allocator() );
0065 
0066     // Default constructor (1)
0067     // Constructs an empty container with a default-constructed allocator.
0068     G4AccVector(const G4String& name = "",
0069                 G4MergeMode mergeMode = G4MergeMode::kAddition);
0070 
0071     // Constructor (2)
0072     // Constructs an empty container with the given allocator alloc.
0073     G4AccVector(const Allocator& alloc,
0074                 G4MergeMode mergeMode = G4MergeMode::kAddition);
0075 
0076     // Constructor (2) with name
0077     // Constructs an empty container with the given allocator alloc.
0078     G4AccVector(const G4String& name,
0079                 const Allocator& alloc,
0080                 G4MergeMode mergeMode = G4MergeMode::kAddition);
0081 
0082     // Constructor (3)
0083     // Constructs the container with count copies of elements with value value
0084     // with a default-constructed allocator.
0085     // G4AccVector(std::size_t count, const T& value,
0086     //                     const Allocator& alloc = Allocator());
0087     G4AccVector(std::size_t count, const T& value,
0088                 G4MergeMode mergeMode = G4MergeMode::kAddition,
0089                 const Allocator& allocator = Allocator());
0090 
0091     // Constructor (3) with name
0092     // Constructs the container with count copies of elements with value value
0093     // with a default-constructed allocator.
0094     // G4AccVector(std::size_t count, const T& value,
0095     //                     const Allocator& alloc = Allocator());
0096     G4AccVector(const G4String& name,
0097                 std::size_t count, const T& value,
0098                 G4MergeMode mergeMode = G4MergeMode::kAddition,
0099                 const Allocator& allocator = Allocator());
0100     // Constructor (4)
0101     // Constructs the container with count default-inserted instances of T.
0102     // No copies are made.
0103     // G4AccVector(std::size_t count,
0104     //                     const Allocator& alloc = Allocator() );
0105     G4AccVector(std::size_t count,
0106                 G4MergeMode mergeMode = G4MergeMode::kAddition,
0107                 const Allocator& allocator = Allocator());
0108 
0109     // Constructor (4) with name
0110     // Constructs the container with count default-inserted instances of T.
0111     // No copies are made.
0112     // G4AccVector(std::size_t count,
0113     //                     const Allocator& alloc = Allocator() );
0114     G4AccVector(const G4String& name,
0115                 std::size_t count,
0116                 G4MergeMode mergeMode = G4MergeMode::kAddition,
0117                 const Allocator& allocator = Allocator());
0118 
0119     // Constructor (10)
0120     // Constructs the container with the contents of the initializer list init.
0121     // G4AccVector(std::initializer_list<T> init,
0122     //                     const Allocator& alloc = Allocator() );
0123     G4AccVector(std::initializer_list<T> init,
0124                 G4MergeMode mergeMode = G4MergeMode::kAddition,
0125                 const Allocator& allocator = Allocator());
0126 
0127     // Constructor (10) with name
0128     // Constructs the container with the contents of the initializer list init.
0129     // G4AccVector(std::initializer_list<T> init,
0130     //                     const Allocator& alloc = Allocator() );
0131     G4AccVector(const G4String& name,
0132                 std::initializer_list<T> init,
0133                 G4MergeMode mergeMode = G4MergeMode::kAddition,
0134                 const Allocator& allocator = Allocator());
0135 
0136     // Copy constructor
0137     G4AccVector(const G4AccVector& rhs) = default;
0138     G4AccVector(const G4AccVector& rhs, const Allocator& allocator);
0139     // Move constructor
0140     G4AccVector(G4AccVector&& rhs) = default;
0141     G4AccVector(G4AccVector&& rhs, const Allocator& allocator);
0142 
0143     // Destructor
0144     ~G4AccVector() override = default;
0145 
0146     // std::vector functions, operators
0147     // operator []
0148     inline T& operator[](typename std::vector<T>::size_type i) { return fVector[i]; }
0149     // at
0150     inline T& at(typename std::vector<T>::size_type i) { return fVector.at(i); }
0151     // size
0152     inline typename std::vector<T>::size_type size() const { return fVector.size(); }
0153     // begin, cbegin
0154     inline typename std::vector<T>::iterator begin() { return fVector.begin(); }
0155     inline typename std::vector<T>::const_iterator begin() const { return fVector.begin(); }
0156     inline typename std::vector<T>::const_iterator cbegin() const { return fVector.cbegin(); }
0157     // end, cend
0158     inline typename std::vector<T>::iterator end() { return fVector.end(); }
0159     inline typename std::vector<T>::const_iterator end() const { return fVector.end(); }
0160     inline typename std::vector<T>::const_iterator cend() const { return fVector.cend(); }
0161     // clear
0162     inline void clear() { fVector.clear(); }
0163     // push_back
0164     inline void push_back(const T& value) { fVector.push_back(value); }
0165     inline void push_back(T&& value ) { fVector.push_back(std::move(value)); }
0166     // emplace_back
0167     template< class... Args >
0168     inline void emplace_back(Args&&... args ) { fVector.emplace_back(args...); }
0169     template< class... Args >
0170     inline T& emplace_back(Args&&... args ) { return fVector.emplace_back(args...); }
0171     // pop_back
0172     inline void pop_back() { fVector.pop_back(); }
0173 
0174     // Methods
0175     void Merge(const G4VAccumulable& other) final;
0176     void Reset() final;
0177     void Print(G4PrintOptions options = G4PrintOptions()) const final;
0178     void SetMergeMode(G4MergeMode value) final;
0179 
0180     // Get methods
0181     G4AccType GetType() const final { return G4AccType::kVector; }
0182     std::vector<T>& GetVector();
0183     const std::vector<T>& GetVector() const;
0184 
0185   private:
0186     // Data members
0187     std::vector<T> fVector {};
0188     T fInitValue = 0;
0189     G4MergeFunction<T> fMergeFunction;
0190  };
0191 
0192 // inline functions
0193 
0194 #include "G4AccVector.icc"
0195 
0196 #endif