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

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