source: tags/Mars-V0.9.2/showplot.cc@ 11032

Last change on this file since 11032 was 7001, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 8.1 KB
Line 
1#include <TROOT.h>
2#include <TClass.h>
3#include <TGClient.h>
4#include <TApplication.h>
5
6#include "MLog.h"
7#include "MLogManip.h"
8
9#include "MArgs.h"
10
11#include "MStatusDisplay.h"
12
13using namespace std;
14
15static void StartUpMessage()
16{
17 // 1 2 3 4 5
18 // 12345678901234567890123456789012345678901234567890
19 gLog << endl;
20 gLog << "showplot --- Mars V" << MARSVER << " compiled on <" << __DATE__ << "> using ROOT v" << ROOTVER << endl;
21 gLog << endl;
22}
23
24static void Usage()
25{
26 // 1 2 3 4 5 6 7 8
27 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
28 gLog << all << endl;
29 gLog << "Sorry the usage is:" << endl;
30 gLog << " showplot [options] filename" << endl << endl;
31 gLog << " Arguments:" << endl;
32 gLog << " filename Input file containing an MStatusArray" << endl << endl;
33 gLog << " Root Options:" << endl;
34 gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
35 gLog << " Options: "<< endl;
36 gLog.Usage();
37 gLog << " -q Quit when job is finished" << endl;
38 gLog << endl;
39 gLog << " General Output Options: "<< endl;
40 gLog << " --print[=printer] Print to printer" << endl;
41 gLog << " --save-as-ps[=filename] Save plots as postscript" << endl;
42 gLog << " --save-as-pdf[=filename] Save plots as pdf-file" << endl;
43 gLog << " --save-as-svg[=filename] Save plots as svg-file" << endl;
44 gLog << " --save-as-root[=filename] Save plots as root file" << endl;
45 gLog << " --save-as-C[=filename] Save plots as root scripts" << endl;
46 gLog << " --tab=num Save only tab number num" << endl << endl;
47 gLog << " Print only options:" << endl;
48 gLog << " --print-cmd='lpr -P%p %f' Set the printer command" << endl;
49 gLog << " --print-dir=/tmp Set the printing temp directory" << endl << endl;
50 gLog << " GUI only options:" << endl;
51 gLog << " --save-as-gif[=filename] Save plots as gif files" << endl;
52 gLog << " --save-as-jpg[=filename] Save plots as jpg files" << endl;
53 gLog << " --save-as-xpm[=filename] Save plots as xpm files" << endl;
54 gLog << " --save-as-png[=filename] Save plots as png files" << endl;
55 gLog << endl;
56 gLog << " --version, -V Show startup message with version number" << endl;
57 gLog << " -?, -h, --help This help" << endl;
58 gLog << endl;
59 gLog << "Description:" << endl;
60 gLog << " Use showplot to display a MStatusArray in an MStatusDisplay." << endl;
61 gLog << " MStatusArrays are typically written by programs showing data" << endl;
62 gLog << " check plots, like callisto." << endl << endl;
63 gLog << "Printing:" << endl;
64 gLog << " For more details see MStatusDisplay::PrintPS" << endl << endl;
65 gLog << "Examples:" << endl;
66 gLog << " showplot filename.root" << endl;
67 gLog << " showplot -b --null --print --print-cmd='psnup -2 %f' filename.root | lpr" << endl;
68 gLog << " showplot -b --print --print-cmd='psbook %f | psnup -2 | lpr' filename.root" << endl;
69 gLog << " showplot -b --print --print-cmd='cat %f' filename.root > filename.ps" << endl;
70 gLog << " showplot -b --save-as-ps filename.root" << endl;
71 gLog << " showplot -q --save-as-gif=tab5.gif --tab=5 filename.root" << endl;
72 gLog << " showplot -b --save-as-ps --print=lp2 filename.root" << endl;
73 gLog << endl;
74}
75
76int main(int argc, char **argv)
77{
78 //
79 // Evaluate arguments
80 //
81 MArgs arg(argc, argv, kTRUE);
82 gLog.Setup(arg);
83
84 StartUpMessage();
85
86 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
87 return 0;
88
89 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
90 {
91 Usage();
92 return 2;
93 }
94
95 const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
96 const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
97
98 const Int_t kTab = arg.GetIntAndRemove("--tab=", -1);
99
100 const Bool_t kPrint = arg.HasOnlyAndRemove("--print") || arg.Has("--print=");
101 const Bool_t kSaveAsPs = arg.HasOnlyAndRemove("--save-as-ps") || arg.Has("--save-as-ps=");
102 const Bool_t kSaveAsPdf = arg.HasOnlyAndRemove("--save-as-pdf") || arg.Has("--save-as-pdf=");
103 const Bool_t kSaveAsSvg = arg.HasOnlyAndRemove("--save-as-svg") || arg.Has("--save-as-svg=");
104 const Bool_t kSaveAsGif = arg.HasOnlyAndRemove("--save-as-gif") || arg.Has("--save-as-gif=");
105 const Bool_t kSaveAsJpg = arg.HasOnlyAndRemove("--save-as-jpg") || arg.Has("--save-as-jpg=");
106 const Bool_t kSaveAsXpm = arg.HasOnlyAndRemove("--save-as-xpm") || arg.Has("--save-as-xpm=");
107 const Bool_t kSaveAsPng = arg.HasOnlyAndRemove("--save-as-png") || arg.Has("--save-as-png=");
108 const Bool_t kSaveAsRoot = arg.HasOnlyAndRemove("--save-as-root") || arg.Has("--save-as-root=");
109 const Bool_t kSaveAsC = arg.HasOnlyAndRemove("--save-as-C") || arg.Has("--save-as-C=");
110
111 TString kNamePrint = arg.GetStringAndRemove("--print=");
112 TString kPrintCmd = arg.GetStringAndRemove("--print-cmd=");
113 TString kPrintDir = arg.GetStringAndRemove("--print-dir=");
114 TString kNamePs = arg.GetStringAndRemove("--save-as-ps=");
115 TString kNamePdf = arg.GetStringAndRemove("--save-as-pdf=");
116 TString kNameSvg = arg.GetStringAndRemove("--save-as-svg=");
117 TString kNameGif = arg.GetStringAndRemove("--save-as-gif=");
118 TString kNameJpg = arg.GetStringAndRemove("--save-as-jpg=");
119 TString kNameXpm = arg.GetStringAndRemove("--save-as-xpm=");
120 TString kNamePng = arg.GetStringAndRemove("--save-as-png=");
121 TString kNameRoot = arg.GetStringAndRemove("--save-as-root=");
122 TString kNameC = arg.GetStringAndRemove("--save-as-C=");
123
124
125 //
126 // check for the right usage of the program
127 //
128 if (arg.GetNumOptions()>0)
129 {
130 gLog << err << "Unknown commandline options..." << endl;
131 arg.Print("options");
132 gLog << endl;
133 return 3;
134 }
135 if (arg.GetNumArguments()!=1)
136 {
137 Usage();
138 return 2;
139 }
140
141 TApplication app("showplot", &argc, argv);
142 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
143 {
144 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
145 return 1;
146 }
147
148 //
149 // Process filenames
150 //
151 const TString kInput = arg.GetArgumentStr(0);
152
153 if (kNamePs.IsNull() && kSaveAsPs)
154 kNamePs = kInput;
155 if (kNamePdf.IsNull() && kSaveAsPdf)
156 kNamePdf = kInput;
157 if (kNameSvg.IsNull() && kSaveAsSvg)
158 kNameSvg = kInput;
159 if (kNameGif.IsNull() && kSaveAsGif)
160 kNameGif = kInput;
161 if (kNameJpg.IsNull() && kSaveAsJpg)
162 kNameJpg = kInput;
163 if (kNameXpm.IsNull() && kSaveAsXpm)
164 kNameXpm = kInput;
165 if (kNamePng.IsNull() && kSaveAsPng)
166 kNamePng = kInput;
167 if (kNameRoot.IsNull() && kSaveAsRoot)
168 kNameRoot = kInput;
169 if (kNameC.IsNull() && kSaveAsC)
170 kNameC = kInput;
171
172 //
173 // Update frequency by default = 1Hz
174 //
175 MStatusDisplay *d = new MStatusDisplay;
176
177 // From now on each 'Exit' means: Terminate the application
178 d->SetTitle(kInput);
179 d->Open(kInput);
180
181 if (kPrint)
182 d->PrintPS(kTab, kNamePrint, kPrintCmd, kPrintDir);
183 if (kSaveAsPs)
184 d->SaveAsPS(kTab, kNamePs);
185 if (kSaveAsPdf)
186 d->SaveAsPDF(kTab, kNamePdf);
187 if (kSaveAsSvg)
188 d->SaveAsSVG(kTab, kNameSvg);
189 if (kSaveAsGif)
190 d->SaveAsGIF(kTab, kNameGif);
191 if (kSaveAsJpg)
192 d->SaveAsJPG(kTab, kNameJpg);
193 if (kSaveAsXpm)
194 d->SaveAsXPM(kTab, kNameXpm);
195 if (kSaveAsPng)
196 d->SaveAsPNG(kTab, kNamePng);
197 if (kSaveAsRoot)
198 d->SaveAsRoot(kTab, kNameRoot);
199 if (kSaveAsC)
200 d->SaveAsC(kTab, kNameC);
201
202 if (kBatch || kQuit)
203 {
204 delete d;
205 return 0;
206 }
207
208 // From now on each 'Close' means: Terminate the application
209 d->SetBit(MStatusDisplay::kExitLoopOnClose);
210
211 // Wait until the user decides to exit the application
212 app.Run(kFALSE);
213 return 0;
214}
Note: See TracBrowser for help on using the repository browser.