ROOT  6.06/09
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 //
19 // BEGIN_HTML
20 // A RooList is a TList with extra support for working with options
21 // that are associated with each node. This is a utility class for RooPlot
22 // END_HTML
23 //
24 
25 #include "RooFit.h"
26 
27 #include "RooList.h"
28 #include "RooList.h"
29 #include "RooMsgService.h"
30 
31 #include "Riostream.h"
32 
33 using namespace std;
34 
36 
37 
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// Find the link corresponding to the named object in this list.
41 /// Return 0 if the object is not found or does not have an Option_t
42 /// string associated with its link. Also print a warning message
43 /// if caller is non-zero.
44 
45 TObjOptLink *RooList::findLink(const char *name, const char *caller) const
46 {
47  if(0 == strlen(name)) return 0;
48  TObjLink *link = FirstLink();
49  while (link) {
50  TObject *obj= link->GetObject();
51  if (obj->GetName() && !strcmp(name, obj->GetName())) break;
52  link = link->Next();
53  }
54  if(0 == link) {
55  if(strlen(caller)) {
56  coutE(InputArguments) << caller << ": cannot find object named \"" << name << "\"" << endl;
57  }
58  return 0;
59  }
60  return dynamic_cast<TObjOptLink*>(link);
61 }
62 
63 
64 ////////////////////////////////////////////////////////////////////////////////
65 /// Move the target object immediately before the specified object,
66 /// preserving any Option_t associated with the target link.
67 
68 Bool_t RooList::moveBefore(const char *before, const char *target, const char *caller)
69 {
70  // Find the target object's link
71  TObjOptLink *targetLink= findLink(target,caller);
72  if(0 == targetLink) return kFALSE;
73 
74  // Find the insert-before object's link
75  TObjOptLink *beforeLink= findLink(before,caller);
76  if(0 == beforeLink) return kFALSE;
77 
78  // Remember the target link's object and options
79  TObject *obj= targetLink->GetObject();
80  TString opt= targetLink->GetOption();
81 
82  // Remove the target object in its present position
83  Remove(targetLink);
84 
85  // Add it back in its new position
86  if(beforeLink == fFirst) {
87  RooList::AddFirst(obj, opt.Data());
88  }
89  else {
90  // coverity[RESOURCE_LEAK]
91  NewOptLink(obj, opt.Data(), beforeLink->Prev());
92  fSize++;
93  Changed();
94  }
95  return kTRUE;
96 }
97 
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 /// Move the target object immediately after the specified object,
101 /// preserving any Option_t associated with the target link.
102 
103 Bool_t RooList::moveAfter(const char *after, const char *target, const char *caller)
104 {
105  // Find the target object's link
106  TObjOptLink *targetLink= findLink(target,caller);
107  if(0 == targetLink) return kFALSE;
108 
109  // Find the insert-after object's link
110  TObjOptLink *afterLink= findLink(after,caller);
111  if(0 == afterLink) return kFALSE;
112 
113  // Remember the target link's object and options
114  TObject *obj= targetLink->GetObject();
115  TString opt= targetLink->GetOption();
116 
117  // Remove the target object in its present position
118  Remove(targetLink);
119 
120  // Add it back in its new position
121  if(afterLink == fLast) {
122  RooList::AddLast(obj, opt.Data());
123  }
124  else {
125  NewOptLink(obj, opt.Data(), afterLink);
126  fSize++;
127  Changed();
128  }
129  return kTRUE;
130 }
#define coutE(a)
Definition: RooMsgService.h:35
virtual void AddFirst(TObject *obj)
Add object at the beginning of the list.
Definition: TList.cxx:92
Basic string class.
Definition: TString.h:137
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:103
virtual void AddLast(TObject *obj)
Add object at the end of the list.
Definition: TList.cxx:136
const char * Data() const
Definition: TString.h:349
ClassImp(RooList) TObjOptLink *RooList TObjLink * link
Find the link corresponding to the named object in this list.
Definition: RooList.cxx:48
#define ClassImp(name)
Definition: Rtypes.h:279
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
Mother of all ROOT objects.
Definition: TObject.h:58
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:68
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
T1 fFirst
Definition: X11Events.mm:85