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 |
|
---|
13 | using namespace std;
|
---|
14 |
|
---|
15 | static 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" << ROOTVER << endl;
|
---|
21 | gLog << endl;
|
---|
22 | }
|
---|
23 |
|
---|
24 | static 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-root[=filename] Save plots as root file" << endl;
|
---|
48 | gLog << " --save-as-C[=filename] Save plots as root scripts" << endl;
|
---|
49 | gLog << " --tab=num Save only tab number num" << endl << endl;
|
---|
50 | gLog << " Print only options:" << endl;
|
---|
51 | gLog << " --print-cmd='lpr -P%p %f' Set the printer command" << endl;
|
---|
52 | gLog << " --print-dir=/tmp Set the printing temp directory" << endl << endl;
|
---|
53 | gLog << " GUI only options:" << endl;
|
---|
54 | gLog << " --save-as-gif[=filename] Save plots as gif files" << endl;
|
---|
55 | gLog << " --save-as-jpg[=filename] Save plots as jpg files" << endl;
|
---|
56 | gLog << " --save-as-xpm[=filename] Save plots as xpm files" << endl;
|
---|
57 | gLog << " --save-as-png[=filename] Save plots as png files" << endl;
|
---|
58 | gLog << endl;
|
---|
59 | gLog << " --version, -V Show startup message with version number" << endl;
|
---|
60 | gLog << " -?, -h, --help This help" << endl;
|
---|
61 | gLog << endl;
|
---|
62 | gLog << "Description:" << endl;
|
---|
63 | gLog << " Use showplot to display a MStatusArray in an MStatusDisplay." << endl;
|
---|
64 | gLog << " MStatusArrays are typically written by programs showing data" << endl;
|
---|
65 | gLog << " check plots, like callisto." << endl << endl;
|
---|
66 | gLog << "Printing:" << endl;
|
---|
67 | gLog << " For more details see MStatusDisplay::PrintPS" << endl << endl;
|
---|
68 | gLog << "Examples:" << endl;
|
---|
69 | gLog << " showplot filename.root" << endl;
|
---|
70 | gLog << " showplot -b --null --print --print-cmd='psnup -2 %f' filename.root | lpr" << endl;
|
---|
71 | gLog << " showplot -b --print --print-cmd='psbook %f | psnup -2 | lpr' filename.root" << endl;
|
---|
72 | gLog << " showplot -b --print --print-cmd='cat %f' filename.root > filename.ps" << endl;
|
---|
73 | gLog << " showplot -b --save-as-ps filename.root" << endl;
|
---|
74 | gLog << " showplot -q --save-as-gif=tab5.gif --tab=5 filename.root" << endl;
|
---|
75 | gLog << " showplot -b --save-as-ps --print=lp2 filename.root" << endl;
|
---|
76 | gLog << endl;
|
---|
77 | }
|
---|
78 |
|
---|
79 | int main(int argc, char **argv)
|
---|
80 | {
|
---|
81 | //
|
---|
82 | // Evaluate arguments
|
---|
83 | //
|
---|
84 | MArgs arg(argc, argv, kTRUE);
|
---|
85 | gLog.Setup(arg);
|
---|
86 |
|
---|
87 | StartUpMessage();
|
---|
88 |
|
---|
89 | if (arg.HasOnly("-V") || arg.HasOnly("--version"))
|
---|
90 | return 0;
|
---|
91 |
|
---|
92 | if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
|
---|
93 | {
|
---|
94 | Usage();
|
---|
95 | return 2;
|
---|
96 | }
|
---|
97 |
|
---|
98 | const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
|
---|
99 | const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
|
---|
100 | const Bool_t kRoot = arg.HasOnlyAndRemove("-r");
|
---|
101 |
|
---|
102 | const Int_t kTab = arg.GetIntAndRemove("--tab=", -1);
|
---|
103 |
|
---|
104 | const Bool_t kPrint = arg.HasOnlyAndRemove("--print") || arg.Has("--print=");
|
---|
105 | const Bool_t kSaveAsPs = arg.HasOnlyAndRemove("--save-as-ps") || arg.Has("--save-as-ps=");
|
---|
106 | const Bool_t kSaveAsPdf = arg.HasOnlyAndRemove("--save-as-pdf") || arg.Has("--save-as-pdf=");
|
---|
107 | const Bool_t kSaveAsSvg = arg.HasOnlyAndRemove("--save-as-svg") || arg.Has("--save-as-svg=");
|
---|
108 | const Bool_t kSaveAsGif = arg.HasOnlyAndRemove("--save-as-gif") || arg.Has("--save-as-gif=");
|
---|
109 | const Bool_t kSaveAsJpg = arg.HasOnlyAndRemove("--save-as-jpg") || arg.Has("--save-as-jpg=");
|
---|
110 | const Bool_t kSaveAsXpm = arg.HasOnlyAndRemove("--save-as-xpm") || arg.Has("--save-as-xpm=");
|
---|
111 | const Bool_t kSaveAsPng = arg.HasOnlyAndRemove("--save-as-png") || arg.Has("--save-as-png=");
|
---|
112 | const Bool_t kSaveAsRoot = arg.HasOnlyAndRemove("--save-as-root") || arg.Has("--save-as-root=");
|
---|
113 | const Bool_t kSaveAsC = arg.HasOnlyAndRemove("--save-as-C") || arg.Has("--save-as-C=");
|
---|
114 |
|
---|
115 | TString kNamePrint = arg.GetStringAndRemove("--print=");
|
---|
116 | TString kPrintCmd = arg.GetStringAndRemove("--print-cmd=");
|
---|
117 | TString kPrintDir = arg.GetStringAndRemove("--print-dir=");
|
---|
118 | TString kNamePs = arg.GetStringAndRemove("--save-as-ps=");
|
---|
119 | TString kNamePdf = arg.GetStringAndRemove("--save-as-pdf=");
|
---|
120 | TString kNameSvg = arg.GetStringAndRemove("--save-as-svg=");
|
---|
121 | TString kNameGif = arg.GetStringAndRemove("--save-as-gif=");
|
---|
122 | TString kNameJpg = arg.GetStringAndRemove("--save-as-jpg=");
|
---|
123 | TString kNameXpm = arg.GetStringAndRemove("--save-as-xpm=");
|
---|
124 | TString kNamePng = arg.GetStringAndRemove("--save-as-png=");
|
---|
125 | TString kNameRoot = arg.GetStringAndRemove("--save-as-root=");
|
---|
126 | TString kNameC = arg.GetStringAndRemove("--save-as-C=");
|
---|
127 |
|
---|
128 |
|
---|
129 | //
|
---|
130 | // check for the right usage of the program
|
---|
131 | //
|
---|
132 | if (arg.GetNumOptions()>0)
|
---|
133 | {
|
---|
134 | gLog << err << "Unknown command line options..." << endl;
|
---|
135 | arg.Print("options");
|
---|
136 | gLog << endl;
|
---|
137 | return 3;
|
---|
138 | }
|
---|
139 | if (arg.GetNumArguments()<1 || arg.GetNumArguments()>2)
|
---|
140 | {
|
---|
141 | Usage();
|
---|
142 | return 2;
|
---|
143 | }
|
---|
144 | if (arg.GetNumArguments()==2 && !arg.GetArgumentStr(1).IsDigit())
|
---|
145 | {
|
---|
146 | Usage();
|
---|
147 | return 2;
|
---|
148 | }
|
---|
149 |
|
---|
150 | TApplication *app = kRoot ? new TRint("showplot", &argc, argv) : new TApplication("showplot", &argc, argv);
|
---|
151 | if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
|
---|
152 | {
|
---|
153 | gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
|
---|
154 | return 1;
|
---|
155 | }
|
---|
156 |
|
---|
157 | //
|
---|
158 | // Process filenames
|
---|
159 | //
|
---|
160 | TString kInput = arg.GetArgumentStr(0);
|
---|
161 | kInput.ToLower();
|
---|
162 |
|
---|
163 | //
|
---|
164 | // Something special for datacenter access
|
---|
165 | //
|
---|
166 | if (arg.GetNumArguments()==2)
|
---|
167 | {
|
---|
168 | const Int_t num = arg.GetArgumentStr(1).Atoi();
|
---|
169 | TString file = "/magic/data/";
|
---|
170 | switch (kInput.Hash())
|
---|
171 | {
|
---|
172 | case 3438106369:
|
---|
173 | case 764164111:
|
---|
174 | file += "callisto";
|
---|
175 | break;
|
---|
176 | default:
|
---|
177 | file += kInput;
|
---|
178 | break;
|
---|
179 | }
|
---|
180 | file += kInput==(TString)"ganymed" ? Form("/%05d", num/100000) : Form("/%04d", num/10000);
|
---|
181 | file += Form("/%08d/", num);
|
---|
182 | file += kInput;
|
---|
183 | file += Form("%08d.root", num);
|
---|
184 |
|
---|
185 | kInput = file;
|
---|
186 |
|
---|
187 | gLog << inf << "Inflated file name: " << kInput << endl;
|
---|
188 | }
|
---|
189 |
|
---|
190 | if (kNamePs.IsNull() && kSaveAsPs)
|
---|
191 | kNamePs = kInput;
|
---|
192 | if (kNamePdf.IsNull() && kSaveAsPdf)
|
---|
193 | kNamePdf = kInput;
|
---|
194 | if (kNameSvg.IsNull() && kSaveAsSvg)
|
---|
195 | kNameSvg = kInput;
|
---|
196 | if (kNameGif.IsNull() && kSaveAsGif)
|
---|
197 | kNameGif = kInput;
|
---|
198 | if (kNameJpg.IsNull() && kSaveAsJpg)
|
---|
199 | kNameJpg = kInput;
|
---|
200 | if (kNameXpm.IsNull() && kSaveAsXpm)
|
---|
201 | kNameXpm = kInput;
|
---|
202 | if (kNamePng.IsNull() && kSaveAsPng)
|
---|
203 | kNamePng = kInput;
|
---|
204 | if (kNameRoot.IsNull() && kSaveAsRoot)
|
---|
205 | kNameRoot = kInput;
|
---|
206 | if (kNameC.IsNull() && kSaveAsC)
|
---|
207 | kNameC = kInput;
|
---|
208 |
|
---|
209 | //
|
---|
210 | // Update frequency by default = 1Hz
|
---|
211 | //
|
---|
212 | MStatusDisplay *d = new MStatusDisplay;
|
---|
213 |
|
---|
214 | // From now on each 'Exit' means: Terminate the application
|
---|
215 | d->SetTitle(kInput);
|
---|
216 | d->SetWindowName(kInput);
|
---|
217 |
|
---|
218 | d->Open(kInput);
|
---|
219 |
|
---|
220 | if (kPrint)
|
---|
221 | d->PrintPS(kTab, kNamePrint, kPrintCmd, kPrintDir);
|
---|
222 | if (kSaveAsPs)
|
---|
223 | d->SaveAsPS(kTab, kNamePs);
|
---|
224 | if (kSaveAsPdf)
|
---|
225 | d->SaveAsPDF(kTab, kNamePdf);
|
---|
226 | if (kSaveAsSvg)
|
---|
227 | d->SaveAsSVG(kTab, kNameSvg);
|
---|
228 | if (kSaveAsGif)
|
---|
229 | d->SaveAsGIF(kTab, kNameGif);
|
---|
230 | if (kSaveAsJpg)
|
---|
231 | d->SaveAsJPG(kTab, kNameJpg);
|
---|
232 | if (kSaveAsXpm)
|
---|
233 | d->SaveAsXPM(kTab, kNameXpm);
|
---|
234 | if (kSaveAsPng)
|
---|
235 | d->SaveAsPNG(kTab, kNamePng);
|
---|
236 | if (kSaveAsRoot)
|
---|
237 | d->SaveAsRoot(kTab, kNameRoot);
|
---|
238 | if (kSaveAsC)
|
---|
239 | d->SaveAsC(kTab, kNameC);
|
---|
240 |
|
---|
241 | if (kBatch || kQuit)
|
---|
242 | {
|
---|
243 | delete d;
|
---|
244 | return 0;
|
---|
245 | }
|
---|
246 |
|
---|
247 | // From now on each 'Close' means: Terminate the application
|
---|
248 | d->SetBit(MStatusDisplay::kExitLoopOnClose);
|
---|
249 |
|
---|
250 | // Wait until the user decides to exit the application
|
---|
251 | app->Run(kFALSE);
|
---|
252 | delete app;
|
---|
253 | return 0;
|
---|
254 | }
|
---|