source: tags/Mars-V0.9.4.1/showplot.cc@ 17433

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