| 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 "MLog.h"
|
|---|
| 11 | #include "MLogManip.h"
|
|---|
| 12 |
|
|---|
| 13 | #include "MArgs.h"
|
|---|
| 14 | #include "MTime.h"
|
|---|
| 15 | #include "MArray.h"
|
|---|
| 16 | #include "MRawEvtData.h"
|
|---|
| 17 | #include "MRawRunHeader.h"
|
|---|
| 18 | #include "MRawEvtHeader.h"
|
|---|
| 19 | #include "MRawCrateArray.h"
|
|---|
| 20 |
|
|---|
| 21 | using namespace std;
|
|---|
| 22 |
|
|---|
| 23 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 24 | // //
|
|---|
| 25 | // This is an easy implementation of the Merging process //
|
|---|
| 26 | // (as compilable prog) //
|
|---|
| 27 | // //
|
|---|
| 28 | // at the moment it reads a binary file ("rawtest.bin") which was written //
|
|---|
| 29 | // in the DAQ raw format. //
|
|---|
| 30 | // //
|
|---|
| 31 | // The data are stored in root container objects (classes derived from //
|
|---|
| 32 | // TObject like MRawRunHeader) //
|
|---|
| 33 | // //
|
|---|
| 34 | // This containers are written to a root file ("rawtest.root") //
|
|---|
| 35 | // //
|
|---|
| 36 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 37 |
|
|---|
| 38 | void Usage()
|
|---|
| 39 | {
|
|---|
| 40 | gLog << "Sorry the usage is:" << endl;
|
|---|
| 41 | gLog << " merpp [-vn] inputfile outputfile [compression level]" << endl << endl;
|
|---|
| 42 | gLog << " input file: Magic DAQ binary file." << endl;
|
|---|
| 43 | gLog << " ouput file: Merpped root file." << endl;
|
|---|
| 44 | gLog << " compr. level: 1..9 [default=1]" << endl;
|
|---|
| 45 | gLog << " -vn: Verbosity level n [default=2]" << endl << endl;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | int main(const int argc, const char **argv)
|
|---|
| 49 | {
|
|---|
| 50 | MArgs arg(argc, argv);
|
|---|
| 51 | arg.Print();
|
|---|
| 52 |
|
|---|
| 53 | gLog << "==================================================" << endl ;
|
|---|
| 54 | gLog << " MERPP v0.1" << endl;
|
|---|
| 55 | gLog << " MARS Merging and Preprocessing Program" << endl ;
|
|---|
| 56 | gLog << " Compiled on <" << __DATE__ << ">" << endl ;
|
|---|
| 57 | gLog << " Using ROOT v" << ROOTVER << endl ;
|
|---|
| 58 | gLog << "==================================================" << endl ;
|
|---|
| 59 | gLog << endl;
|
|---|
| 60 |
|
|---|
| 61 | //
|
|---|
| 62 | // check for the right usage of the program
|
|---|
| 63 | //
|
|---|
| 64 | if (arg.GetNumArguments()<2 || arg.GetNumArguments()>3)
|
|---|
| 65 | {
|
|---|
| 66 | Usage();
|
|---|
| 67 | return -1;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | //
|
|---|
| 71 | // Set verbosity to highest level.
|
|---|
| 72 | //
|
|---|
| 73 | gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetInt("-v") : 2);
|
|---|
| 74 |
|
|---|
| 75 | //
|
|---|
| 76 | // This is to make argv[i] more readable insidethe code
|
|---|
| 77 | //
|
|---|
| 78 | const char *kNamein = arg.GetArgumentStr(0);
|
|---|
| 79 | const char *kNameout = arg.GetArgumentStr(1);
|
|---|
| 80 | const int kComprlvl = arg.GetNumArguments()==3 ? arg.GetArgumentInt(2) : 1;
|
|---|
| 81 |
|
|---|
| 82 | //
|
|---|
| 83 | // initialize ROOT (this is obligatory here)
|
|---|
| 84 | //
|
|---|
| 85 | TROOT merpp("merpp", "Mars - Merging and Preprocessing Program");
|
|---|
| 86 | merpp.SetBatch();
|
|---|
| 87 |
|
|---|
| 88 | //
|
|---|
| 89 | // check whether the given files are OK.
|
|---|
| 90 | //
|
|---|
| 91 | if (gSystem->AccessPathName(kNamein, kFileExists))
|
|---|
| 92 | {
|
|---|
| 93 | gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
|
|---|
| 94 | return -1;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | if (!gSystem->AccessPathName(kNameout, kFileExists))
|
|---|
| 98 | gLog << warn << "Warning: A file '" << kNameout << "' exists." << endl;
|
|---|
| 99 | else
|
|---|
| 100 | if (!gSystem->AccessPathName(kNameout, kWritePermission))
|
|---|
| 101 | {
|
|---|
| 102 | gLog << err << "Sorry, you don't have write permission for '" << kNameout << "'." << endl;
|
|---|
| 103 | return -1;
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | MArray::Class()->IgnoreTObjectStreamer();
|
|---|
| 107 | MParContainer::Class()->IgnoreTObjectStreamer();
|
|---|
| 108 |
|
|---|
| 109 | //
|
|---|
| 110 | // create a (empty) list of parameters which can be used by the tasks
|
|---|
| 111 | // and an (empty) list of tasks which should be executed
|
|---|
| 112 | //
|
|---|
| 113 | MParList plist;
|
|---|
| 114 |
|
|---|
| 115 | MTaskList tasks;
|
|---|
| 116 | plist.AddToList(&tasks);
|
|---|
| 117 |
|
|---|
| 118 | //
|
|---|
| 119 | // ---- Tho following is only necessary to supress some output ----
|
|---|
| 120 | //
|
|---|
| 121 | MRawRunHeader runheader;
|
|---|
| 122 | plist.AddToList(&runheader);
|
|---|
| 123 |
|
|---|
| 124 | MRawEvtHeader evtheader;
|
|---|
| 125 | plist.AddToList(&evtheader);
|
|---|
| 126 |
|
|---|
| 127 | MRawEvtData evtdata;
|
|---|
| 128 | plist.AddToList(&evtdata);
|
|---|
| 129 |
|
|---|
| 130 | MRawCrateArray cratearray;
|
|---|
| 131 | plist.AddToList(&cratearray);
|
|---|
| 132 |
|
|---|
| 133 | MTime evttime("MRawEvtTime");
|
|---|
| 134 | plist.AddToList(&evttime);
|
|---|
| 135 |
|
|---|
| 136 | //
|
|---|
| 137 | // create the tasks which should be executed and add them to the list
|
|---|
| 138 | // in the case you don't need parameter containers, all of them can
|
|---|
| 139 | // be created by MRawFileRead::PreProcess
|
|---|
| 140 | //
|
|---|
| 141 | MRawFileRead reader(kNamein);
|
|---|
| 142 | MRawFileWrite writer(kNameout, "RECREATE", "Magic root-file", kComprlvl);
|
|---|
| 143 | tasks.AddToList(&reader);
|
|---|
| 144 | tasks.AddToList(&writer);
|
|---|
| 145 |
|
|---|
| 146 | //
|
|---|
| 147 | // create the looping object and tell it about the parameters to use
|
|---|
| 148 | // and the tasks to execute
|
|---|
| 149 | //
|
|---|
| 150 | MEvtLoop magic;
|
|---|
| 151 | magic.SetParList(&plist);
|
|---|
| 152 |
|
|---|
| 153 | //
|
|---|
| 154 | // Start the eventloop which reads the raw file (MRawFileRead) and
|
|---|
| 155 | // write all the information into a root file (MRawFileWrite)
|
|---|
| 156 | //
|
|---|
| 157 | // between reading and writing we can do, transformations, checks, etc.
|
|---|
| 158 | // (I'm think of a task like MRawDataCheck)
|
|---|
| 159 | //
|
|---|
| 160 | if (!magic.Eventloop())
|
|---|
| 161 | {
|
|---|
| 162 | gLog << err << "ERROR: Merging and preprocessing failed!" << endl;
|
|---|
| 163 | return -1;
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | gLog << all << "Merpp finished successfull!" << endl;
|
|---|
| 167 | return 0;
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|