source: tags/Mars-V2.1.1/mbase/MPrint.cc

Last change on this file was 5715, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 5.1 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 10/2001 <mailto:tbretz@uni-sw.gwdg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26// //
27// MPrint //
28// //
29// This task calls the Print() function of a parameter container, to //
30// print some information event by event. //
31// Overload TObject::Print() //
32// //
33// Input Containers: //
34// MParContainer //
35// //
36// Output Containers: //
37// -/- //
38// //
39//////////////////////////////////////////////////////////////////////////////
40#include "MPrint.h"
41
42#include "MLog.h"
43#include "MLogManip.h"
44
45#include "MParList.h"
46
47ClassImp(MPrint);
48
49using namespace std;
50
51// --------------------------------------------------------------------------
52//
53// Initializes name and title of the object. It is called by all
54// constructors.
55//
56void MPrint::Init(const char *name, const char *title)
57{
58 fName = name ? name : "MPrint";
59 fTitle = title ? title : "Task to print a parameter container";
60
61 fObject = NULL;
62}
63
64MPrint::MPrint()
65{
66 Init(0, 0);
67 SetBit(kSeparator);
68}
69
70// --------------------------------------------------------------------------
71//
72// Constructor. Remembers the name to search for in the parameter list
73// of the object to be printed. The object must be derived from TObject and
74// TObject::Print(Option_t *) const
75// must be overloaded. You can also set an option string to use
76// when calling TObject::Print
77// If you want that the MPrint instance is removed from the tasklist
78// if the container to be printed is not found in the PreProcess, call:
79// MPrint::EnableSkip();
80//
81MPrint::MPrint(const char *obj, const char *option,
82 const char *name, const char *title)
83{
84 Init(name, title);
85 SetOption(option);
86
87 fObjName = obj;
88}
89
90// --------------------------------------------------------------------------
91//
92// Constructor. Remember the pointer of the object which has to be
93// printed. The object must be derived from TObject and
94// TObject::Print(Option_t *) const
95// must be overloaded. You can also set an option string to use
96// when calling TObject::Print
97// if the container to be printed is not found in the PreProcess, call:
98// MPrint::EnableSkip();
99//
100MPrint::MPrint(const TObject *obj, const char *option,
101 const char* name, const char *title)
102{
103 Init(name, title);
104 SetOption(option);
105
106 fObject = obj;
107 fObjName = obj->GetName();
108}
109
110// --------------------------------------------------------------------------
111//
112// Checks the parameter list for the existance of the parameter container. If
113// the name of it was given in the constructor.
114//
115Int_t MPrint::PreProcess(MParList *pList)
116{
117 //
118 // The pointer is already given by the user.
119 //
120 if (fObject || TestBit(kSeparator))
121 return kTRUE;
122
123 //
124 // Try to find the parameter container with the given name in the list
125 //
126 fObject = pList->FindObject(fObjName);
127 if (fObject)
128 return kTRUE;
129
130 //
131 // If it couldn't get found stop Eventloop
132 //
133 if (TestBit(kSkip))
134 {
135 *fLog << warn << fObjName << " not found... removing task from list." << endl;
136 return kSKIP;
137 }
138 else
139 {
140 *fLog << err << fObjName << " not found... aborting." << endl;
141 return kFALSE;
142 }
143}
144
145// --------------------------------------------------------------------------
146//
147// Calls overloaded TObject::Print
148//
149Int_t MPrint::Process()
150{
151 if (TestBit(kSeparator))
152 gLog.Separator() << endl;
153 else
154 fObject->Print(fOption);
155 return kTRUE;
156}
157
Note: See TracBrowser for help on using the repository browser.