RooList.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooList.cxx 36211 2010-10-08 22:20:06Z wouter $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 
00017 //////////////////////////////////////////////////////////////////////////////
00018 //
00019 // BEGIN_HTML
00020 // A RooList is a TList with extra support for working with options
00021 // that are associated with each node. This is a utility class for RooPlot
00022 // END_HTML
00023 //
00024 
00025 #include "RooFit.h"
00026 
00027 #include "RooList.h"
00028 #include "RooList.h"
00029 #include "RooMsgService.h"
00030 
00031 #include "Riostream.h"
00032 
00033 ClassImp(RooList)
00034 
00035 
00036 
00037 //_____________________________________________________________________________
00038 TObjOptLink *RooList::findLink(const char *name, const char *caller) const 
00039 {
00040   // Find the link corresponding to the named object in this list.
00041   // Return 0 if the object is not found or does not have an Option_t
00042   // string associated with its link. Also print a warning message
00043   // if caller is non-zero.
00044 
00045   if(0 == strlen(name)) return 0;
00046   TObjLink *link = FirstLink();
00047   while (link) {
00048     TObject *obj= link->GetObject();
00049     if (obj->GetName() && !strcmp(name, obj->GetName())) break;
00050     link = link->Next();
00051   }
00052   if(0 == link) {
00053     if(strlen(caller)) {
00054       coutE(InputArguments) << caller << ": cannot find object named \"" << name << "\"" << endl;
00055     }
00056     return 0;
00057   }
00058   return dynamic_cast<TObjOptLink*>(link);
00059 }
00060 
00061 
00062 //_____________________________________________________________________________
00063 Bool_t RooList::moveBefore(const char *before, const char *target, const char *caller) 
00064 {
00065   // Move the target object immediately before the specified object,
00066   // preserving any Option_t associated with the target link.
00067 
00068   // Find the target object's link
00069   TObjOptLink *targetLink= findLink(target,caller);
00070   if(0 == targetLink) return kFALSE;
00071 
00072   // Find the insert-before object's link
00073   TObjOptLink *beforeLink= findLink(before,caller);
00074   if(0 == beforeLink) return kFALSE;
00075 
00076   // Remember the target link's object and options
00077   TObject *obj= targetLink->GetObject();
00078   TString opt= targetLink->GetOption();
00079 
00080   // Remove the target object in its present position
00081   Remove(targetLink);
00082 
00083   // Add it back in its new position
00084   if(beforeLink == fFirst) {
00085     RooList::AddFirst(obj, opt.Data());
00086   }
00087   else {
00088     // coverity[RESOURCE_LEAK]
00089     NewOptLink(obj, opt.Data(), beforeLink->Prev());
00090     fSize++;
00091     Changed();
00092   }
00093   return kTRUE;
00094 }
00095 
00096 
00097 //_____________________________________________________________________________
00098 Bool_t RooList::moveAfter(const char *after, const char *target, const char *caller) 
00099 {
00100   // Move the target object immediately after the specified object,
00101   // preserving any Option_t associated with the target link.
00102 
00103   // Find the target object's link
00104   TObjOptLink *targetLink= findLink(target,caller);
00105   if(0 == targetLink) return kFALSE;
00106 
00107   // Find the insert-after object's link
00108   TObjOptLink *afterLink= findLink(after,caller);
00109   if(0 == afterLink) return kFALSE;
00110 
00111   // Remember the target link's object and options
00112   TObject *obj= targetLink->GetObject();
00113   TString opt= targetLink->GetOption();
00114 
00115   // Remove the target object in its present position
00116   Remove(targetLink);
00117 
00118   // Add it back in its new position
00119   if(afterLink == fLast) {
00120     RooList::AddLast(obj, opt.Data());
00121   }
00122   else {
00123     NewOptLink(obj, opt.Data(), afterLink);
00124     fSize++;
00125     Changed();
00126   }
00127   return kTRUE;
00128 }

Generated on Tue Jul 5 15:06:46 2011 for ROOT_528-00b_version by  doxygen 1.5.1