Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
tpia_particle.cc File Reference
#include <string.h>
#include <tpia_target.h>

Go to the source code of this file.

Functions

tpia_particletpia_particle_create (statusMessageReporting *smr)
 
int tpia_particle_initialize (statusMessageReporting *, tpia_particle *particle)
 
tpia_particletpia_particle_free (statusMessageReporting *smr, tpia_particle *particle)
 
int tpia_particle_release (statusMessageReporting *smr, tpia_particle *particle)
 
int tpia_particle_freeInternalList (statusMessageReporting *smr)
 
tpia_particletpia_particle_getInternalID (statusMessageReporting *smr, const char *const name)
 
int tpia_particle_printInternalSortedList (statusMessageReporting *)
 

Function Documentation

◆ tpia_particle_create()

tpia_particle * tpia_particle_create ( statusMessageReporting smr)

Definition at line 51 of file tpia_particle.cc.

51 {
52
53 //tpia_particle *particle = xData_malloc2( smr, sizeof( tpia_particle ), 0, "particle" );
54 tpia_particle *particle = (tpia_particle*) xData_malloc2( smr, sizeof( tpia_particle ), 0, "particle" );
55
56 if( particle == NULL ) return( NULL );
57 tpia_particle_initialize( smr, particle );
58 return( particle );
59}
int tpia_particle_initialize(statusMessageReporting *, tpia_particle *particle)
#define xData_malloc2(smr, size, zero, forItem)
Definition: xData.h:313

Referenced by tpia_particle_getInternalID().

◆ tpia_particle_free()

tpia_particle * tpia_particle_free ( statusMessageReporting smr,
tpia_particle particle 
)

Definition at line 72 of file tpia_particle.cc.

72 {
73
74 int i, j;
75 tpia_particle **p;
76
77 for( i = 0, p = particleSortedList; i < numberOfParticles; i++, p++ ) {
78 if( *p == particle ) {
79 numberOfParticles--;
80 for( j = i; j < numberOfParticles; j++, p++ ) *p = p[1];
81 break;
82 }
83 }
84 if( particle == particleListEnd ) particleListEnd = particle->prior;
85 if( particle == particleList ) particleList = particle->next;
86 if( particle->prior != NULL ) particle->prior->next = particle->next;
87 if( particle->next != NULL ) particle->next->prior = particle->prior;
88 tpia_particle_release( smr, particle );
89 xData_free( smr, particle );
90 return( NULL );
91}
tpia_particle * prior
Definition: tpia_target.h:125
tpia_particle * next
Definition: tpia_target.h:126
int tpia_particle_release(statusMessageReporting *smr, tpia_particle *particle)
void * xData_free(statusMessageReporting *smr, void *p)
Definition: xDataMisc.cc:89

Referenced by tpia_particle_freeInternalList(), and tpia_particle_getInternalID().

◆ tpia_particle_freeInternalList()

int tpia_particle_freeInternalList ( statusMessageReporting smr)

Definition at line 103 of file tpia_particle.cc.

103 {
104
105 while( particleList != NULL ) tpia_particle_free( smr, particleList );
106 //particleSortedList = xData_free( smr, particleSortedList );
107 particleSortedList = (tpia_particle**) xData_free( smr, particleSortedList );
108 return( 0 );
109}
tpia_particle * tpia_particle_free(statusMessageReporting *smr, tpia_particle *particle)

◆ tpia_particle_getInternalID()

tpia_particle * tpia_particle_getInternalID ( statusMessageReporting smr,
const char *const  name 
)

Definition at line 113 of file tpia_particle.cc.

113 {
114
115 int i, iCmp, min, mid, max, Z, A, m;
116 tpia_particle *particle;
117 char *EOP;
118
119 iCmp = 0;
120 min = mid = 0;
121 max = numberOfParticles;
122 while( min != max ) {
123 mid = ( min + max ) / 2;
124 iCmp = strcmp( name, particleSortedList[mid]->name );
125 if( iCmp == 0 ) return( particleSortedList[mid] );
126 if( iCmp < 0 ) {
127 max = mid - 1;
128 if( mid == 0 ) max = 0; }
129 else {
130 min = mid + 1;
131 if( min > max ) min = max;
132 }
133 }
134 mid = min;
135 if( numberOfParticles > 0 ) {
136 iCmp = strcmp( name, particleSortedList[mid]->name );
137 if( iCmp == 0 ) return( particleSortedList[mid] );
138 if( ( iCmp < 0 ) && ( mid != 0 ) ) {
139 mid--;
140 iCmp = strcmp( name, particleSortedList[mid]->name );
141 }
142 }
143
144 if( ( particle = tpia_particle_create( smr ) ) == NULL ) return( NULL );
145 if( ( particle->spectralID = tpi_spectralID_parse( smr, name, &(EOP) ) ) == NULL ) return( tpia_particle_free( smr, particle ) );
146 particle->name = particle->spectralID->name;
147 if( tpia_miscNameToZAm( smr, particle->name, &Z, &A, &m ) != 0 ) return( tpia_particle_free( smr, particle ) );
148 particle->prior = NULL;
149 particle->next = NULL;
150 particle->Z = Z;
151 particle->A = A;
152 particle->m = m;
153 particle->mass = tpia_particleMass_AMU( smr, particle->name );
154 if( !smr_isOk( smr ) ) return( tpia_particle_free( smr, particle ) );
155 particle->fullMass_MeV = tpia_AMU2MeV * particle->mass + particle->spectralID->level;
156
157 if( sizeOfParticleSortedList < ( numberOfParticles + 1 ) ) {
158 if( sizeOfParticleSortedList == 0 ) {
159 sizeOfParticleSortedList = initialSizeOfList; }
160 else {
161 sizeOfParticleSortedList += incrementalSizeOfList;
162 }
163 //if( ( particleSortedList = xData_realloc2( smr, particleSortedList, sizeOfParticleSortedList * sizeof( tpia_particle * ),
164 if( ( particleSortedList = (tpia_particle** ) xData_realloc2( smr, particleSortedList, sizeOfParticleSortedList * sizeof( tpia_particle * ),
165 "particleSortedList" ) ) == NULL ) return( tpia_particle_free( smr, particle ) );
166 }
167
168 if( particleList == NULL ) {
169 particle->ordinal = 0;
170 particleListEnd = particleList = particle; }
171 else {
172 particle->ordinal = particleListEnd->ordinal + 1;
173 particle->prior = particleListEnd;
174 particleListEnd->next = particle;
175 particleListEnd = particle;
176 }
177
178 if( ( mid != 0 ) || ( iCmp > 0 ) ) mid++;
179 for( i = numberOfParticles; i > mid; i-- ) particleSortedList[i] = particleSortedList[i-1];
180 particleSortedList[mid] = particle;
181 numberOfParticles++;
182
183 return( particle );
184}
int smr_isOk(statusMessageReporting *smr)
double level
Definition: tpi_IDs.h:68
char * name
Definition: tpi_IDs.h:63
tpi_spectralID * spectralID
Definition: tpia_target.h:132
double fullMass_MeV
Definition: tpia_target.h:130
tpi_spectralID * tpi_spectralID_parse(statusMessageReporting *smr, char const *str, char **EOP)
Definition: tpi_IDs.cc:218
double tpia_particleMass_AMU(statusMessageReporting *smr, const char *name)
Definition: tpia_mass.cc:887
tpia_particle * tpia_particle_create(statusMessageReporting *smr)
#define tpia_AMU2MeV
Definition: tpia_target.h:101
int tpia_miscNameToZAm(statusMessageReporting *smr, const char *name, int *Z, int *A, int *m)
Definition: tpia_misc.cc:105
#define xData_realloc2(smr, old, size, forItem)
Definition: xData.h:314

Referenced by tpia_product_getFromElement(), tpia_target_heated_read(), and tpia_target_read().

◆ tpia_particle_initialize()

int tpia_particle_initialize ( statusMessageReporting smr,
tpia_particle particle 
)

Definition at line 64 of file tpia_particle.cc.

64 {
65
66 memset( particle, 0, sizeof( tpia_particle ) );
67 return( 0 );
68}

Referenced by tpia_particle_create().

◆ tpia_particle_printInternalSortedList()

int tpia_particle_printInternalSortedList ( statusMessageReporting smr)

Definition at line 189 of file tpia_particle.cc.

189 {
190
191 int i;
192
193 for( i = 0; i < numberOfParticles; i++ ) printf( "%s\n", particleSortedList[i]->name );
194 return( 0 );
195}

◆ tpia_particle_release()

int tpia_particle_release ( statusMessageReporting smr,
tpia_particle particle 
)

Definition at line 95 of file tpia_particle.cc.

95 {
96
97 if( particle->spectralID != NULL ) tpi_spectralID_free( smr, particle->spectralID );
98 return( 0 );
99}
void * tpi_spectralID_free(statusMessageReporting *smr, tpi_spectralID *spectralID)
Definition: tpi_IDs.cc:191

Referenced by tpia_particle_free().