1 | ////////////////////////////////////////////////////////////////////////
|
---|
2 | //
|
---|
3 | // MRawFile
|
---|
4 | //
|
---|
5 | // This tasks reads the raw binary file like specified in the TDAS???
|
---|
6 | // and writes the data in the corresponding containers which are
|
---|
7 | // either retrieved from the parameter list or created and added.
|
---|
8 | //
|
---|
9 | ////////////////////////////////////////////////////////////////////////
|
---|
10 |
|
---|
11 | #include "MRawFileRead.h"
|
---|
12 |
|
---|
13 | #include <iostream.h>
|
---|
14 | #include <fstream.h>
|
---|
15 |
|
---|
16 | #include "MTime.h"
|
---|
17 | #include "MParList.h"
|
---|
18 | #include "MRawRunHeader.h"
|
---|
19 | #include "MRawEvtHeader.h"
|
---|
20 | #include "MRawEvtData.h"
|
---|
21 | #include "MRawCrateData.h"
|
---|
22 | #include "MRawCrateArray.h"
|
---|
23 |
|
---|
24 | ClassImp(MRawFileRead)
|
---|
25 |
|
---|
26 | MRawFileRead::MRawFileRead(const char *fname, const char *name, const char *title)
|
---|
27 | {
|
---|
28 | *fName = name ? name : "MRawFileRead";
|
---|
29 | *fTitle = title ? title : "Read task to read DAQ binary files";
|
---|
30 |
|
---|
31 | //
|
---|
32 | // open the input stream
|
---|
33 | //
|
---|
34 | fIn = new ifstream(fname);
|
---|
35 |
|
---|
36 | /*
|
---|
37 | FIXME: How can I test whether the construction of
|
---|
38 | the instance was successfull?
|
---|
39 | if (!fIn->is_open())
|
---|
40 | cout << "Error: Trying to open file '" << fname << "'" << endl;
|
---|
41 | */
|
---|
42 | }
|
---|
43 |
|
---|
44 | Bool_t MRawFileRead::PreProcess (MParList *pList)
|
---|
45 | {
|
---|
46 | //
|
---|
47 | // remember the pointer to the parameter list fur further usage
|
---|
48 | //
|
---|
49 | pParList = pList;
|
---|
50 |
|
---|
51 | //
|
---|
52 | // check if all necessary containers exist in the Parameter list.
|
---|
53 | // if not create one and add them to the list
|
---|
54 | //
|
---|
55 | fRawRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
56 | if (!fRawRunHeader)
|
---|
57 | {
|
---|
58 | cout << "MRawFileRead::PreProcess - WARNING: MRawRunHeader not found... creating." << endl;
|
---|
59 | fRawRunHeader = new MRawRunHeader;
|
---|
60 | pList->AddToList(fRawRunHeader);
|
---|
61 | }
|
---|
62 |
|
---|
63 | fRawEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
|
---|
64 | if (!fRawEvtHeader)
|
---|
65 | {
|
---|
66 | cout << "MRawFileRead::PreProcess - WARNING: MRawEvtHeader not found... creating." << endl;
|
---|
67 | fRawEvtHeader = new MRawEvtHeader;
|
---|
68 | pList->AddToList(fRawEvtHeader);
|
---|
69 | }
|
---|
70 |
|
---|
71 | fRawEvtData = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
---|
72 | if (!fRawEvtData)
|
---|
73 | {
|
---|
74 | cout << "MRawFileRead::PreProcess - WARNING: MRawEvtData not found... creating." << endl;
|
---|
75 | fRawEvtData = new MRawEvtData;
|
---|
76 | pList->AddToList(fRawEvtData);
|
---|
77 | }
|
---|
78 |
|
---|
79 | fRawCrateArray = (MRawCrateArray*)pList->FindObject("MRawCrateArray");
|
---|
80 | if (!fRawCrateArray)
|
---|
81 | {
|
---|
82 | cout << "MRawFileRead::PreProcess - WARNING: MRawCrateArray not found... creating." << endl;
|
---|
83 | fRawCrateArray = new MRawCrateArray;
|
---|
84 | pList->AddToList(fRawCrateArray);
|
---|
85 | }
|
---|
86 |
|
---|
87 | fRawEvtTime = (MTime*)pList->FindObject("MRawEvtTime");
|
---|
88 | if (!fRawEvtTime)
|
---|
89 | {
|
---|
90 | cout << "MRawFileRead::PreProcess - WARNING: MRawEvtTime not found... creating." << endl;
|
---|
91 | fRawEvtTime = new MTime("MRawEvtTime");
|
---|
92 | pList->AddToList(fRawEvtTime);
|
---|
93 | }
|
---|
94 |
|
---|
95 | //
|
---|
96 | // Read RUN HEADER (see specification) from input stream
|
---|
97 | //
|
---|
98 | fRawRunHeader->ReadEvt(*fIn);
|
---|
99 | fRawRunHeader->Print();
|
---|
100 |
|
---|
101 | //
|
---|
102 | // Give the run header information to the 'sub-classes'
|
---|
103 | //
|
---|
104 | fRawEvtHeader->Init(fRawRunHeader, fRawEvtTime);
|
---|
105 | fRawEvtData ->Init(fRawRunHeader);
|
---|
106 |
|
---|
107 | return kTRUE;
|
---|
108 | }
|
---|
109 |
|
---|
110 | Bool_t MRawFileRead::Process()
|
---|
111 | {
|
---|
112 | //
|
---|
113 | // Read in the next EVENT HEADER (see specification),
|
---|
114 | // if there is no next event anymore stop eventloop
|
---|
115 | //
|
---|
116 | if (!fRawEvtHeader->ReadEvt(*fIn))
|
---|
117 | return kFALSE;
|
---|
118 | //fRawEvtHeader->Print();
|
---|
119 |
|
---|
120 | //
|
---|
121 | // Delete arrays which stores the pixel information (time slices)
|
---|
122 | //
|
---|
123 | fRawEvtData->DeletePixels();
|
---|
124 |
|
---|
125 | //
|
---|
126 | // clear the TClonesArray which stores the Crate Information
|
---|
127 | //
|
---|
128 | fRawCrateArray->Clear();
|
---|
129 |
|
---|
130 | //
|
---|
131 | // Get number of crates from the run header
|
---|
132 | //
|
---|
133 | const UShort_t nc = fRawRunHeader->GetNumCrates();
|
---|
134 |
|
---|
135 | //
|
---|
136 | // read the CRATE DATA (see specification) from file
|
---|
137 | //
|
---|
138 | for (int i=0; i<nc; i++)
|
---|
139 | {
|
---|
140 | fRawCrateArray->GetEntry(i)->ReadEvt(*fIn);
|
---|
141 | //fRawCrateArray->GetEntry(i)->Print();
|
---|
142 |
|
---|
143 | fRawEvtData->ReadEvt(*fIn);
|
---|
144 | }
|
---|
145 | //fRawEvtData->Print();
|
---|
146 |
|
---|
147 | return kTRUE;
|
---|
148 |
|
---|
149 | }
|
---|
150 |
|
---|