source: tags/Mars-V0.10.1/showplot.cc@ 10108

Last change on this file since 10108 was 8011, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 11.5 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" << ROOT_RELEASE << 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}|{filetype number}" << endl << endl;
31 gLog << " Arguments:" << endl;
32 gLog << " filename Input file containing an MStatusArray" << endl;
33 gLog << " filetype number Open file of filetype calib, signal, star, etc." << endl;
34 gLog << " of sequence or dataset number" << endl << endl;
35 gLog << " Root Options:" << endl;
36 gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
37 gLog << " -r Start the root interpreter" << endl<<endl;
38 gLog << " Options: "<< endl;
39 gLog.Usage();
40 gLog << " -q Quit when job is finished" << endl;
41 gLog << endl;
42 gLog << " General Output Options: "<< endl;
43 gLog << " --print[=printer] Print to printer" << endl;
44 gLog << " --save-as-ps[=filename] Save plots as postscript" << endl;
45 gLog << " --save-as-pdf[=filename] Save plots as pdf-file" << endl;
46 gLog << " --save-as-svg[=filename] Save plots as svg-file" << endl;
47 gLog << " --save-as-root[=filename] Save plots as root file" << endl;
48 gLog << " --save-as-C[=filename] Save plots as root scripts" << endl;
49 gLog << " --tab=num Save only tab number num" << endl << endl;
50 gLog << " Print only options:" << endl;
51 gLog << " --print-cmd='lpr -P%p %f' Set the printer command" << endl;
52 gLog << " --print-dir=/tmp Set the printing temp directory" << endl << endl;
53 gLog << " GUI only options:" << endl;
54 gLog << " --save-as-gif[=filename] Save plots as gif files" << endl;
55 gLog << " --save-as-jpg[=filename] Save plots as jpg files" << endl;
56 gLog << " --save-as-xpm[=filename] Save plots as xpm files" << endl;
57 gLog << " --save-as-png[=filename] Save plots as png files" << endl;
58 gLog << " --save-as-bmp[=filename] Save plots as bmp files" << endl;
59 gLog << " --save-as-xml[=filename] Save plots as xml files" << endl << endl;
60 gLog << " Size options:" << endl;
61 gLog << " --display-width=w Set width of display window to w" << endl;
62 gLog << " --display-height=h Set height of display window to h" << endl;
63 gLog << " --canvas-width=w Set width of canvas' contained by display to w" << endl;
64 gLog << " --canvas-height=h Set height of canvas' contained by display to h" << endl;
65 gLog << " --auto-size Determin optimum size (not available in batch mode)" << endl;
66 gLog << endl;
67 gLog << " --version, -V Show startup message with version number" << endl;
68 gLog << " -?, -h, --help This help" << endl;
69 gLog << endl;
70 gLog << "Description:" << endl;
71 gLog << " Use showplot to display a MStatusArray in an MStatusDisplay." << endl;
72 gLog << " MStatusArrays are typically written by programs showing data" << endl;
73 gLog << " check plots, like callisto." << endl << endl;
74 gLog << " Only the last size option given is taken into account." << endl;
75 gLog << " Width or height is set according to height or width." << endl << endl;
76 gLog << " In batch mode display width and height and auto-size is ignored." << endl;
77 gLog << "Printing:" << endl;
78 gLog << " For more details see MStatusDisplay::PrintPS" << endl << endl;
79 gLog << "Examples:" << endl;
80 gLog << " showplot filename.root" << endl;
81 gLog << " showplot -b --null --print --print-cmd='psnup -2 %f' filename.root | lpr" << endl;
82 gLog << " showplot -b --print --print-cmd='psbook %f | psnup -2 | lpr' filename.root" << endl;
83 gLog << " showplot -b --print --print-cmd='cat %f' filename.root > filename.ps" << endl;
84 gLog << " showplot -b --save-as-ps filename.root" << endl;
85 gLog << " showplot -q --save-as-gif=tab5.gif --tab=5 filename.root" << endl;
86 gLog << " showplot -b --save-as-ps --print=lp2 filename.root" << endl;
87 gLog << endl;
88}
89
90int main(int argc, char **argv)
91{
92 if (!MARS::CheckRootVer())
93 return 0xff;
94
95 //
96 // Evaluate arguments
97 //
98 MArgs arg(argc, argv, kTRUE);
99 gLog.Setup(arg);
100
101 StartUpMessage();
102
103 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
104 return 0;
105
106 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
107 {
108 Usage();
109 return 2;
110 }
111
112 const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
113 const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
114 const Bool_t kRoot = arg.HasOnlyAndRemove("-r");
115
116 const Int_t kTab = arg.GetIntAndRemove("--tab=", -1);
117
118 const Bool_t kPrint = arg.HasOnlyAndRemove("--print") || arg.Has("--print=");
119 const Bool_t kSaveAsPs = arg.HasOnlyAndRemove("--save-as-ps") || arg.Has("--save-as-ps=");
120 const Bool_t kSaveAsPdf = arg.HasOnlyAndRemove("--save-as-pdf") || arg.Has("--save-as-pdf=");
121 const Bool_t kSaveAsSvg = arg.HasOnlyAndRemove("--save-as-svg") || arg.Has("--save-as-svg=");
122 const Bool_t kSaveAsGif = arg.HasOnlyAndRemove("--save-as-gif") || arg.Has("--save-as-gif=");
123 const Bool_t kSaveAsJpg = arg.HasOnlyAndRemove("--save-as-jpg") || arg.Has("--save-as-jpg=");
124 const Bool_t kSaveAsXpm = arg.HasOnlyAndRemove("--save-as-xpm") || arg.Has("--save-as-xpm=");
125 const Bool_t kSaveAsPng = arg.HasOnlyAndRemove("--save-as-png") || arg.Has("--save-as-png=");
126 const Bool_t kSaveAsBmp = arg.HasOnlyAndRemove("--save-as-bmp") || arg.Has("--save-as-bmp=");
127 const Bool_t kSaveAsXml = arg.HasOnlyAndRemove("--save-as-xml") || arg.Has("--save-as-xml=");
128 const Bool_t kSaveAsRoot = arg.HasOnlyAndRemove("--save-as-root") || arg.Has("--save-as-root=");
129 const Bool_t kSaveAsC = arg.HasOnlyAndRemove("--save-as-C") || arg.Has("--save-as-C=");
130
131 const Int_t kCanvasWidth = arg.GetIntAndRemove("--canvas-width=", -1);
132 const Int_t kCanvasHeight = arg.GetIntAndRemove("--canvas-height=", -1);
133
134 const Bool_t kAutoSize = arg.HasOnlyAndRemove("--auto-size");
135 Int_t kDisplayWidth = arg.GetIntAndRemove("--display-width=", -1);
136 Int_t kDisplayHeight = arg.GetIntAndRemove("--display-height=", -1);
137 if (kAutoSize)
138 {
139 kDisplayWidth=0;
140 kDisplayHeight=0;
141 }
142
143 TString kNamePrint = arg.GetStringAndRemove("--print=");
144 TString kPrintCmd = arg.GetStringAndRemove("--print-cmd=");
145 TString kPrintDir = arg.GetStringAndRemove("--print-dir=");
146 TString kNamePs = arg.GetStringAndRemove("--save-as-ps=");
147 TString kNamePdf = arg.GetStringAndRemove("--save-as-pdf=");
148 TString kNameSvg = arg.GetStringAndRemove("--save-as-svg=");
149 TString kNameGif = arg.GetStringAndRemove("--save-as-gif=");
150 TString kNameJpg = arg.GetStringAndRemove("--save-as-jpg=");
151 TString kNameXpm = arg.GetStringAndRemove("--save-as-xpm=");
152 TString kNamePng = arg.GetStringAndRemove("--save-as-png=");
153 TString kNameBmp = arg.GetStringAndRemove("--save-as-bmp=");
154 TString kNameXml = arg.GetStringAndRemove("--save-as-xml=");
155 TString kNameRoot = arg.GetStringAndRemove("--save-as-root=");
156 TString kNameC = arg.GetStringAndRemove("--save-as-C=");
157
158
159 //
160 // check for the right usage of the program
161 //
162 if (arg.GetNumOptions()>0)
163 {
164 gLog << err << "Unknown command line options..." << endl;
165 arg.Print("options");
166 gLog << endl;
167 return 3;
168 }
169 if (arg.GetNumArguments()<1 || arg.GetNumArguments()>2)
170 {
171 Usage();
172 return 2;
173 }
174 if (arg.GetNumArguments()==2 && !arg.GetArgumentStr(1).IsDigit())
175 {
176 Usage();
177 return 2;
178 }
179
180 TApplication *app = kRoot ? new TRint("showplot", &argc, argv) : new TApplication("showplot", &argc, argv);
181 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
182 {
183 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
184 return 1;
185 }
186
187 //
188 // Process filenames
189 //
190 TString kInput = arg.GetArgumentStr(0);
191
192 //
193 // Something special for datacenter access
194 //
195 if (arg.GetNumArguments()==2)
196 {
197 const Int_t num = arg.GetArgumentStr(1).Atoi();
198 TString file = "/magic/data/";
199
200 kInput.ToLower();
201 switch (kInput.Hash())
202 {
203 case 3438106369U:
204 case 764164111U:
205 file += "callisto";
206 break;
207 default:
208 file += kInput;
209 break;
210 }
211 file += kInput==(TString)"ganymed" ? Form("/%05d", num/100000) : Form("/%04d", num/10000);
212 file += Form("/%08d/", num);
213 file += kInput;
214 file += Form("%08d.root", num);
215
216 kInput = file;
217
218 gLog << inf << "Inflated file name: " << kInput << endl;
219 }
220
221 if (kNamePs.IsNull() && kSaveAsPs)
222 kNamePs = kInput;
223 if (kNamePdf.IsNull() && kSaveAsPdf)
224 kNamePdf = kInput;
225 if (kNameSvg.IsNull() && kSaveAsSvg)
226 kNameSvg = kInput;
227 if (kNameGif.IsNull() && kSaveAsGif)
228 kNameGif = kInput;
229 if (kNameJpg.IsNull() && kSaveAsJpg)
230 kNameJpg = kInput;
231 if (kNameXpm.IsNull() && kSaveAsXpm)
232 kNameXpm = kInput;
233 if (kNamePng.IsNull() && kSaveAsPng)
234 kNamePng = kInput;
235 if (kNameBmp.IsNull() && kSaveAsBmp)
236 kNameBmp = kInput;
237 if (kNameXml.IsNull() && kSaveAsXml)
238 kNameXml = kInput;
239 if (kNameRoot.IsNull() && kSaveAsRoot)
240 kNameRoot = kInput;
241 if (kNameC.IsNull() && kSaveAsC)
242 kNameC = kInput;
243
244 //
245 // Update frequency by default = 1Hz
246 //
247 MStatusDisplay *d = new MStatusDisplay(kDisplayWidth, kDisplayHeight);
248
249 // From now on each 'Exit' means: Terminate the application
250 d->SetTitle(kInput);
251 d->SetWindowName(kInput);
252
253 if (kCanvasHeight>0)
254 d->SetCanvasHeight(kCanvasHeight);
255 if (kCanvasWidth>0)
256 d->SetCanvasWidth(kCanvasWidth);
257
258 d->Open(kInput);
259
260 if (kPrint)
261 d->PrintPS(kTab, kNamePrint, kPrintCmd, kPrintDir);
262 if (kSaveAsPs)
263 d->SaveAsPS(kTab, kNamePs);
264 if (kSaveAsPdf)
265 d->SaveAsPDF(kTab, kNamePdf);
266 if (kSaveAsSvg)
267 d->SaveAsSVG(kTab, kNameSvg);
268 if (kSaveAsGif)
269 d->SaveAsGIF(kTab, kNameGif);
270 if (kSaveAsJpg)
271 d->SaveAsJPG(kTab, kNameJpg);
272 if (kSaveAsXpm)
273 d->SaveAsXPM(kTab, kNameXpm);
274 if (kSaveAsPng)
275 d->SaveAsPNG(kTab, kNamePng);
276 if (kSaveAsBmp)
277 d->SaveAsBMP(kTab, kNameBmp);
278 if (kSaveAsXml)
279 d->SaveAsXML(kTab, kNameXml);
280 if (kSaveAsRoot)
281 d->SaveAsRoot(kTab, kNameRoot);
282 if (kSaveAsC)
283 d->SaveAsC(kTab, kNameC);
284
285 if (kBatch || kQuit)
286 {
287 delete d;
288 return 0;
289 }
290
291 // From now on each 'Close' means: Terminate the application
292 d->SetBit(MStatusDisplay::kExitLoopOnClose);
293
294 // Wait until the user decides to exit the application
295 app->Run(kFALSE);
296 delete app;
297 return 0;
298}
Note: See TracBrowser for help on using the repository browser.