StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
getConfigTest.cc
1 /***************************************************************************
2  *
3  * $Id: getConfigTest.cc,v 1.4 2003/09/02 17:59:37 perev Exp $
4  *
5  * Author: Thomas Ullrich, May 1998
6  ***************************************************************************
7  *
8  * Description: Example/test program for StGetConfigValue utility
9  *
10  ***************************************************************************
11  *
12  * $Log: getConfigTest.cc,v $
13  * Revision 1.4 2003/09/02 17:59:37 perev
14  * gcc 3.2 updates + WarnOff
15  *
16  * Revision 1.3 1999/12/21 15:14:41 ullrich
17  * Modified to cope with new compiler version on Sun (CC5.0).
18  *
19  * Revision 1.2 1999/05/19 21:14:42 ullrich
20  * Corrected path of input file
21  *
22  * Revision 1.1 1999/02/17 12:43:56 ullrich
23  * New Revision
24  *
25  * Revision 1.1 1999/01/23 00:26:41 ullrich
26  * Initial Revision
27  *
28  **************************************************************************/
29 #include <Stiostream.h>
30 #include "StGlobals.hh"
31 #include "StGetConfigValue.hh"
32 #include "StThreeVector.hh"
33 #include <vector>
34 #include <unistd.h>
35 #if !defined(ST_NO_NAMESPACES)
36 using std::vector;
37 #endif
38 
39 int main()
40 {
41  const char* filename = "example.conf";
42 
43  if (access(filename, R_OK)) {
44  cerr << "Cannot access file '" << filename << "'" << endl;
45  return 1;
46  }
47 
48  double singleValue = 10;
49  StGetConfigValue(filename, "singleValue", singleValue);
50  cout << "singleValue = " << singleValue << endl;
51 
52  float *manyValues = new float[10];
53  StGetConfigValue(filename, "manyValues", manyValues, 10);
54  cout << "manyValues = ";
55  for (int i=0; i<10; i++) cout << manyValues[i] << ' ';
56  cout << endl;
57 
58 #ifdef ST_NO_TEMPLATE_DEF_ARGS
59  vector<double, allocator<double> > vec(10,0);
60 #else
61 #ifdef GNU_GCC
62  vector<double> vec(10);
63 #else
64  vector<double> vec(10,0);
65 #endif // GNU_GCC %$#&
66 #endif
67  StGetConfigValue(filename, "vec", vec, 5);
68  cout << "vec = ";
69  for (int k=0; k<10; k++) cout << vec[k] << ' ';
70  cout << endl;
71 
73  StGetConfigValue(filename, "vec3", vec3);
74  cout << "vec3 = " << vec3 << endl;
75 
76 #if !defined(__SUNPRO_CC)
77  string anyName("default");
78  StGetConfigValue(filename, "anyName", anyName);
79  cout << "anyName = " << anyName.c_str() << endl;
80 #endif
81 
82  float xfoo = 3.14;
83  StGetConfigValue(filename, "xfoo", xfoo);
84  cout << "xfoo = " << xfoo << endl;
85 
86  return 0;
87 }