source: trunk/MagicSoft/Mars/showplot.cc@ 9584

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