Logo ROOT   6.10/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 /** \class TStatus
13 \ingroup proofkernel
14 
15 This class holds the status of an ongoing operation and collects
16 error messages. It provides a Merge() operation allowing it to
17 be used in PROOF to monitor status in the slaves.
18 No messages indicates success.
19 
20 */
21 
22 #include "TStatus.h"
23 #include "Riostream.h"
24 #include "TBuffer.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 
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Bool_t IsReading() const
Definition: TBuffer.h:81
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:847
virtual void Print(Option_t *option="") const
Standard print function.
Definition: TStatus.cxx:109
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:28
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
void Add(const char *mesg)
Add an error message.
Definition: TStatus.cxx:46
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
Long_t GetResMemMax(Bool_t master=kFALSE) const
Definition: TStatus.h:66
Long_t fResMemMax
Definition: TStatus.h:49
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:213
Long_t fVirtMaxMst
Definition: TStatus.h:50
void Reset()
Definition: TCollection.h:156
Long_t GetVirtMemMax(Bool_t master=kFALSE) const
Definition: TStatus.h:67
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:687
Bool_t IsOk() const
Definition: TStatus.h:57
#define PDB(mask, level)
Definition: TProofDebug.h:56
void Class()
Definition: Class.C:29
This class holds the status of an ongoing operation and collects error messages.
Definition: TStatus.h:35
virtual Int_t Merge(TCollection *list)
PROOF Merge() function.
Definition: TStatus.cxx:64
const char * GetName() const
Returns name of object.
Definition: TObjString.h:39
Long_t fResMaxMst
Definition: TStatus.h:51
Collection abstract base class.
Definition: TCollection.h:42
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:873
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:71
#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
Version_t GetClassVersion() const
Definition: TClass.h:372
#define ClassImp(name)
Definition: Rtypes.h:336
TList fMsgs
Definition: TStatus.h:43
Long_t fVirtMemMax
Definition: TStatus.h:48
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:2885
void Reset()
Reset the iterator on the messages.
Definition: TStatus.cxx:141
Mother of all ROOT objects.
Definition: TObject.h:37
Int_t fExitStatus
Definition: TStatus.h:47
virtual void Add(TObject *obj)
Definition: TList.h:77
TIter fIter
Definition: TStatus.h:44
THashList fInfoMsgs
iterator in messages
Definition: TStatus.h:45
virtual Int_t GetSize() const
Definition: TCollection.h:89
const Bool_t kTRUE
Definition: RtypesCore.h:91
gr SetName("gr")
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0