TCut.cxx

Go to the documentation of this file.
00001 // @(#)root/tree:$Id: TCut.cxx 34588 2010-07-24 04:11:43Z pcanal $
00002 // Author: Rene Brun   14/04/97
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TCut                                                                 //
00015 //                                                                      //
00016 //  A specialized string object used for TTree selections.              //
00017 //  A TCut object has a name and a title. It does not add any data      //
00018 //  members compared to a TNamed. It only add a set of operators to     //
00019 //  facilitate logical string concatenation. For example, assume        //
00020 //     cut1 = "x<1"  and cut2 = "y>2"                                   //
00021 //  then                                                                //
00022 //     cut1 && cut2 will be the string "(x<1)&&(y>2)"                   //
00023 //                                                                      //
00024 //  Operators =, +=, +, *, !, &&, || overloaded.                        //
00025 //                                                                      //
00026 //   Examples of use:                                                   //
00027 //     Root > TCut c1 = "x<1"                                           //
00028 //     Root > TCut c2 = "y<0"                                           //
00029 //     Root > TCut c3 = c1&&c2                                          //
00030 //     Root > ntuple.Draw("x", c1)                                      //
00031 //     Root > ntuple.Draw("x", c1||"x>0")                               //
00032 //     Root > ntuple.Draw("x", c1&&c2)                                  //
00033 //     Root > ntuple.Draw("x", "(x+y)"*(c1&&c2))                        //
00034 //                                                                      //
00035 //////////////////////////////////////////////////////////////////////////
00036 
00037 #include "TCut.h"
00038 
00039 ClassImp(TCut)
00040 
00041 //______________________________________________________________________________
00042 TCut::TCut() : TNamed()
00043 {
00044    // Constructor.
00045 }
00046 
00047 //______________________________________________________________________________
00048 TCut::TCut(const char *title) : TNamed("CUT",title)
00049 {
00050    // Constructor.
00051 }
00052 
00053 //______________________________________________________________________________
00054 TCut::TCut(const char *name, const char *title) : TNamed(name,title)
00055 {
00056    // Constructor.
00057 }
00058 
00059 //______________________________________________________________________________
00060 TCut::TCut(const TCut &cut) : TNamed(cut)
00061 {
00062    // Copy Constructor.
00063 }
00064 
00065 //______________________________________________________________________________
00066 TCut::~TCut()
00067 {
00068    // Typical destructor.
00069 }
00070 
00071 //______________________________________________________________________________
00072 Bool_t TCut::operator==(const char *rhs) const
00073 {
00074    // Comparison.
00075    
00076    return fTitle == rhs;
00077 }
00078 
00079 //______________________________________________________________________________
00080 Bool_t TCut::operator==(const TCut &rhs) const
00081 {
00082    // Comparison.
00083    
00084    return fTitle == rhs.fTitle;
00085 }
00086 
00087 //______________________________________________________________________________
00088 Bool_t TCut::operator!=(const char *rhs) const
00089 {
00090    // Comparison.
00091    
00092    return fTitle != rhs;
00093 }
00094 
00095 //______________________________________________________________________________
00096 Bool_t TCut::operator!=(const TCut &rhs) const
00097 {
00098    // Comparison.
00099    
00100    return fTitle != rhs.fTitle;
00101 }
00102 
00103 //______________________________________________________________________________
00104 TCut& TCut::operator=(const char *rhs)
00105 {
00106    // Assignment.
00107 
00108    fTitle = rhs;
00109    return *this;
00110 }
00111 
00112 //______________________________________________________________________________
00113 TCut& TCut::operator=(const TCut& rhs)
00114 {
00115    // Assignment.
00116 
00117    if (this != &rhs) TNamed::operator=(rhs);
00118    return *this;
00119 }
00120 
00121 //______________________________________________________________________________
00122 TCut& TCut::operator+=(const char *rhs)
00123 {
00124    // Addition.
00125    
00126    if (!rhs || strlen(rhs) == 0) return *this;
00127    if (fTitle.Length() == 0)
00128       fTitle = rhs;
00129    else
00130       fTitle = "(" + fTitle + ")&&(" + TString(rhs) + ")";
00131    return *this;
00132 }
00133 
00134 //______________________________________________________________________________
00135 TCut& TCut::operator+=(const TCut& rhs)
00136 {
00137    // Addition.
00138    
00139    if (rhs.fTitle.Length() == 0) return *this;
00140    if (fTitle.Length() == 0)
00141       fTitle = rhs;
00142    else
00143       fTitle = "(" + fTitle + ")&&(" + rhs.fTitle + ")";
00144    return *this;
00145 }
00146 
00147 //______________________________________________________________________________
00148 TCut& TCut::operator*=(const char *rhs)
00149 {
00150    // Multiplication.
00151 
00152 if (!rhs || strlen(rhs) == 0) return *this;
00153    if (fTitle.Length() == 0)
00154       fTitle = rhs;
00155    else
00156       fTitle = "(" + fTitle + ")*(" + TString(rhs) + ")";
00157    return *this;
00158 }
00159 
00160 //______________________________________________________________________________
00161 TCut& TCut::operator*=(const TCut& rhs)
00162 {
00163    // Multiplication.
00164 
00165    if (rhs.fTitle.Length() == 0) return *this;
00166    if (fTitle.Length() == 0)
00167       fTitle = rhs;
00168    else
00169       fTitle = "(" + fTitle + ")*(" + rhs.fTitle + ")";
00170    return *this;
00171 }
00172 
00173 //______________________________________________________________________________
00174 TCut operator+(const TCut& lhs, const char *rhs)
00175 {
00176    // Addition.
00177    
00178    return TCut(lhs) += rhs;
00179 }
00180 
00181 //______________________________________________________________________________
00182 TCut operator+(const char *lhs, const TCut& rhs)
00183 {
00184    // Addition.
00185    
00186    return TCut(lhs) += rhs;
00187 }
00188 
00189 //______________________________________________________________________________
00190 TCut operator+(const TCut& lhs, const TCut& rhs)
00191 {
00192    // Addition.
00193    
00194    return TCut(lhs) += rhs;
00195 }
00196 
00197 //______________________________________________________________________________
00198 TCut operator*(const TCut& lhs, const char *rhs)
00199 {
00200    // Multiplication.
00201 
00202    return TCut(lhs) *= rhs;
00203 }
00204 
00205 //______________________________________________________________________________
00206 TCut operator*(const char *lhs, const TCut& rhs)
00207 {
00208    // Multiplication.
00209 
00210    return TCut(lhs) *= rhs;
00211 }
00212 
00213 //______________________________________________________________________________
00214 TCut operator*(const TCut& lhs, const TCut& rhs)
00215 {
00216    // Multiplication.
00217 
00218    return TCut(lhs) *= rhs;
00219 }
00220 
00221 //______________________________________________________________________________
00222 TCut operator&&(const TCut& lhs, const char *rhs)
00223 {
00224    // Logical and.
00225 
00226    return TCut(lhs) += rhs;
00227 }
00228 
00229 //______________________________________________________________________________
00230 TCut operator&&(const char *lhs, const TCut& rhs)
00231 {
00232    // Logical and.
00233 
00234    return TCut(lhs) += rhs;
00235 }
00236 
00237 //______________________________________________________________________________
00238 TCut operator&&(const TCut& lhs, const TCut& rhs)
00239 {
00240    // Logical and.
00241 
00242    return TCut(lhs) += rhs;
00243 }
00244 
00245 //______________________________________________________________________________
00246 TCut operator||(const TCut& lhs, const char *rhs)
00247 {
00248    // Logical or.
00249 
00250    if (lhs.fTitle.Length() == 0 && (!rhs || strlen(rhs) == 0)) return TCut();
00251    if (lhs.fTitle.Length() == 0) return TCut(rhs);
00252    if (!rhs || strlen(rhs) == 0) return TCut(lhs);
00253    TString s = "(" + lhs.fTitle + ")||(" + TString(rhs) + ")";
00254    return TCut(s.Data());
00255 }
00256 
00257 //______________________________________________________________________________
00258 TCut operator||(const char *lhs, const TCut& rhs)
00259 {
00260    // Logical or.
00261 
00262    if ((!lhs || strlen(lhs) == 0) && rhs.fTitle.Length() == 0) return TCut();
00263    if (!lhs || strlen(lhs) == 0) return TCut(rhs);
00264    if (rhs.fTitle.Length() == 0) return TCut(lhs);
00265    TString s = "(" + TString(lhs) + ")||(" + rhs.fTitle + ")";
00266    return TCut(s.Data());
00267 }
00268 
00269 //______________________________________________________________________________
00270 TCut operator||(const TCut& lhs, const TCut& rhs)
00271 {
00272    // Logical or.
00273 
00274    if (lhs.fTitle.Length() == 0 && rhs.fTitle.Length() == 0) return TCut();
00275    if (lhs.fTitle.Length() == 0) return TCut(rhs);
00276    if (rhs.fTitle.Length() == 0) return TCut(lhs);
00277    TString s = "(" + lhs.fTitle + ")||(" + rhs.fTitle + ")";
00278    return TCut(s.Data());
00279 }
00280 
00281 //______________________________________________________________________________
00282 TCut operator!(const TCut &rhs)
00283 {
00284    // Logical negation.
00285 
00286    if (rhs.fTitle.Length() == 0) return TCut();
00287    TString s = "!(" + rhs.fTitle + ")";
00288    return TCut(s.Data());
00289 }
00290 

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