| 1 | #include <TROOT.h>
|
|---|
| 2 | #include <TClass.h>
|
|---|
| 3 | #include <TGClient.h>
|
|---|
| 4 | #include <TApplication.h>
|
|---|
| 5 |
|
|---|
| 6 | #include "MLog.h"
|
|---|
| 7 | #include "MLogManip.h"
|
|---|
| 8 |
|
|---|
| 9 | #include "MArgs.h"
|
|---|
| 10 | #include "MArray.h"
|
|---|
| 11 | #include "MDirIter.h"
|
|---|
| 12 |
|
|---|
| 13 | #include "MStatusDisplay.h"
|
|---|
| 14 |
|
|---|
| 15 | #include "MSequence.h"
|
|---|
| 16 | #include "MJPedestal.h"
|
|---|
| 17 | #include "MJCalibration.h"
|
|---|
| 18 | #include "MJCalibrateSignal.h"
|
|---|
| 19 |
|
|---|
| 20 | using namespace std;
|
|---|
| 21 |
|
|---|
| 22 | static void StartUpMessage()
|
|---|
| 23 | {
|
|---|
| 24 | gLog << all << endl;
|
|---|
| 25 |
|
|---|
| 26 | // 1 2 3 4 5
|
|---|
| 27 | // 12345678901234567890123456789012345678901234567890
|
|---|
| 28 | gLog << "========================================================" << endl;
|
|---|
| 29 | gLog << " Callisto - MARS V" << MARSVER << endl;
|
|---|
| 30 | gLog << " MARS -- CALibrate LIght Signals and Time Offsets" << endl;
|
|---|
| 31 | gLog << " Compiled on <" << __DATE__ << ">" << endl;
|
|---|
| 32 | gLog << " Using ROOT v" << ROOTVER << 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 << " callisto [-c] [-y] [options] sequence.txt" << endl << endl;
|
|---|
| 44 | gLog << " Arguments:" << endl;
|
|---|
| 45 | gLog << " sequence.txt: An ascii file defining a sequence of runs" << endl;
|
|---|
| 46 | gLog << " Root Options:" << endl;
|
|---|
| 47 | gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
|
|---|
| 48 | gLog << " Operation Modes:" << endl;
|
|---|
| 49 | gLog << " -c Calculate the calibration constants" << endl;
|
|---|
| 50 | gLog << " -y Extract and calibrate signal" << endl << endl;
|
|---|
| 51 | gLog << " Options:" << endl;
|
|---|
| 52 | gLog.Usage();
|
|---|
| 53 | gLog << " --debug-env Debug setting resources from file" << endl << endl;
|
|---|
| 54 | gLog << endl;
|
|---|
| 55 | gLog << " -f Force overwrite of existing files" << endl;
|
|---|
| 56 | gLog << " --ind=path Path where to search for the data files" << endl;
|
|---|
| 57 | gLog << " [default=standard path in datacenter]" << endl;
|
|---|
| 58 | gLog << " --iny=path Path where to search for the calibration files" << endl;
|
|---|
| 59 | gLog << " [default=local path or output path of Mode-C]" << endl;
|
|---|
| 60 | gLog << " --outc=path Path to write Mode-C result to [def=local path]" << endl;
|
|---|
| 61 | gLog << " --outy=path Path to write Mode-Y result to [def=local path]" << endl;
|
|---|
| 62 | gLog << " --out=path Path to write the all results to [def=local path]" << endl;
|
|---|
| 63 | gLog << " (overwrites --outc and --outy)" << endl;
|
|---|
| 64 | gLog << " --path=path Path to write the all results to [def=local path]" << endl;
|
|---|
| 65 | gLog << " (overwrites --iny, --outc and --outy)" << endl;
|
|---|
| 66 | gLog << " --print-seq Print Sequence information" << endl;
|
|---|
| 67 | gLog << " --print-files Print Files taken from Sequence" << endl;
|
|---|
| 68 | gLog << " --print-only Do not excute anything except print" << endl;
|
|---|
| 69 | gLog << " --config=callisto.rc Resource file [default=callistop.rc]" << endl;
|
|---|
| 70 | gLog << endl;
|
|---|
| 71 | gLog << " -?, -h, --help This help" << endl << endl;
|
|---|
| 72 | gLog << " Setup of the two jobs run by callisto (MJPedestal and MJCalibration)" << endl;
|
|---|
| 73 | gLog << " can be done with the resource file. See MJPedestal and MJCalibration" << endl;
|
|---|
| 74 | gLog << " especially CheckEnv() for more details. Command line options might" << endl;
|
|---|
| 75 | gLog << " be overwritten by the resource file." << endl << endl;
|
|---|
| 76 | gLog << " If running in Mode-C and Mode-Y --iny= is obsolete, instead --outc=" << endl;
|
|---|
| 77 | gLog << " is used." << endl << endl;
|
|---|
| 78 | gLog << " Using --iny=, --outc=, --outy=, --out= or --path= automatically" << endl;
|
|---|
| 79 | gLog << " enables the corresponmding modes. In this case -c/-y are obsolete." << endl << endl;
|
|---|
| 80 | gLog << "Description:" << endl;
|
|---|
| 81 | gLog << " callisto will calculate pedestals from pedestal-files defined in a" << endl;
|
|---|
| 82 | gLog << " sequence-file. This pedestals are used to calculate the calibration" << endl;
|
|---|
| 83 | gLog << " contants. These constants are stored in a so called calibration-file" << endl;
|
|---|
| 84 | gLog << " together with some datacheck plots which can be viewed using either" << endl;
|
|---|
| 85 | gLog << " showplot or MStatusDisplay in the interpreter." << endl << endl;
|
|---|
| 86 | gLog << "Example:" << endl;
|
|---|
| 87 | gLog << " callisto -f --outc=mycal/ --outy=mysignal/ --log sequence02345.txt" << endl;
|
|---|
| 88 | gLog << endl;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | int main(int argc, char **argv)
|
|---|
| 92 | {
|
|---|
| 93 | StartUpMessage();
|
|---|
| 94 |
|
|---|
| 95 | //
|
|---|
| 96 | // Evaluate arguments
|
|---|
| 97 | //
|
|---|
| 98 | MArgs arg(argc, argv);
|
|---|
| 99 |
|
|---|
| 100 | if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
|
|---|
| 101 | {
|
|---|
| 102 | Usage();
|
|---|
| 103 | return -1;
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | gLog.Setup(arg);
|
|---|
| 107 |
|
|---|
| 108 | const TString kConfig = arg.GetStringAndRemove("--config=", "callisto.rc");
|
|---|
| 109 |
|
|---|
| 110 | const Bool_t kPrintSeq = arg.HasOnlyAndRemove("--print-seq");
|
|---|
| 111 | const Bool_t kPrintFiles = arg.HasOnlyAndRemove("--print-files");
|
|---|
| 112 | const Bool_t kPrintOnly = arg.HasOnlyAndRemove("--print-only");
|
|---|
| 113 | const Bool_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env");
|
|---|
| 114 |
|
|---|
| 115 | const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
|
|---|
| 116 |
|
|---|
| 117 | const TString kInpathD = arg.GetStringAndRemove("--ind=", "");
|
|---|
| 118 | TString kInpathY = arg.GetStringAndRemove("--iny=", ".");
|
|---|
| 119 | TString kOutpathY = arg.GetStringAndRemove("--outy=", ".");
|
|---|
| 120 | TString kOutpathC = arg.GetStringAndRemove("--outc=", ".");
|
|---|
| 121 | const TString kOutpath = arg.GetStringAndRemove("--out=", "");
|
|---|
| 122 | const TString kPath = arg.GetStringAndRemove("--path=", "");
|
|---|
| 123 |
|
|---|
| 124 | Bool_t kModeC = arg.HasOnlyAndRemove("-c");
|
|---|
| 125 | Bool_t kModeY = arg.HasOnlyAndRemove("-y");
|
|---|
| 126 |
|
|---|
| 127 | if (!kInpathY.IsNull() || !kOutpathY.IsNull() || !kOutpath.IsNull() || !kPath.IsNull())
|
|---|
| 128 | kModeY = kTRUE;
|
|---|
| 129 | if (!kOutpathC.IsNull() || !kOutpath.IsNull() || !kPath.IsNull())
|
|---|
| 130 | kModeC = kTRUE;
|
|---|
| 131 |
|
|---|
| 132 | if (!kModeC && !kModeY)
|
|---|
| 133 | {
|
|---|
| 134 | gLog << err << "Neither calibration (-c) nor signal extraction (-y) mode specified!" << endl;
|
|---|
| 135 | Usage();
|
|---|
| 136 | return 0;
|
|---|
| 137 | }
|
|---|
| 138 | if (!kOutpath.IsNull())
|
|---|
| 139 | {
|
|---|
| 140 | kOutpathC = kOutpath;
|
|---|
| 141 | kOutpathY = kOutpath;
|
|---|
| 142 | }
|
|---|
| 143 | if (!kPath.IsNull())
|
|---|
| 144 | {
|
|---|
| 145 | kOutpathC = kOutpath;
|
|---|
| 146 | kOutpathY = kOutpath;
|
|---|
| 147 | kInpathY = kOutpath;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | if (kModeC && kModeY)
|
|---|
| 151 | kInpathY = kOutpathC;
|
|---|
| 152 |
|
|---|
| 153 | if (arg.GetNumOptions()>0)
|
|---|
| 154 | {
|
|---|
| 155 | gLog << warn << "WARNING - Unknown commandline options..." << endl;
|
|---|
| 156 | arg.Print("options");
|
|---|
| 157 | gLog << endl;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | //
|
|---|
| 161 | // check for the right usage of the program
|
|---|
| 162 | //
|
|---|
| 163 | if (arg.GetNumArguments()!=1)
|
|---|
| 164 | {
|
|---|
| 165 | Usage();
|
|---|
| 166 | return -1;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | const TString kSequence = arg.GetArgumentStr(0);
|
|---|
| 170 |
|
|---|
| 171 | TApplication app("Callisto", &argc, argv);
|
|---|
| 172 | if (gROOT->IsBatch() || !gClient)
|
|---|
| 173 | {
|
|---|
| 174 | gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
|
|---|
| 175 | return 1;
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | MSequence seq(kSequence);
|
|---|
| 179 | if (kPrintSeq)
|
|---|
| 180 | {
|
|---|
| 181 | gLog << all;
|
|---|
| 182 | gLog.Separator(kSequence);
|
|---|
| 183 | seq.Print();
|
|---|
| 184 | gLog << endl;
|
|---|
| 185 | }
|
|---|
| 186 | if (!seq.IsValid())
|
|---|
| 187 | {
|
|---|
| 188 | gLog << err << "Sequence invalid!" << endl << endl;
|
|---|
| 189 | return -1;
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | if (kPrintFiles)
|
|---|
| 193 | {
|
|---|
| 194 | MDirIter Next1, Next2, Next3;
|
|---|
| 195 | seq.SetupPedRuns(Next1, kInpathD);
|
|---|
| 196 | seq.SetupCalRuns(Next2, kInpathD);
|
|---|
| 197 | seq.SetupDatRuns(Next3, kInpathD);
|
|---|
| 198 |
|
|---|
| 199 | gLog << all;
|
|---|
| 200 | gLog.Separator("Pedestal Files");
|
|---|
| 201 | Next1.Print("all");
|
|---|
| 202 | gLog << endl;
|
|---|
| 203 | gLog.Separator("Calibration Files");
|
|---|
| 204 | Next2.Print("all");
|
|---|
| 205 | gLog << endl;
|
|---|
| 206 | gLog.Separator("Data Files");
|
|---|
| 207 | Next3.Print("all");
|
|---|
| 208 | gLog << endl;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | if (kPrintOnly)
|
|---|
| 212 | return 0;
|
|---|
| 213 |
|
|---|
| 214 | MArray::Class()->IgnoreTObjectStreamer();
|
|---|
| 215 | MParContainer::Class()->IgnoreTObjectStreamer();
|
|---|
| 216 |
|
|---|
| 217 | //
|
|---|
| 218 | // Update frequency by default = 1Hz
|
|---|
| 219 | //
|
|---|
| 220 | MStatusDisplay *d = new MStatusDisplay;
|
|---|
| 221 |
|
|---|
| 222 | // From now on each 'Exit' means: Terminate the application
|
|---|
| 223 | d->SetBit(MStatusDisplay::kExitLoopOnExit);
|
|---|
| 224 | d->SetTitle(kSequence);
|
|---|
| 225 |
|
|---|
| 226 | if (kModeC)
|
|---|
| 227 | {
|
|---|
| 228 | MJPedestal job1(Form("MJPedestalC #%d", seq.GetSequence()));
|
|---|
| 229 | job1.SetSequence(seq);
|
|---|
| 230 | job1.SetEnv(kConfig);
|
|---|
| 231 | job1.SetEnvDebug(kDebugEnv);
|
|---|
| 232 | job1.SetDisplay(d);;
|
|---|
| 233 | job1.SetOverwrite(kOverwrite);
|
|---|
| 234 | job1.SetPathData(kInpathD);
|
|---|
| 235 | // job1.SetPathOut(kOutpathC); // not yet needed
|
|---|
| 236 | // job1.SetPathIn(kInpathC); // not yet needed
|
|---|
| 237 |
|
|---|
| 238 | if (!job1.ProcessFile())
|
|---|
| 239 | {
|
|---|
| 240 | gLog << err << "Calculation of pedestal failed." << endl << endl;
|
|---|
| 241 | return -1;
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | if (!job1.GetDisplay())
|
|---|
| 245 | {
|
|---|
| 246 | gLog << warn << "Display closed by user... execution aborted." << endl << endl;
|
|---|
| 247 | return 1;
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | MJCalibration job2(Form("MJCalibration #%d", seq.GetSequence()));
|
|---|
| 251 | job2.SetSequence(seq);
|
|---|
| 252 | job2.SetEnv(kConfig);
|
|---|
| 253 | job2.SetEnvDebug(kDebugEnv);
|
|---|
| 254 | job2.SetDisplay(d);;
|
|---|
| 255 | job2.SetBadPixels(job1.GetBadPixels());
|
|---|
| 256 | job2.SetOverwrite(kOverwrite);
|
|---|
| 257 | job2.SetPathOut(kOutpathC);
|
|---|
| 258 | job2.SetPathData(kInpathD);
|
|---|
| 259 | // job2.SetPathIn(kInpathC); // not yet needed
|
|---|
| 260 |
|
|---|
| 261 | if (!job2.ProcessFile(job1.GetPedestalCam()))
|
|---|
| 262 | {
|
|---|
| 263 | gLog << err << "Calculation of calibration failed." << endl << endl;
|
|---|
| 264 | return -1;
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|
| 267 | if (!job2.GetDisplay())
|
|---|
| 268 | {
|
|---|
| 269 | gLog << warn << "Display closed by user... execution aborted." << endl << endl;
|
|---|
| 270 | return 1;
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | gLog << all << endl << endl;
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | if (kModeY)
|
|---|
| 277 | {
|
|---|
| 278 | d->Reset();
|
|---|
| 279 |
|
|---|
| 280 | MJPedestal job1(Form("MJPedestalY #%d", seq.GetSequence()));
|
|---|
| 281 | job1.SetSequence(seq);
|
|---|
| 282 | job1.SetEnv(kConfig);
|
|---|
| 283 | job1.SetEnvDebug(kDebugEnv);
|
|---|
| 284 | job1.SetDisplay(d);;
|
|---|
| 285 | //job1.SetPathIn(kInpathY); // not yet needed
|
|---|
| 286 | //job1.SetPathOut(kOutpathY); // not yet needed
|
|---|
| 287 | job1.SetPathData(kInpathD);
|
|---|
| 288 | job1.SetOverwrite(kOverwrite);
|
|---|
| 289 |
|
|---|
| 290 | if (!job1.ProcessFile())
|
|---|
| 291 | {
|
|---|
| 292 | gLog << err << "Calculation of pedestal failed." << endl << endl;
|
|---|
| 293 | return -1;
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | if (!job1.GetDisplay())
|
|---|
| 297 | {
|
|---|
| 298 | gLog << warn << "Display closed by user... execution aborted." << endl << endl;
|
|---|
| 299 | return 1;
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 | MJCalibrateSignal job2(Form("MJCalibrateSignal #%d", seq.GetSequence()));
|
|---|
| 303 | job2.SetSequence(seq);
|
|---|
| 304 | job2.SetDisplay(d);;
|
|---|
| 305 | job2.SetEnv(kConfig);
|
|---|
| 306 | job2.SetEnvDebug(kDebugEnv);
|
|---|
| 307 | job2.SetOverwrite(kOverwrite);
|
|---|
| 308 | job2.SetPathIn(kInpathY);
|
|---|
| 309 | job2.SetPathOut(kOutpathY);
|
|---|
| 310 | job2.SetPathData(kInpathD);
|
|---|
| 311 |
|
|---|
| 312 | // Where to search for calibration files
|
|---|
| 313 | if (!job2.ProcessFile(job1.GetPedestalCam()))
|
|---|
| 314 | return -1;
|
|---|
| 315 |
|
|---|
| 316 | if (!job2.GetDisplay())
|
|---|
| 317 | {
|
|---|
| 318 | gLog << warn << "Display closed by user... execution aborted." << endl << endl;
|
|---|
| 319 | return 1;
|
|---|
| 320 | }
|
|---|
| 321 |
|
|---|
| 322 | gLog << all << endl << endl;
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | // From now on each 'Close' means: Terminate the application
|
|---|
| 326 | d->SetBit(MStatusDisplay::kExitLoopOnClose);
|
|---|
| 327 |
|
|---|
| 328 | // Wait until the user decides to exit the application
|
|---|
| 329 | app.Run(kFALSE);
|
|---|
| 330 | return 0;
|
|---|
| 331 | }
|
|---|