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