Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
22A RooList is a TList with extra support for working with options
23that 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 "RooMsgService.h"
30
31#include "Riostream.h"
32
33using 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
45TObjOptLink *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
68Bool_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
103Bool_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)
const Bool_t kFALSE
Definition RtypesCore.h:92
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
char name[80]
Definition TGX11.cxx:110
A RooList is a TList with extra support for working with options that are associated with each node.
Definition RooList.h:21
TObjOptLink * findLink(const char *name, const char *caller=0) const
Find the link corresponding to the named object in this list.
Definition RooList.cxx:45
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
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
TObjLinkPtr_t NewOptLink(TObject *obj, Option_t *opt, const TObjLinkPtr_t &prev=nullptr)
Return a new TObjOptLink (a TObjLink that also stores the option).
Definition TList.cxx:748
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition TList.cxx:822
virtual void AddFirst(TObject *obj)
Add object at the beginning of the list.
Definition TList.cxx:100
TObjLinkPtr_t fLast
pointer to first entry in linked list
Definition TList.h:53
virtual TObjLink * FirstLink() const
Definition TList.h:108
TObjLinkPtr_t fFirst
Definition TList.h:52
virtual void AddLast(TObject *obj)
Add object at the end of the list.
Definition TList.cxx:152
Mother of all ROOT objects.
Definition TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:359
virtual void Changed()
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369