Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JDraw.cc File Reference

General purpose plot program to draw ROOT objects. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TRootCanvas.h"
#include "TKey.h"
#include "TRegexp.h"
#include "TStyle.h"
#include "TLine.h"
#include "TAttLine.h"
#include "TEllipse.h"
#include "TAttFill.h"
#include "TText.h"
#include "TAttText.h"
#include "TBox.h"
#include "JROOT/JCanvas.hh"
#include "JGizmo/JRootObjectID.hh"
#include "JGizmo/JGizmoToolkit.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

General purpose plot program to draw ROOT objects.

The option -f corresponds to <file name>:<object name>.

Author
mdejong

Definition in file JDraw.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 35 of file JDraw.cc.

36{
37 using namespace std;
38 using namespace JPP;
39
40 vector<JRootObjectID> inputFile;
41 string outputFile;
42 JCanvas canvas;
43 bool batch;
44 int debug;
45
46 try {
47
48 JParser<> zap("General purpose plot program to draw ROOT objects.");
49
50 zap['f'] = make_field(inputFile, "<input file>:<object name>");
51 zap['o'] = make_field(outputFile, "graphics output") = "";
52 zap['w'] = make_field(canvas, "size of canvas <nx>x<ny> [pixels]") = JCanvas(500, 500);
53 zap['B'] = make_field(batch, "batch processing");
54 zap['d'] = make_field(debug) = 0;
55
56 zap(argc, argv);
57 }
58 catch(const exception &error) {
59 FATAL(error.what() << endl);
60 }
61
62
63 gROOT->SetBatch(batch);
64
65 TApplication* tp = new TApplication("user", NULL, NULL);
66 TCanvas* cv = new TCanvas("c1", "c1", canvas.x, canvas.y);
67
68 if (!batch) {
69 ((TRootCanvas *) cv->GetCanvasImp())->Connect("CloseWindow()", "TApplication", tp, "Terminate()");
70 }
71
72 cv->SetFillStyle(4000);
73 cv->SetFillColor(kWhite);
74 cv->Divide(1,1);
75 cv->cd(1);
76
77 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
78
79 DEBUG("Input: " << *input << endl);
80
81 TDirectory* dir = getDirectory(*input);
82
83 if (dir == NULL) {
84 ERROR("File: " << input->getFullFilename() << " not opened." << endl);
85 continue;
86 }
87
88 const TRegexp regexp(input->getObjectName());
89
90 TIter iter(dir->GetListOfKeys());
91
92 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
93
94 const TString tag(key->GetName());
95
96 DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
97
98 // option match
99
100 if (tag.Contains(regexp) && isTObject(key)) {
101
102 TObject* p = key->ReadObj();
103
104 if (dynamic_cast<TText*> (p) ||
105 dynamic_cast<TLine*> (p) ||
106 dynamic_cast<TEllipse*>(p) ||
107 dynamic_cast<TBox*> (p)) {
108
109 DEBUG("Add object: " << tag << " with name <" << p->GetName() << ">" << endl);
110
111 p->Draw("SAME");
112 }
113 }
114 }
115 }
116
117 cv->Update();
118
119 if (outputFile != "") {
120 cv->SaveAs(outputFile.c_str());
121 }
122
123 if (!batch) {
124 tp->Run();
125 }
126}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ERROR(A)
Definition JMessage.hh:66
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Utility class to parse command line options.
Definition JParser.hh:1698
Data structure for size of TCanvas.
Definition JCanvas.hh:26
int y
number of pixels in Y
Definition JCanvas.hh:99
int x
number of pixels in X
Definition JCanvas.hh:98
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).