Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:54

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 // G4PDefManager
0027 //
0028 // Class description:
0029 //
0030 // Utility template class for splitting read/write data for
0031 // thread-safety from classes: G4ParticleDefinition, G4VDecayChannel.
0032 //
0033 // The type G4PDefManager is introduced to encapsulate the methods used by
0034 // both the master thread and worker threads to allocate memory space for
0035 // the fields encapsulated by the class G4PDefData. When each thread
0036 // changes the value for these fields, it refers to them using a macro
0037 // definition defined below. For every G4ParticleDefinition instance,
0038 // there is a corresponding G4PDefData instance. All G4PDefData instances
0039 // are organized by the class G4PDefManager as an array.
0040 // The field "int g4particleDefinitionInstanceID" is added to the class
0041 // G4ParticleDefinition.
0042 // The value of this field in each G4ParticleDefinition instance is the
0043 // subscript of the corresponding G4PDefData instance.
0044 // In order to use the class G4PDefManager, we add a static member in the
0045 // class G4ParticleDefinition as follows:
0046 // "static G4PDefManager subInstanceManager".
0047 // Both the master thread and worker threads change the length of the array
0048 // for G4PDefData instances mutually along with G4ParticleDefinition
0049 // instances are created. For each worker thread, it dynamically creates ions.
0050 // Consider any thread A, if there is any other thread which creates an ion.
0051 // This ion is shared by the thread A. So the thread A leaves an empty space
0052 // in the array of G4PDefData instances for the ion.
0053 
0054 // Author: Xin Dong, 25.01.2009 - First implementation
0055 //                                from automatic MT conversion
0056 // --------------------------------------------------------------------
0057 #ifndef G4PDefManager_hh
0058 #define G4PDefManager_hh
0059 
0060 #include "G4AutoLock.hh"
0061 #include "globals.hh"
0062 
0063 #include "pwdefs.hh"
0064 #include <stdlib.h>
0065 
0066 class G4ProcessManager;
0067 class G4VTrackingManager;
0068 
0069 class G4PDefData
0070 {
0071     // G4PDefData is the private data from the object to be split.
0072     // Encapsulates the fields of the class G4ParticleDefinition
0073     // that may not be read-only.
0074 
0075   public:
0076     void initialize();
0077 
0078     G4ProcessManager* theProcessManager = nullptr;
0079     G4VTrackingManager* theTrackingManager = nullptr;
0080 };
0081 
0082 class G4PDefManager
0083 {
0084   public:
0085     G4PDefManager();
0086 
0087     // Invoked by the master or work thread to create a new subinstance
0088     // whenever a new split class instance is created. For each worker
0089     // thread, ions are created dynamically.
0090     G4int CreateSubInstance();
0091 
0092     // Invoked by each worker thread to grow the subinstance array and
0093     // initialize each new subinstance using a particular method defined
0094     // by the subclass.
0095     void NewSubInstances();
0096 
0097     // Invoked by all threads to free the subinstance array.
0098     void FreeSlave();
0099 
0100     G4PDefData* GetOffset();
0101 
0102     void UseWorkArea(G4PDefData* newOffset);
0103 
0104     G4PDefData* FreeWorkArea();
0105 
0106     G4PART_DLL static G4int& slavetotalspace();  // thread-local
0107     G4PART_DLL static G4PDefData*& offset();  // thread-local
0108 
0109   private:
0110     G4int totalobj{0};
0111     G4Mutex mutex;
0112 };
0113 
0114 #endif