source: tags/Mars-V0.6/mhist/MFillH.cc

Last change on this file was 1082, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 7.4 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/2001 <mailto:tbretz@uni-sw.gwdg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26// //
27// MFillH //
28// //
29// This is a common interface (task) to fill mars histograms. Every mars //
30// histogram which is derived from MH can be filled with this task. //
31// //
32// You must specifiy the parameter container with which data the histogram //
33// container should be filled, and the histogram container which has //
34// to be filled. This can be done by either specifing the name of the //
35// objects in the parameter list or by specifiing a pointer to the object. //
36// (s. Constructor) //
37// //
38// WARNING: //
39// Because MFillH is a generalized task to fill histograms it doesn't //
40// know about which branches from a file are necessary to fill the //
41// histograms. If you are reading data from a file which is directly //
42// filled into a histogram via MFillH, please call either //
43// MReadTree::DisableAutoScheme() or enable the necessary branches by //
44// yourself, using MReadTree::EnableBranch() //
45// //
46// Checkout the Warning in MTaskList. //
47// //
48// Input Containers: //
49// A parameter container //
50// //
51// Output Containers: //
52// A histogram container //
53// //
54//////////////////////////////////////////////////////////////////////////////
55#include "MFillH.h"
56
57#include "MLog.h"
58#include "MLogManip.h"
59
60#include "MH.h"
61#include "MParList.h"
62
63ClassImp(MFillH);
64
65// --------------------------------------------------------------------------
66//
67// Initializes name and title of the object. It is called by all
68// constructors.
69//
70void MFillH::Init(const char *name, const char *title)
71{
72 fName = name ? name : "MFillH";
73 fTitle = title ? title : "Task to fill Mars histograms";
74
75 fH = NULL;
76 fParContainer = NULL;
77}
78
79// --------------------------------------------------------------------------
80//
81// Constructor.
82//
83// - par is the name of the parameter container which should be filled into
84// the histogram
85// - hist is the name of the histogram container (which must have been
86// derived from MH)
87//
88MFillH::MFillH(const char *par, const char *hist, const char *name, const char *title)
89{
90 Init(name, title);
91
92 fHName = hist;
93 fParContainerName = par;
94}
95
96// --------------------------------------------------------------------------
97//
98// Constructor.
99//
100// - par is a pointer to the instance of your parameter container from which
101// the data should be used to fill the histogram.
102// - hist is the name of the histogram container (which must have been
103// derived from MH)
104//
105MFillH::MFillH(const MParContainer *par, const char *hist, const char *name, const char *title)
106{
107 Init(name, title);
108
109 fHName = hist;
110 fParContainer = par;
111 fParContainerName = par->GetName();
112}
113
114// --------------------------------------------------------------------------
115//
116// Constructor.
117//
118// - par is a pointer to the instance of your parameter container from which
119// the data should be used to fill the histogram.
120// - hist is a pointer to the instance of your histogram container (which must
121// have been derived from MH) into which the data should flow
122//
123MFillH::MFillH(const char *par, MH *hist, const char *name, const char *title)
124{
125 Init(name, title);
126
127 fH = hist;
128 fHName = hist->GetName();
129 fParContainerName = par;
130}
131
132// --------------------------------------------------------------------------
133//
134// Constructor.
135//
136// - par is a pointer to the instance of your parameter container from which
137// the data should be used to fill the histogram.
138// - hist is the name of the histogram container (which must have been
139// derived from MH)
140//
141MFillH::MFillH(const MParContainer *par, MH *hist, const char *name, const char *title)
142{
143 Init(name, title);
144
145 fH = hist;
146 fHName = hist->GetName();
147 fParContainer = par;
148 fParContainerName = par->GetName();
149}
150
151// --------------------------------------------------------------------------
152//
153// Checks the parameter list for the existance of the parameter container. If
154// the name of it was given in the constructor. It checks also for the
155// existance of the histogram container in the parameter list if a name was
156// given. If it is not available it tried to create a histogram container
157// with the same type as the given object name.
158//
159Bool_t MFillH::PreProcess(MParList *pList)
160{
161 if (!fParContainer)
162 {
163 fParContainer = (MParContainer*)pList->FindObject(fParContainerName);
164 if (!fParContainer)
165 {
166 *fLog << err << dbginf << fParContainerName << " [MParContainer] not found... aborting." << endl;
167 return kFALSE;
168 }
169 }
170
171 if (!fH)
172 {
173 fH = (MH*)pList->FindCreateObj(fHName);
174 if (!fH)
175 return kFALSE;
176 }
177
178 if (!fH->InheritsFrom("MH"))
179 {
180 *fLog << err << dbginf << fH->GetDescriptor() << " ";
181 *fLog << "doesn't inherit from MH - cannot be used for MFillH... aborting." << endl;
182 return kFALSE;
183 }
184
185 return kTRUE;
186}
187
188// --------------------------------------------------------------------------
189//
190// Fills the data from the parameter conatiner into the histogram container
191//
192Bool_t MFillH::Process()
193{
194 fH->Fill(fParContainer);
195
196 return kTRUE;
197}
198
199// --------------------------------------------------------------------------
200//
201// Set the ReadyToSave flag of the histogram container, because now all data
202// has been filled into the histogram.
203//
204Bool_t MFillH::PostProcess()
205{
206 fH->SetReadyToSave();
207 return kTRUE;
208}
Note: See TracBrowser for help on using the repository browser.