| 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 "MEnv.h"
|
|---|
| 12 | #include "MArgs.h"
|
|---|
| 13 | #include "MArray.h"
|
|---|
| 14 | #include "MDirIter.h"
|
|---|
| 15 |
|
|---|
| 16 | #include "MStatusDisplay.h"
|
|---|
| 17 |
|
|---|
| 18 | #include "MDataSet.h"
|
|---|
| 19 | #include "MJSpectrum.h"
|
|---|
| 20 |
|
|---|
| 21 | using namespace std;
|
|---|
| 22 |
|
|---|
| 23 | static void StartUpMessage()
|
|---|
| 24 | {
|
|---|
| 25 | gLog << all << endl;
|
|---|
| 26 |
|
|---|
| 27 | // 1 2 3 4 5
|
|---|
| 28 | // 12345678901234567890123456789012345678901234567890123456
|
|---|
| 29 | gLog << "========================================================" << endl;
|
|---|
| 30 | gLog << " Sponde - MARS V" << MARSVER << endl;
|
|---|
| 31 | gLog << " MARS -- SPectrum ON DEmand" << endl;
|
|---|
| 32 | gLog << " Compiled with ROOT v" << ROOT_RELEASE << " on <" << __DATE__ << ">" << endl;
|
|---|
| 33 | gLog << "========================================================" << endl;
|
|---|
| 34 | gLog << endl;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | static 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 << " sponde [options] inputfile.root mcdataset.txt [outputfile.root]" << endl << endl;
|
|---|
| 44 | gLog << " Arguments:" << endl;
|
|---|
| 45 | gLog << " inputfile.root: Ganymed output [and result] file" << endl;
|
|---|
| 46 | gLog << " mcdataset.txt: Dataset describing the Monte Carlos to be used" << endl;
|
|---|
| 47 | gLog << " For more details see MDataSet." << endl;
|
|---|
| 48 | gLog << " outputfile.root: Optional file in which the result is stored" << endl << endl;
|
|---|
| 49 | gLog << " Root Options:" << endl;
|
|---|
| 50 | gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
|
|---|
| 51 | gLog << " Operation Mode:" << endl;
|
|---|
| 52 | gLog << " --refill Refill the excess histogram from result file" << endl;
|
|---|
| 53 | gLog << " (usefull to change the binning)" << endl;
|
|---|
| 54 | // gLog << " --accurate Fill original energy/theta distribution from data" << endl;
|
|---|
| 55 | // gLog << " (do not weight the histogram)" << endl;
|
|---|
| 56 | gLog << " --raw-mc Use the mc sample as it is" << endl << endl;
|
|---|
| 57 | gLog << " Options:" << endl;
|
|---|
| 58 | gLog.Usage();
|
|---|
| 59 | gLog << " --debug-env=0 Disable debugging setting resources <default>" << endl;
|
|---|
| 60 | gLog << " --debug-env[=1] Display untouched resources after program execution" << endl;
|
|---|
| 61 | gLog << " --debug-env=2 Display untouched resources after eventloop setup" << endl;
|
|---|
| 62 | gLog << " --debug-env=3 Debug setting resources from resource file" << endl;
|
|---|
| 63 | gLog << " --debug-mem Debug memory usage" << endl << endl;
|
|---|
| 64 | gLog << endl;
|
|---|
| 65 | gLog << " -q Quit when job is finished" << endl;
|
|---|
| 66 | gLog << " -f Force overwrite of existing files" << endl;
|
|---|
| 67 | gLog << " --print-ds Print Dataset information" << endl;
|
|---|
| 68 | gLog << " --print-files Print Files taken from Sequences ('+' found, '-' missing)" << endl;
|
|---|
| 69 | gLog << " --config=sponde.rc Resource file [default=sponde.rc]" << endl;
|
|---|
| 70 | gLog << " --force-theta Force execution even with non-fitting theta distributions." << endl;
|
|---|
| 71 | gLog << endl;
|
|---|
| 72 | gLog << " --version, -V Show startup message with version number" << endl;
|
|---|
| 73 | gLog << " -?, -h, --help This help" << endl << endl;
|
|---|
| 74 | gLog << "Background:" << endl;
|
|---|
| 75 | gLog << " Sponde is a natural satellite of Jupiter. It was discovered by a team" << endl;
|
|---|
| 76 | gLog << " of astronomers from the University of Hawaii led by Scott S. Sheppard," << endl;
|
|---|
| 77 | gLog << " et al in 2001, and given the temporary designation S/2001 J 5. Sponde" << endl;
|
|---|
| 78 | gLog << " is about 2 kilometers in diameter, and orbits Jupiter at an average" << endl;
|
|---|
| 79 | gLog << " of 23,487,000 kilometers. It is also designated as Jupiter XXXVI." << endl;
|
|---|
| 80 | gLog << " It is named after one of the Horae (Hours), which presided over the" << endl;
|
|---|
| 81 | gLog << " seventh hour (libations poured after lunch). The Hours, godesses of" << endl;
|
|---|
| 82 | gLog << " the time of day but also of the seasons, were daughters of Zeus and" << endl;
|
|---|
| 83 | gLog << " Themis." << endl;
|
|---|
| 84 | gLog << " It belongs to the Pasipha group, irregular retrograde moons orbiting" << endl;
|
|---|
| 85 | gLog << " Jupiter at distances ranging between 22.8 and 24.1 Gm, and with" << endl;
|
|---|
| 86 | gLog << " inclinations ranging between 144.5ø and 158.3ø." << endl << endl;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | int main(int argc, char **argv)
|
|---|
| 90 | {
|
|---|
| 91 | if (!MARS::CheckRootVer())
|
|---|
| 92 | return 0xff;
|
|---|
| 93 |
|
|---|
| 94 | //
|
|---|
| 95 | // Evaluate arguments
|
|---|
| 96 | //
|
|---|
| 97 | MArgs arg(argc, argv, kTRUE);
|
|---|
| 98 | gLog.Setup(arg);
|
|---|
| 99 |
|
|---|
| 100 | StartUpMessage();
|
|---|
| 101 |
|
|---|
| 102 | if (arg.HasOnly("-V") || arg.HasOnly("--version"))
|
|---|
| 103 | return 0;
|
|---|
| 104 |
|
|---|
| 105 | if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
|
|---|
| 106 | {
|
|---|
| 107 | Usage();
|
|---|
| 108 | return 2;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | const TString kConfig = arg.GetStringAndRemove("--config=", "sponde.rc");
|
|---|
| 112 |
|
|---|
| 113 | const Bool_t kPrintSeq = arg.HasOnlyAndRemove("--print-ds");
|
|---|
| 114 | const Bool_t kPrintFiles = arg.HasOnlyAndRemove("--print-files");
|
|---|
| 115 | const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
|
|---|
| 116 | Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
|
|---|
| 117 | kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
|
|---|
| 118 |
|
|---|
| 119 | const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
|
|---|
| 120 | const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
|
|---|
| 121 | const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
|
|---|
| 122 |
|
|---|
| 123 | const Bool_t kRefill = arg.HasOnlyAndRemove("--refill");
|
|---|
| 124 | // const Bool_t kSimple = !arg.HasOnlyAndRemove("--accurate");
|
|---|
| 125 | const Bool_t kForceTheta = arg.HasOnlyAndRemove("--force-theta");
|
|---|
| 126 | const Bool_t kRawMc = arg.HasOnlyAndRemove("--raw-mc");
|
|---|
| 127 |
|
|---|
| 128 | if (arg.GetNumOptions()>0)
|
|---|
| 129 | {
|
|---|
| 130 | gLog << warn << "WARNING - Unknown command line options..." << endl;
|
|---|
| 131 | arg.Print("options");
|
|---|
| 132 | gLog << endl;
|
|---|
| 133 | return 2;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | //
|
|---|
| 137 | // check for the right usage of the program
|
|---|
| 138 | //
|
|---|
| 139 | if (arg.GetNumArguments()<2 || arg.GetNumArguments()>3)
|
|---|
| 140 | {
|
|---|
| 141 | Usage();
|
|---|
| 142 | return 2;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | //
|
|---|
| 146 | // Setup sequence file and check for its existence
|
|---|
| 147 | //
|
|---|
| 148 | const TString kInfile = arg.GetArgumentStr(0);
|
|---|
| 149 | const TString kDataset = arg.GetArgumentStr(1);
|
|---|
| 150 | const TString kOutfile = arg.GetArgumentStr(2);
|
|---|
| 151 |
|
|---|
| 152 | if (gSystem->AccessPathName(kInfile, kFileExists))
|
|---|
| 153 | {
|
|---|
| 154 | gLog << err << "Sorry, sequences file '" << kInfile << "' doesn't exist." << endl;
|
|---|
| 155 | return 2;
|
|---|
| 156 | }
|
|---|
| 157 | if (gSystem->AccessPathName(kDataset, kFileExists))
|
|---|
| 158 | {
|
|---|
| 159 | gLog << err << "Sorry, dataset file '" << kDataset << "' doesn't exist." << endl;
|
|---|
| 160 | return 2;
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | if (kDebugMem)
|
|---|
| 164 | TObject::SetObjectStat(kTRUE);
|
|---|
| 165 |
|
|---|
| 166 | //
|
|---|
| 167 | // Setup sequence and check its validity
|
|---|
| 168 | //
|
|---|
| 169 | MDataSet seq(kDataset);
|
|---|
| 170 | if (kPrintSeq || kPrintFiles)
|
|---|
| 171 | {
|
|---|
| 172 | gLog << all;
|
|---|
| 173 | gLog.Separator(kDataset);
|
|---|
| 174 | seq.Print(kPrintFiles?"files":"");
|
|---|
| 175 | gLog << endl;
|
|---|
| 176 | }
|
|---|
| 177 | if (!seq.IsValid())
|
|---|
| 178 | {
|
|---|
| 179 | gLog << err << "Dataset read but not valid (maybe analysis number not set)!" << endl << endl;
|
|---|
| 180 | return 2;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | if (!seq.IsMonteCarlo())
|
|---|
| 184 | gLog << warn << "Dataset file seems not to be a Monte Carlo dataset." << endl << endl;
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 | //
|
|---|
| 188 | // Initialize root
|
|---|
| 189 | //
|
|---|
| 190 | MArray::Class()->IgnoreTObjectStreamer();
|
|---|
| 191 | MParContainer::Class()->IgnoreTObjectStreamer();
|
|---|
| 192 |
|
|---|
| 193 | TApplication app("sponde", &argc, argv);
|
|---|
| 194 | if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
|
|---|
| 195 | {
|
|---|
| 196 | gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
|
|---|
| 197 | return 1;
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | //
|
|---|
| 201 | // Update frequency by default = 1Hz
|
|---|
| 202 | //
|
|---|
| 203 | MStatusDisplay *d = new MStatusDisplay;
|
|---|
| 204 |
|
|---|
| 205 | // From now on each 'Exit' means: Terminate the application
|
|---|
| 206 | d->SetBit(MStatusDisplay::kExitLoopOnExit);
|
|---|
| 207 | d->SetTitle(kDataset);
|
|---|
| 208 |
|
|---|
| 209 | //
|
|---|
| 210 | // Calculate pedestal for pedestal-calculation and calibration
|
|---|
| 211 | //
|
|---|
| 212 | MEnv env(kConfig);
|
|---|
| 213 | if (!env.IsValid())
|
|---|
| 214 | {
|
|---|
| 215 | gLog << err << "Configuration file " << kConfig << " not found." << endl;
|
|---|
| 216 | return 0xfe;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | MJSpectrum job(Form("MJSpectrum #%d", seq.GetNumAnalysis()));
|
|---|
| 220 | job.SetEnv(&env);
|
|---|
| 221 | job.SetEnvDebug(kDebugEnv);
|
|---|
| 222 | job.SetDisplay(d);;
|
|---|
| 223 | job.SetOverwrite(kOverwrite);
|
|---|
| 224 | job.SetPathOut(kOutfile);
|
|---|
| 225 | job.SetPathIn(kInfile);
|
|---|
| 226 |
|
|---|
| 227 | job.ForceTheta(kForceTheta);
|
|---|
| 228 | job.EnableRefilling(kRefill);
|
|---|
| 229 | // job.EnableSimpleMode(kSimple);
|
|---|
| 230 | job.EnableRawMc(kRawMc);
|
|---|
| 231 |
|
|---|
| 232 | if (!job.Process(seq))
|
|---|
| 233 | {
|
|---|
| 234 | gLog << err << "Calculation of spectrum failed." << endl << endl;
|
|---|
| 235 | return 2;
|
|---|
| 236 | }
|
|---|
| 237 | if (kDebugEnv>0)
|
|---|
| 238 | env.PrintUntouched();
|
|---|
| 239 |
|
|---|
| 240 | if (!job.GetDisplay())
|
|---|
| 241 | {
|
|---|
| 242 | gLog << warn << "Display closed by user... execution aborted." << endl << endl;
|
|---|
| 243 | return 1;
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | if (kBatch || kQuit)
|
|---|
| 247 | delete d;
|
|---|
| 248 | else
|
|---|
| 249 | {
|
|---|
| 250 | // From now on each 'Close' means: Terminate the application
|
|---|
| 251 | d->SetBit(MStatusDisplay::kExitLoopOnClose);
|
|---|
| 252 |
|
|---|
| 253 | // Wait until the user decides to exit the application
|
|---|
| 254 | app.Run(kFALSE);
|
|---|
| 255 | }
|
|---|
| 256 |
|
|---|
| 257 | if (TObject::GetObjectStat())
|
|---|
| 258 | {
|
|---|
| 259 | TObject::SetObjectStat(kFALSE);
|
|---|
| 260 | gObjectTable->Print();
|
|---|
| 261 | }
|
|---|
| 262 |
|
|---|
| 263 | return 0;
|
|---|
| 264 | }
|
|---|