ATLAS Offline Software
Rand4Hits.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ISF_FASTCALOGPU_RAND4HITS_H
6 #define ISF_FASTCALOGPU_RAND4HITS_H
7 
8 #include <vector>
9 #include <random>
10 
11 #include "GpuGeneral_structs.h"
12 
13 class Rand4Hits {
14 public:
15  Rand4Hits() = default;
17 
18  float* rand_ptr( int nhits ) {
19  if ( over_alloc( nhits ) ) {
20  rd_regen();
21  return m_rand_ptr;
22  } else {
23  float* f_ptr = &( m_rand_ptr[3 * m_current_hits] );
24  return f_ptr;
25  }
26  };
27  float* rand_ptr_base() { return m_rand_ptr; }
28  void set_rand_ptr( float* ptr ) { m_rand_ptr = ptr; };
29  void set_t_a_hits( int nhits ) { m_total_a_hits = nhits; };
30  void set_c_hits( int nhits ) { m_current_hits = nhits; };
31  unsigned int get_c_hits() { return m_current_hits; };
32  unsigned int get_t_a_hits() { return m_total_a_hits; };
33 
34  void create_gen( unsigned long long seed, size_t numhits, bool useCPU = false );
35 
36  void allocate_simulation( long long maxhits, unsigned short maxbins, unsigned short maxhitct, unsigned long n_cells );
37 
38  float* get_cells_energy() { return m_cells_energy; };
39  Cell_E* get_cell_e() { return m_cell_e; };
40  Cell_E* get_cell_e_h() { return m_cell_e_h; };
41 
42  int* get_ct() { return m_ct; };
43 
44  unsigned long* get_hitcells() { return m_hitcells; };
45  int* get_hitcells_ct() { return m_hitcells_ct; };
46 
47  void rd_regen();
48 
49  void add_a_hits( int nhits ) {
50  if ( over_alloc( nhits ) )
51  m_current_hits = nhits;
52  else
53  m_current_hits += nhits;
54  };
55  bool over_alloc( int nhits ) {
56  return m_current_hits + nhits > m_total_a_hits;
57  }; // return true if hits over spill, need regenerat rand..
58 
59 private:
60  float* genCPU( size_t num );
61  void createCPUGen( unsigned long long seed );
62  void destroyCPUGen();
63 
64  float* m_rand_ptr{nullptr};
65  unsigned int m_total_a_hits{0};
66  unsigned int m_current_hits{0};
67  void* m_gen{nullptr};
68  bool m_useCPU{false};
69 
70  // patch in some GPU pointers for cudaMalloc
71  float* m_cells_energy {0};
73  int* m_ct {0};
74 
75  // host side ;
76  unsigned long* m_hitcells{nullptr};
77  int* m_hitcells_ct{nullptr};
78  Cell_E* m_cell_e_h{nullptr};
79 
80  std::vector<float> m_rnd_cpu;
81 
82 };
83 
84 #endif
Rand4Hits::get_hitcells_ct
int * get_hitcells_ct()
Definition: Rand4Hits.h:45
Rand4Hits::get_t_a_hits
unsigned int get_t_a_hits()
Definition: Rand4Hits.h:32
Rand4Hits::get_cell_e_h
Cell_E * get_cell_e_h()
Definition: Rand4Hits.h:40
Rand4Hits::m_ct
int * m_ct
Definition: Rand4Hits.h:73
Rand4Hits::m_cell_e_h
Cell_E * m_cell_e_h
Definition: Rand4Hits.h:78
Rand4Hits::createCPUGen
void createCPUGen(unsigned long long seed)
Definition: Rand4Hits_cpu.cxx:7
Rand4Hits::get_cells_energy
float * get_cells_energy()
Definition: Rand4Hits.h:38
Rand4Hits::m_useCPU
bool m_useCPU
Definition: Rand4Hits.h:68
Rand4Hits::m_current_hits
unsigned int m_current_hits
Definition: Rand4Hits.h:66
Rand4Hits::set_rand_ptr
void set_rand_ptr(float *ptr)
Definition: Rand4Hits.h:28
Rand4Hits::rand_ptr_base
float * rand_ptr_base()
Definition: Rand4Hits.h:27
Rand4Hits::~Rand4Hits
~Rand4Hits()
Rand4Hits::m_rand_ptr
float * m_rand_ptr
Definition: Rand4Hits.h:64
Rand4Hits::set_c_hits
void set_c_hits(int nhits)
Definition: Rand4Hits.h:30
Rand4Hits::rd_regen
void rd_regen()
Rand4Hits::allocate_simulation
void allocate_simulation(long long maxhits, unsigned short maxbins, unsigned short maxhitct, unsigned long n_cells)
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
Rand4Hits::get_ct
int * get_ct()
Definition: Rand4Hits.h:42
Rand4Hits::genCPU
float * genCPU(size_t num)
Definition: Rand4Hits_cpu.cxx:16
Rand4Hits::create_gen
void create_gen(unsigned long long seed, size_t numhits, bool useCPU=false)
Rand4Hits::get_c_hits
unsigned int get_c_hits()
Definition: Rand4Hits.h:31
Rand4Hits::m_hitcells_ct
int * m_hitcells_ct
Definition: Rand4Hits.h:77
Rand4Hits::get_hitcells
unsigned long * get_hitcells()
Definition: Rand4Hits.h:44
Rand4Hits::over_alloc
bool over_alloc(int nhits)
Definition: Rand4Hits.h:55
GpuGeneral_structs.h
Rand4Hits::m_hitcells
unsigned long * m_hitcells
Definition: Rand4Hits.h:76
Rand4Hits::m_cells_energy
float * m_cells_energy
Definition: Rand4Hits.h:71
trigbs_pickEvents.num
num
Definition: trigbs_pickEvents.py:76
Rand4Hits::m_rnd_cpu
std::vector< float > m_rnd_cpu
Definition: Rand4Hits.h:80
Rand4Hits
Definition: Rand4Hits.h:13
Rand4Hits::destroyCPUGen
void destroyCPUGen()
Definition: Rand4Hits_cpu.cxx:12
Rand4Hits::rand_ptr
float * rand_ptr(int nhits)
Definition: Rand4Hits.h:18
Rand4Hits::add_a_hits
void add_a_hits(int nhits)
Definition: Rand4Hits.h:49
Rand4Hits::get_cell_e
Cell_E * get_cell_e()
Definition: Rand4Hits.h:39
Rand4Hits::Rand4Hits
Rand4Hits()=default
Rand4Hits::m_total_a_hits
unsigned int m_total_a_hits
Definition: Rand4Hits.h:65
Rand4Hits::m_cell_e
Cell_E * m_cell_e
Definition: Rand4Hits.h:72
Rand4Hits::set_t_a_hits
void set_t_a_hits(int nhits)
Definition: Rand4Hits.h:29
Rand4Hits::m_gen
void * m_gen
Definition: Rand4Hits.h:67
Cell_E
Definition: GpuGeneral_structs.h:9