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

Go to the source code of this file.

Functions

int tpia_frame_clear (statusMessageReporting *, tpia_data_frame *frame)
 
int tpia_frame_setFromElement (statusMessageReporting *smr, xData_element *element, int dimension, tpia_data_frame *frame)
 
int tpia_frame_setFromString (statusMessageReporting *smr, const char *forItem, const char *value, int dimension, tpia_data_frame *frame)
 
int tpia_frame_getDimensions (statusMessageReporting *, tpia_data_frame *frame)
 
char * tpia_frame_toString (statusMessageReporting *smr, const char *, tpia_data_frame *frame)
 
int tpia_frame_setColumns (statusMessageReporting *smr, tpia_data_frame *frame, int nColumns, int *values)
 
int tpia_frame_setColumn (statusMessageReporting *smr, tpia_data_frame *frame, int column, int value)
 
int tpia_frame_getColumn (statusMessageReporting *smr, tpia_data_frame *frame, int column)
 

Function Documentation

◆ tpia_frame_clear()

int tpia_frame_clear ( statusMessageReporting smr,
tpia_data_frame frame 
)

Definition at line 53 of file tpia_frame.cc.

53 {
54
55 frame->frames = 0;
56 return( 0 );
57}
unsigned int frames
Definition: tpia_target.h:140

Referenced by tpia_frame_setColumns().

◆ tpia_frame_getColumn()

int tpia_frame_getColumn ( statusMessageReporting smr,
tpia_data_frame frame,
int  column 
)

Definition at line 213 of file tpia_frame.cc.

213 {
214
215 unsigned int value;
216
217 if( ( column < 0 ) || ( column >= tpia_maxNumberOfFrames ) ) {
218 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "bad column = %d value for getting frame (0 <= column < %d)", column, tpia_maxNumberOfFrames );
219 return( -1 ); }
220 else {
221 value = frame->frames >> ( 2 * column );
222 }
223 return( (int) ( value & 3 ) );
224}
int smr_setMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
#define tpia_maxNumberOfFrames
Definition: tpia_target.h:82

Referenced by tpia_frame_toString(), and tpia_kinetics_COMKineticEnergy2LabEnergyAndMomentum().

◆ tpia_frame_getDimensions()

int tpia_frame_getDimensions ( statusMessageReporting smr,
tpia_data_frame frame 
)

Definition at line 121 of file tpia_frame.cc.

121 {
122
123 int i, dimension = 0;
124 unsigned value = frame->frames;
125
126 for( i = 0; i < tpia_maxNumberOfFrames; i++ ) {
127 if( ( value & 3 ) == 0 ) break;
128 dimension++;
129 value = value >> 2;
130 }
131 return( dimension );
132}

Referenced by tpia_frame_toString().

◆ tpia_frame_setColumn()

int tpia_frame_setColumn ( statusMessageReporting smr,
tpia_data_frame frame,
int  column,
int  value 
)

Definition at line 190 of file tpia_frame.cc.

190 {
191
192 int i;
193
194 if( ( column < 0 ) || ( column >= tpia_maxNumberOfFrames ) ) {
195 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "bad column = %d value for setting frame (0 <= column < %d)", column, tpia_maxNumberOfFrames );
196 return( 1 ); }
197 else {
198 if( ( value < tpia_referenceFrame_None ) || ( value > tpia_referenceFrame_Max ) ) {
199 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "bad frame value = %d for column = %d", value, column );
200 return( 1 ); }
201 else {
202 i = 3 << ( 2 * column );
203 frame->frames = frame->frames & (~i);
204 value = value << ( 2 * column );
205 frame->frames = frame->frames | value;
206 }
207 }
208 return( 0 );
209}
#define tpia_referenceFrame_None
Definition: tpia_target.h:83
#define tpia_referenceFrame_Max
Definition: tpia_target.h:86

Referenced by G4GIDI_target::getElasticFinalState(), G4GIDI_target::getFinalState(), tpia_frame_setColumns(), and tpia_frame_setFromString().

◆ tpia_frame_setColumns()

int tpia_frame_setColumns ( statusMessageReporting smr,
tpia_data_frame frame,
int  nColumns,
int *  values 
)

Definition at line 178 of file tpia_frame.cc.

178 {
179
180 int i;
181
182 tpia_frame_clear( smr, frame );
183 for( i = 0; i < nColumns; i++ ) if( tpia_frame_setColumn( smr, frame, i, values[i] ) != 0 ) return( 1 );
184
185 return( 0 );
186}
int tpia_frame_clear(statusMessageReporting *, tpia_data_frame *frame)
Definition: tpia_frame.cc:53
int tpia_frame_setColumn(statusMessageReporting *smr, tpia_data_frame *frame, int column, int value)
Definition: tpia_frame.cc:190

Referenced by tpia_decayChannel_sampleProductsAtE().

◆ tpia_frame_setFromElement()

int tpia_frame_setFromElement ( statusMessageReporting smr,
xData_element element,
int  dimension,
tpia_data_frame frame 
)

Definition at line 61 of file tpia_frame.cc.

61 {
62
63 char const *value = xData_getAttributesValueInElement( element, "frame" );
64
65 if( value == NULL ) {
66 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "element is missing frame attribute" );
67 return( 1 );
68 }
69 return( tpia_frame_setFromString( smr, element->fullName, value, dimension, frame ) );
70}
char * fullName
Definition: xData.h:185
int tpia_frame_setFromString(statusMessageReporting *smr, const char *forItem, const char *value, int dimension, tpia_data_frame *frame)
Definition: tpia_frame.cc:74
int tpia_misc_setMessageError_Element(statusMessageReporting *smr, void *userInterface, xData_element *element, const char *file, int line, int code, const char *fmt,...)
Definition: tpia_misc.cc:183
const char * xData_getAttributesValueInElement(xData_element *element, const char *name)
Definition: xData.cc:546

Referenced by tpia_angular_getFromElement(), tpia_angularEnergy_getFromElement(), tpia_channel_getFromElement(), tpia_Legendre_getFromElement(), and tpia_multiplicity_getFromElement().

◆ tpia_frame_setFromString()

int tpia_frame_setFromString ( statusMessageReporting smr,
const char *  forItem,
const char *  value,
int  dimension,
tpia_data_frame frame 
)

Definition at line 74 of file tpia_frame.cc.

74 {
75
76 char const *e;
77 int status = 1, i;
78
79 for( i = 0; i < tpia_maxNumberOfFrames; i++ ) tpia_frame_setColumn( smr, frame, i, tpia_referenceFrame_None );
80 if( dimension > tpia_maxNumberOfFrames ) {
81 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "dimension argument = %d is greater than tpia_maxNumberOfFrames = %d", dimension,
83 return( status );
84 }
85 for( i = 0, e = value; ( i < dimension ) && ( *e != 0 ); i++ ) {
86 if( strstr( e, lab_Str ) == e ) {
88 e += 3; }
89 else if( strstr( e, COM_Str ) == e ) {
91 e += 12; }
92 else {
93 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "bad frame '%s' for %s", value, forItem );
94 break;
95 }
96 if( *e != 0 ) {
97 if( *e != ',' ) {
98 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "bad separater for frame '%s' for %s", value, forItem );
99 break;
100 }
101 e++;
102 }
103 }
104 if( smr_isOk( smr ) ) {
105 if( i == dimension ) {
106 if( *e == 0 ) {
107 status = 0; }
108 else {
109 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "extra values for frame '%s' for %s", value, forItem );
110 } }
111 else {
112 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "missing values for frame '%s' for %s", value, forItem );
113 }
114 }
115 return( status );
116}
int smr_isOk(statusMessageReporting *smr)
#define tpia_referenceFrame_lab
Definition: tpia_target.h:85
#define tpia_referenceFrame_COM
Definition: tpia_target.h:84

Referenced by tpia_angular_initialize(), tpia_angularEnergy_initialize(), tpia_frame_setFromElement(), tpia_Legendre_initialize(), and tpia_multiplicity_initialize().

◆ tpia_frame_toString()

char * tpia_frame_toString ( statusMessageReporting smr,
const char *  fromItem,
tpia_data_frame frame 
)

Definition at line 137 of file tpia_frame.cc.

137 {
138
139 int i, n = tpia_frame_getDimensions( smr, frame ), value, nStr = 0;
140 char *str = NULL, *p;
141
142 if( nlab_Str == 0 ) {
143 nlab_Str = strlen( lab_Str );
144 nCOM_Str = strlen( COM_Str );
145 }
146 for( i = 0; i < n; i++ ) {
147 value = tpia_frame_getColumn( smr, frame, i );
148 if( value == tpia_referenceFrame_COM ) {
149 nStr += nCOM_Str + 1; }
150 else if( value == tpia_referenceFrame_lab ) {
151 nStr += nlab_Str + 1; }
152 else {
153 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "bad frame value = %d for column = %d", value, i );
154 return( NULL );
155 }
156 }
157 if( nStr == 0 ) nStr = 1;
158 //if( ( str = xData_malloc2( smr, nStr, 1, "str" ) ) == NULL ) return( NULL );
159 if( ( str = (char*) xData_malloc2( smr, nStr, 1, "str" ) ) == NULL ) return( NULL );
160 for( i = 0, p = str - 1; i < n; i++ ) {
161 p++;
162 value = tpia_frame_getColumn( smr, frame, i );
163 if( value == tpia_referenceFrame_COM ) {
164 strcpy( p, COM_Str );
165 p += nCOM_Str; }
166 else {
167 strcpy( p, lab_Str );
168 p += nlab_Str;
169 }
170 *p = ',';
171 }
172 *p = 0;
173 return( str );
174}
int tpia_frame_getColumn(statusMessageReporting *smr, tpia_data_frame *frame, int column)
Definition: tpia_frame.cc:213
int tpia_frame_getDimensions(statusMessageReporting *, tpia_data_frame *frame)
Definition: tpia_frame.cc:121
#define xData_malloc2(smr, size, zero, forItem)
Definition: xData.h:313