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

Last change on this file since 761 was 749, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 4.5 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz 12/2000 (tbretz@uni-sw.gwdg.de)
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25////////////////////////////////////////////////////////////////////////
26//
27// MRawFile
28//
29// This tasks reads the raw binary file like specified in the TDAS???
30// and writes the data in the corresponding containers which are
31// either retrieved from the parameter list or created and added.
32//
33////////////////////////////////////////////////////////////////////////
34
35#include "MRawFileRead.h"
36
37#include <fstream.h>
38
39#include "MLog.h"
40#include "MTime.h"
41#include "MParList.h"
42#include "MRawRunHeader.h"
43#include "MRawEvtHeader.h"
44#include "MRawEvtData.h"
45#include "MRawCrateData.h"
46#include "MRawCrateArray.h"
47
48ClassImp(MRawFileRead)
49
50
51/*/ ----------- please don't delete ------------
52#define kBUFSZ 1024
53
54class bifstream : public istream, public streambuf
55{
56private:
57 char fBuffer[kBUFSZ]; //!
58 FILE *fd;
59
60 int sync()
61 {
62 memset(fBuffer, 0, kBUFSZ);
63 return 0;
64 }
65 int underflow()
66 {
67 int sz=fread(fBuffer, kBUFSZ, 1, fd);
68 setg(fBuffer, fBuffer, fBuffer+kBUFSZ);
69
70 return sz==kBUFSZ ? *(unsigned char*)fBuffer : EOF;//EOF;
71 }
72public:
73 bifstream(const char *name) : istream(this)
74 {
75 fd = fopen(name, "rb");
76 setbuf(fBuffer, kBUFSZ);
77 }
78};
79*/
80
81MRawFileRead::MRawFileRead(const char *fname, const char *name, const char *title)
82{
83 *fName = name ? name : "MRawFileRead";
84 *fTitle = title ? title : "Read task to read DAQ binary files";
85
86 //
87 // open the input stream
88 //
89 fIn = new ifstream(fname);
90
91 if (!(*fIn))
92 *fLog << "Error: Trying to open file '" << fname << "'" << endl;
93}
94
95MRawFileRead::~MRawFileRead()
96{
97 delete fIn;
98}
99
100Bool_t MRawFileRead::PreProcess(MParList *pList)
101{
102 //
103 // remember the pointer to the parameter list fur further usage
104 //
105
106 //
107 // check if all necessary containers exist in the Parameter list.
108 // if not create one and add them to the list
109 //
110 fRawRunHeader = (MRawRunHeader*)pList->FindCreateObj("MRawRunHeader");
111 if (!fRawRunHeader)
112 return kFALSE;
113
114 fRawEvtHeader = (MRawEvtHeader*)pList->FindCreateObj("MRawEvtHeader");
115 if (!fRawEvtHeader)
116 return kFALSE;
117
118 fRawEvtData = (MRawEvtData*)pList->FindCreateObj("MRawEvtData");
119 if (!fRawEvtData)
120 return kFALSE;
121
122 fRawCrateArray = (MRawCrateArray*)pList->FindCreateObj("MRawCrateArray");
123 if (!fRawCrateArray)
124 return kFALSE;
125
126 fRawEvtTime = (MTime*)pList->FindCreateObj("MRawEvtTime");
127 if (!fRawEvtTime)
128 return kTRUE;
129
130 //
131 // Read RUN HEADER (see specification) from input stream
132 //
133 fRawRunHeader->ReadEvt(*fIn);
134 fRawRunHeader->Print();
135
136 if (fRawRunHeader->GetMagicNumber()!=kMagicNumber)
137 return kFALSE;
138
139 //
140 // Give the run header information to the 'sub-classes'
141 //
142 fRawEvtHeader->Init(fRawRunHeader, fRawEvtTime);
143 fRawEvtData ->Init(fRawRunHeader);
144
145 return kTRUE;
146}
147
148Bool_t MRawFileRead::Process()
149{
150 //
151 // Read in the next EVENT HEADER (see specification),
152 // if there is no next event anymore stop eventloop
153 //
154 if (!fRawEvtHeader->ReadEvt(*fIn))
155 return kFALSE;
156
157 //
158 // Delete arrays which stores the pixel information (time slices)
159 //
160 fRawEvtData->DeletePixels();
161
162 //
163 // clear the TClonesArray which stores the Crate Information
164 //
165 fRawCrateArray->Clear();
166
167 //
168 // Get number of crates from the run header
169 //
170 const UShort_t nc = fRawRunHeader->GetNumCrates();
171
172 //
173 // read the CRATE DATA (see specification) from file
174 //
175 for (int i=0; i<nc; i++)
176 {
177 fRawCrateArray->GetEntry(i)->ReadEvt(*fIn);
178
179 fRawEvtData->ReadEvt(*fIn);
180 }
181
182 return kTRUE;
183}
184
Note: See TracBrowser for help on using the repository browser.