Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:15:44

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 // Class description:
0027 //
0028 // This is a stack class used for transferring a sub-event.
0029 
0030 // Author: Makoto Asai (JLAB) - 23/Aug/23
0031 // --------------------------------------------------------------------
0032 #ifndef G4SubEvent_hh
0033 #define G4SubEvent_hh 1
0034 
0035 #include <vector>
0036 
0037 class G4Event;
0038 
0039 #include "globals.hh"
0040 #include "evtdefs.hh"
0041 #include "G4Allocator.hh"
0042 #include "G4StackedTrack.hh"
0043 #include "G4Types.hh"
0044 
0045 class G4SubEvent : public std::vector<G4StackedTrack>
0046 {
0047   public:
0048 
0049     G4SubEvent() = default;
0050     explicit G4SubEvent(G4int ty, std::size_t maxEnt)
0051       : fSubEventType(ty), fMaxEnt(maxEnt) {;}
0052    ~G4SubEvent();
0053   
0054     G4SubEvent& operator=(const G4SubEvent&) = delete;
0055 
0056     inline void *operator new(std::size_t);
0057     inline void operator delete(void* anEvent);
0058 
0059     G4bool operator==(const G4SubEvent&) const = delete;
0060     G4bool operator!=(const G4SubEvent&) const = delete;
0061   
0062     inline void PushToStack(const G4StackedTrack& aStackedTrack)
0063     { push_back(aStackedTrack); }
0064     G4StackedTrack PopFromStack();
0065   
0066     void clearAndDestroy();
0067 
0068     inline G4int GetSubEventType() const { return fSubEventType; }
0069     inline std::size_t GetNTrack() const { return size(); }
0070     inline std::size_t GetMaxNTrack() const { return fMaxEnt; }
0071   
0072     G4double getTotalEnergy() const;
0073 
0074     // pointer to G4Event where this sub-event belongs to
0075     inline void SetEvent(G4Event* evt) { fpEvent = evt; }
0076     inline G4Event* GetEvent() const { return fpEvent; }
0077   
0078   private:
0079 
0080     G4int fSubEventType = -1;
0081     std::size_t fMaxEnt = 1000;
0082     G4Event* fpEvent = nullptr;
0083 
0084 };
0085 
0086 extern G4EVENT_DLL G4Allocator<G4SubEvent>*& aSubEventAllocator();
0087 
0088 inline void* G4SubEvent::operator new(std::size_t)
0089 {
0090   if (aSubEventAllocator() == nullptr)
0091   {
0092     aSubEventAllocator() = new G4Allocator<G4SubEvent>;
0093   }
0094   return (void*)aSubEventAllocator()->MallocSingle();
0095 }
0096 
0097 inline void G4SubEvent::operator delete(void* aSubEvent)
0098 {
0099   aSubEventAllocator()->FreeSingle((G4SubEvent*)aSubEvent);
0100 }
0101 
0102 #endif