source: branches/MarsISDCBranchBasedOn17887/showplot.cc@ 20103

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