Geant4 Cross Reference |
1 /* 1 /* 2 # <<BEGIN-copyright>> 2 # <<BEGIN-copyright>> 3 # <<END-copyright>> 3 # <<END-copyright>> 4 */ 4 */ 5 5 6 #include <iostream> 6 #include <iostream> 7 #include <stdlib.h> 7 #include <stdlib.h> 8 8 9 #include "GIDI_settings.hh" 9 #include "GIDI_settings.hh" 10 10 11 /* 11 /* 12 ============================================== 12 ========================================================= 13 */ 13 */ 14 GIDI_settings_group::GIDI_settings_group( std: 14 GIDI_settings_group::GIDI_settings_group( std::string const &label, int size1 ) { 15 15 16 initialize( label, size1, size1, NULL ); 16 initialize( label, size1, size1, NULL ); 17 } 17 } 18 /* 18 /* 19 ============================================== 19 ========================================================= 20 */ 20 */ 21 GIDI_settings_group::GIDI_settings_group( std: 21 GIDI_settings_group::GIDI_settings_group( std::string const &label, int length, double const *boundaries ) { 22 22 23 initialize( label, length, length, boundar 23 initialize( label, length, length, boundaries ); 24 } 24 } 25 /* 25 /* 26 ============================================== 26 ========================================================= 27 */ 27 */ 28 GIDI_settings_group::GIDI_settings_group( std: 28 GIDI_settings_group::GIDI_settings_group( std::string const &label, std::vector<double> const &boundaries) { 29 29 30 int size1 = (int) boundaries.size( ); 30 int size1 = (int) boundaries.size( ); 31 31 32 initialize( label, size1, size1, &(boundar 32 initialize( label, size1, size1, &(boundaries[0]) ); 33 } 33 } 34 /* 34 /* 35 ============================================== 35 ========================================================= 36 */ 36 */ 37 GIDI_settings_group::GIDI_settings_group( GIDI 37 GIDI_settings_group::GIDI_settings_group( GIDI_settings_group const &group ) { 38 38 39 initialize( group.mLabel, group.size( ), g 39 initialize( group.mLabel, group.size( ), group.size( ), &(group.mBoundaries[0]) ); 40 } 40 } 41 /* 41 /* 42 ============================================== 42 ========================================================= 43 */ 43 */ 44 void GIDI_settings_group::initialize( std::str 44 void GIDI_settings_group::initialize( std::string const &label, int size1, int length, double const *boundaries ) { 45 45 46 int i1; 46 int i1; 47 47 48 mLabel = label; 48 mLabel = label; 49 if( size1 < length ) size1 = length; 49 if( size1 < length ) size1 = length; 50 if( size1 < 0 ) size1 = 0; 50 if( size1 < 0 ) size1 = 0; 51 mBoundaries.resize( size1, 0 ); 51 mBoundaries.resize( size1, 0 ); 52 for( i1 = 0; i1 < length; ++i1 ) mBoundari 52 for( i1 = 0; i1 < length; ++i1 ) mBoundaries[i1] = boundaries[i1]; 53 } 53 } 54 /* 54 /* 55 ============================================== 55 ========================================================= 56 */ 56 */ 57 GIDI_settings_group& GIDI_settings_group::oper 57 GIDI_settings_group& GIDI_settings_group::operator=( const GIDI_settings_group &group ) { 58 if ( this != &group ) { 58 if ( this != &group ) { 59 initialize( group.mLabel, group.size(), gr 59 initialize( group.mLabel, group.size(), group.size(), &(group.mBoundaries[0]) ); 60 } 60 } 61 return *this; 61 return *this; 62 } 62 } 63 /* 63 /* 64 ============================================== 64 ========================================================= 65 */ 65 */ 66 GIDI_settings_group::~GIDI_settings_group( ) { 66 GIDI_settings_group::~GIDI_settings_group( ) { 67 67 68 } 68 } 69 /* 69 /* 70 ============================================== 70 ========================================================= 71 */ 71 */ 72 int GIDI_settings_group::getGroupIndexFromEner 72 int GIDI_settings_group::getGroupIndexFromEnergy( double energy, bool encloseOutOfRange ) const { 73 73 74 int iMin = 0, iMid, iMax = (int) mBoundari 74 int iMin = 0, iMid, iMax = (int) mBoundaries.size( ), iMaxM1 = iMax - 1; 75 75 76 if( iMax == 0 ) return( -3 ); 76 if( iMax == 0 ) return( -3 ); 77 if( energy < mBoundaries[0] ) { 77 if( energy < mBoundaries[0] ) { 78 if( encloseOutOfRange ) return( 0 ); 78 if( encloseOutOfRange ) return( 0 ); 79 return( -2 ); 79 return( -2 ); 80 } 80 } 81 if( energy > mBoundaries[iMaxM1] ) { 81 if( energy > mBoundaries[iMaxM1] ) { 82 if( encloseOutOfRange ) return( iMax - 82 if( encloseOutOfRange ) return( iMax - 2 ); 83 return( -1 ); 83 return( -1 ); 84 } 84 } 85 while( 1 ) { // Loop checking, 11.06.2015, 85 while( 1 ) { // Loop checking, 11.06.2015, T. Koi 86 iMid = ( iMin + iMax ) >> 1; 86 iMid = ( iMin + iMax ) >> 1; 87 if( iMid == iMin ) break; 87 if( iMid == iMin ) break; 88 if( energy < mBoundaries[iMid] ) { 88 if( energy < mBoundaries[iMid] ) { 89 iMax = iMid; } 89 iMax = iMid; } 90 else { 90 else { 91 iMin = iMid; 91 iMin = iMid; 92 } 92 } 93 } 93 } 94 if( iMin == iMaxM1 ) iMin--; 94 if( iMin == iMaxM1 ) iMin--; 95 return( iMin ); 95 return( iMin ); 96 } 96 } 97 /* 97 /* 98 ============================================== 98 ========================================================= 99 */ 99 */ 100 void GIDI_settings_group::print( bool outline, 100 void GIDI_settings_group::print( bool outline, int valuesPerLine ) const { 101 101 102 int nbs = size( ); 102 int nbs = size( ); 103 char buffer[128]; 103 char buffer[128]; 104 104 105 std::cout << "GROUP: label = '" << mLabel 105 std::cout << "GROUP: label = '" << mLabel << "': length = " << nbs << std::endl; 106 if( outline ) return; 106 if( outline ) return; 107 for( int ib = 0; ib < nbs; ib++ ) { 107 for( int ib = 0; ib < nbs; ib++ ) { 108 snprintf( buffer, sizeof buffer, "%16. << 108 sprintf( buffer, "%16.8e", mBoundaries[ib] ); 109 std::cout << buffer; 109 std::cout << buffer; 110 if( ( ( ib + 1 ) % valuesPerLine ) == 110 if( ( ( ib + 1 ) % valuesPerLine ) == 0 ) std::cout << std::endl; 111 } 111 } 112 if( nbs % valuesPerLine ) std::cout << std 112 if( nbs % valuesPerLine ) std::cout << std::endl; 113 } 113 } 114 114 115 #if 0 115 #if 0 116 /* ---- GIDI_settings_groups_from_bdfls ---- 116 /* ---- GIDI_settings_groups_from_bdfls ---- */ 117 /* 117 /* 118 ============================================== 118 ========================================================= 119 */ 119 */ 120 GIDI_settings_groups_from_bdfls::GIDI_settings 120 GIDI_settings_groups_from_bdfls::GIDI_settings_groups_from_bdfls( std::string const &fileName ) { 121 121 122 initialize( fileName.c_str( ) ); 122 initialize( fileName.c_str( ) ); 123 } 123 } 124 /* 124 /* 125 ============================================== 125 ========================================================= 126 */ 126 */ 127 GIDI_settings_groups_from_bdfls::GIDI_settings 127 GIDI_settings_groups_from_bdfls::GIDI_settings_groups_from_bdfls( char const *fileName ) { 128 128 129 initialize( fileName ); 129 initialize( fileName ); 130 } 130 } 131 /* 131 /* 132 ============================================== 132 ========================================================= 133 */ 133 */ 134 GIDI_settings_groups_from_bdfls::GIDI_settings 134 GIDI_settings_groups_from_bdfls::GIDI_settings_groups_from_bdfls( cbdfls_file const *bdfls ) { 135 135 136 initialize2( bdfls ); 136 initialize2( bdfls ); 137 } 137 } 138 /* 138 /* 139 ============================================== 139 ========================================================= 140 */ 140 */ 141 void GIDI_settings_groups_from_bdfls::initiali 141 void GIDI_settings_groups_from_bdfls::initialize( char const *fileName ) { 142 142 143 cbdfls_file *bdfls; 143 cbdfls_file *bdfls; 144 cbdflsErrors Error; 144 cbdflsErrors Error; 145 145 146 if( ( bdfls = cbdflsOpen( fileName, &Error 146 if( ( bdfls = cbdflsOpen( fileName, &Error ) ) == NULL ) throw Error; 147 initialize2( bdfls ); 147 initialize2( bdfls ); 148 cbdflsRelease( bdfls ); 148 cbdflsRelease( bdfls ); 149 } 149 } 150 /* 150 /* 151 ============================================== 151 ========================================================= 152 */ 152 */ 153 void GIDI_settings_groups_from_bdfls::initiali 153 void GIDI_settings_groups_from_bdfls::initialize2( cbdfls_file const *bdfls ) { 154 154 155 int ng, ngbs, *gids; 155 int ng, ngbs, *gids; 156 double *boundaries; 156 double *boundaries; 157 std::string label( "" ); 157 std::string label( "" ); 158 char cLabel[100]; 158 char cLabel[100]; 159 159 160 ng = cbdflsGIDs( (cbdfls_file *) bdfls, &g 160 ng = cbdflsGIDs( (cbdfls_file *) bdfls, &gids ); 161 for( int ig = 0; ig < ng; ++ig ) { 161 for( int ig = 0; ig < ng; ++ig ) { 162 ngbs = cbdflsGetGroup( (cbdfls_file *) 162 ngbs = cbdflsGetGroup( (cbdfls_file *) bdfls, gids[ig], &boundaries ); 163 snprintf( cLabel, sizeof xLabel, "LLNL << 163 sprintf( cLabel, "LLNL_gid_%.3d", gids[ig] ); 164 label = cLabel; 164 label = cLabel; 165 mGroups.push_back( GIDI_settings_group 165 mGroups.push_back( GIDI_settings_group( label, ngbs, boundaries ) ); 166 } 166 } 167 } 167 } 168 /* 168 /* 169 ============================================== 169 ========================================================= 170 */ 170 */ 171 GIDI_settings_groups_from_bdfls::~GIDI_setting 171 GIDI_settings_groups_from_bdfls::~GIDI_settings_groups_from_bdfls( ) { 172 172 173 } 173 } 174 /* 174 /* 175 ============================================== 175 ========================================================= 176 */ 176 */ 177 GIDI_settings_group GIDI_settings_groups_from_ 177 GIDI_settings_group GIDI_settings_groups_from_bdfls::getViaGID( int gid ) const { 178 178 179 std::string label( "" ); 179 std::string label( "" ); 180 char cLabel[100]; 180 char cLabel[100]; 181 181 182 snprintf( cLabel, sizeof cLabel, "LLNL_gid << 182 sprintf( cLabel, "LLNL_gid_%.3d", gid ); 183 label = cLabel; 183 label = cLabel; 184 for( int ig = 0; ig < (int) mGroups.size( 184 for( int ig = 0; ig < (int) mGroups.size( ); ++ig ) { 185 if( mGroups[ig].isLabel( label ) ) ret 185 if( mGroups[ig].isLabel( label ) ) return( mGroups[ig] ); 186 } 186 } 187 throw 1; 187 throw 1; 188 } 188 } 189 /* 189 /* 190 ============================================== 190 ========================================================= 191 */ 191 */ 192 std::vector<std::string> GIDI_settings_groups_ 192 std::vector<std::string> GIDI_settings_groups_from_bdfls::getLabels( void ) const { 193 193 194 int size = (int) mGroups.size( ); 194 int size = (int) mGroups.size( ); 195 std::vector<std::string> labels( size ); 195 std::vector<std::string> labels( size ); 196 196 197 for( int if1 = 0; if1 < size; ++if1 ) labe 197 for( int if1 = 0; if1 < size; ++if1 ) labels[if1] = mGroups[if1].getLabel( ); 198 return( labels ); 198 return( labels ); 199 } 199 } 200 /* 200 /* 201 ============================================== 201 ========================================================= 202 */ 202 */ 203 std::vector<int> GIDI_settings_groups_from_bdf 203 std::vector<int> GIDI_settings_groups_from_bdfls::getGIDs( void ) const { 204 204 205 int size = (int) mGroups.size( ); 205 int size = (int) mGroups.size( ); 206 std::vector<int> fids( size ); 206 std::vector<int> fids( size ); 207 char *e; 207 char *e; 208 208 209 for( int if1 = 0; if1 < size; ++if1 ) { 209 for( int if1 = 0; if1 < size; ++if1 ) { 210 fids[if1] = (int) strtol( &(mGroups[if 210 fids[if1] = (int) strtol( &(mGroups[if1].getLabel( ).c_str( )[9]), &e, 10 ); 211 } 211 } 212 return( fids ); 212 return( fids ); 213 } 213 } 214 /* 214 /* 215 ============================================== 215 ========================================================= 216 */ 216 */ 217 void GIDI_settings_groups_from_bdfls::print( b 217 void GIDI_settings_groups_from_bdfls::print( bool outline, int valuesPerLine ) const { 218 218 219 int ngs = (int) mGroups.size( ); 219 int ngs = (int) mGroups.size( ); 220 220 221 std::cout << "BDFLS GROUPs: number of grou 221 std::cout << "BDFLS GROUPs: number of groups = " << ngs << std::endl; 222 for( int if1 = 0; if1 < ngs ; ++if1 ) mGro 222 for( int if1 = 0; if1 < ngs ; ++if1 ) mGroups[if1].print( outline, valuesPerLine ); 223 } 223 } 224 #endif 224 #endif 225 225