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

Last change on this file since 9577 was 9576, checked in by tbretz, 15 years ago
*** empty log message ***
File size: 13.1 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 << " -q Quit when job is finished" << endl;
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 -q --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 kQuit = arg.HasOnlyAndRemove("-q");
167 const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
168 const Bool_t kRoot = arg.HasOnlyAndRemove("-r");
169 const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
170
171 const Int_t kTab = arg.GetIntAndRemove("--tab=", -1);
172
173 const Bool_t kPrint = arg.HasOnlyAndRemove("--print") || arg.Has("--print=");
174 const Bool_t kSaveAsPs = arg.HasOnlyAndRemove("--save-as-ps") || arg.Has("--save-as-ps=");
175 const Bool_t kSaveAsPdf = arg.HasOnlyAndRemove("--save-as-pdf") || arg.Has("--save-as-pdf=");
176 const Bool_t kSaveAsSvg = arg.HasOnlyAndRemove("--save-as-svg") || arg.Has("--save-as-svg=");
177 const Bool_t kSaveAsGif = arg.HasOnlyAndRemove("--save-as-gif") || arg.Has("--save-as-gif=");
178 const Bool_t kSaveAsJpg = arg.HasOnlyAndRemove("--save-as-jpg") || arg.Has("--save-as-jpg=");
179 const Bool_t kSaveAsXpm = arg.HasOnlyAndRemove("--save-as-xpm") || arg.Has("--save-as-xpm=");
180 const Bool_t kSaveAsPng = arg.HasOnlyAndRemove("--save-as-png") || arg.Has("--save-as-png=");
181 const Bool_t kSaveAsBmp = arg.HasOnlyAndRemove("--save-as-bmp") || arg.Has("--save-as-bmp=");
182 const Bool_t kSaveAsXml = arg.HasOnlyAndRemove("--save-as-xml") || arg.Has("--save-as-xml=");
183 const Bool_t kSaveAsCsv = arg.HasOnlyAndRemove("--save-as-csv") || arg.Has("--save-as-csv=");
184 const Bool_t kSaveAsTiff = arg.HasOnlyAndRemove("--save-as-tiff") || arg.Has("--save-as-tiff=");
185 const Bool_t kSaveAsRoot = arg.HasOnlyAndRemove("--save-as-root") || arg.Has("--save-as-root=");
186 const Bool_t kSaveAsC = arg.HasOnlyAndRemove("--save-as-C") || arg.Has("--save-as-C=");
187
188 const Int_t kCanvasWidth = arg.GetIntAndRemove("--canvas-width=", -1);
189 const Int_t kCanvasHeight = arg.GetIntAndRemove("--canvas-height=", -1);
190
191 const Bool_t kAutoSize = arg.HasOnlyAndRemove("--auto-size");
192 Int_t kDisplayWidth = arg.GetIntAndRemove("--display-width=", -1);
193 Int_t kDisplayHeight = arg.GetIntAndRemove("--display-height=", -1);
194 if (kAutoSize)
195 {
196 kDisplayWidth=0;
197 kDisplayHeight=0;
198 }
199
200 //
201 // Get file name(s)
202 //
203 const TString kInput = InflatePath(arg);
204 const TString kTitle = kInput.IsNull() ? arg.GetArgumentStr(0) + "..." : kInput;
205
206 //
207 // Process filenames
208 //
209 const TString kNamePrint = arg.GetStringAndRemove("--print=", kInput);
210 const TString kPrintCmd = arg.GetStringAndRemove("--print-cmd=", kInput);
211 const TString kPrintDir = arg.GetStringAndRemove("--print-dir=", kInput);
212 const TString kNamePs = arg.GetStringAndRemove("--save-as-ps=", kInput);
213 const TString kNamePdf = arg.GetStringAndRemove("--save-as-pdf=", kInput);
214 const TString kNameSvg = arg.GetStringAndRemove("--save-as-svg=", kInput);
215 const TString kNameGif = arg.GetStringAndRemove("--save-as-gif=", kInput);
216 const TString kNameJpg = arg.GetStringAndRemove("--save-as-jpg=", kInput);
217 const TString kNameXpm = arg.GetStringAndRemove("--save-as-xpm=", kInput);
218 const TString kNamePng = arg.GetStringAndRemove("--save-as-png=", kInput);
219 const TString kNameBmp = arg.GetStringAndRemove("--save-as-bmp=", kInput);
220 const TString kNameXml = arg.GetStringAndRemove("--save-as-xml=", kInput);
221 const TString kNameCsv = arg.GetStringAndRemove("--save-as-csv=", kInput);
222 const TString kNameTiff = arg.GetStringAndRemove("--save-as-tiff=", kInput);
223 const TString kNameRoot = arg.GetStringAndRemove("--save-as-root=", kInput);
224 const TString kNameC = arg.GetStringAndRemove("--save-as-C=", kInput);
225
226 //
227 // check for the right usage of the program
228 //
229 if (arg.GetNumOptions()>0)
230 {
231 gLog << err << "Unknown command line options..." << endl;
232 arg.Print("options");
233 gLog << endl;
234 return 3;
235 }
236
237 if (kDebugMem)
238 TObject::SetObjectStat(kTRUE);
239
240 //
241 // Initialize root environment
242 //
243 TApplication *app = kRoot ? new TRint("showplot", &argc, argv) : new TApplication("showplot", &argc, argv);
244 if ((!gROOT->IsBatch() && !gClient) || (gROOT->IsBatch() && !kBatch))
245 {
246 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
247 return 1;
248 }
249
250 //
251 // Update frequency by default = 1Hz
252 //
253 MStatusDisplay *d = new MStatusDisplay(kDisplayWidth, kDisplayHeight);
254
255 // From now on each 'Exit' means: Terminate the application
256 d->SetTitle(kTitle);
257 d->SetWindowName(kTitle);
258
259 if (kCanvasHeight>0)
260 d->SetCanvasHeight(kCanvasHeight);
261 if (kCanvasWidth>0)
262 d->SetCanvasWidth(kCanvasWidth);
263
264 if (!kInput.IsNull())
265 d->Open(kInput);
266 else
267 {
268 for (int i=0; i<arg.GetNumArguments(); i++)
269 d->Open(arg.GetArgumentStr(i));
270 }
271
272 if (kPrint)
273 d->PrintPS(kTab, kNamePrint, kPrintCmd, kPrintDir);
274 if (kSaveAsPs)
275 d->SaveAsPS(kTab, kNamePs);
276 if (kSaveAsPdf)
277 d->SaveAsPDF(kTab, kNamePdf);
278 if (kSaveAsSvg)
279 d->SaveAsSVG(kTab, kNameSvg);
280 if (kSaveAsGif)
281 d->SaveAsGIF(kTab, kNameGif);
282 if (kSaveAsJpg)
283 d->SaveAsJPG(kTab, kNameJpg);
284 if (kSaveAsXpm)
285 d->SaveAsXPM(kTab, kNameXpm);
286 if (kSaveAsPng)
287 d->SaveAsPNG(kTab, kNamePng);
288 if (kSaveAsBmp)
289 d->SaveAsBMP(kTab, kNameBmp);
290 if (kSaveAsXml)
291 d->SaveAsXML(kTab, kNameXml);
292 if (kSaveAsCsv)
293 d->SaveAsCSV(kTab, kNameCsv);
294 if (kSaveAsTiff)
295 d->SaveAsTIFF(kTab, kNameTiff);
296 if (kSaveAsRoot)
297 d->SaveAsRoot(kTab, kNameRoot);
298 if (kSaveAsC)
299 d->SaveAsC(kTab, kNameC);
300
301 if (arg.GetNumArguments()>0)
302 {
303 if (d->GetNumTabs())
304 gLog << all << d->GetNumTabs() << " tab(s) displayed." << endl;
305 else
306 gLog << err << "Display empty... closing." << endl;
307 }
308 gLog << endl;
309
310 if (kBatch || kQuit || (arg.GetNumArguments()>0 && d->GetNumTabs()==0))
311 {
312 delete d;
313 return 0;
314 }
315
316 // From now on each 'Close' means: Terminate the application
317 d->SetBit(MStatusDisplay::kExitLoopOnClose);
318
319 // Wait until the user decides to exit the application
320 app->Run(kFALSE);
321 delete app;
322
323 if (TObject::GetObjectStat())
324 {
325 TObject::SetObjectStat(kFALSE);
326 gObjectTable->Print();
327 }
328
329 return 0;
330}
Note: See TracBrowser for help on using the repository browser.