source: tags/Mars-V2.1/showplot.cc@ 10075

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