tpia_multiplicity.cc

Go to the documentation of this file.
00001 /*
00002 # <<BEGIN-copyright>>
00003 # Copyright (c) 2010, Lawrence Livermore National Security, LLC. 
00004 # Produced at the Lawrence Livermore National Laboratory 
00005 # Written by Bret R. Beck, beck6@llnl.gov. 
00006 # CODE-461393
00007 # All rights reserved. 
00008 #  
00009 # This file is part of GIDI. For details, see nuclear.llnl.gov. 
00010 # Please also read the "Additional BSD Notice" at nuclear.llnl.gov. 
00011 # 
00012 # Redistribution and use in source and binary forms, with or without modification, 
00013 # are permitted provided that the following conditions are met: 
00014 #
00015 #      1) Redistributions of source code must retain the above copyright notice, 
00016 #         this list of conditions and the disclaimer below.
00017 #      2) Redistributions in binary form must reproduce the above copyright notice, 
00018 #         this list of conditions and the disclaimer (as noted below) in the 
00019 #          documentation and/or other materials provided with the distribution.
00020 #      3) Neither the name of the LLNS/LLNL nor the names of its contributors may be 
00021 #         used to endorse or promote products derived from this software without 
00022 #         specific prior written permission. 
00023 #
00024 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
00025 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00026 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT 
00027 # SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR 
00028 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00029 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
00030 # OR SERVICES;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
00031 # AND ON  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00032 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
00033 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00034 # <<END-copyright>>
00035 */
00036 #include <string.h>
00037 #include <ctype.h>
00038 
00039 #include <tpia_target.h>
00040 #include <tpia_misc.h>
00041 
00042 #if defined __cplusplus
00043 namespace GIDI {
00044 using namespace GIDI;
00045 #endif
00046 
00047 /*
00048 ************************************************************
00049 */
00050 tpia_multiplicity *tpia_multiplicity_create( statusMessageReporting *smr ) {
00051 
00052     tpia_multiplicity *multiplicity;
00053 
00054     //if( ( multiplicity = xData_malloc2( smr, sizeof( tpia_multiplicity ), 0, "multiplicity" ) ) == NULL ) return( NULL );
00055     if( ( multiplicity = (tpia_multiplicity*) xData_malloc2( smr, sizeof( tpia_multiplicity ), 0, "multiplicity" ) ) == NULL ) return( NULL );
00056     if( tpia_multiplicity_initialize( smr, multiplicity ) ) multiplicity = tpia_multiplicity_free( smr, multiplicity );
00057     return( multiplicity );
00058 }
00059 /*
00060 ************************************************************
00061 */
00062 int tpia_multiplicity_initialize( statusMessageReporting *smr, tpia_multiplicity *multiplicity ) {
00063 
00064     memset( multiplicity, 0, sizeof( tpia_multiplicity ) );
00065     if( tpia_frame_setFromString( smr, "", "", 0, &(multiplicity->frame) ) ) return( 1 );
00066     return( 0 );
00067 }
00068 /*
00069 ************************************************************
00070 */
00071 tpia_multiplicity *tpia_multiplicity_free( statusMessageReporting *smr, tpia_multiplicity *multiplicity ) {
00072 
00073     tpia_multiplicity_release( smr, multiplicity );
00074     xData_free( smr, multiplicity );
00075     return( NULL );
00076 }
00077 /*
00078 ************************************************************
00079 */
00080 int tpia_multiplicity_release( statusMessageReporting *smr, tpia_multiplicity *multiplicity ) {
00081 
00082     //multiplicity->grouped.data = xData_free( smr, multiplicity->grouped.data );
00083     multiplicity->grouped.data = (double*) xData_free( smr, multiplicity->grouped.data );
00084     //multiplicity->pointwise = xData_free( smr, multiplicity->pointwise );
00085     multiplicity->pointwise = (double*) xData_free( smr, multiplicity->pointwise );
00086     tpia_multiplicity_initialize( smr, multiplicity );
00087     return( 0 );
00088 }
00089 /*
00090 ************************************************************
00091 */
00092 tpia_multiplicity *tpia_multiplicity_createGetFromElement( statusMessageReporting *smr, xData_element *multiplicityElement, int nGroups ) {
00093 
00094     tpia_multiplicity *multiplicity;
00095 
00096     if( ( multiplicity = tpia_multiplicity_create( smr ) ) == NULL ) return( NULL );
00097     if( tpia_multiplicity_getFromElement( smr, multiplicityElement, multiplicity, nGroups ) != 0 ) multiplicity = tpia_multiplicity_free( smr, multiplicity  );
00098     return( multiplicity );
00099 }
00100 /*
00101 ************************************************************
00102 */
00103 //int tpia_multiplicity_getFromElement( statusMessageReporting *smr, xData_element *multiplicityElement, tpia_multiplicity *multiplicity, int nGroups ) {
00104 int tpia_multiplicity_getFromElement( statusMessageReporting *smr, xData_element *multiplicityElement, tpia_multiplicity *multiplicity, int ) {
00105 
00106     const char *timeScale;
00107     int isDelayedNeutrons;
00108     xData_element *data;
00109 
00110     xData_addToAccessed( smr, multiplicityElement, 1 );
00111     if( ( tpia_frame_setFromElement( smr, multiplicityElement, 2, &(multiplicity->frame) ) ) != 0 ) return( 1 );
00112     if( tpia_multiplicity_getTimeScaleFromElement( smr, multiplicityElement, &timeScale, &isDelayedNeutrons, &(multiplicity->timeScale) ) ) return( 1 );
00113     for( data = xData_getFirstElement( multiplicityElement ); data != NULL; data = xData_getNextElement( data ) ) {
00114         if( strcmp( data->name, "grouped" ) == 0 ) {
00115             if( tpia_misc_get2d_xShared_yHistogram_data_Grouped( smr, data, &(multiplicity->grouped) ) ) return( 1 ); }
00116         else if( strcmp( data->name, "pointwise" ) == 0 ) {
00117             if( ( multiplicity->pointwise = tpia_misc_get2dx_y_data( smr, data, &multiplicity->numberOfPointwise ) ) == NULL ) return( 1 ); }
00118         else {
00119             tpia_misc_setMessageError_Element( smr, NULL, multiplicityElement, __FILE__, __LINE__, 1, "unsupported multiplicity type = %s", data->name );
00120             return( 1 );
00121         }
00122     }
00123     return( 0 );
00124 }
00125 /*
00126 ************************************************************
00127 */
00128 int tpia_multiplicity_getTimeScaleFromElement( statusMessageReporting *smr, xData_element *element, const char **timeScale, int *isDelayedNeutrons, 
00129         double *dTimeScale ) {
00130 
00131     const char *p;
00132     char *e;
00133 
00134     *isDelayedNeutrons = 0;
00135     *dTimeScale = 0.;
00136     *timeScale = xData_getAttributesValue( &(element->attributes), "timeScale" );
00137     if( *timeScale != NULL ) {
00138         if( strcmp( *timeScale, "prompt" ) ) {
00139             if( strncmp( *timeScale, "delayed", 7 ) ) {
00140                 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "invalid timeScale attribute = %s", *timeScale );
00141                 return( 1 ); }
00142             else {
00143                 for( p = &((*timeScale)[7]); *p; p++ ) if( !isspace( *p ) ) break;
00144                 if( *p != '=' ) {
00145                     tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "timeScale attribute '%s' missing '='", *timeScale );
00146                     return( 1 );
00147                 }
00148                 p++;
00149                 *dTimeScale = strtod( p, &e );
00150                 if( *e != 0 ) {
00151                     tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "could not convert timeScale attribute '%s' to double",
00152                         *timeScale );
00153                     return( 1 );
00154                 }
00155                 *isDelayedNeutrons = 1;
00156             }
00157         }
00158     }
00159     return( 0 );
00160 }
00161 
00162 #if defined __cplusplus
00163 }
00164 #endif

Generated on Mon May 27 17:50:35 2013 for Geant4 by  doxygen 1.4.7