Geant4  10.01
tpia_multiplicity.cc
Go to the documentation of this file.
1 /*
2 # <<BEGIN-copyright>>
3 # Copyright (c) 2010, Lawrence Livermore National Security, LLC.
4 # Produced at the Lawrence Livermore National Laboratory
5 # Written by Bret R. Beck, beck6@llnl.gov.
6 # CODE-461393
7 # All rights reserved.
8 #
9 # This file is part of GIDI. For details, see nuclear.llnl.gov.
10 # Please also read the "Additional BSD Notice" at nuclear.llnl.gov.
11 #
12 # Redistribution and use in source and binary forms, with or without modification,
13 # are permitted provided that the following conditions are met:
14 #
15 # 1) Redistributions of source code must retain the above copyright notice,
16 # this list of conditions and the disclaimer below.
17 # 2) Redistributions in binary form must reproduce the above copyright notice,
18 # this list of conditions and the disclaimer (as noted below) in the
19 # documentation and/or other materials provided with the distribution.
20 # 3) Neither the name of the LLNS/LLNL nor the names of its contributors may be
21 # used to endorse or promote products derived from this software without
22 # specific prior written permission.
23 #
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
25 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27 # SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR
28 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
31 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 # <<END-copyright>>
35 */
36 #include <string.h>
37 #include <ctype.h>
38 
39 #include <tpia_target.h>
40 #include <tpia_misc.h>
41 
42 #if defined __cplusplus
43 namespace GIDI {
44 using namespace GIDI;
45 #endif
46 
47 /*
48 ************************************************************
49 */
50 tpia_multiplicity *tpia_multiplicity_create( statusMessageReporting *smr ) {
51 
52  tpia_multiplicity *multiplicity;
53 
54  //if( ( multiplicity = xData_malloc2( smr, sizeof( tpia_multiplicity ), 0, "multiplicity" ) ) == NULL ) return( NULL );
55  if( ( multiplicity = (tpia_multiplicity*) xData_malloc2( smr, sizeof( tpia_multiplicity ), 0, "multiplicity" ) ) == NULL ) return( NULL );
56  if( tpia_multiplicity_initialize( smr, multiplicity ) ) multiplicity = tpia_multiplicity_free( smr, multiplicity );
57  return( multiplicity );
58 }
59 /*
60 ************************************************************
61 */
62 int tpia_multiplicity_initialize( statusMessageReporting *smr, tpia_multiplicity *multiplicity ) {
63 
64  memset( multiplicity, 0, sizeof( tpia_multiplicity ) );
65  if( tpia_frame_setFromString( smr, "", "", 0, &(multiplicity->frame) ) ) return( 1 );
66  return( 0 );
67 }
68 /*
69 ************************************************************
70 */
71 tpia_multiplicity *tpia_multiplicity_free( statusMessageReporting *smr, tpia_multiplicity *multiplicity ) {
72 
73  tpia_multiplicity_release( smr, multiplicity );
74  xData_free( smr, multiplicity );
75  return( NULL );
76 }
77 /*
78 ************************************************************
79 */
80 int tpia_multiplicity_release( statusMessageReporting *smr, tpia_multiplicity *multiplicity ) {
81 
82  //multiplicity->grouped.data = xData_free( smr, multiplicity->grouped.data );
83  multiplicity->grouped.data = (double*) xData_free( smr, multiplicity->grouped.data );
84  //multiplicity->pointwise = xData_free( smr, multiplicity->pointwise );
85  multiplicity->pointwise = (double*) xData_free( smr, multiplicity->pointwise );
86  tpia_multiplicity_initialize( smr, multiplicity );
87  return( 0 );
88 }
89 /*
90 ************************************************************
91 */
92 tpia_multiplicity *tpia_multiplicity_createGetFromElement( statusMessageReporting *smr, xData_element *multiplicityElement, int nGroups ) {
93 
94  tpia_multiplicity *multiplicity;
95 
96  if( ( multiplicity = tpia_multiplicity_create( smr ) ) == NULL ) return( NULL );
97  if( tpia_multiplicity_getFromElement( smr, multiplicityElement, multiplicity, nGroups ) != 0 ) multiplicity = tpia_multiplicity_free( smr, multiplicity );
98  return( multiplicity );
99 }
100 /*
101 ************************************************************
102 */
103 //int tpia_multiplicity_getFromElement( statusMessageReporting *smr, xData_element *multiplicityElement, tpia_multiplicity *multiplicity, int nGroups ) {
104 int tpia_multiplicity_getFromElement( statusMessageReporting *smr, xData_element *multiplicityElement, tpia_multiplicity *multiplicity, int ) {
105 
106  const char *timeScale;
107  int isDelayedNeutrons;
108  xData_element *data;
109 
110  xData_addToAccessed( smr, multiplicityElement, 1 );
111  if( ( tpia_frame_setFromElement( smr, multiplicityElement, 2, &(multiplicity->frame) ) ) != 0 ) return( 1 );
112  if( tpia_multiplicity_getTimeScaleFromElement( smr, multiplicityElement, &timeScale, &isDelayedNeutrons, &(multiplicity->timeScale) ) ) return( 1 );
113  for( data = xData_getFirstElement( multiplicityElement ); data != NULL; data = xData_getNextElement( data ) ) {
114  if( strcmp( data->name, "grouped" ) == 0 ) {
115  if( tpia_misc_get2d_xShared_yHistogram_data_Grouped( smr, data, &(multiplicity->grouped) ) ) return( 1 ); }
116  else if( strcmp( data->name, "pointwise" ) == 0 ) {
117  if( ( multiplicity->pointwise = tpia_misc_get2dx_y_data( smr, data, &multiplicity->numberOfPointwise ) ) == NULL ) return( 1 ); }
118  else {
119  tpia_misc_setMessageError_Element( smr, NULL, multiplicityElement, __FILE__, __LINE__, 1, "unsupported multiplicity type = %s", data->name );
120  return( 1 );
121  }
122  }
123  return( 0 );
124 }
125 /*
126 ************************************************************
127 */
128 int tpia_multiplicity_getTimeScaleFromElement( statusMessageReporting *smr, xData_element *element, const char **timeScale, int *isDelayedNeutrons,
129  double *dTimeScale ) {
130 
131  const char *p;
132  char *e;
133 
134  *isDelayedNeutrons = 0;
135  *dTimeScale = 0.;
136  *timeScale = xData_getAttributesValue( &(element->attributes), "timeScale" );
137  if( *timeScale != NULL ) {
138  if( strcmp( *timeScale, "prompt" ) ) {
139  if( strncmp( *timeScale, "delayed", 7 ) ) {
140  tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "invalid timeScale attribute = %s", *timeScale );
141  return( 1 ); }
142  else {
143  for( p = &((*timeScale)[7]); *p; p++ ) if( !isspace( *p ) ) break;
144  if( *p != '=' ) {
145  tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "timeScale attribute '%s' missing '='", *timeScale );
146  return( 1 );
147  }
148  p++;
149  *dTimeScale = strtod( p, &e );
150  if( *e != 0 ) {
151  tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "could not convert timeScale attribute '%s' to double",
152  *timeScale );
153  return( 1 );
154  }
155  *isDelayedNeutrons = 1;
156  }
157  }
158  }
159  return( 0 );
160 }
161 
162 #if defined __cplusplus
163 }
164 #endif
int tpia_multiplicity_release(statusMessageReporting *smr, tpia_multiplicity *multiplicity)
int xData_addToAccessed(statusMessageReporting *, xData_element *element, int increment)
Definition: xData.cc:1078
int tpia_misc_get2d_xShared_yHistogram_data_Grouped(statusMessageReporting *smr, xData_element *element, tpia_1dData *group)
Definition: tpia_misc.cc:291
tpia_multiplicity * tpia_multiplicity_free(statusMessageReporting *smr, tpia_multiplicity *multiplicity)
tpia_multiplicity * tpia_multiplicity_create(statusMessageReporting *smr)
tpia_multiplicity * tpia_multiplicity_createGetFromElement(statusMessageReporting *smr, xData_element *multiplicityElement, int nGroups)
xData_element * xData_getNextElement(xData_element *element)
Definition: xData.cc:478
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:185
int tpia_multiplicity_initialize(statusMessageReporting *smr, tpia_multiplicity *multiplicity)
char * xData_getAttributesValue(xData_attributionList *attributes, const char *name)
Definition: xData.cc:530
int tpia_frame_setFromString(statusMessageReporting *smr, const char *forItem, const char *value, int dimension, tpia_data_frame *frame)
Definition: tpia_frame.cc:75
xData_element * xData_getFirstElement(xData_element *element)
Definition: xData.cc:477
int tpia_multiplicity_getFromElement(statusMessageReporting *smr, xData_element *multiplicityElement, tpia_multiplicity *multiplicity, int)
int tpia_multiplicity_getTimeScaleFromElement(statusMessageReporting *smr, xData_element *element, const char **timeScale, int *isDelayedNeutrons, double *dTimeScale)
int tpia_frame_setFromElement(statusMessageReporting *smr, xData_element *element, int dimension, tpia_data_frame *frame)
Definition: tpia_frame.cc:62
void * xData_free(statusMessageReporting *, void *p)
Definition: xDataMisc.cc:89
double * tpia_misc_get2dx_y_data(statusMessageReporting *smr, xData_element *element, xData_Int *length)
Definition: tpia_misc.cc:230