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

Last change on this file since 3460 was 3460, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.3 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 *fLog << endl << dbg << "INIT SIZE: " << i << endl;
76}
77
78// --------------------------------------------------------------------------
79//
80// Get the size of the MBadPixelsCam
81//
82Int_t MBadPixelsCam::GetSize() const
83{
84 return fArray->GetEntriesFast();
85}
86
87// --------------------------------------------------------------------------
88//
89// Copy 'constructor'
90//
91void MBadPixelsCam::Copy(TObject &object) const
92{
93 MBadPixelsCam &cam = (MBadPixelsCam&)object;
94
95 const Int_t n = GetSize();
96 if (n==0)
97 return;
98
99 cam.InitSize(n);
100 for (int i=0; i<n; i++)
101 (*this)[i].Copy(cam[i]);
102}
103
104// --------------------------------------------------------------------------
105//
106// Get i-th pixel (pixel number)
107//
108MBadPixelsPix &MBadPixelsCam::operator[](Int_t i)
109{
110 *fLog << dbg << "A: " << GetSize() << ": " << i << " " << fArray->UncheckedAt(i) << endl;
111 return *static_cast<MBadPixelsPix*>(fArray->UncheckedAt(i));
112}
113
114// --------------------------------------------------------------------------
115//
116// Get i-th pixel (pixel number)
117//
118const MBadPixelsPix &MBadPixelsCam::operator[](Int_t i) const
119{
120 *fLog << dbg << "B: " << GetSize() << ": " << i << " " << fArray->UncheckedAt(i) << endl;
121 return *static_cast<MBadPixelsPix*>(fArray->UncheckedAt(i));
122}
123
124// --------------------------------------------------------------------------
125//
126// Merge two MBadPixelsCam together, see also MBadPixelsPix::Merge
127//
128void MBadPixelsCam::Merge(const MBadPixelsCam &cam)
129{
130 const Int_t n = cam.GetSize();
131 if (n==0)
132 {
133 *fLog << warn << "MBadPixelsCam::Merge: Container empty." << endl;
134 return;
135 }
136
137 if (GetSize()==0)
138 InitSize(n);
139
140 if (n!=GetSize())
141 {
142 *fLog << warn << "MBadPixelsCam::Merge: Size mismatch... ignored." << endl;
143 return;
144 }
145
146 for (int i=0; i<n; i++)
147 (*this)[i].Merge(cam[i]);
148}
149
150// --------------------------------------------------------------------------
151//
152// Clear the contents of all bad pixels (set=0 means Ok)
153//
154void MBadPixelsCam::Clear(Option_t *o)
155{
156 fArray->ForEach(TObject, Clear)();
157}
158
159// --------------------------------------------------------------------------
160//
161// Print the contents of all bad pixels
162//
163void MBadPixelsCam::Print(Option_t *o) const
164{
165 *fLog << all << GetDescriptor() << ":" << endl;
166 fArray->ForEach(TObject, Print)();
167}
168
169// --------------------------------------------------------------------------
170//
171// Read from an ascii file of the format:
172// pixel1 pixel2 pixel3 pixel4
173// while pixel1,2,3,4 are the pixel indices used in the software.
174//
175// To read the pixels corresponding to a given run you can give run!=0
176// and a file of the format:
177// 1234: 17 193 292
178// 1235: 17 193 292 293
179//
180void MBadPixelsCam::AsciiRead(ifstream &fin, UInt_t run=0)
181{
182 Int_t len;
183 TString str;
184
185 while (1)
186 {
187 str.ReadLine(fin);
188 if (!fin)
189 return;
190
191 Int_t r;
192
193 const Int_t n = sscanf(str.Data(), " %d : %n", &r, &len);
194 if (n!=1)
195 return;
196
197 if (run==0 || run && (UInt_t)r==run)
198 break;
199 }
200
201 str.Remove(0, len);
202
203 while (1)
204 {
205 Int_t idx;
206 const Int_t n = sscanf(str.Data(), " %d %n", &idx, &len);
207 if (n!=1)
208 break;
209
210 str.Remove(0, len);
211
212 if (idx>=GetSize())
213 InitSize(idx);
214
215 (*this)[idx].SetUnsuitableRun();
216 }
217}
218
219// --------------------------------------------------------------------------
220//
221// Write the information into an ascii file. If a run-number is given the
222// run-number will lead the line.
223//
224Bool_t MBadPixelsCam::AsciiWrite(ostream &fout, UInt_t run=0) const
225{
226 if (run)
227 fout << run << ":";
228
229 for (int i=0; i<GetSize(); i++)
230 if ((*this)[i].IsUnsuitableRun())
231 fout << " " << i;
232
233 if (run && GetSize())
234 fout << endl;
235
236 return kTRUE;
237}
238
239Bool_t MBadPixelsCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
240{
241 val = (*this)[idx].GetInfo()[0];
242 return (*this)[idx].IsOK();
243}
244
245void MBadPixelsCam::DrawPixelContent(Int_t num) const
246{
247 *fLog << warn << "MBadPixelsCam::DrawPixelContent - not available." << endl;
248}
Note: See TracBrowser for help on using the repository browser.