source: trunk/MagicSoft/Mars/mraw/MRawRead.cc@ 2695

Last change on this file since 2695 was 2675, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.4 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 <mailto:tbretz@uni-sw.gwdg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MRawRead
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// Input Containers:
34// -/-
35//
36// Output Containers:
37// MRawRunHeader
38// MRawEvtHeader
39// MRawEvtData
40// MRawCrateArray
41// MRawEvtTime
42//
43//////////////////////////////////////////////////////////////////////////////
44#include "MRawRead.h"
45
46#include <fstream>
47
48#include "MLog.h"
49#include "MLogManip.h"
50
51#include "MTime.h"
52#include "MParList.h"
53#include "MRawRunHeader.h"
54#include "MRawEvtHeader.h"
55#include "MRawEvtData.h"
56#include "MRawCrateData.h"
57#include "MRawCrateArray.h"
58
59ClassImp(MRawRead);
60
61using namespace std;
62
63// --------------------------------------------------------------------------
64//
65// Default constructor. It tries to open the given file.
66//
67MRawRead::MRawRead(const char *name, const char *title)
68{
69 fName = name ? name : "MRawRead";
70 fTitle = title ? title : "Bas class for reading DAQ files";
71}
72
73// --------------------------------------------------------------------------
74//
75// The PreProcess of this task checks for the following containers in the
76// list:
77// MRawRunHeader <output> if not found it is created
78// MRawEvtHeader <output> if not found it is created
79// MRawEvtData <output> if not found it is created
80// MRawCrateArray <output> if not found it is created
81// MRawEvtTime <output> if not found it is created (MTime)
82//
83// If all containers are found or created the run header is read from the
84// binary file and printed. If the Magic-Number (file identification)
85// doesn't match we stop the eventloop.
86//
87// Now the EvtHeader and EvtData containers are initialized.
88//
89Int_t MRawRead::PreProcess(MParList *pList)
90{
91 if (!OpenStream())
92 return kFALSE;
93
94 //
95 // check if all necessary containers exist in the Parameter list.
96 // if not create one and add them to the list
97 //
98 fRawRunHeader = (MRawRunHeader*)pList->FindCreateObj("MRawRunHeader");
99 if (!fRawRunHeader)
100 return kFALSE;
101
102 fRawEvtHeader = (MRawEvtHeader*)pList->FindCreateObj("MRawEvtHeader");
103 if (!fRawEvtHeader)
104 return kFALSE;
105
106 fRawEvtData = (MRawEvtData*)pList->FindCreateObj("MRawEvtData");
107 if (!fRawEvtData)
108 return kFALSE;
109
110 fRawCrateArray = (MRawCrateArray*)pList->FindCreateObj("MRawCrateArray");
111 if (!fRawCrateArray)
112 return kFALSE;
113
114 fRawEvtTime = (MTime*)pList->FindCreateObj("MTime");
115 if (!fRawEvtTime)
116 return kFALSE;
117
118 //
119 // Give the run header information to the 'sub-classes'
120 //
121 fRawEvtHeader->Init(fRawRunHeader, fRawEvtTime);
122 fRawEvtData ->Init(fRawRunHeader, fRawCrateArray);
123
124 return kTRUE;
125}
126
127Bool_t MRawRead::ReadEvent(istream &fin)
128{
129 //
130 // Read in the next EVENT HEADER (see specification),
131 // if there is no next event anymore stop eventloop
132 //
133 if (!fRawEvtHeader->ReadEvt(fin))
134 return kFALSE;
135
136 //
137 // Get number of crates from the run header
138 //
139 const UShort_t nc = fRawRunHeader->GetNumCrates();
140
141 //
142 // Delete arrays which stores the pixel information (time slices)
143 //
144 fRawEvtData->ResetPixels();
145
146 //
147 // clear the TClonesArray which stores the Crate Information
148 // and create a new array of the correct size
149 //
150 fRawCrateArray->SetSize(nc);
151
152 //
153 // Get file format version
154 //
155 const UShort_t ver = fRawRunHeader->GetFormatVersion();
156
157 //
158 // read the CRATE DATA (see specification) from file
159 //
160 for (int i=0; i<nc; i++)
161 {
162 fRawCrateArray->GetEntry(i)->ReadEvt(fin, ver);
163 if (!fin)
164 return kFALSE;
165
166 fRawEvtData->ReadEvt(fin);
167 if (!fin)
168 return kFALSE;
169 }
170
171 {
172 // FIXME This is a stupid workaround for the missing time stamp!
173 // Might be used depending on the run number in the future
174 static Double_t tm = 0; // Range of roughly 8min
175 const UInt_t ct = (*fRawCrateArray)[0]->GetFADCClockTick();
176
177 tm = ct<tm ? fmod(tm, (UInt_t)(-1))+(UInt_t)(-1)+ct : ct;
178
179 const Double_t mhz = 9.375; // [1e6 ticks/s]
180 const Double_t t = tm/mhz; // [us]
181 const UInt_t ns = (UInt_t)fmod(t*1e3, 1e6);
182 const UShort_t ms = (UShort_t)fmod(t/1e3, 1e3);
183 const Byte_t s = (Byte_t)fmod(t/1e6, 60);
184
185 // Create an artificial time stamp!
186 UInt_t m = (Byte_t)fmod(t/60e6, 60);
187 //const Byte_t h = (Byte_t)(t/3600e6);
188 m += fRawRunHeader->GetRunNumber()*10;
189 m %= 360; // 6h
190
191 fRawEvtTime->Set(fRawRunHeader->GetRunStart().Year(),
192 fRawRunHeader->GetRunStart().Month(),
193 fRawRunHeader->GetRunStart().Day(),
194 m/60, m%60, s, ms, ns);
195 }
196 return kTRUE;
197}
Note: See TracBrowser for help on using the repository browser.