Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:27

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id: RooStringVar.h,v 1.23 2007/05/11 09:11:30 verkerke Exp $
0005  * Authors:                                                                  *
0006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
0007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
0008  *                                                                           *
0009  * Copyright (c) 2000-2005, Regents of the University of California          *
0010  *                          and Stanford University. All rights reserved.    *
0011  *                                                                           *
0012  * Redistribution and use in source and binary forms,                        *
0013  * with or without modification, are permitted according to the terms        *
0014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
0015  *****************************************************************************/
0016 #ifndef ROO_STRING_VAR
0017 #define ROO_STRING_VAR
0018 
0019 #include "RooAbsArg.h"
0020 
0021 #include <string>
0022 
0023 class RooStringVar final : public RooAbsArg {
0024 public:
0025   // Constructors, assignment etc.
0026   RooStringVar() { }
0027   RooStringVar(const char *name, const char *title, const char* value, Int_t size=1024) ;
0028   RooStringVar(const RooStringVar& other, const char* name=nullptr);
0029   TObject* clone(const char* newname) const override { return new RooStringVar(*this,newname); }
0030 
0031   // Parameter value and error accessors
0032   virtual operator TString() {return TString(_string.c_str()); }
0033   const char* getVal() const { clearValueDirty(); return _string.c_str(); }
0034   void setVal(const char* newVal) { _string = newVal ? newVal : ""; setValueDirty(); }
0035   virtual RooAbsArg& operator=(const char* newVal) { setVal(newVal); return *this; }
0036 
0037   // We implement a fundamental type of AbsArg that can be stored in a dataset
0038   bool isFundamental() const override { return true; }
0039 
0040   // I/O streaming interface (machine readable)
0041   bool readFromStream(std::istream& is, bool compact, bool verbose) override;
0042   void writeToStream(std::ostream& os, bool /*compact*/) const override { os << _string; }
0043 
0044   // Return value and unit accessors
0045   bool operator==(const char* val) const { return _string == val; }
0046   bool operator==(const RooAbsArg& other) const override {
0047     auto otherStr = dynamic_cast<const RooStringVar*>(&other);
0048     return otherStr && _string == otherStr->_string;
0049   }
0050   bool isIdentical(const RooAbsArg& other, bool /*assumeSameType*/) const override { return *this == other; }
0051 
0052   // Printing interface (human readable)
0053   void printValue(std::ostream& os) const override { os << _string; }
0054 
0055 
0056    RooFit::OwningPtr<RooAbsArg> createFundamental(const char *newname = nullptr) const override
0057    {
0058       return RooFit::makeOwningPtr<RooAbsArg>(
0059          std::make_unique<RooStringVar>(newname ? newname : GetName(), GetTitle(), "", 1));
0060    }
0061 
0062 protected:
0063   // Internal consistency checking (needed by RooDataSet)
0064   bool isValid() const override { return true; }
0065   virtual bool isValidString(const char*, bool /*printError=false*/) const { return true; }
0066 
0067   void syncCache(const RooArgSet* /*nset*/ = nullptr) override { }
0068   void copyCache(const RooAbsArg* source, bool valueOnly=false, bool setValDiry=true) override;
0069   void attachToTree(TTree& t, Int_t bufSize=32000) override;
0070   void attachToVStore(RooVectorDataStore&) override { }
0071   void fillTreeBranch(TTree& t) override;
0072   void setTreeBranchStatus(TTree& t, bool active) override;
0073 
0074 private:
0075   std::string _string;
0076   std::string* _stringAddr; //! Required to connect to TTree branch
0077   ClassDefOverride(RooStringVar,2) // String-valued variable
0078 };
0079 
0080 #endif