Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
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 */
17struct 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 */
86int 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 Width_t width = 1;
103 } line;
104 int debug;
105
106 try {
107
108 JProperties properties(JEquationParameters("=", "\n", "", "#"));
109
110 properties.insert(zmake_property(fill.color));
111 properties.insert(zmake_property(fill.style));
112 properties.insert(zmake_property(line.color));
113 properties.insert(zmake_property(line.style));
114 properties.insert(zmake_property(line.width));
115
116 JParser<> zap("Auxiliary program to create TEllipse");
117
118 zap['o'] = make_field(outputFile);
119 zap['p'] = make_field(parameters, "x y r1 [r2 [phimin phimax]]");
120 zap['@'] = make_field(properties, "ellipse attributes") = JPARSER::initialised();
121 zap['d'] = make_field(debug) = 1;
122
123 zap(argc, argv);
124 }
125 catch(const exception &error) {
126 FATAL(error.what() << endl);
127 }
128
129
130 TFile out(outputFile.c_str(), "recreate");
131
132 for (size_t i = 0; i != parameters.size(); ++i) {
133
134 TEllipse* p = new TEllipse(parameters[i].x1, parameters[i].y1, parameters[i].r1, parameters[i].r2, parameters[i].phimin, parameters[i].phimax);
135
136 p->SetFillColor(fill.color);
137 p->SetFillStyle(fill.style);
138 p->SetLineColor(line.color);
139 p->SetLineStyle(line.style);
140 p->SetLineWidth(line.width);
141
142 out.WriteTObject(p);
143 }
144
145 out.Write();
146 out.Close();
147}
Container I/O.
string outputFile
int main(int argc, char **argv)
Definition JEllipse.cc:86
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Utility class to parse parameter values.
#define zmake_property(A)
Utility class to parse parameter values.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Definition JContainer.hh:42
Auxiliary data structure for ellipse.
Definition JEllipse.cc:17
friend std::istream & operator>>(std::istream &in, JEllipse &ellipse)
Read ellipse from input stream.
Definition JEllipse.cc:26
double r2
Definition JEllipse.cc:75
double y1
Definition JEllipse.cc:73
double x1
Definition JEllipse.cc:72
double phimin
Definition JEllipse.cc:76
friend std::ostream & operator<<(std::ostream &out, const JEllipse &ellipse)
Write ellipse to output stream.
Definition JEllipse.cc:60
double phimax
Definition JEllipse.cc:77
double r1
Definition JEllipse.cc:74
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68