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 <fstream.h>
|
---|
14 |
|
---|
15 | #include "MLog.h"
|
---|
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 |
|
---|
27 | /*/ ----------- please don't delete ------------
|
---|
28 | #define kBUFSZ 1024
|
---|
29 |
|
---|
30 | class bifstream : public istream, public streambuf
|
---|
31 | {
|
---|
32 | private:
|
---|
33 | char fBuffer[kBUFSZ]; //!
|
---|
34 | FILE *fd;
|
---|
35 |
|
---|
36 | int sync()
|
---|
37 | {
|
---|
38 | memset(fBuffer, 0, kBUFSZ);
|
---|
39 | return 0;
|
---|
40 | }
|
---|
41 | int underflow()
|
---|
42 | {
|
---|
43 | int sz=fread(fBuffer, kBUFSZ, 1, fd);
|
---|
44 | setg(fBuffer, fBuffer, fBuffer+kBUFSZ);
|
---|
45 |
|
---|
46 | return sz==kBUFSZ ? *(unsigned char*)fBuffer : EOF;//EOF;
|
---|
47 | }
|
---|
48 | public:
|
---|
49 | bifstream(const char *name) : istream(this)
|
---|
50 | {
|
---|
51 | fd = fopen(name, "rb");
|
---|
52 | setbuf(fBuffer, kBUFSZ);
|
---|
53 | }
|
---|
54 | };
|
---|
55 | */
|
---|
56 |
|
---|
57 | MRawFileRead::MRawFileRead(const char *fname, const char *name, const char *title)
|
---|
58 | {
|
---|
59 | *fName = name ? name : "MRawFileRead";
|
---|
60 | *fTitle = title ? title : "Read task to read DAQ binary files";
|
---|
61 |
|
---|
62 | //
|
---|
63 | // open the input stream
|
---|
64 | //
|
---|
65 | fIn = new ifstream(fname);
|
---|
66 |
|
---|
67 | if (!(*fIn))
|
---|
68 | *fLog << "Error: Trying to open file '" << fname << "'" << endl;
|
---|
69 | }
|
---|
70 |
|
---|
71 | MRawFileRead::~MRawFileRead()
|
---|
72 | {
|
---|
73 | delete fIn;
|
---|
74 | }
|
---|
75 |
|
---|
76 | Bool_t MRawFileRead::PreProcess(MParList *pList)
|
---|
77 | {
|
---|
78 | //
|
---|
79 | // remember the pointer to the parameter list fur further usage
|
---|
80 | //
|
---|
81 |
|
---|
82 | //
|
---|
83 | // check if all necessary containers exist in the Parameter list.
|
---|
84 | // if not create one and add them to the list
|
---|
85 | //
|
---|
86 | fRawRunHeader = (MRawRunHeader*)pList->FindCreateObj("MRawRunHeader");
|
---|
87 | if (!fRawRunHeader)
|
---|
88 | return kFALSE;
|
---|
89 |
|
---|
90 | fRawEvtHeader = (MRawEvtHeader*)pList->FindCreateObj("MRawEvtHeader");
|
---|
91 | if (!fRawEvtHeader)
|
---|
92 | return kFALSE;
|
---|
93 |
|
---|
94 | fRawEvtData = (MRawEvtData*)pList->FindCreateObj("MRawEvtData");
|
---|
95 | if (!fRawEvtData)
|
---|
96 | return kFALSE;
|
---|
97 |
|
---|
98 | fRawCrateArray = (MRawCrateArray*)pList->FindCreateObj("MRawCrateArray");
|
---|
99 | if (!fRawCrateArray)
|
---|
100 | return kFALSE;
|
---|
101 |
|
---|
102 | fRawEvtTime = (MTime*)pList->FindCreateObj("MRawEvtTime");
|
---|
103 | if (!fRawEvtTime)
|
---|
104 | return kTRUE;
|
---|
105 |
|
---|
106 | //
|
---|
107 | // Read RUN HEADER (see specification) from input stream
|
---|
108 | //
|
---|
109 | fRawRunHeader->ReadEvt(*fIn);
|
---|
110 | fRawRunHeader->Print();
|
---|
111 |
|
---|
112 | if (fRawRunHeader->GetMagicNumber()!=kMagicNumber)
|
---|
113 | return kFALSE;
|
---|
114 |
|
---|
115 | //
|
---|
116 | // Give the run header information to the 'sub-classes'
|
---|
117 | //
|
---|
118 | fRawEvtHeader->Init(fRawRunHeader, fRawEvtTime);
|
---|
119 | fRawEvtData ->Init(fRawRunHeader);
|
---|
120 |
|
---|
121 | return kTRUE;
|
---|
122 | }
|
---|
123 |
|
---|
124 | Bool_t MRawFileRead::Process()
|
---|
125 | {
|
---|
126 | //
|
---|
127 | // Read in the next EVENT HEADER (see specification),
|
---|
128 | // if there is no next event anymore stop eventloop
|
---|
129 | //
|
---|
130 | if (!fRawEvtHeader->ReadEvt(*fIn))
|
---|
131 | return kFALSE;
|
---|
132 |
|
---|
133 | //
|
---|
134 | // Delete arrays which stores the pixel information (time slices)
|
---|
135 | //
|
---|
136 | fRawEvtData->DeletePixels();
|
---|
137 |
|
---|
138 | //
|
---|
139 | // clear the TClonesArray which stores the Crate Information
|
---|
140 | //
|
---|
141 | fRawCrateArray->Clear();
|
---|
142 |
|
---|
143 | //
|
---|
144 | // Get number of crates from the run header
|
---|
145 | //
|
---|
146 | const UShort_t nc = fRawRunHeader->GetNumCrates();
|
---|
147 |
|
---|
148 | //
|
---|
149 | // read the CRATE DATA (see specification) from file
|
---|
150 | //
|
---|
151 | for (int i=0; i<nc; i++)
|
---|
152 | {
|
---|
153 | fRawCrateArray->GetEntry(i)->ReadEvt(*fIn);
|
---|
154 |
|
---|
155 | fRawEvtData->ReadEvt(*fIn);
|
---|
156 | }
|
---|
157 |
|
---|
158 | return kTRUE;
|
---|
159 | }
|
---|
160 |
|
---|