Jpp  18.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JLine.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <vector>
4 
5 #include "TROOT.h"
6 #include "TFile.h"
7 #include "TLine.h"
8 
9 #include "Jeep/JContainer.hh"
10 #include "Jeep/JProperties.hh"
11 #include "Jeep/JParser.hh"
12 #include "Jeep/JMessage.hh"
13 
14 
15 /**
16  * Auxiliary data structure for line.
17  */
18 struct JLine {
19 
20  /**
21  * Read line from input stream.
22  *
23  * \param in input stream
24  * \param line line
25  * \return input stream
26  */
27  friend inline std::istream& operator>>(std::istream& in, JLine& line)
28  {
29  return in >> line.x1 >> line.y1 >> line.x2 >> line.y2;
30  }
31 
32  /**
33  * Write line to output stream.
34  *
35  * \param out output stream
36  * \param line line
37  * \return output stream
38  */
39  friend inline std::ostream& operator<<(std::ostream& out, const JLine& line)
40  {
41  return out << line.x1 << ' ' << line.y1 << ' ' << line.x2 << ' ' << line.y2;
42  }
43 
44  double x1;
45  double y1;
46  double x2;
47  double y2;
48 };
49 
50 
51 /**
52  * \file
53  * Auxiliary program to create TLine.
54  * \author mdejong
55  */
56 int main(int argc, char **argv)
57 {
58  using namespace std;
59  using namespace JPP;
60 
61  typedef JContainer< vector<JLine> > JParameters_t;
62 
63  string outputFile;
64  JParameters_t parameters;
65  Color_t color = kBlack;
66  Style_t style = kSolid;
67  Width_t width = 2;
68  int debug;
69 
70  try {
71 
72  JProperties properties;
73 
74  properties.insert(gmake_property(color));
75  properties.insert(gmake_property(style));
76  properties.insert(gmake_property(width));
77 
78  JParser<> zap("Auxiliary program to create TLine.");
79 
80  zap['o'] = make_field(outputFile);
81  zap['p'] = make_field(parameters, "x1 y1 x2 y2");
82  zap['@'] = make_field(properties, "line attributes") = JPARSER::initialised();
83  zap['d'] = make_field(debug) = 1;
84 
85  zap(argc, argv);
86  }
87  catch(const exception &error) {
88  FATAL(error.what() << endl);
89  }
90 
91 
92  TFile out(outputFile.c_str(), "recreate");
93 
94  for (size_t i = 0; i != parameters.size(); ++i) {
95 
96  TLine* p = new TLine(parameters[i].x1, parameters[i].y1, parameters[i].x2, parameters[i].y2);
97 
98  p->SetLineColor(color);
99  p->SetLineStyle(style);
100  p->SetLineWidth(width);
101 
102  out.WriteTObject(p);
103  }
104 
105  out.Write();
106  out.Close();
107 }
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
double y1
Definition: JLine.cc:45
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
double y2
Definition: JLine.cc:47
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
double x2
Definition: JLine.cc:46
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.
friend std::istream & operator>>(std::istream &in, JLine &line)
Read line from input stream.
Definition: JLine.cc:27
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
double x1
Definition: JLine.cc:44
General purpose messaging.
friend std::ostream & operator<<(std::ostream &out, const JLine &line)
Write line to output stream.
Definition: JLine.cc:39
#define FATAL(A)
Definition: JMessage.hh:67
Auxiliary data structure for line.
Definition: JLine.cc:18
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
Utility class to parse command line options.
Container I/O.
int debug
debug level