ROOT  6.06/09
Reference Guide
TStatus.cxx
Go to the documentation of this file.
1 // @(#)root/proofplayer:$Id$
2 // Author: Maarten Ballintijn 7/06/2004
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TStatus //
15 // //
16 // This class holds the status of an ongoing operation and collects //
17 // error messages. It provides a Merge() operation allowing it to //
18 // be used in PROOF to monitor status in the slaves. //
19 // No messages indicates success. //
20 // //
21 //////////////////////////////////////////////////////////////////////////
22 
23 #include "TStatus.h"
24 #include "Riostream.h"
25 #include "TClass.h"
26 #include "TProofDebug.h"
27 
29 
30 ////////////////////////////////////////////////////////////////////////////////
31 /// Default constructor.
32 
33 TStatus::TStatus() : fIter(&fMsgs), fExitStatus(-1),
34  fVirtMemMax(-1), fResMemMax(-1),
35  fVirtMaxMst(-1), fResMaxMst(-1)
36 {
37  SetName("PROOF_Status");
38  fMsgs.SetOwner(kTRUE);
39  fInfoMsgs.SetOwner(kTRUE);
40  ResetBit(TStatus::kNotOk);
41 }
42 
43 ////////////////////////////////////////////////////////////////////////////////
44 /// Add an error message.
45 
46 void TStatus::Add(const char *mesg)
47 {
48  fMsgs.Add(new TObjString(mesg));
50  Reset();
51 }
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Add an info message.
55 
56 void TStatus::AddInfo(const char *mesg)
57 {
58  fInfoMsgs.Add(new TObjString(mesg));
59 }
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 /// PROOF Merge() function.
63 
65 {
66  TIter stats(li);
67  PDB(kOutput,1)
68  Info("Merge", "start: max virtual memory: %.2f MB \tmax resident memory: %.2f MB ",
69  GetVirtMemMax()/1024., GetResMemMax()/1024.);
70  while (TObject *obj = stats()) {
71  TStatus *s = dynamic_cast<TStatus*>(obj);
72  if (s == 0) continue;
73 
74  TObjString *os = 0;
75  // Errors
76  TIter nxem(&(s->fMsgs));
77  while ((os = (TObjString *) nxem())) {
78  Add(os->GetName());
79  }
80 
81  // Infos (no duplications)
82  TIter nxwm(&(s->fInfoMsgs));
83  while ((os = (TObjString *) nxwm())) {
84  if (!fInfoMsgs.FindObject(os->GetName()))
85  AddInfo(os->GetName());
86  }
87 
89  // Check the master values (relevantt if merging submaster info)
91  PDB(kOutput,1)
92  Info("Merge", "during: max virtual memory: %.2f MB \t"
93  "max resident memory: %.2f MB ",
94  GetVirtMemMax()/1024., GetResMemMax()/1024.);
95  if (GetVirtMemMax(kTRUE) > 0) {
96  PDB(kOutput,1)
97  Info("Merge", "during: max master virtual memory: %.2f MB \t"
98  "max master resident memory: %.2f MB ",
99  GetVirtMemMax(kTRUE)/1024., GetResMemMax(kTRUE)/1024.);
100  }
101  }
102 
103  return fMsgs.GetSize();
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Standard print function.
108 
109 void TStatus::Print(Option_t * /*option*/) const
110 {
111  Printf("OBJ: %s\t%s\t%s", IsA()->GetName(), GetName(), (IsOk() ? "OK" : "ERROR"));
112 
113  TObjString *os = 0;
114  // Errors first
115  if (fMsgs.GetSize() > 0) {
116  Printf("\n Errors:");
117  TIter nxem(&fMsgs);
118  while ((os = (TObjString *) nxem()))
119  Printf("\t%s",os->GetName());
120  Printf(" ");
121  }
122 
123  // Infos
124  if (fInfoMsgs.GetSize() > 0) {
125  Printf("\n Infos:");
126  TIter nxem(&fInfoMsgs);
127  while ((os = (TObjString *) nxem()))
128  Printf("\t%s",os->GetName());
129  Printf(" ");
130  }
131 
132  Printf(" Max worker virtual memory: %.2f MB \tMax worker resident memory: %.2f MB ",
133  GetVirtMemMax()/1024., GetResMemMax()/1024.);
134  Printf(" Max master virtual memory: %.2f MB \tMax master resident memory: %.2f MB ",
135  GetVirtMemMax(kTRUE)/1024., GetResMemMax(kTRUE)/1024.);
136 }
137 
138 ////////////////////////////////////////////////////////////////////////////////
139 /// Reset the iterator on the messages.
140 
142 {
143  fIter.Reset();
144 }
145 
146 ////////////////////////////////////////////////////////////////////////////////
147 /// Return the next message or 0.
148 
149 const char *TStatus::NextMesg()
150 {
151  TObjString *os = (TObjString *) fIter();
152  if (os) return os->GetName();
153  return 0;
154 }
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// Set max memory values
158 
159 void TStatus::SetMemValues(Long_t vmem, Long_t rmem, Bool_t master)
160 {
161  if (master) {
162  if (vmem > 0. && (fVirtMaxMst < 0. || vmem > fVirtMaxMst)) fVirtMaxMst = vmem;
163  if (rmem > 0. && (fResMaxMst < 0. || rmem > fResMaxMst)) fResMaxMst = rmem;
164  } else {
165  if (vmem > 0. && (fVirtMemMax < 0. || vmem > fVirtMemMax)) fVirtMemMax = vmem;
166  if (rmem > 0. && (fResMemMax < 0. || rmem > fResMemMax)) fResMemMax = rmem;
167  }
168 }
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// Stream an object of class TStatus.
172 
173 void TStatus::Streamer(TBuffer &R__b)
174 {
175  if (R__b.IsReading()) {
176  UInt_t R__s, R__c;
177  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
178  if (R__v > 4) {
179  R__b.ReadClassBuffer(TStatus::Class(), this, R__v, R__s, R__c);
180  } else {
181  // For version <= 4 masters we need a special streamer
182  TNamed::Streamer(R__b);
183  std::set<std::string> msgs;
184  TClass *cl = TClass::GetClass("set<string>");
185  if (cl) {
186  UInt_t SS__s = 0, SS__c = 0;
187  UInt_t SS__v = cl->GetClassVersion();
188  R__b.ReadClassBuffer(cl, &msgs, SS__v, SS__s, SS__c);
189  } else {
190  Error("Streamer", "no info found for 'set<string>' - skip");
191  return;
192  }
193  std::set<std::string>::const_iterator it;
194  for (it = msgs.begin(); it != msgs.end(); it++) {
195  fMsgs.Add(new TObjString((*it).c_str()));
196  }
197  if (R__v > 2) {
198  R__b >> fExitStatus;
199  }
200  if (R__v > 1) {
201  R__b >> fVirtMemMax;
202  R__b >> fResMemMax;
203  }
204  if (R__v > 3) {
205  R__b >> fVirtMaxMst;
206  R__b >> fResMaxMst;
207  }
208  }
209  } else {
210  R__b.WriteClassBuffer(TStatus::Class(),this);
211  }
212 }
213 
214 
const char * GetName() const
Returns name of object.
Definition: TObjString.h:42
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
Bool_t IsOk() const
Definition: TStatus.h:61
Bool_t IsReading() const
Definition: TBuffer.h:81
short Version_t
Definition: RtypesCore.h:61
void SetMemValues(Long_t vmem=-1, Long_t rmem=-1, Bool_t master=kFALSE)
Set max memory values.
Definition: TStatus.cxx:159
Collectable string class.
Definition: TObjString.h:32
const char Option_t
Definition: RtypesCore.h:62
const char * NextMesg()
Return the next message or 0.
Definition: TStatus.cxx:149
void AddInfo(const char *mesg)
Add an info message.
Definition: TStatus.cxx:56
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:212
Long_t GetVirtMemMax(Bool_t master=kFALSE) const
Definition: TStatus.h:71
void Add(const char *mesg)
Add an error message.
Definition: TStatus.cxx:46
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
Long_t fResMemMax
Definition: TStatus.h:53
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Long_t fVirtMaxMst
Definition: TStatus.h:54
void Reset()
Definition: TCollection.h:161
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
ClassImp(TStatus) TStatus
Default constructor.
Definition: TStatus.cxx:28
#define PDB(mask, level)
Definition: TProofDebug.h:58
void Class()
Definition: Class.C:29
virtual Int_t Merge(TCollection *list)
PROOF Merge() function.
Definition: TStatus.cxx:64
Long_t GetResMemMax(Bool_t master=kFALSE) const
Definition: TStatus.h:70
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
Long_t fResMaxMst
Definition: TStatus.h:55
Collection abstract base class.
Definition: TCollection.h:48
TClass * IsA() const
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
Version_t GetClassVersion() const
Definition: TClass.h:382
#define Printf
Definition: TGeoToOCC.h:18
long Long_t
Definition: RtypesCore.h:50
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Int_t GetSize() const
Definition: TCollection.h:95
TList fMsgs
Definition: TStatus.h:47
Long_t fVirtMemMax
Definition: TStatus.h:52
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2881
void Reset()
Reset the iterator on the messages.
Definition: TStatus.cxx:141
Mother of all ROOT objects.
Definition: TObject.h:58
Int_t fExitStatus
Definition: TStatus.h:51
virtual void Add(TObject *obj)
Definition: TList.h:81
virtual void Print(Option_t *option="") const
Standard print function.
Definition: TStatus.cxx:109
TIter fIter
Definition: TStatus.h:48
THashList fInfoMsgs
iterator in messages
Definition: TStatus.h:49
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
gr SetName("gr")
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0