| 1 | #include <TSystem.h> | 
|---|
| 2 |  | 
|---|
| 3 | #include "MParList.h" | 
|---|
| 4 | #include "MTaskList.h" | 
|---|
| 5 | #include "MEvtLoop.h" | 
|---|
| 6 |  | 
|---|
| 7 | #include "MRawFileRead.h" | 
|---|
| 8 | #include "MRawFileWrite.h" | 
|---|
| 9 |  | 
|---|
| 10 | #include "MReportFileRead.h" | 
|---|
| 11 | #include "MWriteRootFile.h" | 
|---|
| 12 |  | 
|---|
| 13 | #include "MLog.h" | 
|---|
| 14 | #include "MLogManip.h" | 
|---|
| 15 |  | 
|---|
| 16 | #include "MArgs.h" | 
|---|
| 17 | #include "MTime.h" | 
|---|
| 18 | #include "MArray.h" | 
|---|
| 19 | #include "MRawEvtData.h" | 
|---|
| 20 | #include "MRawRunHeader.h" | 
|---|
| 21 | #include "MRawEvtHeader.h" | 
|---|
| 22 | #include "MRawCrateArray.h" | 
|---|
| 23 |  | 
|---|
| 24 | using namespace std; | 
|---|
| 25 |  | 
|---|
| 26 | ////////////////////////////////////////////////////////////////////////////// | 
|---|
| 27 | //                                                                          // | 
|---|
| 28 | // This is an easy implementation of the Merging process                    // | 
|---|
| 29 | // (as compilable prog)                                                     // | 
|---|
| 30 | //                                                                          // | 
|---|
| 31 | // at the moment it reads a binary file ("rawtest.bin") which was written   // | 
|---|
| 32 | // in the DAQ raw format.                                                   // | 
|---|
| 33 | //                                                                          // | 
|---|
| 34 | // The data are stored in root container objects (classes derived from      // | 
|---|
| 35 | // TObject like MRawRunHeader)                                              // | 
|---|
| 36 | //                                                                          // | 
|---|
| 37 | // This containers are written to a root file ("rawtest.root")              // | 
|---|
| 38 | //                                                                          // | 
|---|
| 39 | ////////////////////////////////////////////////////////////////////////////// | 
|---|
| 40 |  | 
|---|
| 41 | static void StartUpMessage() | 
|---|
| 42 | { | 
|---|
| 43 | gLog << all << endl; | 
|---|
| 44 |  | 
|---|
| 45 | //                1         2         3         4         5 | 
|---|
| 46 | //       12345678901234567890123456789012345678901234567890 | 
|---|
| 47 | gLog << "==================================================" << endl; | 
|---|
| 48 | gLog << "                MERPP - MARS V" << MARSVER          << endl; | 
|---|
| 49 | gLog << "     MARS - Merging and Preprocessing Program"      << endl; | 
|---|
| 50 | gLog << "            Compiled on <" << __DATE__ << ">"       << endl; | 
|---|
| 51 | gLog << "               Using ROOT v" << ROOTVER             << endl; | 
|---|
| 52 | gLog << "==================================================" << endl; | 
|---|
| 53 | gLog << endl; | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 | static void Usage() | 
|---|
| 57 | { | 
|---|
| 58 | gLog << all << endl; | 
|---|
| 59 | gLog << "Sorry the usage is:" << endl; | 
|---|
| 60 | gLog << "   merpp [-h] [-?] [-a0] [-vn] [-cn] [-u1]" << endl; | 
|---|
| 61 | gLog << "         inputfile[.rep,[.raw]] [outputfile[.root]]" << endl << endl; | 
|---|
| 62 | gLog << "     inputfile.raw:  Magic DAQ binary file." << endl; | 
|---|
| 63 | gLog << "     inputfile.rep:  Magic Central Control report file." << endl; | 
|---|
| 64 | gLog << "     ouputfile.root: Merpped root file." << endl; | 
|---|
| 65 | gLog << "     -a0: Do not use Ansii codes." << endl; | 
|---|
| 66 | gLog << "     -u1: Update file." << endl; | 
|---|
| 67 | gLog << "     -cn: Compression level n=1..9 [default=2]" << endl; | 
|---|
| 68 | gLog << "     -vn: Verbosity level n [default=2]" << endl; | 
|---|
| 69 | gLog << "     -?/-h: This help" << endl << endl; | 
|---|
| 70 | gLog << "   REMARK: At the moment you can process a .raw _or_ a .rep file, only!" << endl << endl; | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | int main(const int argc, char **argv) | 
|---|
| 74 | { | 
|---|
| 75 | StartUpMessage(); | 
|---|
| 76 |  | 
|---|
| 77 | // | 
|---|
| 78 | // Evaluate arguments | 
|---|
| 79 | // | 
|---|
| 80 | MArgs arg(argc, argv); | 
|---|
| 81 |  | 
|---|
| 82 | if (arg.HasOption("-?") || arg.HasOption("-h")) | 
|---|
| 83 | { | 
|---|
| 84 | Usage(); | 
|---|
| 85 | return -1; | 
|---|
| 86 | } | 
|---|
| 87 |  | 
|---|
| 88 | if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0) | 
|---|
| 89 | gLog.SetNoColors(); | 
|---|
| 90 |  | 
|---|
| 91 | const Int_t kComprlvl = arg.HasOption("-c") ? arg.GetIntAndRemove("-c") : 1; | 
|---|
| 92 | Bool_t kUpdate = arg.HasOption("-u") && arg.GetIntAndRemove("-u")==1; | 
|---|
| 93 |  | 
|---|
| 94 | gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2); | 
|---|
| 95 |  | 
|---|
| 96 | // | 
|---|
| 97 | // check for the right usage of the program | 
|---|
| 98 | // | 
|---|
| 99 | if (arg.GetNumArguments()<1 || arg.GetNumArguments()>2) | 
|---|
| 100 | { | 
|---|
| 101 | Usage(); | 
|---|
| 102 | return -1; | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | // | 
|---|
| 106 | // This is to make argv[i] more readable insidethe code | 
|---|
| 107 | // | 
|---|
| 108 | TString kNamein  = arg.GetArgumentStr(0); | 
|---|
| 109 | TString kNameout = arg.GetArgumentStr(1); | 
|---|
| 110 |  | 
|---|
| 111 | const Bool_t isreport = kNamein.EndsWith(".rep"); | 
|---|
| 112 |  | 
|---|
| 113 | if (!kNamein.EndsWith(".raw") && !isreport) | 
|---|
| 114 | kNamein += ".raw"; | 
|---|
| 115 |  | 
|---|
| 116 | if (kNameout.IsNull()) | 
|---|
| 117 | kNameout = kNamein(0, kNamein.Last('.')); | 
|---|
| 118 |  | 
|---|
| 119 | if (!kNameout.EndsWith(".root")) | 
|---|
| 120 | kNameout += ".root"; | 
|---|
| 121 |  | 
|---|
| 122 | // | 
|---|
| 123 | // Initialize Non-GUI (batch) mode | 
|---|
| 124 | // | 
|---|
| 125 | gROOT->SetBatch(); | 
|---|
| 126 |  | 
|---|
| 127 | // | 
|---|
| 128 | // check whether the given files are OK. | 
|---|
| 129 | // | 
|---|
| 130 | if (gSystem->AccessPathName(kNamein, kFileExists)) | 
|---|
| 131 | { | 
|---|
| 132 | gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl; | 
|---|
| 133 | return -1; | 
|---|
| 134 | } | 
|---|
| 135 |  | 
|---|
| 136 | const Bool_t fileexist = !gSystem->AccessPathName(kNameout, kFileExists); | 
|---|
| 137 | const Bool_t writeperm = !gSystem->AccessPathName(kNameout, kWritePermission); | 
|---|
| 138 |  | 
|---|
| 139 | if (fileexist && !writeperm) | 
|---|
| 140 | { | 
|---|
| 141 | gLog << err << "Sorry, you don't have write permission for '" << kNameout << "'." << endl; | 
|---|
| 142 | return -1; | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 | if (fileexist && !kUpdate) | 
|---|
| 146 | { | 
|---|
| 147 | gLog << err << "Sorry, file '" << kNameout << "' already existing." << endl; | 
|---|
| 148 | return -1; | 
|---|
| 149 | } | 
|---|
| 150 |  | 
|---|
| 151 | if (!fileexist && kUpdate) | 
|---|
| 152 | { | 
|---|
| 153 | gLog << warn << "File '" << kNameout << "' doesn't yet exist." << endl; | 
|---|
| 154 | kUpdate=kFALSE; | 
|---|
| 155 | } | 
|---|
| 156 |  | 
|---|
| 157 | MArray::Class()->IgnoreTObjectStreamer(); | 
|---|
| 158 | MParContainer::Class()->IgnoreTObjectStreamer(); | 
|---|
| 159 |  | 
|---|
| 160 | // | 
|---|
| 161 | // create a (empty) list of parameters which can be used by the tasks | 
|---|
| 162 | // and an (empty) list of tasks which should be executed | 
|---|
| 163 | // | 
|---|
| 164 | MParList plist; | 
|---|
| 165 |  | 
|---|
| 166 | MTaskList tasks; | 
|---|
| 167 | tasks.SetOwner(); | 
|---|
| 168 | plist.AddToList(&tasks); | 
|---|
| 169 |  | 
|---|
| 170 | // | 
|---|
| 171 | // ---- The following is only necessary to supress some output ---- | 
|---|
| 172 | // | 
|---|
| 173 | MRawRunHeader runheader; | 
|---|
| 174 | plist.AddToList(&runheader); | 
|---|
| 175 |  | 
|---|
| 176 | MRawEvtHeader evtheader; | 
|---|
| 177 | plist.AddToList(&evtheader); | 
|---|
| 178 |  | 
|---|
| 179 | MRawEvtData evtdata; | 
|---|
| 180 | plist.AddToList(&evtdata); | 
|---|
| 181 |  | 
|---|
| 182 | MRawCrateArray cratearray; | 
|---|
| 183 | plist.AddToList(&cratearray); | 
|---|
| 184 |  | 
|---|
| 185 | MTime evttime; | 
|---|
| 186 | plist.AddToList(&evttime); | 
|---|
| 187 |  | 
|---|
| 188 | // | 
|---|
| 189 | // create the tasks which should be executed and add them to the list | 
|---|
| 190 | // in the case you don't need parameter containers, all of them can | 
|---|
| 191 | // be created by MRawFileRead::PreProcess | 
|---|
| 192 | // | 
|---|
| 193 | MTask *read  = 0; | 
|---|
| 194 | MTask *write = 0; | 
|---|
| 195 |  | 
|---|
| 196 | const TString option(kUpdate ? "UPDATE" : "RECREATE"); | 
|---|
| 197 | if (isreport) | 
|---|
| 198 | { | 
|---|
| 199 | MReportFileRead *r = new MReportFileRead(kNamein); | 
|---|
| 200 | r->AddToList("MReportDAQ"); | 
|---|
| 201 | r->AddToList("MReportDrive"); | 
|---|
| 202 | r->AddToList("MReportCamera"); | 
|---|
| 203 | r->AddToList("MReportTrigger"); | 
|---|
| 204 | read = r; | 
|---|
| 205 |  | 
|---|
| 206 | MWriteRootFile *w = new MWriteRootFile(kNameout, option, "Magic root-file", kComprlvl); | 
|---|
| 207 | /* | 
|---|
| 208 | w->AddContainer("MReportDAQ",         "DAQ"); | 
|---|
| 209 | w->AddContainer("MTimeDAQ",           "DAQ"); | 
|---|
| 210 | w->AddContainer("MReportDrive",       "Drive"); | 
|---|
| 211 | w->AddContainer("MTimeDrive",         "Drive"); | 
|---|
| 212 | */ | 
|---|
| 213 | w->AddContainer("MReportCamera",      "Camera"); | 
|---|
| 214 | w->AddContainer("MTimeCamera",        "Camera"); | 
|---|
| 215 | w->AddContainer("MCameraAUX",         "Camera"); | 
|---|
| 216 | w->AddContainer("MCameraCalibration", "Camera"); | 
|---|
| 217 | w->AddContainer("MCameraCooling",     "Camera"); | 
|---|
| 218 | w->AddContainer("MCameraHV",          "Camera"); | 
|---|
| 219 | w->AddContainer("MCameraLV",          "Camera"); | 
|---|
| 220 | w->AddContainer("MCameraLids",        "Camera"); | 
|---|
| 221 | w->AddContainer("MReportTrigger",     "Trigger"); | 
|---|
| 222 | w->AddContainer("MTimeTrigger",       "Trigger"); | 
|---|
| 223 | w->AddContainer("MReportDrive",       "Drive"); | 
|---|
| 224 | w->AddContainer("MTimeDrive",         "Drive"); | 
|---|
| 225 | write = w; | 
|---|
| 226 | } | 
|---|
| 227 | else | 
|---|
| 228 | { | 
|---|
| 229 | read  = new MRawFileRead(kNamein); | 
|---|
| 230 | write = new MRawFileWrite(kNameout, option, "Magic root-file", kComprlvl); | 
|---|
| 231 | } | 
|---|
| 232 | tasks.AddToList(read); | 
|---|
| 233 | tasks.AddToList(write); | 
|---|
| 234 |  | 
|---|
| 235 | // | 
|---|
| 236 | // create the looping object and tell it about the parameters to use | 
|---|
| 237 | // and the tasks to execute | 
|---|
| 238 | // | 
|---|
| 239 | MEvtLoop magic; | 
|---|
| 240 | magic.SetParList(&plist); | 
|---|
| 241 |  | 
|---|
| 242 | // | 
|---|
| 243 | // Start the eventloop which reads the raw file (MRawFileRead) and | 
|---|
| 244 | // write all the information into a root file (MRawFileWrite) | 
|---|
| 245 | // | 
|---|
| 246 | // between reading and writing we can do, transformations, checks, etc. | 
|---|
| 247 | // (I'm think of a task like MRawDataCheck) | 
|---|
| 248 | // | 
|---|
| 249 | if (!magic.Eventloop()) | 
|---|
| 250 | { | 
|---|
| 251 | gLog << err << "ERROR: Merging and preprocessing failed!" << endl; | 
|---|
| 252 | return -1; | 
|---|
| 253 | } | 
|---|
| 254 |  | 
|---|
| 255 | gLog << all << "Merpp finished successfull!" << endl; | 
|---|
| 256 | return 0; | 
|---|
| 257 | } | 
|---|
| 258 |  | 
|---|
| 259 |  | 
|---|