RooStringVar.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooStringVar.cxx 36230 2010-10-09 20:21:02Z 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 // RooStringVar implements a string values RooAbsArg
00021 // END_HTML
00022 //
00023 
00024 #include "RooFit.h"
00025 #include "Riostream.h"
00026 
00027 #include <math.h>
00028 #include <stdlib.h>
00029 #include <string.h>
00030 #include <ctype.h>
00031 #include "TObjString.h"
00032 #include "TTree.h"
00033 #include "RooStringVar.h"
00034 #include "RooStreamParser.h"
00035 #include "RooMsgService.h"
00036 
00037 
00038 
00039 ClassImp(RooStringVar)
00040 
00041 
00042               
00043 
00044 //_____________________________________________________________________________
00045 RooStringVar::RooStringVar(const char *name, const char *title, const char* value, Int_t size) :
00046   RooAbsString(name, title, size)
00047 {
00048   // Constructor with initial value and internal buffer size
00049 
00050   if(!isValidString(value)) {
00051     coutW(InputArguments) << "RooStringVar::RooStringVar(" << GetName() 
00052          << "): initial contents too long and ignored" << endl ;
00053   } else {
00054     strlcpy(_value,value,_len) ;
00055   }
00056 
00057   setValueDirty() ;
00058   setShapeDirty() ;
00059 }  
00060 
00061 
00062 
00063 //_____________________________________________________________________________
00064 RooStringVar::RooStringVar(const RooStringVar& other, const char* name) :
00065   RooAbsString(other, name)
00066 {
00067   // Copy constructor
00068 }
00069 
00070 
00071 
00072 //_____________________________________________________________________________
00073 RooStringVar::~RooStringVar() 
00074 {
00075   // Destructor
00076 }
00077 
00078 
00079 
00080 //_____________________________________________________________________________
00081 RooStringVar::operator TString() 
00082 {
00083 
00084   // Cast operator to TString
00085   return TString(_value) ;
00086 }
00087 
00088 
00089 
00090 //_____________________________________________________________________________
00091 void RooStringVar::setVal(const char* value) 
00092 {
00093   // Set value to given TString
00094 
00095   if (!isValidString(value)) {    
00096     coutW(InputArguments) << "RooStringVar::setVal(" << GetName() << "): new string too long and ignored" << endl ;
00097   } else {
00098     if (value) {
00099       strlcpy(_value,value,_len) ;
00100     } else {
00101       _value[0] = 0 ;
00102     }
00103   }
00104 }
00105 
00106 
00107 
00108 //_____________________________________________________________________________
00109 RooAbsArg& RooStringVar::operator=(const char* newValue) 
00110 {
00111   // Set value to given TString
00112 
00113   if (!isValidString(newValue)) {
00114     coutW(InputArguments) << "RooStringVar::operator=(" << GetName() << "): new string too long and ignored" << endl ;
00115   } else {
00116     if (newValue) {
00117       strlcpy(_value,newValue,_len) ;
00118     } else {
00119       _value[0] = 0 ;
00120     }
00121   }
00122 
00123   return *this ;
00124 }
00125 
00126 
00127 
00128 //_____________________________________________________________________________
00129 Bool_t RooStringVar::readFromStream(istream& is, Bool_t compact, Bool_t verbose) 
00130 {
00131   // Read object contents from given stream
00132 
00133   TString token,errorPrefix("RooStringVar::readFromStream(") ;
00134   errorPrefix.Append(GetName()) ;
00135   errorPrefix.Append(")") ;
00136   RooStreamParser parser(is,errorPrefix) ;
00137 
00138   TString newValue ;
00139   Bool_t ret(kFALSE) ;
00140 
00141   if (compact) {
00142     parser.readString(newValue,kTRUE) ;
00143   } else {
00144     newValue = parser.readLine() ;
00145   }
00146   
00147   if (!isValidString(newValue)) {
00148     if (verbose) 
00149       coutW(InputArguments) << "RooStringVar::readFromStream(" << GetName() 
00150                             << "): new string too long and ignored" << endl ;
00151   } else {
00152     strlcpy(_value,newValue,_len) ;
00153   }
00154 
00155   return ret ;
00156 }
00157 
00158 
00159 //_____________________________________________________________________________
00160 void RooStringVar::writeToStream(ostream& os, Bool_t /*compact*/) const
00161 {
00162   // Write object contents to given stream
00163 
00164   os << getVal() ;
00165 }
00166 
00167 

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