| 1 | #include <TSystem.h>
|
|---|
| 2 |
|
|---|
| 3 | #include "MParList.h"
|
|---|
| 4 | #include "MTaskList.h"
|
|---|
| 5 | #include "MEvtLoop.h"
|
|---|
| 6 |
|
|---|
| 7 | #include "MRawFileRead.h"
|
|---|
| 8 | #include "MSqlInsertRun.h"
|
|---|
| 9 | #include "MRawFileWrite.h"
|
|---|
| 10 |
|
|---|
| 11 | #include "MReportFileRead.h"
|
|---|
| 12 | #include "MWriteRootFile.h"
|
|---|
| 13 |
|
|---|
| 14 | #include "MLog.h"
|
|---|
| 15 | #include "MLogManip.h"
|
|---|
| 16 |
|
|---|
| 17 | #include "MArgs.h"
|
|---|
| 18 | #include "MTime.h"
|
|---|
| 19 | #include "MArray.h"
|
|---|
| 20 | #include "MRawEvtData.h"
|
|---|
| 21 | #include "MRawRunHeader.h"
|
|---|
| 22 | #include "MRawEvtHeader.h"
|
|---|
| 23 | #include "MRawCrateArray.h"
|
|---|
| 24 |
|
|---|
| 25 | #include "MFDataMember.h"
|
|---|
| 26 |
|
|---|
| 27 | using namespace std;
|
|---|
| 28 |
|
|---|
| 29 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 30 | // //
|
|---|
| 31 | // This is an easy implementation of the Merging process //
|
|---|
| 32 | // (as compilable prog) //
|
|---|
| 33 | // //
|
|---|
| 34 | // at the moment it reads a binary file ("rawtest.bin") which was written //
|
|---|
| 35 | // in the DAQ raw format. //
|
|---|
| 36 | // //
|
|---|
| 37 | // The data are stored in root container objects (classes derived from //
|
|---|
| 38 | // TObject like MRawRunHeader) //
|
|---|
| 39 | // //
|
|---|
| 40 | // This containers are written to a root file ("rawtest.root") //
|
|---|
| 41 | // //
|
|---|
| 42 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 43 |
|
|---|
| 44 | static void StartUpMessage()
|
|---|
| 45 | {
|
|---|
| 46 | gLog << all << endl;
|
|---|
| 47 |
|
|---|
| 48 | // 1 2 3 4 5
|
|---|
| 49 | // 12345678901234567890123456789012345678901234567890
|
|---|
| 50 | gLog << "==================================================" << endl;
|
|---|
| 51 | gLog << " MERPP - MARS V" << MARSVER << endl;
|
|---|
| 52 | gLog << " MARS - Merging and Preprocessing Program" << endl;
|
|---|
| 53 | gLog << " Compiled on <" << __DATE__ << ">" << endl;
|
|---|
| 54 | gLog << " Using ROOT v" << ROOTVER << endl;
|
|---|
| 55 | gLog << "==================================================" << endl;
|
|---|
| 56 | gLog << endl;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | static void Usage()
|
|---|
| 60 | {
|
|---|
| 61 | gLog << all << endl;
|
|---|
| 62 | gLog << "Sorry the usage is:" << endl;
|
|---|
| 63 | gLog << " merpp [-h] [-?] [-a] [-vn] [-cn] [-u, -f]" << endl;
|
|---|
| 64 | gLog << " inputfile[.rep,[.raw],[.txt]] [outputfile[.root]]" << endl << endl;
|
|---|
| 65 | gLog << " inputfile.raw: Magic DAQ binary file." << endl;
|
|---|
| 66 | gLog << " inputfile.rep: Magic Central Control report file." << endl;
|
|---|
| 67 | gLog << " inputfile.txt: Magic DC currents file." << endl;
|
|---|
| 68 | gLog << " ouputfile.root: Merpped root file." << endl;
|
|---|
| 69 | gLog << " -c# Compression level #=1..9 [default=2]" << endl;
|
|---|
| 70 | gLog << " -v# Verbosity level # [default=2]" << endl;
|
|---|
| 71 | gLog << " -u, --update Update file" << endl;
|
|---|
| 72 | gLog << " -a, --no-colors Do not use Ansii color codes" << endl;
|
|---|
| 73 | gLog << " -f Force overwrite of an existing file" << endl;
|
|---|
| 74 | gLog << " --sql=mysql://user:password@url Insert run into database <raw data only>" << endl;
|
|---|
| 75 | gLog << " --start=yyyy-mm-dd/hh:mm:ss.mmm Start event time for merpping report files" << endl;
|
|---|
| 76 | gLog << " --stop=yyyy-mm-dd/hh:mm:ss.mmm Stop event time for merpping report files" << endl;
|
|---|
| 77 | gLog << " --run=# Only data corresponding to this run number" << endl;
|
|---|
| 78 | gLog << " --debug[=n] Enable root debugging (Default: gDebug=1)" << endl;
|
|---|
| 79 | gLog << " -?, -h, --help This help" << endl << endl;
|
|---|
| 80 | gLog << " REMARK: At the moment you can process a .raw _or_ a .rep file, only!" << endl << endl;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | // FIXME: Move to MTime (maybe 'InterpreteCmdline')
|
|---|
| 84 | MTime AnalyseTime(TString str)
|
|---|
| 85 | {
|
|---|
| 86 | Int_t y=0, ms=0, mon=0, d=0, h=0, m=0, s=0;
|
|---|
| 87 |
|
|---|
| 88 | const Int_t n = sscanf(str.Data(), "%d-%d-%d/%d:%d:%d.%d", &y, &mon, &d, &h, &m, &s, &ms);
|
|---|
| 89 |
|
|---|
| 90 | if (n<6 || n>7)
|
|---|
| 91 | {
|
|---|
| 92 | gLog << warn << "'" << str << "' no valid Time... ignored." << endl;
|
|---|
| 93 | return MTime();
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | MTime t;
|
|---|
| 97 | t.Set(y, mon, d, h, m, s, ms);
|
|---|
| 98 | return t;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | int main(const int argc, char **argv)
|
|---|
| 102 | {
|
|---|
| 103 | StartUpMessage();
|
|---|
| 104 |
|
|---|
| 105 | //
|
|---|
| 106 | // Evaluate arguments
|
|---|
| 107 | //
|
|---|
| 108 | MArgs arg(argc, argv);
|
|---|
| 109 |
|
|---|
| 110 | if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
|
|---|
| 111 | {
|
|---|
| 112 | Usage();
|
|---|
| 113 | return -1;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | if (arg.HasOnlyAndRemove("--no-colors") || arg.HasOnlyAndRemove("-a"))
|
|---|
| 117 | gLog.SetNoColors();
|
|---|
| 118 |
|
|---|
| 119 | const Int_t kComprlvl = arg.HasOption("-c") ? arg.GetIntAndRemove("-c") : 1;
|
|---|
| 120 | Bool_t kUpdate = arg.HasOnlyAndRemove("--update") || arg.HasOnlyAndRemove("-u");
|
|---|
| 121 | const Bool_t kForce = arg.HasOnlyAndRemove("-f");
|
|---|
| 122 |
|
|---|
| 123 | gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
|
|---|
| 124 |
|
|---|
| 125 | gDebug = arg.HasOption("--debug=") ? arg.GetIntAndRemove("--debug=") : 0;
|
|---|
| 126 | if (gDebug==0 && arg.HasOnlyAndRemove("--debug"))
|
|---|
| 127 | gDebug=1;
|
|---|
| 128 |
|
|---|
| 129 | MTime kTimeStart;
|
|---|
| 130 | MTime kTimeStop;
|
|---|
| 131 | if (arg.HasOption("--star="))
|
|---|
| 132 | kTimeStart = AnalyseTime(arg.GetStringAndRemove("--start="));
|
|---|
| 133 | if (arg.HasOption("--stop="))
|
|---|
| 134 | kTimeStop = AnalyseTime(arg.GetStringAndRemove("--stop="));
|
|---|
| 135 |
|
|---|
| 136 | const Int_t kRunNumber = arg.HasOption("--run=") ? arg.GetIntAndRemove("--run=") : -1;
|
|---|
| 137 | const TString kSqlDataBase(arg.GetStringAndRemove("--sql="));
|
|---|
| 138 |
|
|---|
| 139 | if (kTimeStart)
|
|---|
| 140 | gLog << inf << "Start Time: " << kTimeStart << endl;
|
|---|
| 141 | if (kTimeStop)
|
|---|
| 142 | gLog << inf << "Stop Time: " << kTimeStop << endl;
|
|---|
| 143 |
|
|---|
| 144 | //
|
|---|
| 145 | // check for the right usage of the program
|
|---|
| 146 | //
|
|---|
| 147 | if (arg.GetNumArguments()<1 || arg.GetNumArguments()>2)
|
|---|
| 148 | {
|
|---|
| 149 | Usage();
|
|---|
| 150 | return -1;
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | //
|
|---|
| 154 | // This is to make argv[i] more readable insidethe code
|
|---|
| 155 | //
|
|---|
| 156 | TString kNamein = arg.GetArgumentStr(0);
|
|---|
| 157 | TString kNameout = arg.GetArgumentStr(1);
|
|---|
| 158 |
|
|---|
| 159 | const Bool_t isreport = kNamein.EndsWith(".rep");
|
|---|
| 160 | const Bool_t isdc = kNamein.EndsWith(".txt");
|
|---|
| 161 | const Bool_t israw = !isreport && !isdc;
|
|---|
| 162 |
|
|---|
| 163 | if (!kNamein.EndsWith(".raw") && israw)
|
|---|
| 164 | kNamein += ".raw";
|
|---|
| 165 |
|
|---|
| 166 | if (kNameout.IsNull())
|
|---|
| 167 | kNameout = kNamein(0, kNamein.Last('.'));
|
|---|
| 168 |
|
|---|
| 169 | if (!kNameout.EndsWith(".root"))
|
|---|
| 170 | kNameout += ".root";
|
|---|
| 171 |
|
|---|
| 172 | if (!kSqlDataBase.IsNull() && !israw)
|
|---|
| 173 | gLog << warn << "WARNING - Option '--sql=' only valid for raw-files... ignored." << endl;
|
|---|
| 174 |
|
|---|
| 175 | //
|
|---|
| 176 | // Initialize Non-GUI (batch) mode
|
|---|
| 177 | //
|
|---|
| 178 | gROOT->SetBatch();
|
|---|
| 179 |
|
|---|
| 180 | //
|
|---|
| 181 | // check whether the given files are OK.
|
|---|
| 182 | //
|
|---|
| 183 | if (gSystem->AccessPathName(kNamein, kFileExists))
|
|---|
| 184 | {
|
|---|
| 185 | gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
|
|---|
| 186 | return -1;
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | const Bool_t fileexist = !gSystem->AccessPathName(kNameout, kFileExists);
|
|---|
| 190 | const Bool_t writeperm = !gSystem->AccessPathName(kNameout, kWritePermission);
|
|---|
| 191 |
|
|---|
| 192 | if (fileexist && !writeperm)
|
|---|
| 193 | {
|
|---|
| 194 | gLog << err << "Sorry, you don't have write permission for '" << kNameout << "'." << endl;
|
|---|
| 195 | return -1;
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | if (fileexist && !kUpdate && !kForce)
|
|---|
| 199 | {
|
|---|
| 200 | gLog << err << "Sorry, file '" << kNameout << "' already existing." << endl;
|
|---|
| 201 | return -1;
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | if (!fileexist && kUpdate)
|
|---|
| 205 | {
|
|---|
| 206 | gLog << warn << "File '" << kNameout << "' doesn't yet exist." << endl;
|
|---|
| 207 | kUpdate=kFALSE;
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | MArray::Class()->IgnoreTObjectStreamer();
|
|---|
| 211 | MParContainer::Class()->IgnoreTObjectStreamer();
|
|---|
| 212 |
|
|---|
| 213 | //
|
|---|
| 214 | // create a (empty) list of parameters which can be used by the tasks
|
|---|
| 215 | // and an (empty) list of tasks which should be executed
|
|---|
| 216 | //
|
|---|
| 217 | MParList plist;
|
|---|
| 218 |
|
|---|
| 219 | MTaskList tasks;
|
|---|
| 220 | tasks.SetOwner();
|
|---|
| 221 | plist.AddToList(&tasks);
|
|---|
| 222 |
|
|---|
| 223 | //
|
|---|
| 224 | // ---- The following is only necessary to supress some output ----
|
|---|
| 225 | /*
|
|---|
| 226 | MRawRunHeader runheader;
|
|---|
| 227 | plist.AddToList(&runheader);
|
|---|
| 228 |
|
|---|
| 229 | MRawEvtHeader evtheader;
|
|---|
| 230 | plist.AddToList(&evtheader);
|
|---|
| 231 |
|
|---|
| 232 | MRawEvtData evtdata;
|
|---|
| 233 | plist.AddToList(&evtdata);
|
|---|
| 234 |
|
|---|
| 235 | MRawCrateArray cratearray;
|
|---|
| 236 | plist.AddToList(&cratearray);
|
|---|
| 237 |
|
|---|
| 238 | MTime evttime;
|
|---|
| 239 | plist.AddToList(&evttime);
|
|---|
| 240 | */
|
|---|
| 241 |
|
|---|
| 242 | //
|
|---|
| 243 | // create the tasks which should be executed and add them to the list
|
|---|
| 244 | // in the case you don't need parameter containers, all of them can
|
|---|
| 245 | // be created by MRawFileRead::PreProcess
|
|---|
| 246 | //
|
|---|
| 247 | MTask *read = 0;
|
|---|
| 248 | MFilter *filter = 0;
|
|---|
| 249 | MTask *write = 0;
|
|---|
| 250 |
|
|---|
| 251 | const TString option(kUpdate ? "UPDATE" : "RECREATE");
|
|---|
| 252 | if (isreport || isdc)
|
|---|
| 253 | {
|
|---|
| 254 | MWriteRootFile *w = new MWriteRootFile(kNameout, option, "Magic root-file", kComprlvl);
|
|---|
| 255 | if (isdc)
|
|---|
| 256 | {
|
|---|
| 257 | w->AddContainer("MTimeCurrents", "Currents");
|
|---|
| 258 | w->AddContainer("MCameraDC", "Currents");
|
|---|
| 259 | w->AddContainer("MReportCurrents", "Currents");
|
|---|
| 260 | }
|
|---|
| 261 | else
|
|---|
| 262 | {
|
|---|
| 263 | w->AddContainer("MReportCamera", "Camera");
|
|---|
| 264 | w->AddContainer("MTimeCamera", "Camera");
|
|---|
| 265 | w->AddContainer("MCameraAUX", "Camera");
|
|---|
| 266 | w->AddContainer("MCameraCalibration", "Camera");
|
|---|
| 267 | w->AddContainer("MCameraCooling", "Camera");
|
|---|
| 268 | w->AddContainer("MCameraHV", "Camera");
|
|---|
| 269 | w->AddContainer("MCameraLV", "Camera");
|
|---|
| 270 | w->AddContainer("MCameraLids", "Camera");
|
|---|
| 271 | w->AddContainer("MReportTrigger", "Trigger");
|
|---|
| 272 | w->AddContainer("MTimeTrigger", "Trigger");
|
|---|
| 273 | w->AddContainer("MReportDrive", "Drive");
|
|---|
| 274 | w->AddContainer("MTimeDrive", "Drive");
|
|---|
| 275 | w->AddContainer("MReportCC", "CC");
|
|---|
| 276 | w->AddContainer("MTimeCC", "CC");
|
|---|
| 277 | // w->AddContainer("MReportDAQ", "DAQ");
|
|---|
| 278 | // w->AddContainer("MTimeDAQ", "DAQ");
|
|---|
| 279 | }
|
|---|
| 280 | write = w;
|
|---|
| 281 |
|
|---|
| 282 | MReportFileRead *r = new MReportFileRead(kNamein);
|
|---|
| 283 | r->SetTimeStart(kTimeStart);
|
|---|
| 284 | r->SetTimeStop(kTimeStop);
|
|---|
| 285 | if (isdc)
|
|---|
| 286 | {
|
|---|
| 287 | r->SetHasNoHeader();
|
|---|
| 288 | r->AddToList("MReportCurrents");
|
|---|
| 289 | }
|
|---|
| 290 | else
|
|---|
| 291 | {
|
|---|
| 292 | r->AddToList("MReportCC");
|
|---|
| 293 | //r->AddToList("MReportDAQ");
|
|---|
| 294 | r->AddToList("MReportDrive");
|
|---|
| 295 | r->AddToList("MReportCamera");
|
|---|
| 296 | r->AddToList("MReportTrigger");
|
|---|
| 297 | if (kRunNumber>0)
|
|---|
| 298 | {
|
|---|
| 299 | r->AddToList("MReportRun");
|
|---|
| 300 | filter = new MFDataMember("MReportRun.fRunNumber", '=', kRunNumber);
|
|---|
| 301 | w->SetFilter(filter);
|
|---|
| 302 | }
|
|---|
| 303 | }
|
|---|
| 304 | read = r;
|
|---|
| 305 | }
|
|---|
| 306 | else
|
|---|
| 307 | {
|
|---|
| 308 | read = new MRawFileRead(kNamein);
|
|---|
| 309 | write = new MRawFileWrite(kNameout, option, "Magic root-file", kComprlvl);
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | tasks.AddToList(read);
|
|---|
| 313 | if (filter)
|
|---|
| 314 | tasks.AddToList(filter);
|
|---|
| 315 | if (israw && !kSqlDataBase.IsNull())
|
|---|
| 316 | {
|
|---|
| 317 | MSqlInsertRun *ins = new MSqlInsertRun(kSqlDataBase);
|
|---|
| 318 | ins->SetUpdate();
|
|---|
| 319 | tasks.AddToList(ins);
|
|---|
| 320 | }
|
|---|
| 321 | tasks.AddToList(write);
|
|---|
| 322 |
|
|---|
| 323 | //
|
|---|
| 324 | // create the looping object and tell it about the parameters to use
|
|---|
| 325 | // and the tasks to execute
|
|---|
| 326 | //
|
|---|
| 327 | MEvtLoop magic;
|
|---|
| 328 | magic.SetParList(&plist);
|
|---|
| 329 |
|
|---|
| 330 | //
|
|---|
| 331 | // Start the eventloop which reads the raw file (MRawFileRead) and
|
|---|
| 332 | // write all the information into a root file (MRawFileWrite)
|
|---|
| 333 | //
|
|---|
| 334 | // between reading and writing we can do, transformations, checks, etc.
|
|---|
| 335 | // (I'm think of a task like MRawDataCheck)
|
|---|
| 336 | //
|
|---|
| 337 | if (!magic.Eventloop())
|
|---|
| 338 | {
|
|---|
| 339 | gLog << err << "ERROR: Merging and preprocessing failed!" << endl;
|
|---|
| 340 | return -1;
|
|---|
| 341 | }
|
|---|
| 342 |
|
|---|
| 343 | tasks.PrintStatistics();
|
|---|
| 344 |
|
|---|
| 345 | gLog << all << "Merpp finished successfull!" << endl;
|
|---|
| 346 | return 0;
|
|---|
| 347 | }
|
|---|