Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JBox.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 "TBox.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 box.
16 */
17struct JBox {
18
19 /**
20 * Read box from input stream.
21 *
22 * \param in input stream
23 * \param box box
24 * \return input stream
25 */
26 friend inline std::istream& operator>>(std::istream& in, JBox& box)
27 {
28 return in >> box.x1 >> box.y1 >> box.x2 >> box.y2;
29 }
30
31 /**
32 * Write box to output stream.
33 *
34 * \param out output stream
35 * \param box box
36 * \return output stream
37 */
38 friend inline std::ostream& operator<<(std::ostream& out, const JBox& box)
39 {
40 out << box.x1 << ' '
41 << box.y1 << ' '
42 << box.x2 << ' '
43 << box.y2;
44
45 return out;
46 }
47
48 double x1;
49 double y1;
50 double x2;
51 double y2;
52};
53
54
55/**
56 * \file
57 * Auxiliary program to create TBox.
58 * \author mdejong
59 */
60int main(int argc, char **argv)
61{
62 using namespace std;
63 using namespace JPP;
64
65 typedef JContainer< vector<JBox> > JParameters_t;
66
67 string outputFile;
68 JParameters_t parameters;
69 struct {
70 Color_t color = kBlack;
71 Style_t style = 0; // hollow
72 } fill;
73 struct {
74 Color_t color = kBlack;
75 Style_t style = kSolid;
76 Width_t width = 1;
77 } line;
78 int debug;
79
80 try {
81
82 JProperties properties(JEquationParameters("=", "\n", "", "#"));
83
84 properties.insert(zmake_property(fill.color));
85 properties.insert(zmake_property(fill.style));
86 properties.insert(zmake_property(line.color));
87 properties.insert(zmake_property(line.style));
88 properties.insert(zmake_property(line.width));
89
90 JParser<> zap("Auxiliary program to create TBox");
91
92 zap['o'] = make_field(outputFile);
93 zap['p'] = make_field(parameters, "x1 y1 x2 y2");
94 zap['@'] = make_field(properties, "box attributes") = JPARSER::initialised();
95 zap['d'] = make_field(debug) = 1;
96
97 zap(argc, argv);
98 }
99 catch(const exception &error) {
100 FATAL(error.what() << endl);
101 }
102
103
104 TFile out(outputFile.c_str(), "recreate");
105
106 for (size_t i = 0; i != parameters.size(); ++i) {
107
108 TBox* p = new TBox(parameters[i].x1, parameters[i].y1, parameters[i].x2, parameters[i].y2);
109
110 p->SetFillColor(fill.color);
111 p->SetFillStyle(fill.style);
112 p->SetLineColor(line.color);
113 p->SetLineStyle(line.style);
114 p->SetLineWidth(line.width);
115
116 out.WriteTObject(p);
117 }
118
119 out.Write();
120 out.Close();
121}
int main(int argc, char **argv)
Definition JBox.cc:60
Container I/O.
string outputFile
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 data structure for box.
Definition JBox.cc:17
friend std::istream & operator>>(std::istream &in, JBox &box)
Read box from input stream.
Definition JBox.cc:26
double y1
Definition JBox.cc:49
double x2
Definition JBox.cc:50
double x1
Definition JBox.cc:48
friend std::ostream & operator<<(std::ostream &out, const JBox &box)
Write box to output stream.
Definition JBox.cc:38
double y2
Definition JBox.cc:51
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Definition JContainer.hh:42
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68