Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TProofChain.cxx
Go to the documentation of this file.
1 
2 // @(#)root/proof:$Id$
3 // Author: G. Ganis Nov 2006
4 
5 /*************************************************************************
6  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 //////////////////////////////////////////////////////////////////////////
14 // //
15 // TProofChain //
16 // //
17 // A TChain proxy on PROOF. //
18 // Uses an internal TDSet to handle processing. //
19 // //
20 //////////////////////////////////////////////////////////////////////////
21 
22 #include "TProofChain.h"
23 #include "TDSet.h"
24 #include "TList.h"
25 #include "TProof.h"
26 #include "TROOT.h"
27 #include "TEventList.h"
28 #include "TEntryList.h"
29 
30 ClassImp(TProofChain);
31 
32 ////////////////////////////////////////////////////////////////////////////////
33 /// Crates a new PROOF chain proxy.
34 
35 TProofChain::TProofChain() : TChain()
36 {
37  fChain = 0;
38  fTree = 0;
39  fSet = 0;
40  fDirectory = gDirectory;
41  ResetBit(kOwnsChain);
42 }
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Crates a new PROOF chain proxy containing the files from the chain.
46 
47 TProofChain::TProofChain(TChain *chain, Bool_t gettreeheader) : TChain()
48 {
49  fChain = chain;
50  fTree = 0;
51  fSet = chain ? new TDSet((const TChain &)(*chain)) : 0;
52  fDirectory = gDirectory;
53  if (gProof) {
54  gProof->AddChain(chain);
55  ConnectProof();
56  if (gProof->IsLite()) {
57  SetBit(kProofLite);
58  fTree = fChain;
59  } else {
60  if (gettreeheader && fSet)
61  fTree = gProof->GetTreeHeader(fSet);
62  }
63  }
64  ResetBit(kOwnsChain);
65  fEntryList = (chain) ? chain->GetEntryList() : 0;
66  fEventList = (chain) ? chain->GetEventList() : 0;
67 }
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// Creates a new PROOF chain proxy containing the files from the dset.
71 
72 TProofChain::TProofChain(TDSet *dset, Bool_t gettreeheader) : TChain()
73 {
74  fChain = 0;
75  fTree = 0;
76  fSet = dset;
77  fDirectory = gDirectory;
78  if (gProof) {
79  ConnectProof();
80  if (gettreeheader && dset)
81  fTree = gProof->GetTreeHeader(dset);
82  if (gProof->IsLite())
83  SetBit(kProofLite);
84  }
85  if (fTree && fSet) {
86  fChain = new TChain(fTree->GetName());
87  TIter nxe(fSet->GetListOfElements());
88  TDSetElement *e = 0;
89  while ((e = (TDSetElement *) nxe())) {
90  fChain->AddFile(e->GetName());
91  }
92  SetBit(kOwnsChain);
93  if (TestBit(kProofLite))
94  fTree = fChain;
95  }
96  TObject *en = (dset) ? dset->GetEntryList() : 0;
97  if (en) {
98  if (en->InheritsFrom("TEntryList")) {
99  fEntryList = (TEntryList *) en;
100  } else {
101  fEventList = (TEventList *) en;
102  }
103  }
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Destructor.
108 
109 TProofChain::~TProofChain()
110 {
111  if (fChain) {
112  SafeDelete(fSet);
113  // Remove the chain from the private lists in the TProof objects
114  TIter nxp(gROOT->GetListOfSockets());
115  TObject *o = 0;
116  TProof *p = 0;
117  while ((o = nxp()))
118  if ((p = dynamic_cast<TProof *>(o)))
119  p->RemoveChain(fChain);
120  if (fTree == fChain) fTree = 0;
121  if (TestBit(kOwnsChain)) {
122  SafeDelete(fChain);
123  } else {
124  fChain = 0;
125  }
126  } else {
127  // Not owner
128  fSet = 0;
129  }
130  SafeDelete(fTree);
131  fDirectory = 0;
132 
133 }
134 
135 ////////////////////////////////////////////////////////////////////////////////
136 /// Forwards the execution to the dummy tree header.
137 /// See TTree::Browse().
138 
139 void TProofChain::Browse(TBrowser *b)
140 {
141  fSet->Browse(b);
142 }
143 
144 ////////////////////////////////////////////////////////////////////////////////
145 /// Forwards the execution to the TDSet.
146 /// Returns -1 in case of error or number of selected events in case of success.
147 /// See TDSet::Browse().
148 
149 Long64_t TProofChain::Draw(const char *varexp, const TCut &selection,
150  Option_t *option, Long64_t nentries, Long64_t firstentry)
151 {
152  if (!gProof) {
153  Error("Draw", "no active PROOF session");
154  return -1;
155  }
156  ConnectProof();
157 
158  fReadEntry = firstentry;
159 
160  // Set either the entry-list (priority) or the event-list
161  if (fEntryList) {
162  fSet->SetEntryList(fEntryList);
163  } else if (fEventList) {
164  fSet->SetEntryList(fEventList);
165  } else {
166  // Disable previous settings, if any
167  fSet->SetEntryList(0);
168  }
169 
170  // Fill drawing attributes
171  FillDrawAttributes(gProof);
172 
173  // Add alias information, if any
174  AddAliases();
175 
176  Long64_t rv = fSet->Draw(varexp, selection, option, nentries, firstentry);
177  return rv;
178 }
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Forwards the execution to the TDSet.
182 /// Returns -1 in case of error or number of selected events in case of success.
183 /// See TDSet::Browse().
184 
185 Long64_t TProofChain::Draw(const char *varexp, const char *selection,
186  Option_t *option,Long64_t nentries, Long64_t firstentry)
187 {
188  if (!gProof) {
189  Error("Draw", "no active PROOF session");
190  return -1;
191  }
192  ConnectProof();
193 
194  fReadEntry = firstentry;
195 
196  // Set either the entry-list (priority) or the event-list
197  if (fEntryList) {
198  fSet->SetEntryList(fEntryList);
199  } else if (fEventList) {
200  fSet->SetEntryList(fEventList);
201  } else {
202  // Disable previous settings, if any
203  fSet->SetEntryList(0);
204  }
205 
206  // Fill drawing attributes
207  FillDrawAttributes(gProof);
208 
209  // Add alias information, if any
210  AddAliases();
211 
212  Long64_t rv = fSet->Draw(varexp, selection, option, nentries, firstentry);
213  return rv;
214 }
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Aliases are added to the input list. The names are comma-separated in the
218 /// TNamed 'PROOF_ListOfAliases'. For each name, there is an trey named 'alias:<name>'.
219 
220 void TProofChain::AddAliases()
221 {
222  TList *al = fChain->GetListOfAliases();
223  if (al && al->GetSize() > 0) {
224  TIter nxa(al);
225  TNamed *nm = 0, *nmo = 0;
226  TString names, nma;
227  while ((nm = (TNamed *)nxa())) {
228  names += nm->GetName();
229  names += ",";
230  nma.Form("alias:%s", nm->GetName());
231  nmo = (TNamed *)((gProof->GetInputList()) ? gProof->GetInputList()->FindObject(nma) : 0);
232  if (nmo) {
233  nmo->SetTitle(nm->GetTitle());
234  } else {
235  gProof->AddInput(new TNamed(nma.Data(), nm->GetTitle()));
236  }
237  }
238  nmo = (TNamed *)((gProof->GetInputList()) ? gProof->GetInputList()->FindObject("PROOF_ListOfAliases") : 0);
239  if (nmo) {
240  nmo->SetTitle(names.Data());
241  } else {
242  gProof->AddInput(new TNamed("PROOF_ListOfAliases", names.Data()));
243  }
244  }
245 }
246 
247 ////////////////////////////////////////////////////////////////////////////////
248 /// Communicate the drawing attributes for this chain to the input list
249 /// so that the draw selectors can use them, in case of need.
250 /// The drawing attributes are:
251 ///
252 /// LineColor Line color
253 /// LineStyle Line style
254 /// LineWidth Line width
255 /// MarkerColor Marker color index
256 /// MarkerSize Marker size
257 /// MarkerStyle Marker style
258 /// FillColor Area fill color
259 /// FillStyle Area fill style
260 
261 void TProofChain::FillDrawAttributes(TProof *p)
262 {
263  if (!p || !fChain) {
264  Error("FillDrawAttributes", "invalid PROOF or mother chain pointers!");
265  return;
266  }
267 
268  // Weight
269  p->SetParameter("PROOF_ChainWeight", fChain->GetWeight());
270 
271  // Line Attributes
272  p->SetParameter("PROOF_LineColor", (Int_t) fChain->GetLineColor());
273  p->SetParameter("PROOF_LineStyle", (Int_t) fChain->GetLineStyle());
274  p->SetParameter("PROOF_LineWidth", (Int_t) fChain->GetLineWidth());
275 
276  // Marker Attributes
277  p->SetParameter("PROOF_MarkerColor", (Int_t) fChain->GetMarkerColor());
278  p->SetParameter("PROOF_MarkerSize", (Int_t) fChain->GetMarkerSize()*1000);
279  p->SetParameter("PROOF_MarkerStyle", (Int_t) fChain->GetMarkerStyle());
280 
281  // Area fill attributes
282  p->SetParameter("PROOF_FillColor", (Int_t) fChain->GetFillColor());
283  p->SetParameter("PROOF_FillStyle", (Int_t) fChain->GetFillStyle());
284 
285  if (gDebug > 0) {
286  Info("FillDrawAttributes","line: color:%d, style:%d, width:%d",
287  fChain->GetLineColor(), fChain->GetLineStyle(), fChain->GetLineWidth());
288  Info("FillDrawAttributes","marker: color:%d, style:%d, size:%f",
289  fChain->GetMarkerColor(), fChain->GetMarkerStyle(), fChain->GetMarkerSize());
290  Info("FillDrawAttributes","area: color:%d, style:%d",
291  fChain->GetFillColor(), fChain->GetFillStyle());
292  }
293 }
294 
295 ////////////////////////////////////////////////////////////////////////////////
296 /// Forwards the execution to the dummy tree header.
297 /// See TTree::FindBranch().
298 
299 TBranch *TProofChain::FindBranch(const char* branchname)
300 {
301  return (fTree ? fTree->FindBranch(branchname) : (TBranch *)0);
302 }
303 
304 ////////////////////////////////////////////////////////////////////////////////
305 /// Forwards the execution to the dummy tree header.
306 /// See TTree::FindLeaf().
307 
308 TLeaf *TProofChain::FindLeaf(const char* searchname)
309 {
310  return (fTree ? fTree->FindLeaf(searchname) : (TLeaf *)0);
311 }
312 
313 ////////////////////////////////////////////////////////////////////////////////
314 /// Forwards the execution to the dummy tree header.
315 /// See TTree::GetBranch().
316 
317 TBranch *TProofChain::GetBranch(const char *name)
318 {
319  return (fTree ? fTree->GetBranch(name) : (TBranch *)0);
320 }
321 
322 ////////////////////////////////////////////////////////////////////////////////
323 /// Forwards the execution to the dummy tree header.
324 /// See TTree::GetBranchStatus().
325 
326 Bool_t TProofChain::GetBranchStatus(const char *branchname) const
327 {
328  return (fTree ? fTree->GetBranchStatus(branchname) : kFALSE);
329 }
330 
331 ////////////////////////////////////////////////////////////////////////////////
332 /// Forwards the execution to the dummy tree header.
333 /// See TTree::GetPlayer().
334 
335 TVirtualTreePlayer *TProofChain::GetPlayer()
336 {
337  return (fTree ? fTree->GetPlayer() : (TVirtualTreePlayer *)0);
338 }
339 
340 ////////////////////////////////////////////////////////////////////////////////
341 /// Forwards the execution to the TDSet.
342 /// The return value is -1 in case of error and TSelector::GetStatus() in
343 /// in case of success.
344 /// See TDSet::Process().
345 
346 Long64_t TProofChain::Process(const char *filename, Option_t *option,
347  Long64_t nentries, Long64_t firstentry)
348 {
349  // Set either the entry-list (priority) or the event-list
350  TObject *enl = 0;
351  if (fEntryList) {
352  enl = fEntryList;
353  } else if (fEventList) {
354  enl = fEventList;
355  }
356 
357  return fSet->Process(filename, option, nentries, firstentry, enl);
358 }
359 
360 ////////////////////////////////////////////////////////////////////////////////
361 /// The return value is -1 in case of error and TSelector::GetStatus() in
362 /// in case of success.
363 
364 Long64_t TProofChain::Process(TSelector *selector, Option_t *option,
365  Long64_t nentries, Long64_t firstentry)
366 {
367  // Set either the entry-list (priority) or the event-list
368  TObject *enl = 0;
369  if (fEntryList) {
370  enl = fEntryList;
371  } else if (fEventList) {
372  enl = fEventList;
373  }
374 
375  return fSet->Process(selector, option, nentries, firstentry, enl);
376 }
377 
378 ////////////////////////////////////////////////////////////////////////////////
379 /// See TTree::SetDebug
380 
381 void TProofChain::SetDebug(Int_t level, Long64_t min, Long64_t max)
382 {
383  TTree::SetDebug(level, min, max);
384 }
385 
386 ////////////////////////////////////////////////////////////////////////////////
387 /// See TTree::GetName.
388 
389 void TProofChain::SetName(const char *name)
390 {
391  TTree::SetName(name);
392 }
393 
394 ////////////////////////////////////////////////////////////////////////////////
395 /// Returns the total number of entries in the TProofChain, which is
396 /// the number of entries in the TDSet that it holds.
397 
398 Long64_t TProofChain::GetEntries() const
399 {
400  // this was used for holding the total number of entries
401  if (TestBit(kProofLite)) {
402  return (fTree ? fTree->GetEntries() : (Long64_t)(-1));
403  } else {
404  return (fTree ? fTree->GetMaxEntryLoop() : (Long64_t)(-1));
405  }
406 }
407 
408 ////////////////////////////////////////////////////////////////////////////////
409 /// See TTree::GetEntries(const char *selection)
410 /// Not implemented in TProofChain. Shouldn't be used.
411 
412 Long64_t TProofChain::GetEntries(const char *selection)
413 {
414  if (TestBit(kProofLite)) {
415  return (fTree ? fTree->GetEntries(selection) : (Long64_t)(-1));
416  } else {
417  Warning("GetEntries", "GetEntries(selection) not yet implemented");
418  return ((Long64_t)(-1));
419  }
420 }
421 
422 ////////////////////////////////////////////////////////////////////////////////
423 /// Changes the number of processed entries.
424 
425 void TProofChain::Progress(Long64_t total, Long64_t processed)
426 {
427  if (gROOT->IsInterrupted() && gProof)
428  gProof->StopProcess(kTRUE);
429  if (total) { }
430 
431  fReadEntry = processed;
432 }
433 
434 ////////////////////////////////////////////////////////////////////////////////
435 /// Returns the number of processed entries.
436 
437 Long64_t TProofChain::GetReadEntry() const
438 {
439  return fReadEntry;
440 }
441 
442 ////////////////////////////////////////////////////////////////////////////////
443 /// Releases PROOF. Disconnect the "progress" signal.
444 
445 void TProofChain::ReleaseProof()
446 {
447  if (!gProof)
448  return;
449  gProof->Disconnect("Progress(Long64_t,Long64_t)",
450  this, "Progress(Long64_t,Long64_t)");
451 }
452 
453 ////////////////////////////////////////////////////////////////////////////////
454 /// Connects the proof "Progress" signal.
455 
456 void TProofChain::ConnectProof()
457 {
458  if (gProof)
459  gProof->Connect("Progress(Long64_t,Long64_t)", "TProofChain",
460  this, "Progress(Long64_t,Long64_t)");
461 }