source: tags/Mars-V2.4/showplot.cc@ 12922

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