Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
tpia_misc.h File Reference

Go to the source code of this file.

Macros

#define tpia_misc_pointerToAttributeIfAllOk2(smr, element, required, attributes, name)    tpia_misc_pointerToAttributeIfAllOk( smr, element, NULL, required, attributes, name, __FILE__, __LINE__ )
 
#define tpia_misc_pointerToAttributeIfAllOk3(smr, path, required, attributes, name)    tpia_misc_pointerToAttributeIfAllOk( smr, NULL, path, required, attributes, name, __FILE__, __LINE__ )
 

Functions

char * tpia_misc_pointerToAttributeIfAllOk (statusMessageReporting *smr, xData_element *element, const char *path, int required, xData_attributionList *attributes, const char *name, const char *file, int line)
 
int tpia_misc_setMessageError_Element (statusMessageReporting *smr, void *userInterface, xData_element *element, const char *file, int line, int code, const char *fmt,...)
 
xData_Int tpia_misc_binarySearch (xData_Int n, double *ds, double d)
 
tpia_EqualProbableBinSpectrumtpia_misc_getEqualProbableBin (statusMessageReporting *smr, xData_element *parent, xData_Int *n, xData_Int *nBins)
 
tpia_EqualProbableBinSpectrumtpia_misc_getEqualProbableBins (statusMessageReporting *smr, xData_element *parent, const char *name, xData_Int nBins, xData_Int *n)
 

Macro Definition Documentation

◆ tpia_misc_pointerToAttributeIfAllOk2

#define tpia_misc_pointerToAttributeIfAllOk2 (   smr,
  element,
  required,
  attributes,
  name 
)     tpia_misc_pointerToAttributeIfAllOk( smr, element, NULL, required, attributes, name, __FILE__, __LINE__ )

Definition at line 42 of file tpia_misc.h.

◆ tpia_misc_pointerToAttributeIfAllOk3

#define tpia_misc_pointerToAttributeIfAllOk3 (   smr,
  path,
  required,
  attributes,
  name 
)     tpia_misc_pointerToAttributeIfAllOk( smr, NULL, path, required, attributes, name, __FILE__, __LINE__ )

Definition at line 44 of file tpia_misc.h.

Function Documentation

◆ tpia_misc_binarySearch()

xData_Int tpia_misc_binarySearch ( xData_Int  n,
double *  ds,
double  d 
)

Definition at line 208 of file tpia_misc.cc.

208 {
209
210 xData_Int imin = 0, imid, imax = n - 1;
211
212 if( d < ds[0] ) return( -2 );
213 if( d > ds[n-1] ) return( -1 );
214 while( 1 ) {
215 imid = ( imin + imax ) >> 1;
216 if( imid == imin ) break;
217 if( d < ds[imid] ) {
218 imax = imid; }
219 else {
220 imin = imid;
221 }
222 }
223 return( imin );
224}
int xData_Int
Definition: xData.h:50

Referenced by tpia_target_heated_getEIndex().

◆ tpia_misc_getEqualProbableBin()

tpia_EqualProbableBinSpectrum * tpia_misc_getEqualProbableBin ( statusMessageReporting smr,
xData_element parent,
xData_Int n,
xData_Int nBins 
)

Definition at line 317 of file tpia_misc.cc.

317 {
318
319 xData_element *element;
320
321 xData_addToAccessed( smr, parent, 1 );
322 //if( ( element = xData_getOneElementByTagName( smr, parent, "equalProbableBins", 0 ) ) == NULL ) return( NULL );
323 if( ( element = xData_getOneElementByTagName( smr, parent, (char*) "equalProbableBins", 0 ) ) == NULL ) return( NULL );
324 if( xData_convertAttributeTo_xData_Int( smr, element, "nBins", nBins ) != 0 ) {
325 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "missing or invalid nBins attribute" );
326 return( NULL );
327 }
328 return( tpia_misc_getEqualProbableBins( smr, element, "energy", *nBins, n ) );
329}
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
tpia_EqualProbableBinSpectrum * tpia_misc_getEqualProbableBins(statusMessageReporting *smr, xData_element *parent, const char *name, xData_Int nBins, xData_Int *n)
Definition: tpia_misc.cc:333
xData_element * xData_getOneElementByTagName(statusMessageReporting *smr, xData_element *element, char *name, int required)
Definition: xData.cc:810
int xData_addToAccessed(statusMessageReporting *smr, xData_element *element, int increment)
Definition: xData.cc:1078
xData_Int xData_convertAttributeTo_xData_Int(statusMessageReporting *smr, xData_element *element, const char *name, xData_Int *n)
Definition: xData.cc:710

Referenced by tpia_angular_getFromElement().

◆ tpia_misc_getEqualProbableBins()

tpia_EqualProbableBinSpectrum * tpia_misc_getEqualProbableBins ( statusMessageReporting smr,
xData_element parent,
const char *  name,
xData_Int  nBins,
xData_Int n 
)

Definition at line 333 of file tpia_misc.cc.

334 {
335
336
337 int i, j;
338 xData_Int index, size;
339 xData_elementList *list;
340 xData_element *element, *xData;
341 double *d;
342 tpia_EqualProbableBinSpectrum *epbs = NULL, *epb;
343
344 xData_addToAccessed( smr, parent, 1 );
345 list = xData_getElementsByTagNameAndSort( smr, parent, name, NULL, NULL );
346 if( list->n == 0 ) {
347 tpia_misc_setMessageError_Element( smr, NULL, parent, __FILE__, __LINE__, 1, "bins does not contain any %s elements", name ); }
348 else {
349 *n = list->n;
350 size = list->n * ( sizeof( tpia_EqualProbableBinSpectrum ) + ( nBins + 1 ) * sizeof( double ) );
351 //if( ( epbs = xData_malloc2( smr, size, 0, "energies" ) ) != NULL ) {
352 if( ( epbs = (tpia_EqualProbableBinSpectrum*) xData_malloc2( smr, size, 0, "energies" ) ) != NULL ) {
353 d = (double *) &(epbs[list->n]);
354 for( i = 0, epb = epbs; i < list->n; i++, epb++ ) { /* Loop to test nBins and index are proper. */
355 element = list->items[i].element;
356 xData_addToAccessed( smr, element, 1 );
357 if( xData_convertAttributeTo_xData_Int( smr, element, "index", &index ) != 0 ) {
358 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "missing or invalid index attribute" );
359 //epbs = xData_free( smr, epbs );
360 epbs = (tpia_EqualProbableBinSpectrum*) xData_free( smr, epbs );
361 break;
362 }
363 if( index != i ) {
364 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "index = %lld is not incremental", index );
365 //epbs = xData_free( smr, epbs );
366 epbs = (tpia_EqualProbableBinSpectrum*) xData_free( smr, epbs );
367 break;
368 }
369 if( ( j = xData_convertAttributeToDouble( smr, element, "value", &(epb->value) ) ) != 0 ) {
370 if( j == 1 ) {
371 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "element does not have value attribute" ); }
372 else {
373 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "failed to convert value attribute to double" );
374 }
375 //epbs = xData_free( smr, epbs );
376 epbs = (tpia_EqualProbableBinSpectrum*) xData_free( smr, epbs );
377 break;
378 }
379 if( ( xData = xData_getElements_xDataElement( smr, element ) ) == NULL ) {
380 //epbs = xData_free( smr, epbs );
381 epbs = (tpia_EqualProbableBinSpectrum*) xData_free( smr, epbs );
382 break;
383 }
384 xData_addToAccessed( smr, xData, 1 );
385 epb->index = index;
386 epb->nBins = nBins;
387 epb->bins = d;
388 if( xData_1d_x_copyData( smr, xData, ( nBins + 1 ) * sizeof( double ), d ) != 0 ) {
389 //epbs = xData_free( smr, epbs );
390 epbs = (tpia_EqualProbableBinSpectrum*) xData_free( smr, epbs );
391 break;
392 }
393 d += nBins + 1;
394 }
395 }
396 }
397 xData_freeElementList( smr, list );
398 return( epbs );
399}
xData_element * element
Definition: xData.h:145
xData_elementListItem * items
Definition: xData.h:151
struct tpia_EqualProbableBinSpectrum_s tpia_EqualProbableBinSpectrum
Definition: tpia_target.h:62
int xData_convertAttributeToDouble(statusMessageReporting *smr, xData_element *element, const char *name, double *d)
Definition: xData.cc:730
void * xData_free(statusMessageReporting *smr, void *p)
Definition: xDataMisc.cc:89
void xData_freeElementList(statusMessageReporting *smr, xData_elementList *list)
Definition: xData.cc:832
xData_elementList * xData_getElementsByTagNameAndSort(statusMessageReporting *smr, xData_element *element, const char *tagName, const char *sortAttributeName, xData_sortElementFunc sortFunction)
Definition: xData.cc:788
int xData_1d_x_copyData(statusMessageReporting *smr, xData_element *element, xData_Int nAllocatedBytes, double *d)
Definition: xData_1d_x.cc:84
#define xData_malloc2(smr, size, zero, forItem)
Definition: xData.h:313
xData_element * xData_getElements_xDataElement(statusMessageReporting *smr, xData_element *element)
Definition: xData.cc:622

Referenced by tpia_angularEnergy_getFromElement(), and tpia_misc_getEqualProbableBin().

◆ tpia_misc_pointerToAttributeIfAllOk()

char * tpia_misc_pointerToAttributeIfAllOk ( statusMessageReporting smr,
xData_element element,
const char *  path,
int  required,
xData_attributionList attributes,
const char *  name,
const char *  file,
int  line 
)

Definition at line 163 of file tpia_misc.cc.

164 {
165
166 char *value;
167
168 if( !smr_isOk( smr ) ) return( NULL );
169 if( ( value = xData_getAttributesValue( attributes, name ) ) == NULL ) {
170 if( required ) {
171 if( element != NULL ) {
172 tpia_misc_setMessageError_Element( smr, NULL, element, file, line, 1, "element does not have attribute named %s", name ); }
173 else {
174 smr_setMessageError( smr, NULL, file, line, 1, "element does not have attribute named %s for file = %d", name, path );
175 }
176 }
177 }
178 return( value );
179}
int smr_setMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
int smr_isOk(statusMessageReporting *smr)
char * xData_getAttributesValue(xData_attributionList *attributes, const char *name)
Definition: xData.cc:530

◆ tpia_misc_setMessageError_Element()

int tpia_misc_setMessageError_Element ( statusMessageReporting smr,
void *  userInterface,
xData_element element,
const char *  file,
int  line,
int  code,
const char *  fmt,
  ... 
)

Definition at line 183 of file tpia_misc.cc.

184 {
185
186 int status = 0;
187 va_list args;
188 char *msg;
189
190 va_start( args, fmt );
191 msg = smr_vallocateFormatMessage( fmt, &args );
192 va_end( args );
193 if( msg == NULL ) {
194 status = 1;
195 va_start( args, fmt );
196 smr_vsetMessageError( smr, userInterface, file, line, code, fmt, &args );
197 va_end( args ); }
198 else {
199 status = smr_setMessageError( smr, userInterface, file, line, code, "%s for element %s at line %d column %d", msg, element->fullName,
200 (int) element->docInfo.line, (int) element->docInfo.column );
201 free( msg );
202 }
203 return( status );
204}
int smr_vsetMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt, va_list *args)
char * smr_vallocateFormatMessage(const char *fmt, va_list *args)
size_t line
Definition: xData.h:117
size_t column
Definition: xData.h:118
xData_docInfo docInfo
Definition: xData.h:177
char * fullName
Definition: xData.h:185

Referenced by tpia_angularEnergy_getFromElement(), tpia_frame_setFromElement(), tpia_Legendre_getFromElement(), tpia_misc_getEqualProbableBin(), tpia_misc_getEqualProbableBins(), tpia_misc_pointerToAttributeIfAllOk(), tpia_multiplicity_getFromElement(), tpia_multiplicity_getTimeScaleFromElement(), tpia_product_getFromElement(), tpia_target_heated_read(), and tpia_target_read().