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

Last change on this file since 2728 was 2728, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 7.0 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
127// --------------------------------------------------------------------------
128//
129// This is a workaround for the oldest runs (run-number<3490)
130// for which no time stamp was available.
131// For this runs a fake time stamp is created
132//
133// Be carefull: This is NOT thread safe!
134//
135void MRawRead::CreateFakeTime() const
136{
137 static Double_t tm = 0; // Range of roughly 8min
138 const UInt_t ct = (*fRawCrateArray)[0]->GetFADCClockTick();
139
140 tm = ct<tm ? fmod(tm, (UInt_t)(-1))+(UInt_t)(-1)+ct : ct;
141
142 const Double_t mhz = 9.375; // [1e6 ticks/s]
143 const Double_t t = tm/mhz; // [us]
144 const UInt_t ns = (UInt_t)fmod(t*1e3, 1e6);
145 const UShort_t ms = (UShort_t)fmod(t/1e3, 1e3);
146 const Byte_t s = (Byte_t)fmod(t/1e6, 60);
147
148 // Create an artificial time stamp!
149 UInt_t m = (Byte_t)fmod(t/60e6, 60);
150 //const Byte_t h = (Byte_t)(t/3600e6);
151 m += fRawRunHeader->GetRunNumber()*10;
152 m %= 360; // 6h
153
154 fRawEvtTime->Set(fRawRunHeader->GetRunStart().Year(),
155 fRawRunHeader->GetRunStart().Month(),
156 fRawRunHeader->GetRunStart().Day(),
157 m/60, m%60, s, ms, ns);
158}
159
160// --------------------------------------------------------------------------
161//
162// Read a single event from the stream
163//
164Bool_t MRawRead::ReadEvent(istream &fin)
165{
166 //
167 // Read in the next EVENT HEADER (see specification),
168 // if there is no next event anymore stop eventloop
169 //
170 if (!fRawEvtHeader->ReadEvt(fin))
171 return kFALSE;
172
173 //
174 // Get number of crates from the run header
175 //
176 const UShort_t nc = fRawRunHeader->GetNumCrates();
177
178 //
179 // Delete arrays which stores the pixel information (time slices)
180 //
181 fRawEvtData->ResetPixels();
182
183 //
184 // clear the TClonesArray which stores the Crate Information
185 // and create a new array of the correct size
186 //
187 fRawCrateArray->SetSize(nc);
188
189 //
190 // Get file format version
191 //
192 const UShort_t ver = fRawRunHeader->GetFormatVersion();
193
194 //
195 // read the CRATE DATA (see specification) from file
196 //
197 for (int i=0; i<nc; i++)
198 {
199 fRawCrateArray->GetEntry(i)->ReadEvt(fin, ver);
200 if (!fin)
201 return kFALSE;
202
203 fRawEvtData->ReadEvt(fin);
204 if (!fin)
205 return kFALSE;
206 }
207
208 // This is a workaround for the oldest runs (run-number<3490)
209 // for which no time stamp was available.
210 // For this runs a fake time stamp is created
211 if (fRawRunHeader->GetRunNumber()<3490)
212 CreateFakeTime();
213
214 // FIXME: For all other runs we should enhance the precision
215 // of the time-stamp by using the FADCClockTick
216
217 return kTRUE;
218}
Note: See TracBrowser for help on using the repository browser.