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

Last change on this file since 11556 was 11556, checked in by tbretz, 13 years ago
Replaced MZlib by izstream; added check for TELESCOP key.
File size: 4.2 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 "fits.h"
46#include "MTime.h"
47
48#include "MArrayB.h"
49#include "MArrayS.h"
50
51#include "MRawRunHeader.h"
52#include "MRawEvtHeader.h"
53#include "MRawEvtData.h"
54
55ClassImp(MRawFitsRead);
56
57using namespace std;
58
59// --------------------------------------------------------------------------
60//
61// Default constructor. It tries to open the given file.
62//
63MRawFitsRead::MRawFitsRead(const char *fname, const char *name, const char *title)
64 : MRawFileRead(fname, name, title)
65{
66}
67
68Bool_t MRawFitsRead::IsFits(const char *name)
69{
70 return fits(name).good();
71}
72
73istream *MRawFitsRead::OpenFile(const char *filename)
74{
75 return new fits(filename);
76}
77
78Bool_t MRawFitsRead::ReadRunHeader(istream &stream)
79{
80 fits &fin = static_cast<fits&>(stream);
81
82 if (fin.GetStr("TELESCOP")!="FACT")
83 {
84 gLog << err << "Not a valid FACT FITS file (key TELESCOP not 'FACT')." << endl;
85 return kFALSE;
86 }
87
88 fRawRunHeader->SetValidMagicNumber();
89 fRawRunHeader->SetNumEvents(fin.GetUInt("NAXIS2"));
90 fRawRunHeader->InitPixels(fin.GetUInt("NPIX"));
91 fRawRunHeader->SetObservation("", "FACT");
92 fRawRunHeader->SetRunInfo(0, fin.GetUInt("NIGHT"), fin.GetUInt("RUNID"));
93 fRawRunHeader->InitFact(fin.GetUInt("NPIX")/9, 9, fin.GetUInt("NROI"));
94 fRawRunHeader->SetFormat(0xf172, fin.GetUInt("BLDVER"));
95 fRawRunHeader->SetRunType(0/*data*/);
96
97 return
98 fin.HasKey("NPIX") && fin.HasKey("RUNID") &&
99 fin.HasKey("NROI") && fin.HasKey("BLDVER") &&
100 fin.HasKey("NIGHT");
101}
102
103Bool_t::MRawFitsRead::InitReadData(istream &stream)
104{
105 fits &fin = static_cast<fits&>(stream);
106
107 MArrayB **data = reinterpret_cast<MArrayB**>(fRawEvtData1->DataMember("fHiGainFadcSamples"));
108 MArrayS **cell = reinterpret_cast<MArrayS**>(fRawEvtData1->DataMember("fStartCells"));
109 UInt_t *evtnum = reinterpret_cast<UInt_t*> (fRawEvtHeader->DataMember("fDAQEvtNumber"));
110
111 if (!data || !cell || !evtnum)
112 return kFALSE;
113
114 fRawEvtData1->ResetPixels();
115 fRawEvtData2->ResetPixels(0, 0);
116 fRawEvtData1->InitStartCells();
117
118 if (!fin.SetRefAddress("EventNum", *evtnum))
119 return kFALSE;
120
121 fPCTime.resize(2);
122 if (!fin.SetVecAddress("PCTime", fPCTime))
123 return kFALSE;
124
125 if (!fin.SetPtrAddress("Data", (int16_t*)(*data)->GetArray(), (*data)->GetSize()/2))
126 return kFALSE;
127
128 if (!fin.SetPtrAddress("StartCell", (uint16_t*)(*cell)->GetArray(), (*cell)->GetSize()))
129 return kFALSE;
130
131 fRawEvtData1->SetIndices();
132
133 return kTRUE;
134}
135
136Bool_t MRawFitsRead::ReadEvent(istream &stream)
137{
138 if (!static_cast<fits&>(stream).GetNextRow())
139 return kFALSE;
140
141 fRawEvtTime->SetUnixTime(fPCTime[0], fPCTime[1]);
142
143 // FIXME: Correctly sort the pixels here!
144
145 fRawEvtData1->SetReadyToSave();
146 fRawEvtData2->SetReadyToSave();
147
148 return kTRUE;
149}
150
151void MRawFitsRead::SkipEvent(istream &fin)
152{
153 static_cast<fits&>(fin).SkipNextRow();
154}
Note: See TracBrowser for help on using the repository browser.