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