Jpp  18.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEllipse.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 
4 #include "TROOT.h"
5 #include "TFile.h"
6 #include "TEllipse.h"
7 
8 #include "Jeep/JContainer.hh"
9 #include "Jeep/JProperties.hh"
10 #include "Jeep/JParser.hh"
11 #include "Jeep/JMessage.hh"
12 
13 
14 /**
15  * Auxiliary data structure for ellipse.
16  */
17 struct JEllipse {
18 
19  /**
20  * Read ellipse from input stream.
21  *
22  * \param in input stream
23  * \param ellipse ellipse
24  * \return input stream
25  */
26  friend inline std::istream& operator>>(std::istream& in, JEllipse& ellipse)
27  {
28  if (in >> ellipse.x1 >> ellipse.y1 >> ellipse.r1) {
29 
30  if (in >> ellipse.r2) {
31 
32  if (in >> ellipse.phimin >> ellipse.phimax) {
33 
34  } else {
35 
36  ellipse.phimin = 0.0;
37  ellipse.phimax = 360.0;
38  }
39 
40  } else {
41 
42  ellipse.r2 = ellipse.r1;
43  ellipse.phimin = 0.0;
44  ellipse.phimax = 360.0;
45  }
46 
47  in.clear();
48  }
49 
50  return in;
51  }
52 
53  /**
54  * Write ellipse to output stream.
55  *
56  * \param out output stream
57  * \param ellipse ellipse
58  * \return output stream
59  */
60  friend inline std::ostream& operator<<(std::ostream& out, const JEllipse& ellipse)
61  {
62  out << ellipse.x1 << ' '
63  << ellipse.y1 << ' '
64  << ellipse.r1 << ' '
65  << ellipse.r2 << ' '
66  << ellipse.phimin << ' '
67  << ellipse.phimax;
68 
69  return out;
70  }
71 
72  double x1;
73  double y1;
74  double r1;
75  double r2;
76  double phimin;
77  double phimax;
78 };
79 
80 
81 /**
82  * \file
83  * Auxiliary program to create TEllipse.
84  * \author mdejong
85  */
86 int main(int argc, char **argv)
87 {
88  using namespace std;
89  using namespace JPP;
90 
91  typedef JContainer< vector<JEllipse> > JParameters_t;
92 
93  string outputFile;
94  JParameters_t parameters;
95  struct {
96  Color_t color = kBlack;
97  Style_t style = 0; // hollow
98  } fill;
99  struct {
100  Color_t color = kBlack;
101  Style_t style = kSolid;
102  } line;
103  int debug;
104 
105  try {
106 
107  JProperties properties(JEquationParameters("=", "\n", "", "#"));
108 
109  properties.insert(zmake_property(fill.color));
110  properties.insert(zmake_property(fill.style));
111  properties.insert(zmake_property(line.color));
112  properties.insert(zmake_property(line.style));
113 
114  JParser<> zap("Auxiliary program to create TEllipse");
115 
116  zap['o'] = make_field(outputFile);
117  zap['p'] = make_field(parameters, "x y r1 [r2 [phimin phimax]]");
118  zap['@'] = make_field(properties, "ellipse attributes") = JPARSER::initialised();
119  zap['d'] = make_field(debug) = 1;
120 
121  zap(argc, argv);
122  }
123  catch(const exception &error) {
124  FATAL(error.what() << endl);
125  }
126 
127 
128  TFile out(outputFile.c_str(), "recreate");
129 
130  for (size_t i = 0; i != parameters.size(); ++i) {
131 
132  TEllipse* p = new TEllipse(parameters[i].x1, parameters[i].y1, parameters[i].r1, parameters[i].r2, parameters[i].phimin, parameters[i].phimax);
133 
134  p->SetFillColor(fill.color);
135  p->SetFillStyle(fill.style);
136  p->SetLineColor(line.color);
137  p->SetLineStyle(line.style);
138 
139  out.WriteTObject(p);
140  }
141 
142  out.Write();
143  out.Close();
144 }
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
double r2
Definition: JEllipse.cc:75
double x1
Definition: JEllipse.cc:72
Utility class to parse parameter values.
Definition: JProperties.hh:497
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Simple data structure to support I/O of equations (see class JLANG::JEquation).
friend std::ostream & operator<<(std::ostream &out, const JEllipse &ellipse)
Write ellipse to output stream.
Definition: JEllipse.cc:60
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
string outputFile
Utility class to parse parameter values.
double phimax
Definition: JEllipse.cc:77
friend std::istream & operator>>(std::istream &in, JEllipse &ellipse)
Read ellipse from input stream.
Definition: JEllipse.cc:26
double r1
Definition: JEllipse.cc:74
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
double y1
Definition: JEllipse.cc:73
Auxiliary data structure for ellipse.
Definition: JEllipse.cc:17
double phimin
Definition: JEllipse.cc:76
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
#define zmake_property(A)
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
Container I/O.
int debug
debug level