source: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc@ 3435

Last change on this file since 3435 was 3420, checked in by gaug, 21 years ago
*** empty log message ***
File size: 6.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 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MBadPixelsCam //
28//
29//Storage container to store bad pixel of the camera...//
30//
31/////////////////////////////////////////////////////////////////////////////
32#include "MBadPixelsCam.h"
33
34#include <fstream>
35
36#include <TClonesArray.h>
37
38#include "MLog.h"
39#include "MLogManip.h"
40
41#include "MBadPixelsPix.h"
42
43ClassImp(MBadPixelsCam);
44
45using namespace std;
46
47// --------------------------------------------------------------------------
48//
49// Default constructor.
50//
51MBadPixelsCam::MBadPixelsCam(const char *name, const char *title)
52{
53 fName = name ? name : "MBadPixelsCam";
54 fTitle = title ? title : "";
55
56 fArray = new TClonesArray("MBadPixelsPix", 1);
57}
58
59// --------------------------------------------------------------------------
60//
61// Delete the array conatining the bad pixel information
62//
63MBadPixelsCam::~MBadPixelsCam()
64{
65 delete fArray;
66}
67
68// --------------------------------------------------------------------------
69//
70// Set the size of the camera
71//
72void MBadPixelsCam::InitSize(const UInt_t i)
73{
74 fArray->ExpandCreate(i);
75}
76
77// --------------------------------------------------------------------------
78//
79// Get the size of the MBadPixelsCam
80//
81Int_t MBadPixelsCam::GetSize() const
82{
83 return fArray->GetEntriesFast();
84}
85
86// --------------------------------------------------------------------------
87//
88// Copy 'constructor'
89//
90void MBadPixelsCam::Copy(TObject &object) const
91{
92 MBadPixelsCam &cam = (MBadPixelsCam&)object;
93
94 const Int_t n = GetSize();
95 if (n==0)
96 return;
97
98 cam.InitSize(n);
99 for (int i=0; i<n; i++)
100 (*this)[i].Copy(cam[i]);
101}
102
103// --------------------------------------------------------------------------
104//
105// Get i-th pixel (pixel number)
106//
107MBadPixelsPix &MBadPixelsCam::operator[](Int_t i)
108{
109 return *static_cast<MBadPixelsPix*>(fArray->UncheckedAt(i));
110}
111
112// --------------------------------------------------------------------------
113//
114// Get i-th pixel (pixel number)
115//
116const MBadPixelsPix &MBadPixelsCam::operator[](Int_t i) const
117{
118 return *static_cast<MBadPixelsPix*>(fArray->UncheckedAt(i));
119}
120
121// --------------------------------------------------------------------------
122//
123// Merge two MBadPixelsCam together, see also MBadPixelsPix::Merge
124//
125void MBadPixelsCam::Merge(const MBadPixelsCam &cam)
126{
127 const Int_t n = cam.GetSize();
128 if (n==0)
129 {
130 *fLog << warn << "MBadPixelsCam::Merge: Container empty." << endl;
131 return;
132 }
133
134 if (GetSize()==0)
135 InitSize(n);
136
137 if (n!=GetSize())
138 {
139 *fLog << warn << "MBadPixelsCam::Merge: Size mismatch... ignored." << endl;
140 return;
141 }
142
143 for (int i=0; i<n; i++)
144 (*this)[i].Merge(cam[i]);
145}
146
147// --------------------------------------------------------------------------
148//
149// Clear the contents of all bad pixels (set=0 means Ok)
150//
151void MBadPixelsCam::Clear(Option_t *o)
152{
153 fArray->ForEach(TObject, Clear)();
154}
155
156// --------------------------------------------------------------------------
157//
158// Print the contents of all bad pixels
159//
160void MBadPixelsCam::Print(Option_t *o) const
161{
162 *fLog << all << GetDescriptor() << ":" << endl;
163 fArray->ForEach(TObject, Print)();
164}
165
166// --------------------------------------------------------------------------
167//
168// Read from an ascii file of the format:
169// pixel1 pixel2 pixel3 pixel4
170// while pixel1,2,3,4 are the pixel indices used in the software.
171//
172// To read the pixels corresponding to a given run you can give run!=0
173// and a file of the format:
174// 1234: 17 193 292
175// 1235: 17 193 292 293
176//
177void MBadPixelsCam::AsciiRead(ifstream &fin, UInt_t run=0)
178{
179 Int_t len;
180 TString str;
181
182 while (1)
183 {
184 str.ReadLine(fin);
185 if (!fin)
186 return;
187
188 Int_t r;
189
190 const Int_t n = sscanf(str.Data(), " %d : %n", &r, &len);
191 if (n!=1)
192 return;
193
194 if (run==0 || run && (UInt_t)r==run)
195 break;
196 }
197
198 str.Remove(0, len);
199
200 while (1)
201 {
202 Int_t idx;
203 const Int_t n = sscanf(str.Data(), " %d %n", &idx, &len);
204 if (n!=1)
205 break;
206
207 str.Remove(0, len);
208
209 if (idx>=GetSize())
210 InitSize(idx);
211
212 (*this)[idx].SetUnsuitableRun();
213 }
214}
215
216// --------------------------------------------------------------------------
217//
218// Write the information into an ascii file. If a run-number is given the
219// run-number will lead the line.
220//
221Bool_t MBadPixelsCam::AsciiWrite(ostream &fout, UInt_t run=0) const
222{
223 if (run)
224 fout << run << ":";
225
226 for (int i=0; i<GetSize(); i++)
227 if ((*this)[i].IsUnsuitableRun())
228 fout << " " << i;
229
230 if (run && GetSize())
231 fout << endl;
232
233 return kTRUE;
234}
235
236Bool_t MBadPixelsCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
237{
238 val = (*this)[idx].GetInfo()[0];
239 return (*this)[idx].IsOK();
240}
241
242void MBadPixelsCam::DrawPixelContent(Int_t num) const
243{
244 *fLog << warn << "MBadPixelsCam::DrawPixelContent - not available." << endl;
245}
Note: See TracBrowser for help on using the repository browser.