source: trunk/MagicSoft/Mars/ganymed.cc@ 6525

Last change on this file since 6525 was 6453, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 7.6 KB
Line 
1#include <TROOT.h>
2#include <TClass.h>
3#include <TSystem.h>
4#include <TGClient.h>
5#include <TApplication.h>
6#include <TObjectTable.h>
7
8#include "MLog.h"
9#include "MLogManip.h"
10
11#include "MArgs.h"
12#include "MArray.h"
13#include "MDirIter.h"
14
15#include "MStatusDisplay.h"
16
17#include "MDataSet.h"
18#include "MJCut.h"
19
20using namespace std;
21
22static void StartUpMessage()
23{
24 gLog << all << endl;
25
26 // 1 2 3 4 5
27 // 12345678901234567890123456789012345678901234567890
28 gLog << "========================================================" << endl;
29 gLog << " Ganymed - MARS V" << MARSVER << endl;
30 gLog << " MARS -- Gammas Are Now Your Most Exciting Discovery" << endl;
31 gLog << " Compiled on <" << __DATE__ << ">" << endl;
32 gLog << " Using ROOT v" << ROOTVER << endl;
33 gLog << "========================================================" << endl;
34 gLog << endl;
35}
36
37static void Usage()
38{
39 // 1 2 3 4 5 6 7 8
40 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
41 gLog << all << endl;
42 gLog << "Sorry the usage is:" << endl;
43 gLog << " ganymed [-c] [-y] [options] sequences.txt" << endl << endl;
44 gLog << " Arguments:" << endl;
45 gLog << " dataset.txt: Ascii file defining a collection of sequences" << endl;
46 gLog << " For more details see MDataSet." << endl;
47 gLog << " Root Options:" << endl;
48 gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
49 gLog << " Options:" << endl;
50 gLog.Usage();
51 gLog << " --debug-env Debug setting resources from file" << endl;
52 gLog << " --debug-mem Debug memory usage" << endl << endl;
53 gLog << endl;
54 gLog << " -q Quit when job is finished" << endl;
55 gLog << " -f Force overwrite of existing files" << endl;
56 gLog << " --n=[n] Analysis number" << endl;
57 gLog << " --out=path Path to write the all output to [def=local path]" << endl;
58 gLog << " --outf=filename Filename for output file (eg. status display)" << endl;
59 gLog << " --sum[=filename] Enable writing of summary file (events after cut0)" << endl;
60 gLog << " --res[=filename] Enable writing of result file (surviving events)" << endl;
61 gLog << " --write-only Only write output files. No histograms filled." << endl;
62 gLog << " --print-seq Print Sequences information" << endl;
63 gLog << " --print-files Print Files taken from Sequences ('+' found, '-' missing)" << endl;
64 gLog << " --config=ganymed.rc Resource file [default=ganymed.rc]" << endl;
65 gLog << endl;
66 gLog << " --version, -V Show startup message with version number" << endl;
67 gLog << " -?, -h, --help This help" << endl;
68 gLog << endl;
69}
70
71int main(int argc, char **argv)
72{
73 StartUpMessage();
74
75 //
76 // Evaluate arguments
77 //
78 MArgs arg(argc, argv, kTRUE);
79
80 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
81 return 0;
82
83 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
84 {
85 Usage();
86 return -1;
87 }
88
89 gLog.Setup(arg);
90
91 const TString kConfig = arg.GetStringAndRemove("--config=", "ganymed.rc");
92
93 const Bool_t kPrintSeq = arg.HasOnlyAndRemove("--print-seq");
94 const Bool_t kPrintFiles = arg.HasOnlyAndRemove("--print-files");
95 const Bool_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env");
96 const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
97 const Bool_t kWriteOnly = arg.HasOnlyAndRemove("--write-only");
98
99 const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
100 const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
101 const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
102 //const Bool_t kForceExec = arg.HasOnlyAndRemove("-ff");
103
104 const Int_t kNumAnalysis = arg.GetIntAndRemove("--n=", -1);
105 const TString kOutpath = arg.GetStringAndRemove("--out=", ".");
106 const TString kOutfile = arg.GetStringAndRemove("--outf=", "");
107 const Bool_t kWriteSummary = arg.HasOnlyAndRemove("--sum");
108 const TString kNameSummary = arg.GetStringAndRemove("--sum=");
109 const Bool_t kWriteResult = arg.HasOnlyAndRemove("--res");
110 const TString kNameResult = arg.GetStringAndRemove("--res=");
111
112 if (arg.GetNumOptions()>0)
113 {
114 gLog << warn << "WARNING - Unknown commandline options..." << endl;
115 arg.Print("options");
116 gLog << endl;
117 }
118
119 //
120 // check for the right usage of the program
121 //
122 if (arg.GetNumArguments()!=1)
123 {
124 Usage();
125 return -1;
126 }
127
128 //
129 // Setup sequence file and check for its existance
130 //
131 const TString kSequences = arg.GetArgumentStr(0);
132
133 if (gSystem->AccessPathName(kSequences, kFileExists))
134 {
135 gLog << err << "Sorry, sequences file '" << kSequences << "' doesn't exist." << endl;
136 return -1;
137 }
138
139 if (kDebugMem)
140 TObject::SetObjectStat(kTRUE);
141
142 //
143 // Setup sequence and check its validity
144 //
145 MDataSet seq(kSequences);
146 if (kNumAnalysis>=0)
147 seq.SetNumAnalysis(kNumAnalysis);
148 if (kPrintSeq || kPrintFiles)
149 {
150 gLog << all;
151 gLog.Separator(kSequences);
152 seq.Print(kPrintFiles?"files":"");
153 gLog << endl;
154 }
155 if (!seq.IsValid())
156 {
157 gLog << err << "Sequences read but not valid!" << endl << endl;
158 return -1;
159 }
160
161 //
162 // Initialize root
163 //
164 MArray::Class()->IgnoreTObjectStreamer();
165 MParContainer::Class()->IgnoreTObjectStreamer();
166
167 TApplication app("Ganymed", &argc, argv);
168 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
169 {
170 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
171 return 1;
172 }
173
174 //
175 // Update frequency by default = 1Hz
176 //
177 MStatusDisplay *d = new MStatusDisplay;
178
179 // From now on each 'Exit' means: Terminate the application
180 d->SetBit(MStatusDisplay::kExitLoopOnExit);
181 d->SetTitle(kSequences);
182
183 //
184 // Calculate pedestal for pedestal-calculation and calibration
185 //
186 MJCut job(Form("MJCut #%d", seq.GetNumAnalysis()));
187 job.SetEnv(kConfig);
188 job.SetEnvDebug(kDebugEnv);
189 job.SetDisplay(d);;
190 job.SetOverwrite(kOverwrite);
191 job.SetPathOut(kOutpath);
192 job.SetNameOutFile(kOutfile);
193 job.SetNameSummaryFile(kNameSummary);
194 job.SetNameResultFile(kNameResult);
195 job.EnableWriteOnly(kWriteOnly);
196 if (kWriteSummary) // Don't change flag set in SetNameSummaryFile
197 job.EnableStorageOfSummary();
198 if (kWriteResult) // Don't change flag set in SetNameSummaryFile
199 job.EnableStorageOfResult();
200
201 if (!job.ProcessFile(seq))
202 {
203 gLog << err << "Calculation of cuts failed." << endl << endl;
204 return -1;
205 }
206
207 if (!job.GetDisplay())
208 {
209 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
210 return 1;
211 }
212
213 if (kBatch || kQuit)
214 delete d;
215 else
216 {
217 // From now on each 'Close' means: Terminate the application
218 d->SetBit(MStatusDisplay::kExitLoopOnClose);
219
220 // Wait until the user decides to exit the application
221 app.Run(kFALSE);
222 }
223
224 if (TObject::GetObjectStat())
225 {
226 TObject::SetObjectStat(kFALSE);
227 gObjectTable->Print();
228 }
229
230 return 0;
231}
Note: See TracBrowser for help on using the repository browser.