Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
28 ClassImp(TStatus);
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));
49  SetBit(TStatus::kNotOk);
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 
64 Int_t TStatus::Merge(TCollection *li)
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 
88  SetMemValues(s->GetVirtMemMax(), s->GetResMemMax());
89  // Check the master values (relevantt if merging submaster info)
90  SetMemValues(s->GetVirtMemMax(kTRUE), s->GetResMemMax(kTRUE), kTRUE);
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 
141 void TStatus::Reset()
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