Logo ROOT   6.08/07
Reference Guide
RooList.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * @(#)root/roofitcore:$Id$
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 
17 /**
18 \file RooList.cxx
19 \class RooList
20 \ingroup Roofitcore
21 
22 A RooList is a TList with extra support for working with options
23 that are associated with each node. This is a utility class for RooPlot
24 **/
25 
26 #include "RooFit.h"
27 
28 #include "RooList.h"
29 #include "RooList.h"
30 #include "RooMsgService.h"
31 
32 #include "Riostream.h"
33 
34 using namespace std;
35 
37 
38 
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// Find the link corresponding to the named object in this list.
42 /// Return 0 if the object is not found or does not have an Option_t
43 /// string associated with its link. Also print a warning message
44 /// if caller is non-zero.
45 
46 TObjOptLink *RooList::findLink(const char *name, const char *caller) const
47 {
48  if(0 == strlen(name)) return 0;
49  TObjLink *link = FirstLink();
50  while (link) {
51  TObject *obj= link->GetObject();
52  if (obj->GetName() && !strcmp(name, obj->GetName())) break;
53  link = link->Next();
54  }
55  if(0 == link) {
56  if(strlen(caller)) {
57  coutE(InputArguments) << caller << ": cannot find object named \"" << name << "\"" << endl;
58  }
59  return 0;
60  }
61  return dynamic_cast<TObjOptLink*>(link);
62 }
63 
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// Move the target object immediately before the specified object,
67 /// preserving any Option_t associated with the target link.
68 
69 Bool_t RooList::moveBefore(const char *before, const char *target, const char *caller)
70 {
71  // Find the target object's link
72  TObjOptLink *targetLink= findLink(target,caller);
73  if(0 == targetLink) return kFALSE;
74 
75  // Find the insert-before object's link
76  TObjOptLink *beforeLink= findLink(before,caller);
77  if(0 == beforeLink) return kFALSE;
78 
79  // Remember the target link's object and options
80  TObject *obj= targetLink->GetObject();
81  TString opt= targetLink->GetOption();
82 
83  // Remove the target object in its present position
84  Remove(targetLink);
85 
86  // Add it back in its new position
87  if(beforeLink == fFirst) {
88  RooList::AddFirst(obj, opt.Data());
89  }
90  else {
91  // coverity[RESOURCE_LEAK]
92  NewOptLink(obj, opt.Data(), beforeLink->Prev());
93  fSize++;
94  Changed();
95  }
96  return kTRUE;
97 }
98 
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// Move the target object immediately after the specified object,
102 /// preserving any Option_t associated with the target link.
103 
104 Bool_t RooList::moveAfter(const char *after, const char *target, const char *caller)
105 {
106  // Find the target object's link
107  TObjOptLink *targetLink= findLink(target,caller);
108  if(0 == targetLink) return kFALSE;
109 
110  // Find the insert-after object's link
111  TObjOptLink *afterLink= findLink(after,caller);
112  if(0 == afterLink) return kFALSE;
113 
114  // Remember the target link's object and options
115  TObject *obj= targetLink->GetObject();
116  TString opt= targetLink->GetOption();
117 
118  // Remove the target object in its present position
119  Remove(targetLink);
120 
121  // Add it back in its new position
122  if(afterLink == fLast) {
123  RooList::AddLast(obj, opt.Data());
124  }
125  else {
126  NewOptLink(obj, opt.Data(), afterLink);
127  fSize++;
128  Changed();
129  }
130  return kTRUE;
131 }
#define coutE(a)
Definition: RooMsgService.h:35
virtual void AddFirst(TObject *obj)
Add object at the beginning of the list.
Definition: TList.cxx:93
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
STL namespace.
Bool_t moveAfter(const char *after, const char *target, const char *caller=0)
Move the target object immediately after the specified object, preserving any Option_t associated wit...
Definition: RooList.cxx:104
virtual void AddLast(TObject *obj)
Add object at the end of the list.
Definition: TList.cxx:137
A RooList is a TList with extra support for working with options that are associated with each node...
Definition: RooList.h:21
#define ClassImp(name)
Definition: Rtypes.h:279
Mother of all ROOT objects.
Definition: TObject.h:37
Bool_t moveBefore(const char *before, const char *target, const char *caller=0)
Move the target object immediately before the specified object, preserving any Option_t associated wi...
Definition: RooList.cxx:69
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:416
const Bool_t kTRUE
Definition: Rtypes.h:91
char name[80]
Definition: TGX11.cxx:109
T1 fFirst
Definition: X11Events.mm:86