source: trunk/MagicSoft/Mars/mraw/MRawFileRead.cc@ 687

Last change on this file since 687 was 666, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 3.6 KB
Line 
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
24ClassImp(MRawFileRead)
25
26
27// ----------- please don't delete ------------
28#define kBUFSZ 1024
29
30class bifstream : public istream, public streambuf
31{
32private:
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 }
48public:
49 bifstream(const char *name) : istream(this)
50 {
51 fd = fopen(name, "rb");
52 setbuf(fBuffer, kBUFSZ);
53 }
54};
55
56
57MRawFileRead::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 bifstream(fname);
66
67 if (!(*fIn))
68 *fLog << "Error: Trying to open file '" << fname << "'" << endl;
69}
70
71MRawFileRead::~MRawFileRead()
72{
73 delete fIn;
74}
75
76Bool_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 //
113 // Give the run header information to the 'sub-classes'
114 //
115 fRawEvtHeader->Init(fRawRunHeader, fRawEvtTime);
116 fRawEvtData ->Init(fRawRunHeader);
117
118 return kTRUE;
119}
120
121Bool_t MRawFileRead::Process()
122{
123 //
124 // Read in the next EVENT HEADER (see specification),
125 // if there is no next event anymore stop eventloop
126 //
127 if (!fRawEvtHeader->ReadEvt(*fIn))
128 return kFALSE;
129
130 //
131 // Delete arrays which stores the pixel information (time slices)
132 //
133 fRawEvtData->DeletePixels();
134
135 //
136 // clear the TClonesArray which stores the Crate Information
137 //
138 fRawCrateArray->Clear();
139
140 //
141 // Get number of crates from the run header
142 //
143 const UShort_t nc = fRawRunHeader->GetNumCrates();
144
145 //
146 // read the CRATE DATA (see specification) from file
147 //
148 for (int i=0; i<nc; i++)
149 {
150 fRawCrateArray->GetEntry(i)->ReadEvt(*fIn);
151
152 fRawEvtData->ReadEvt(*fIn);
153 }
154
155 return kTRUE;
156}
157
Note: See TracBrowser for help on using the repository browser.