source: trunk/Mars/mraw/MRawFitsRead.cc@ 11489

Last change on this file since 11489 was 11459, checked in by tbretz, 13 years ago
File size: 3.7 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 07/2011 <mailto:thomas.bretz@epfl.ch>
19!
20! Copyright: MAGIC Software Development, 2000-2011
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MRawFitsRead
28//
29// This tasks reads the fits data file in the form used by FACT.
30//
31// Input Containers:
32// -/-
33//
34// Output Containers:
35// MRawRunHeader, MRawEvtHeader, MRawEvtData, MRawEvtTime
36//
37//////////////////////////////////////////////////////////////////////////////
38#include "MRawFitsRead.h"
39
40#include <TClass.h>
41
42#include "MLog.h"
43#include "MLogManip.h"
44
45#include "MFits.h"
46#include "MTime.h"
47
48#include "MArrayB.h"
49
50#include "MRawRunHeader.h"
51#include "MRawEvtHeader.h"
52#include "MRawEvtData.h"
53
54ClassImp(MRawFitsRead);
55
56using namespace std;
57
58// --------------------------------------------------------------------------
59//
60// Default constructor. It tries to open the given file.
61//
62MRawFitsRead::MRawFitsRead(const char *fname, const char *name, const char *title)
63 : MRawFileRead(fname, name, title)
64{
65}
66
67Bool_t MRawFitsRead::IsFits(const char *name)
68{
69 MZlib fin(name);
70 if (!fin)
71 return 0;
72
73 Byte_t c[6];
74 fin.read((char*)c, 6);
75 if (!fin)
76 return 0;
77
78 return memcmp(c, "SIMPLE", 6)==0;
79}
80
81istream *MRawFitsRead::OpenFile(const char *filename)
82{
83 return new MFits(filename);
84}
85
86Bool_t MRawFitsRead::ReadRunHeader(istream &stream)
87{
88 MFits &fin = static_cast<MFits&>(stream);
89
90 fRawRunHeader->SetValidMagicNumber();
91 fRawRunHeader->SetNumEvents(fin.GetUInt("NAXIS2"));
92 fRawRunHeader->InitPixels(fin.GetUInt("NPIX"));
93 fRawRunHeader->SetObservation("", "FACT");
94 fRawRunHeader->SetRunInfo(0, fin.GetUInt("NIGHT"), fin.GetUInt("RUNID"));
95 fRawRunHeader->InitFact(fin.GetUInt("NPIX")/9, 9, fin.GetUInt("NROI"));
96 fRawRunHeader->SetFormat(0xf172, fin.GetUInt("BLDVER"));
97 fRawRunHeader->SetRunType(0/*data*/);
98
99 return kTRUE;
100}
101
102Bool_t::MRawFitsRead::InitReadData(istream &stream)
103{
104 MFits &fin = static_cast<MFits&>(stream);
105
106 MArrayB **data = reinterpret_cast<MArrayB**>(fRawEvtData1->DataMember("fHiGainFadcSamples"));
107 UInt_t *evtnum = reinterpret_cast<UInt_t*> (fRawEvtHeader->DataMember("fDAQEvtNumber"));
108
109 if (!data || !evtnum)
110 return kFALSE;
111
112 fRawEvtData1->ResetPixels();
113 fRawEvtData2->ResetPixels(0, 0);
114
115 if (!fin.SetRefAddress("EventNum", *evtnum))
116 return kFALSE;
117
118 if (!fin.SetRefAddress("PCTime", fPCTime))
119 return kFALSE;
120
121 if (!fin.SetPtrAddress("Data", (uint16_t*)(*data)->GetArray(), (*data)->GetSize()/2))
122 return kFALSE;
123
124 fRawEvtData1->SetIndices();
125
126 return kTRUE;
127}
128
129Bool_t MRawFitsRead::ReadEvent(istream &stream)
130{
131 if (!static_cast<MFits&>(stream).GetNextRow())
132 return kFALSE;
133
134 fRawEvtTime->SetUnixTime(fPCTime, 0);
135
136 fRawEvtData1->SetReadyToSave();
137 fRawEvtData2->SetReadyToSave();
138
139 return kTRUE;
140}
141
142void MRawFitsRead::SkipEvent(istream &fin)
143{
144 static_cast<MFits&>(fin).SkipNextRow();
145}
Note: See TracBrowser for help on using the repository browser.