ROOTPWA
vamp.cc
Go to the documentation of this file.
1 #include <complex>
2 #include <iostream>
3 #include <iomanip>
4 #include <limits>
5 #include <sstream>
6 #include <cstdlib>
7 #include <unistd.h>
8 
9 
10 using namespace std;
11 
12 
13 void
14 printUsage(char* prog)
15 {
16  cerr << "usage:" << endl
17  << " " << prog << " [-h] [-m maxEvents] [-B] < inputfile" << endl
18  << "-B\tconvert ascii to binary mode" << endl;
19 
20 }
21 
22 
23 int
24 main(int argc, char** argv)
25 {
26  int maxEvents = 0;
27  int nRead = 0;
28  int binaryMode = 0;
29 
30  extern char* optarg;
31  int c;
32  while ((c = getopt(argc, argv, "m:h:B")) != -1)
33  switch (c) {
34  case 'm':
35  maxEvents = atoi(optarg);
36  break;
37  case 'B':
38  binaryMode = 1;
39  break;
40  case 'h':
41  case '?':
42  printUsage(argv[0]);
43  exit(0);
44  }
45 
46  complex<double> a;
47  const unsigned int size = sizeof(a);
48  if (binaryMode) {
49  while ((cin >> a) && (maxEvents ? (nRead < maxEvents) : 1)) {
50  nRead++;
51  cout.write((char*) &a, size);
52  }
53  } else {
54  while ((cin.read((char*) &a, size)) && (maxEvents ? (nRead < maxEvents) : 1)) {
55  nRead++;
56  const unsigned int nmbDigits = numeric_limits<double>::digits10 + 1;
57  ostringstream s;
58  s.precision(nmbDigits);
59  s.setf(ios_base::scientific, ios_base::floatfield);
60  s << a;
61  cout << s.str() << endl;
62  }
63  }
64 
65  return 0;
66 }