| 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 "MSequence.h" | 
|---|
| 19 | #include "MJPedestal.h" | 
|---|
| 20 | #include "MJCalibration.h" | 
|---|
| 21 | #include "MJCalibrateSignal.h" | 
|---|
| 22 | #include "MJCalibTest.h" | 
|---|
| 23 |  | 
|---|
| 24 | using namespace std; | 
|---|
| 25 |  | 
|---|
| 26 | static void StartUpMessage() | 
|---|
| 27 | { | 
|---|
| 28 | gLog << all << endl; | 
|---|
| 29 |  | 
|---|
| 30 | //                1         2         3         4         5 | 
|---|
| 31 | //       12345678901234567890123456789012345678901234567890 | 
|---|
| 32 | gLog << "========================================================" << endl; | 
|---|
| 33 | gLog << "                 Callisto - MARS V" << MARSVER            << endl; | 
|---|
| 34 | gLog << "    MARS -- CALibrate LIght Signals and Time Offsets"     << endl; | 
|---|
| 35 | gLog << "      Compiled with ROOT v" << ROOT_RELEASE << " on <" << __DATE__ << ">" << endl; | 
|---|
| 36 | gLog << "========================================================" << endl; | 
|---|
| 37 | gLog << endl; | 
|---|
| 38 | } | 
|---|
| 39 |  | 
|---|
| 40 | static void Usage() | 
|---|
| 41 | { | 
|---|
| 42 | //                1         2         3         4         5         6         7         8 | 
|---|
| 43 | //       12345678901234567890123456789012345678901234567890123456789012345678901234567890 | 
|---|
| 44 | gLog << all << endl; | 
|---|
| 45 | gLog << "Sorry the usage is:" << endl; | 
|---|
| 46 | gLog << " callisto [-c] [-y] [options] sequence.txt|number" << endl << endl; | 
|---|
| 47 | gLog << " Arguments:" << endl; | 
|---|
| 48 | gLog << "   sequence.txt:             ASCII file defining a sequence of runs" << endl; | 
|---|
| 49 | gLog << "   number:                   The sequence number (using file in the datacenter)" << endl; | 
|---|
| 50 | gLog << "                             For more details see MSequence" << endl; | 
|---|
| 51 | gLog << " Root Options:" << endl; | 
|---|
| 52 | gLog << "   -b                        Batch mode (no graphical output to screen)" << endl<<endl; | 
|---|
| 53 | gLog << " Operation Modes:" << endl; | 
|---|
| 54 | gLog << "   -c                        Calculate the calibration constants" << endl; | 
|---|
| 55 | gLog << "   -y                        Extract and calibrate signal" << endl << endl; | 
|---|
| 56 | gLog << " Data Type (exclusive):" << endl; | 
|---|
| 57 | gLog << "   -raw                      Read input from raw-data <default>" << endl; | 
|---|
| 58 | gLog << "   -mc                       Input root-files are monte carlo files" << endl; | 
|---|
| 59 | gLog << "   -root                     Read input from root-files (merpped)" << endl << endl; | 
|---|
| 60 | gLog << " Options:" << endl; | 
|---|
| 61 | gLog.Usage(); | 
|---|
| 62 | gLog << "   --debug-env=0             Disable debugging setting resources <default>" << endl; | 
|---|
| 63 | gLog << "   --debug-env[=1]           Display untouched resources after program execution" << endl; | 
|---|
| 64 | gLog << "   --debug-env=2             Display untouched resources after eventloop setup" << endl; | 
|---|
| 65 | gLog << "   --debug-env=3             Debug setting resources from resource file" << endl; | 
|---|
| 66 | gLog << "   --debug-mem               Debug memory usage" << endl << endl; | 
|---|
| 67 | gLog << endl; | 
|---|
| 68 | gLog << "   -q                        Quit when job is finished" << endl; | 
|---|
| 69 | gLog << "   -f                        Force overwrite of existing files" << endl; | 
|---|
| 70 | gLog << "   --ind=path                Path where to search for the data files" << endl; | 
|---|
| 71 | gLog << "                             [default=standard path in datacenter]" << endl; | 
|---|
| 72 | gLog << "   --iny=path                Path where to search for the calibration files" << endl; | 
|---|
| 73 | gLog << "                             [default=local path or output path of Mode-C]" << endl; | 
|---|
| 74 | gLog << "   --outc=path               Path to write Mode-C result to   [def=local path]" << endl; | 
|---|
| 75 | gLog << "   --outy=path               Path to write Mode-Y result to   [def=local path]" << endl; | 
|---|
| 76 | gLog << "   --out=path                Path to write the all results to [def=local path]" << endl; | 
|---|
| 77 | gLog << "                             (overwrites --outc and --outy)" << endl; | 
|---|
| 78 | gLog << "   --path=path               Path to write the all results to [def=local path]" << endl; | 
|---|
| 79 | gLog << "                             (overwrites --iny, --outc and --outy)" << endl; | 
|---|
| 80 | gLog << "   --print-seq               Print Sequence information" << endl; | 
|---|
| 81 | gLog << "   --print-files             Print Files taken from Sequence" << endl; | 
|---|
| 82 | gLog << "   --print-found             Print Files found from Sequence" << endl; | 
|---|
| 83 | gLog << "   --use-test                Apply calibration constants to same calibration" << endl; | 
|---|
| 84 | gLog << "                             file (for testing, calibration mode only)" << endl; | 
|---|
| 85 | gLog << "   --moon                    Force using pedestal fits instead of calculated RMS" << endl; | 
|---|
| 86 | gLog << "   --config=callisto.rc      Resource file [default=callisto.rc]" << endl; | 
|---|
| 87 | gLog << endl; | 
|---|
| 88 | gLog << "   --version, -V             Show startup message with version number" << endl; | 
|---|
| 89 | gLog << "   -?, -h, --help            This help" << endl << endl; | 
|---|
| 90 | gLog << " Setup of the two jobs run by callisto (MJPedestal and MJCalibration)" << endl; | 
|---|
| 91 | gLog << " can be done with the resource file. See MJPedestal and MJCalibration" << endl; | 
|---|
| 92 | gLog << " especially CheckEnv() for more details.   Command line options might" << endl; | 
|---|
| 93 | gLog << " be overwritten by the resource file." << endl << endl; | 
|---|
| 94 | gLog << " If running in Mode-C and Mode-Y --iny= is obsolete,  instead --outc=" << endl; | 
|---|
| 95 | gLog << " is used." << endl << endl; | 
|---|
| 96 | gLog << " Using  --iny=,  --outc=,  --outy=,  --out=  or --path= automatically" << endl; | 
|---|
| 97 | gLog << " enables the corresponding modes.  In this case  -c/-y are obsolete." << endl << endl; | 
|---|
| 98 | gLog << "Description:" << endl; | 
|---|
| 99 | gLog << " callisto will calculate pedestals  from  pedestal-files defined in a" << endl; | 
|---|
| 100 | gLog << " sequence-file.  This pedestals are used to calculate the calibration" << endl; | 
|---|
| 101 | gLog << " constants. These constants are stored in a so called calibration-file" << endl; | 
|---|
| 102 | gLog << " together with some datacheck plots  which can be viewed using either" << endl; | 
|---|
| 103 | gLog << " showplot or MStatusDisplay in the interpreter.  A description  of  a" << endl; | 
|---|
| 104 | gLog << " sequence-file can be found in the class reference of MSequence." << endl << endl; | 
|---|
| 105 | gLog << "Background:" << endl; | 
|---|
| 106 | gLog << " Callisto is a large,  icy,  dark-colored,  low-density outer moon of" << endl; | 
|---|
| 107 | gLog << " Jupiter that is scarred with  impact craters  and  ejecta.  It has a" << endl; | 
|---|
| 108 | gLog << " diameter of about 4800km, the second-largest moon of Jupiter;  it is" << endl; | 
|---|
| 109 | gLog << " roughly the size of  Mercury.  Callisto has the largest-known impact" << endl; | 
|---|
| 110 | gLog << " crater in the Solar System, Valhalla, which has a bright patch 600km" << endl; | 
|---|
| 111 | gLog << " across  and  rings that go out  to almost  3000km.  Callisto  orbits" << endl; | 
|---|
| 112 | gLog << " Jupiter at a mean distance of 1,883,000km. Its mass is 1.1e23 kg. It" << endl; | 
|---|
| 113 | gLog << " takes Callisto  16.7 days to orbit  Jupiter  in a synchronous orbit." << endl; | 
|---|
| 114 | gLog << " Jupiter's moon Callisto was discovered independently by  Galileo and" << endl; | 
|---|
| 115 | gLog << " S.Marius in 1610." << endl << endl; | 
|---|
| 116 | gLog << "Example:" << endl; | 
|---|
| 117 | gLog << " callisto -f --outc=mycal/ --outy=mysignal/ --log sequence02345.txt" << endl; | 
|---|
| 118 | gLog << endl; | 
|---|
| 119 | } | 
|---|
| 120 |  | 
|---|
| 121 | static void PrintFiles(const MSequence &seq, const TString &kInpathD, Bool_t raw, Bool_t showall) | 
|---|
| 122 | { | 
|---|
| 123 | const char *prep = showall ? "Found" : "Scheduled"; | 
|---|
| 124 |  | 
|---|
| 125 | MDirIter Next1, Next2, Next3; | 
|---|
| 126 | seq.SetupPedRuns(Next1, kInpathD, raw); | 
|---|
| 127 | seq.SetupCalRuns(Next2, kInpathD, raw); | 
|---|
| 128 | seq.SetupDatRuns(Next3, kInpathD, raw); | 
|---|
| 129 |  | 
|---|
| 130 | gLog << all; | 
|---|
| 131 | gLog.Separator(Form("%s Pedestal Files", prep)); | 
|---|
| 132 | Next1.Print(showall?"all":""); | 
|---|
| 133 | gLog << endl; | 
|---|
| 134 | gLog.Separator(Form("%s Calibration Files", prep)); | 
|---|
| 135 | Next2.Print(showall?"all":""); | 
|---|
| 136 | gLog << endl; | 
|---|
| 137 | gLog.Separator(Form("%s Data Files", prep)); | 
|---|
| 138 | Next3.Print(showall?"all":""); | 
|---|
| 139 | gLog << endl; | 
|---|
| 140 | } | 
|---|
| 141 |  | 
|---|
| 142 | int main(int argc, char **argv) | 
|---|
| 143 | { | 
|---|
| 144 | if (!MARS::CheckRootVer()) | 
|---|
| 145 | return 0xff; | 
|---|
| 146 |  | 
|---|
| 147 | MLog::RedirectErrorHandler(MLog::kColor); | 
|---|
| 148 |  | 
|---|
| 149 | // | 
|---|
| 150 | // Evaluate arguments | 
|---|
| 151 | // | 
|---|
| 152 | MArgs arg(argc, argv, kTRUE); | 
|---|
| 153 | gLog.Setup(arg); | 
|---|
| 154 |  | 
|---|
| 155 | StartUpMessage(); | 
|---|
| 156 |  | 
|---|
| 157 | if (arg.HasOnly("-V") || arg.HasOnly("--version")) | 
|---|
| 158 | return 0; | 
|---|
| 159 |  | 
|---|
| 160 | if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help")) | 
|---|
| 161 | { | 
|---|
| 162 | Usage(); | 
|---|
| 163 | return 2; | 
|---|
| 164 | } | 
|---|
| 165 |  | 
|---|
| 166 | const TString kConfig     = arg.GetStringAndRemove("--config=", "callisto.rc"); | 
|---|
| 167 |  | 
|---|
| 168 | const Bool_t  kPrintSeq   = arg.HasOnlyAndRemove("--print-seq"); | 
|---|
| 169 | const Bool_t  kPrintFiles = arg.HasOnlyAndRemove("--print-files"); | 
|---|
| 170 | const Bool_t  kPrintFound = arg.HasOnlyAndRemove("--print-found"); | 
|---|
| 171 | const Bool_t  kUseTest    = arg.HasOnlyAndRemove("--use-test"); | 
|---|
| 172 | const Bool_t  kDebugMem   = arg.HasOnlyAndRemove("--debug-mem"); | 
|---|
| 173 | Bool_t  kMoon       = arg.HasOnlyAndRemove("--moon"); | 
|---|
| 174 | Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0; | 
|---|
| 175 | kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv); | 
|---|
| 176 |  | 
|---|
| 177 | const Bool_t  kQuit       = arg.HasOnlyAndRemove("-q"); | 
|---|
| 178 | const Bool_t  kBatch      = arg.HasOnlyAndRemove("-b"); | 
|---|
| 179 | const Bool_t  kOverwrite  = arg.HasOnlyAndRemove("-f"); | 
|---|
| 180 | //const Bool_t  kForceExec  = arg.HasOnlyAndRemove("-ff"); | 
|---|
| 181 |  | 
|---|
| 182 | const TString kInpathD    = arg.GetStringAndRemove("--ind=",  ""); | 
|---|
| 183 | TString kInpathY    = arg.GetStringAndRemove("--iny=",  ""); | 
|---|
| 184 | TString kOutpathY   = arg.GetStringAndRemove("--outy=", ""); | 
|---|
| 185 | TString kOutpathC   = arg.GetStringAndRemove("--outc=", ""); | 
|---|
| 186 | const TString kOutpath    = arg.GetStringAndRemove("--out=",  ""); | 
|---|
| 187 | const TString kPath       = arg.GetStringAndRemove("--path=", ""); | 
|---|
| 188 |  | 
|---|
| 189 | Bool_t  kModeC      = arg.HasOnlyAndRemove("-c"); | 
|---|
| 190 | Bool_t  kModeY      = arg.HasOnlyAndRemove("-y"); | 
|---|
| 191 |  | 
|---|
| 192 | MJCalib::DataType_t kDataType = MJCalib::kIsUseRawData; // root | 
|---|
| 193 | if (arg.HasOnlyAndRemove("-root")) | 
|---|
| 194 | kDataType = MJCalib::kIsUseRootData; // root | 
|---|
| 195 | if (arg.HasOnlyAndRemove("-raw")) | 
|---|
| 196 | kDataType = MJCalib::kIsUseRawData;  // raw | 
|---|
| 197 | if (arg.HasOnlyAndRemove("-mc")) | 
|---|
| 198 | kDataType = MJCalib::kIsUseMC;       // monte carlo | 
|---|
| 199 |  | 
|---|
| 200 | if (!kInpathY.IsNull() || !kOutpathY.IsNull() || !kOutpath.IsNull() || !kPath.IsNull()) | 
|---|
| 201 | kModeY = kTRUE; | 
|---|
| 202 | if (!kOutpathC.IsNull() || !kOutpath.IsNull() || !kPath.IsNull()) | 
|---|
| 203 | kModeC = kTRUE; | 
|---|
| 204 |  | 
|---|
| 205 | // | 
|---|
| 206 | // check for the right usage of the program | 
|---|
| 207 | // | 
|---|
| 208 | if (arg.GetNumArguments()!=1) | 
|---|
| 209 | { | 
|---|
| 210 | Usage(); | 
|---|
| 211 | return 2; | 
|---|
| 212 | } | 
|---|
| 213 |  | 
|---|
| 214 | if (arg.GetNumOptions()>0) | 
|---|
| 215 | { | 
|---|
| 216 | gLog << warn << "WARNING - Unknown commandline options..." << endl; | 
|---|
| 217 | arg.Print("options"); | 
|---|
| 218 | gLog << endl; | 
|---|
| 219 | return 2; | 
|---|
| 220 | } | 
|---|
| 221 |  | 
|---|
| 222 | if (!kModeC && !kModeY /*&& !kUseTest*/) | 
|---|
| 223 | { | 
|---|
| 224 | gLog << err << "Neither calibration (-c), signal extraction (-y) or test-mode (--use-test)" << endl; | 
|---|
| 225 | gLog <<        "specified! You can also give the operation mode by the options defining the" << endl; | 
|---|
| 226 | gLog <<        "output path --outc, --outy or --out." << endl; | 
|---|
| 227 | Usage(); | 
|---|
| 228 | return 2; | 
|---|
| 229 | } | 
|---|
| 230 |  | 
|---|
| 231 | if ((kModeC/* || kUseTest*/) && kOutpathC.IsNull()) | 
|---|
| 232 | kOutpathC = "."; | 
|---|
| 233 | if (kModeY) | 
|---|
| 234 | { | 
|---|
| 235 | if (kInpathY.IsNull()) | 
|---|
| 236 | kInpathY = "."; | 
|---|
| 237 | if (kOutpathY.IsNull()) | 
|---|
| 238 | kOutpathY = "."; | 
|---|
| 239 | } | 
|---|
| 240 | if (!kOutpath.IsNull()) | 
|---|
| 241 | { | 
|---|
| 242 | kOutpathC = kOutpath; | 
|---|
| 243 | kOutpathY = kOutpath; | 
|---|
| 244 | } | 
|---|
| 245 | if (!kPath.IsNull()) | 
|---|
| 246 | { | 
|---|
| 247 | kOutpathC = kOutpath; | 
|---|
| 248 | kOutpathY = kOutpath; | 
|---|
| 249 | kInpathY  = kOutpath; | 
|---|
| 250 | } | 
|---|
| 251 |  | 
|---|
| 252 | if (kModeC && kModeY) | 
|---|
| 253 | kInpathY = kOutpathC; | 
|---|
| 254 |  | 
|---|
| 255 | // | 
|---|
| 256 | // Setup sequence file and check for its existance | 
|---|
| 257 | // | 
|---|
| 258 | TString kSequence = arg.GetArgumentStr(0); | 
|---|
| 259 |  | 
|---|
| 260 | if (kSequence.IsDigit()) | 
|---|
| 261 | { | 
|---|
| 262 | const Int_t numseq = kSequence.Atoi(); | 
|---|
| 263 | kSequence = Form("/magic/sequences/%04d/sequence%08d.txt", numseq/10000, numseq); | 
|---|
| 264 | gLog << inf << "Inflated sequence file: " << kSequence << endl; | 
|---|
| 265 | } | 
|---|
| 266 |  | 
|---|
| 267 | if (gSystem->AccessPathName(kSequence, kFileExists)) | 
|---|
| 268 | { | 
|---|
| 269 | gLog << err << "Sorry, sequence file '" << kSequence << "' doesn't exist." << endl; | 
|---|
| 270 | return 3; | 
|---|
| 271 | } | 
|---|
| 272 |  | 
|---|
| 273 | if (gSystem->AccessPathName(kConfig, kFileExists)) | 
|---|
| 274 | { | 
|---|
| 275 | gLog << err << "Sorry, config file '" << kConfig << "' doesn't exist." << endl; | 
|---|
| 276 | return 4; | 
|---|
| 277 | } | 
|---|
| 278 |  | 
|---|
| 279 | if (kDebugMem) | 
|---|
| 280 | TObject::SetObjectStat(kTRUE); | 
|---|
| 281 |  | 
|---|
| 282 | // | 
|---|
| 283 | // Setup sequence and check its validity | 
|---|
| 284 | // | 
|---|
| 285 | MSequence seq(kSequence); | 
|---|
| 286 | if (kPrintSeq) | 
|---|
| 287 | { | 
|---|
| 288 | gLog << all; | 
|---|
| 289 | gLog.Separator(kSequence); | 
|---|
| 290 | seq.Print(); | 
|---|
| 291 | gLog << endl; | 
|---|
| 292 | } | 
|---|
| 293 | if (!seq.IsValid()) | 
|---|
| 294 | { | 
|---|
| 295 | gLog << err << "Sequence read but not valid!" << endl << endl; | 
|---|
| 296 | return 5; | 
|---|
| 297 | } | 
|---|
| 298 |  | 
|---|
| 299 | // | 
|---|
| 300 | // Process print options | 
|---|
| 301 | // | 
|---|
| 302 | if (kPrintFiles) | 
|---|
| 303 | PrintFiles(seq, kInpathD, kDataType==MJCalib::kIsUseRawData, kFALSE); | 
|---|
| 304 | if (kPrintFound) | 
|---|
| 305 | PrintFiles(seq, kInpathD, kDataType==MJCalib::kIsUseRawData, kTRUE); | 
|---|
| 306 |  | 
|---|
| 307 | if (seq.HasMoon()) | 
|---|
| 308 | kMoon = kTRUE; | 
|---|
| 309 |  | 
|---|
| 310 |  | 
|---|
| 311 | /* | 
|---|
| 312 | // | 
|---|
| 313 | // Check for existance of all files | 
|---|
| 314 | // | 
|---|
| 315 | MDirIter iter; | 
|---|
| 316 | const Int_t n0 = seq.SetupAllRuns(iter, kInpathD, "[DPC]"); | 
|---|
| 317 | const Int_t n1 = seq.GetNumAllRuns(); | 
|---|
| 318 | if (n0 != n1) | 
|---|
| 319 | { | 
|---|
| 320 | if (kForceExec) | 
|---|
| 321 | gLog << warn << "WARNING"; | 
|---|
| 322 | else | 
|---|
| 323 | gLog << err << "ERROR"; | 
|---|
| 324 | gLog << " - " << n1 << " files in sequence defined, but " << n0 << " found in "; | 
|---|
| 325 | gLog << (kInpathD.IsNull() ? "<defaultpath>" : kInpathD.Data()) << endl; | 
|---|
| 326 | if (!kForceExec) | 
|---|
| 327 | return 2; | 
|---|
| 328 | } | 
|---|
| 329 |  | 
|---|
| 330 | if (kPrintOnly) | 
|---|
| 331 | return 0; | 
|---|
| 332 | */ | 
|---|
| 333 | // | 
|---|
| 334 | // Initialize root | 
|---|
| 335 | // | 
|---|
| 336 | MArray::Class()->IgnoreTObjectStreamer(); | 
|---|
| 337 | MParContainer::Class()->IgnoreTObjectStreamer(); | 
|---|
| 338 |  | 
|---|
| 339 | TApplication app("callisto", &argc, argv); | 
|---|
| 340 | if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch) | 
|---|
| 341 | { | 
|---|
| 342 | gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl; | 
|---|
| 343 | return 1; | 
|---|
| 344 | } | 
|---|
| 345 |  | 
|---|
| 346 | // | 
|---|
| 347 | // Update frequency by default = 1Hz | 
|---|
| 348 | // | 
|---|
| 349 | MStatusDisplay *d = new MStatusDisplay; | 
|---|
| 350 |  | 
|---|
| 351 | // From now on each 'Exit' means: Terminate the application | 
|---|
| 352 | d->SetBit(MStatusDisplay::kExitLoopOnExit); | 
|---|
| 353 | d->SetTitle(kSequence); | 
|---|
| 354 |  | 
|---|
| 355 | MEnv env(kConfig); | 
|---|
| 356 | if (!env.IsValid()) | 
|---|
| 357 | { | 
|---|
| 358 | gLog << err << "Configuration file " << kConfig << " not found." << endl; | 
|---|
| 359 | return 0xfe; | 
|---|
| 360 | } | 
|---|
| 361 |  | 
|---|
| 362 | if (kModeC/* || kUseTest*/) | 
|---|
| 363 | { | 
|---|
| 364 | // | 
|---|
| 365 | // Calculate pedestal for pedestal-calculation and calibration | 
|---|
| 366 | // | 
|---|
| 367 | MJPedestal job1(Form("MJPedestalC1 #%d", seq.GetSequence())); | 
|---|
| 368 | job1.SetNoStorage(); | 
|---|
| 369 | job1.SetSequence(seq); | 
|---|
| 370 | job1.SetEnv(&env); | 
|---|
| 371 | job1.SetEnvDebug(kDebugEnv); | 
|---|
| 372 | job1.SetDisplay(d); | 
|---|
| 373 | job1.SetOverwrite(kOverwrite); | 
|---|
| 374 | job1.SetPathData(kInpathD); | 
|---|
| 375 | job1.SetDataType(kDataType); | 
|---|
| 376 | job1.SetUseHists(kMoon); | 
|---|
| 377 |  | 
|---|
| 378 |  | 
|---|
| 379 | job1.SetExtractionFundamental(); | 
|---|
| 380 | // job1.SetPathOut(kOutpathC); // not yet needed | 
|---|
| 381 | // job1.SetPathIn(kInpathC);   // DO NOT CALL IT. IT WOULD READ THE XEXTRACTOR FROM calib-file | 
|---|
| 382 |  | 
|---|
| 383 | if (!job1.Process()) | 
|---|
| 384 | { | 
|---|
| 385 | gLog << err << "Calculation of pedestal failed." << endl << endl; | 
|---|
| 386 | return 6; | 
|---|
| 387 | } | 
|---|
| 388 |  | 
|---|
| 389 | if (!job1.GetDisplay()) | 
|---|
| 390 | { | 
|---|
| 391 | gLog << warn << "Display closed by user... execution aborted." << endl << endl; | 
|---|
| 392 | return 1; | 
|---|
| 393 | } | 
|---|
| 394 |  | 
|---|
| 395 | // | 
|---|
| 396 | // Calculate pedestal and pedestal resolution | 
|---|
| 397 | // | 
|---|
| 398 | MJPedestal job2(Form("MJPedestalC2 #%d", seq.GetSequence())); | 
|---|
| 399 | job2.SetNoStorage(); | 
|---|
| 400 | job2.SetSequence(seq); | 
|---|
| 401 | job2.SetEnv(&env); | 
|---|
| 402 | job2.SetEnvDebug(kDebugEnv); | 
|---|
| 403 | job2.SetDisplay(d);; | 
|---|
| 404 | job2.SetOverwrite(kOverwrite); | 
|---|
| 405 | job2.SetPathData(kInpathD); | 
|---|
| 406 | job2.SetDataType(kDataType); | 
|---|
| 407 | job2.SetUseHists(kMoon); | 
|---|
| 408 | job2.SetDeadPixelCheck(); | 
|---|
| 409 | // job1.SetPathOut(kOutpathC); // not yet needed | 
|---|
| 410 | // job1.SetPathIn(kInpathC);   // DO NOT CALL IT. IT WOULD READ THE XEXTRACTOR FROM calib-file | 
|---|
| 411 |  | 
|---|
| 412 | //job2.SetExtractorResolution(); | 
|---|
| 413 | job2.SetExtractionWithExtractorRndm(); | 
|---|
| 414 | job2.SetExtractor(job1.GetExtractor()); | 
|---|
| 415 | job2.SetPedestals(job1.GetPedestalCam()); | 
|---|
| 416 | job2.SetBadPixels(job1.GetBadPixels()); | 
|---|
| 417 |  | 
|---|
| 418 | // Please check the Changelog of 2005/04/20 about further deatils of the next comment | 
|---|
| 419 | //if (job1.GetExtractor().InheritsFrom("MExtractTimeAndCharge")) | 
|---|
| 420 | if (!job2.Process()) | 
|---|
| 421 | { | 
|---|
| 422 | gLog << err << "Calculation of pedestal resolution failed." << endl << endl; | 
|---|
| 423 | return 7; | 
|---|
| 424 | } | 
|---|
| 425 |  | 
|---|
| 426 | if (!job2.GetDisplay()) | 
|---|
| 427 | { | 
|---|
| 428 | gLog << warn << "Display closed by user... execution aborted." << endl << endl; | 
|---|
| 429 | return 1; | 
|---|
| 430 | } | 
|---|
| 431 |  | 
|---|
| 432 | // | 
|---|
| 433 | // Do calibration | 
|---|
| 434 | // | 
|---|
| 435 | MJCalibration job3(Form("MJCalibration #%d", seq.GetSequence())); | 
|---|
| 436 | job3.SetSequence(seq); | 
|---|
| 437 | job3.SetEnv(&env); | 
|---|
| 438 | job3.SetEnvDebug(kDebugEnv); | 
|---|
| 439 | job3.SetDisplay(d); | 
|---|
| 440 | job3.SetOverwrite(kOverwrite); | 
|---|
| 441 | job3.SetPathOut(kOutpathC); | 
|---|
| 442 | job3.SetPathData(kInpathD); | 
|---|
| 443 | job3.SetDataType(kDataType); | 
|---|
| 444 | // job2.SetPathIn(kInpathC); // not yet needed | 
|---|
| 445 |  | 
|---|
| 446 | job3.SetBadPixels(job2.GetBadPixels()); | 
|---|
| 447 | job3.SetExtractor(job2.GetExtractor()); | 
|---|
| 448 | job3.SetExtractorCam(job2.GetPedestalCam()); | 
|---|
| 449 |  | 
|---|
| 450 | if (!job3.Process(job1.GetPedestalCam())) | 
|---|
| 451 | { | 
|---|
| 452 | gLog << err << "Calculation of calibration failed." << endl << endl; | 
|---|
| 453 | return 8; | 
|---|
| 454 | } | 
|---|
| 455 |  | 
|---|
| 456 | if (kDebugEnv>0) | 
|---|
| 457 | env.PrintUntouched(); | 
|---|
| 458 |  | 
|---|
| 459 | if (!job3.GetDisplay()) | 
|---|
| 460 | { | 
|---|
| 461 | gLog << warn << "Display closed by user... execution aborted." << endl << endl; | 
|---|
| 462 | return 1; | 
|---|
| 463 | } | 
|---|
| 464 |  | 
|---|
| 465 | if (kUseTest) | 
|---|
| 466 | { | 
|---|
| 467 | MJCalibTest job4(Form("MJCalibTest #%d", seq.GetSequence())); | 
|---|
| 468 | job4.SetBadPixels(job2.GetBadPixels()); | 
|---|
| 469 | job4.SetSequence(seq); | 
|---|
| 470 | job4.SetEnv(&env); | 
|---|
| 471 | job4.SetEnvDebug(kDebugEnv); | 
|---|
| 472 | job4.SetDisplay(d);; | 
|---|
| 473 | job4.SetOverwrite(kOverwrite); | 
|---|
| 474 | job4.SetPathOut(kOutpathC); | 
|---|
| 475 | job4.SetPathData(kInpathD); | 
|---|
| 476 | job4.SetDataType(kDataType); | 
|---|
| 477 |  | 
|---|
| 478 | if (!job4.Process(job1.GetPedestalCam())) | 
|---|
| 479 | { | 
|---|
| 480 | gLog << err << "Calibration of calibration failed." << endl << endl; | 
|---|
| 481 | return 9; | 
|---|
| 482 | } | 
|---|
| 483 |  | 
|---|
| 484 | if (kDebugEnv>0) | 
|---|
| 485 | env.PrintUntouched(); | 
|---|
| 486 |  | 
|---|
| 487 | if (!job4.GetDisplay()) | 
|---|
| 488 | { | 
|---|
| 489 | gLog << warn << "Display closed by user... execution aborted." << endl << endl; | 
|---|
| 490 | return 1; | 
|---|
| 491 | } | 
|---|
| 492 | } | 
|---|
| 493 | } | 
|---|
| 494 |  | 
|---|
| 495 | if (kModeY) | 
|---|
| 496 | { | 
|---|
| 497 | d->Reset(); | 
|---|
| 498 |  | 
|---|
| 499 | // | 
|---|
| 500 | // Calculate starting pedestal for data extraction | 
|---|
| 501 | // | 
|---|
| 502 | MJPedestal job1(Form("MJPedestalY1 #%d", seq.GetSequence())); | 
|---|
| 503 | job1.SetNoStorage(); | 
|---|
| 504 | job1.SetSequence(seq); | 
|---|
| 505 | job1.SetEnv(&env); | 
|---|
| 506 | job1.SetEnvDebug(kDebugEnv); | 
|---|
| 507 | job1.SetDisplay(d); | 
|---|
| 508 | job1.SetNoDisplay(); | 
|---|
| 509 | job1.SetOverwrite(kOverwrite); | 
|---|
| 510 | job1.SetPathData(kInpathD); | 
|---|
| 511 | job1.SetPathIn(kInpathY);   // --> READ Extractor from calib-file | 
|---|
| 512 | job1.SetDataType(kDataType); | 
|---|
| 513 | //job1.SetPathOut(kOutpathY);   // not yet needed | 
|---|
| 514 | job1.SetUseData(); | 
|---|
| 515 | job1.SetExtractionFundamental(); | 
|---|
| 516 | job1.SetUseHists(kMoon); | 
|---|
| 517 |  | 
|---|
| 518 | if (!job1.Process()) | 
|---|
| 519 | { | 
|---|
| 520 | gLog << err << "Calculation of fundamental pedestal failed." << endl << endl; | 
|---|
| 521 | return 10; | 
|---|
| 522 | } | 
|---|
| 523 |  | 
|---|
| 524 | if (!job1.GetDisplay()) | 
|---|
| 525 | { | 
|---|
| 526 | gLog << warn << "Display closed by user... execution aborted." << endl << endl; | 
|---|
| 527 | return 1; | 
|---|
| 528 | } | 
|---|
| 529 |  | 
|---|
| 530 | // | 
|---|
| 531 | // Calculate pedestal and pedestal resolution | 
|---|
| 532 | // | 
|---|
| 533 | MJPedestal job2(Form("MJPedestalY2 #%d", seq.GetSequence())); | 
|---|
| 534 | job2.SetNoStorage(); | 
|---|
| 535 | job2.SetSequence(seq); | 
|---|
| 536 | job2.SetEnv(&env); | 
|---|
| 537 | job2.SetEnvDebug(kDebugEnv); | 
|---|
| 538 | job2.SetDisplay(d); | 
|---|
| 539 | job2.SetNoDisplay(); | 
|---|
| 540 | job2.SetOverwrite(kOverwrite); | 
|---|
| 541 | job2.SetPathData(kInpathD); | 
|---|
| 542 | job2.SetPathIn(kInpathY); | 
|---|
| 543 | job2.SetDataType(kDataType); | 
|---|
| 544 | job2.SetPulsePosCheck(kDataType!=MJCalib::kIsUseMC); | 
|---|
| 545 | job2.SetPathOut(kOutpathY); // for updating the extractor | 
|---|
| 546 |  | 
|---|
| 547 | job2.SetUseData(); | 
|---|
| 548 | job2.SetExtractionWithExtractorRndm(); | 
|---|
| 549 | job2.SetExtractor(job1.GetExtractor()); | 
|---|
| 550 | job2.SetPedestals(job1.GetPedestalCam()); | 
|---|
| 551 | job2.SetBadPixels(job1.GetBadPixels()); | 
|---|
| 552 | job2.SetUseHists(kMoon); | 
|---|
| 553 |  | 
|---|
| 554 | // Please check the Changelog of 2005/04/20 about further deatils of the next comment | 
|---|
| 555 | //if (job1.GetExtractor().InheritsFrom("MExtractTimeAndCharge")) | 
|---|
| 556 | const Int_t rc = job2.Process(); | 
|---|
| 557 | if (rc<=0) | 
|---|
| 558 | { | 
|---|
| 559 | // rc==0:  Error | 
|---|
| 560 | // rc==-1: too much to the left | 
|---|
| 561 | // rc==-2: too much to the right | 
|---|
| 562 | // rc==-3: too much to the right (beyond limits) | 
|---|
| 563 |  | 
|---|
| 564 | gLog << err << "Calculation of pedestal from extractor (random) failed." << endl << endl; | 
|---|
| 565 |  | 
|---|
| 566 | //error coding for the automatic analysis (to be filled into the database) | 
|---|
| 567 | switch (rc) | 
|---|
| 568 | { | 
|---|
| 569 | case 0: | 
|---|
| 570 | return 11; | 
|---|
| 571 | case -1: | 
|---|
| 572 | return 12; | 
|---|
| 573 | case -2: | 
|---|
| 574 | return 13; | 
|---|
| 575 | case -3: | 
|---|
| 576 | return 14; | 
|---|
| 577 | } | 
|---|
| 578 | return 2; | 
|---|
| 579 | } | 
|---|
| 580 |  | 
|---|
| 581 | if (!job2.GetDisplay()) | 
|---|
| 582 | { | 
|---|
| 583 | gLog << warn << "Display closed by user... execution aborted." << endl << endl; | 
|---|
| 584 | return 1; | 
|---|
| 585 | } | 
|---|
| 586 |  | 
|---|
| 587 | // | 
|---|
| 588 | // Calculate pedestal and pedestal resolution | 
|---|
| 589 | // | 
|---|
| 590 | MJPedestal job3(Form("MJPedestalY3 #%d", seq.GetSequence())); | 
|---|
| 591 | job3.SetNoStorage(); | 
|---|
| 592 | job3.SetSequence(seq); | 
|---|
| 593 | job3.SetEnv(&env); | 
|---|
| 594 | job3.SetEnvDebug(kDebugEnv); | 
|---|
| 595 | job3.SetDisplay(d); | 
|---|
| 596 | job3.SetNoDisplay(); | 
|---|
| 597 | job3.SetOverwrite(kOverwrite); | 
|---|
| 598 | job3.SetPathData(kInpathD); | 
|---|
| 599 | job3.SetPathIn(kInpathY); | 
|---|
| 600 | job3.SetDataType(kDataType); | 
|---|
| 601 | // job1.SetPathOut(kOutpathC); // not yet needed | 
|---|
| 602 | // job1.SetPathIn(kInpathC);   // not yet needed | 
|---|
| 603 |  | 
|---|
| 604 | job3.SetUseData(); | 
|---|
| 605 | job3.SetExtractionWithExtractor(); | 
|---|
| 606 | job3.SetExtractor(job2.GetExtractor()); | 
|---|
| 607 | job3.SetPedestals(job1.GetPedestalCam()); | 
|---|
| 608 | job3.SetBadPixels(job1.GetBadPixels()); | 
|---|
| 609 | job3.SetUseHists(kMoon); | 
|---|
| 610 |  | 
|---|
| 611 | if (!job3.Process()) | 
|---|
| 612 | { | 
|---|
| 613 | gLog << err << "Calculation of pedestal from extractor failed." << endl << endl; | 
|---|
| 614 | return 15; | 
|---|
| 615 | } | 
|---|
| 616 |  | 
|---|
| 617 | if (!job3.GetDisplay()) | 
|---|
| 618 | { | 
|---|
| 619 | gLog << warn << "Display closed by user... execution aborted." << endl << endl; | 
|---|
| 620 | return 1; | 
|---|
| 621 | } | 
|---|
| 622 |  | 
|---|
| 623 | // | 
|---|
| 624 | // Extract signal and calibrate it | 
|---|
| 625 | // | 
|---|
| 626 | MJCalibrateSignal job4(Form("MJCalibrateSignal #%d", seq.GetSequence())); | 
|---|
| 627 | job4.SetSequence(seq); | 
|---|
| 628 | job4.SetDisplay(d);; | 
|---|
| 629 | job4.SetEnv(&env); | 
|---|
| 630 | job4.SetEnvDebug(kDebugEnv); | 
|---|
| 631 | job4.SetOverwrite(kOverwrite); | 
|---|
| 632 | job4.SetPathIn(kInpathY); | 
|---|
| 633 | job4.SetPathOut(kOutpathY); | 
|---|
| 634 | job4.SetPathData(kInpathD); | 
|---|
| 635 | job4.SetDataType(kDataType); | 
|---|
| 636 | if (kDataType!=MJCalib::kIsUseMC) | 
|---|
| 637 | job4.SetExtractor(job2.GetExtractor()); | 
|---|
| 638 |  | 
|---|
| 639 | // Where to search for calibration files | 
|---|
| 640 | if (!job4.Process(job1.GetPedestalCam(), job3.GetPedestalCam(), job2.GetPedestalCam())) | 
|---|
| 641 | return 16; | 
|---|
| 642 |  | 
|---|
| 643 | if (kDebugEnv>0) | 
|---|
| 644 | env.PrintUntouched(); | 
|---|
| 645 |  | 
|---|
| 646 | if (!job4.GetDisplay()) | 
|---|
| 647 | { | 
|---|
| 648 | gLog << warn << "Display closed by user... execution aborted." << endl << endl; | 
|---|
| 649 | return 1; | 
|---|
| 650 | } | 
|---|
| 651 | } | 
|---|
| 652 |  | 
|---|
| 653 | if (kBatch || kQuit) | 
|---|
| 654 | delete d; | 
|---|
| 655 | else | 
|---|
| 656 | { | 
|---|
| 657 | // From now on each 'Close' means: Terminate the application | 
|---|
| 658 | d->SetBit(MStatusDisplay::kExitLoopOnClose); | 
|---|
| 659 |  | 
|---|
| 660 | // Wait until the user decides to exit the application | 
|---|
| 661 | app.Run(kFALSE); | 
|---|
| 662 | } | 
|---|
| 663 |  | 
|---|
| 664 | if (TObject::GetObjectStat()) | 
|---|
| 665 | { | 
|---|
| 666 | TObject::SetObjectStat(kFALSE); | 
|---|
| 667 | gObjectTable->Print(); | 
|---|
| 668 | } | 
|---|
| 669 |  | 
|---|
| 670 | return 0; | 
|---|
| 671 | } | 
|---|
| 672 |  | 
|---|