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

Last change on this file since 11490 was 11490, checked in by tbretz, 13 years ago
Replaced fPCTime by a two byte buffer and init full time; added StartCell to reading.
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 "MFits.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 MZlib fin(name);
71 if (!fin)
72 return 0;
73
74 Byte_t c[6];
75 fin.read((char*)c, 6);
76 if (!fin)
77 return 0;
78
79 return memcmp(c, "SIMPLE", 6)==0;
80}
81
82istream *MRawFitsRead::OpenFile(const char *filename)
83{
84 return new MFits(filename);
85}
86
87Bool_t MRawFitsRead::ReadRunHeader(istream &stream)
88{
89 MFits &fin = static_cast<MFits&>(stream);
90
91 fRawRunHeader->SetValidMagicNumber();
92 fRawRunHeader->SetNumEvents(fin.GetUInt("NAXIS2"));
93 fRawRunHeader->InitPixels(fin.GetUInt("NPIX"));
94 fRawRunHeader->SetObservation("", "FACT");
95 fRawRunHeader->SetRunInfo(0, fin.GetUInt("NIGHT"), fin.GetUInt("RUNID"));
96 fRawRunHeader->InitFact(fin.GetUInt("NPIX")/9, 9, fin.GetUInt("NROI"));
97 fRawRunHeader->SetFormat(0xf172, fin.GetUInt("BLDVER"));
98 fRawRunHeader->SetRunType(0/*data*/);
99
100 return
101 fin.HasKey("NPIX") && fin.HasKey("RUNID") &&
102 fin.HasKey("NROI") && fin.HasKey("BLDVER") &&
103 fin.HasKey("NIGHT");
104}
105
106Bool_t::MRawFitsRead::InitReadData(istream &stream)
107{
108 MFits &fin = static_cast<MFits&>(stream);
109
110 MArrayB **data = reinterpret_cast<MArrayB**>(fRawEvtData1->DataMember("fHiGainFadcSamples"));
111 MArrayS **cell = reinterpret_cast<MArrayS**>(fRawEvtData1->DataMember("fStartCells"));
112 UInt_t *evtnum = reinterpret_cast<UInt_t*> (fRawEvtHeader->DataMember("fDAQEvtNumber"));
113
114 if (!data || !cell || !evtnum)
115 return kFALSE;
116
117 fRawEvtData1->ResetPixels();
118 fRawEvtData2->ResetPixels(0, 0);
119 fRawEvtData1->InitStartCells();
120
121 if (!fin.SetRefAddress("EventNum", *evtnum))
122 return kFALSE;
123
124 fPCTime.resize(2);
125 if (!fin.SetVecAddress("PCTime", fPCTime))
126 return kFALSE;
127
128 if (!fin.SetPtrAddress("Data", (int16_t*)(*data)->GetArray(), (*data)->GetSize()/2))
129 return kFALSE;
130
131 if (!fin.SetPtrAddress("StartCell", (uint16_t*)(*cell)->GetArray(), (*cell)->GetSize()))
132 return kFALSE;
133
134 fRawEvtData1->SetIndices();
135
136 return kTRUE;
137}
138
139Bool_t MRawFitsRead::ReadEvent(istream &stream)
140{
141 if (!static_cast<MFits&>(stream).GetNextRow())
142 return kFALSE;
143
144 fRawEvtTime->SetUnixTime(fPCTime[0], fPCTime[1]);
145
146 // FIXME: Correctly sort the pixels here!
147
148 fRawEvtData1->SetReadyToSave();
149 fRawEvtData2->SetReadyToSave();
150
151 return kTRUE;
152}
153
154void MRawFitsRead::SkipEvent(istream &fin)
155{
156 static_cast<MFits&>(fin).SkipNextRow();
157}
Note: See TracBrowser for help on using the repository browser.