Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPMTAngularAcceptance.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <fstream>
4 #include <iomanip>
5 #include <limits>
6 
7 #include "Jeep/JPrint.hh"
8 #include "Jeep/JParser.hh"
9 #include "Jeep/JMessage.hh"
10 
11 
12 /**
13  * \author mdejong
14  */
15 
16 /**
17  * Auxiliary program to convert PMT QE(angle) data.
18  */
19 int main(int argc, char **argv)
20 {
21  using namespace std;
22 
23  string inputFile;
24  int debug;
25 
26  try {
27 
28  JParser<> zap("Auxiliary program to convert PMT QE(angle) data.");
29 
30  zap['f'] = make_field(inputFile);
31  zap['d'] = make_field(debug) = 1;
32 
33  zap(argc, argv);
34  }
35  catch(const exception &error) {
36  FATAL(error.what() << endl);
37  }
38 
39 
40  const string DEG("deg");
41 
42 
43  if (inputFile != "") {
44 
45  ifstream in(inputFile.c_str());
46 
47  while (in.peek() == '#') {
48  in.ignore(numeric_limits<streamsize>::max(), '\n');
49  }
50 
51  // header
52 
53  vector<double> energy;
54 
55  string buffer, key;
56 
57  if (getline(in,buffer)) {
58 
59  istringstream is(buffer);
60 
61  is >> key;
62 
63  for (double x; is >> x; ) {
64  energy.push_back(x);
65  }
66  }
67 
68  in.ignore(numeric_limits<streamsize>::max(), '\n');
69 
70 
71  // data
72 
73  while (getline(in,buffer)) {
74 
75  istringstream is(buffer);
76 
77  // first column
78 
79  is >> key;
80 
81  const size_t pos = key.find(DEG);
82 
83  if (pos != string::npos) {
84  key.replace(pos, DEG.size(), "");
85  }
86 
87  double angle;
88 
89  istringstream(key) >> angle;
90 
91  // following columns
92 
93  size_t i = 0;
94 
95  for (double y ; is >> y; ++i) {
96 
97  if (i != energy.size()) {
98  cout << " (*this)"
99  << noshowpos
100  << "[" << FIXED(5,1) << angle << "]"
101  << "[" << FIXED(3,1) << energy[i] << "]"
102  << " = "
103  << showpos
104  << FIXED(9,5) << y
105  << ";" << endl;
106  } else {
107  FATAL("Inconsistent data " << i << " != " << energy.size() << endl);
108  }
109  }
110 
111  if (i != energy.size()) {
112  FATAL("Inconsistent data " << i << " != " << energy.size() << endl);
113  }
114  }
115 
116  in.close();
117  }
118 }
Utility class to parse command line options.
Definition: JParser.hh:1410
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:461
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:468
int debug
debug level
Definition: JSirene.cc:59
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:65
Utility class to parse command line options.
int main(int argc, char *argv[])
Definition: Main.cpp:15