Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-13 09:10:47

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id$
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_ABS_DATA_STORE
0017 #define ROO_ABS_DATA_STORE
0018 
0019 #include "Rtypes.h"
0020 #include "RooArgSet.h"
0021 #include "RooAbsData.h"
0022 
0023 #include <string_view>
0024 #include "TNamed.h"
0025 
0026 #include <list>
0027 #include <vector>
0028 
0029 class RooAbsArg ;
0030 class RooArgList ;
0031 class TTree ;
0032 
0033 
0034 class RooAbsDataStore : public TNamed, public RooPrintable {
0035 public:
0036 
0037   RooAbsDataStore() {}
0038   RooAbsDataStore(RooStringView name, RooStringView title, const RooArgSet& vars)
0039     : TNamed(name,title), _vars{vars} {}
0040   RooAbsDataStore(const RooAbsDataStore& other, const char* newname=nullptr)
0041     : RooAbsDataStore(other, other._vars, newname) {}
0042   RooAbsDataStore(const RooAbsDataStore& other, const RooArgSet& vars, const char* newname=nullptr)
0043     : TNamed(other), RooPrintable(other), _vars{vars}, _doDirtyProp{other._doDirtyProp}
0044   {
0045     if(newname) SetName(newname);
0046   }
0047 
0048   virtual RooAbsDataStore* clone(const char* newname=nullptr) const = 0 ;
0049   virtual RooAbsDataStore* clone(const RooArgSet& vars, const char* newname=nullptr) const = 0 ;
0050 
0051   virtual std::unique_ptr<RooAbsDataStore> reduce(RooStringView name, RooStringView title,
0052                                   const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
0053                                   std::size_t nStart, std::size_t nStop) = 0 ;
0054 
0055   // Write current row
0056   virtual Int_t fill() = 0 ;
0057 
0058   // Retrieve a row
0059   virtual const RooArgSet* get(Int_t index) const = 0 ;
0060   virtual const RooArgSet* get() const { return &_vars ; }
0061   virtual double weight() const = 0 ;
0062 
0063   virtual double weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const = 0 ;
0064   virtual void weightError(double& lo, double& hi, RooAbsData::ErrorType etype=RooAbsData::Poisson) const = 0 ;
0065 
0066   double weight(Int_t index) const {
0067     get(index) ;
0068     return weight() ;
0069   }
0070   virtual bool isWeighted() const = 0 ;
0071 
0072   /// Retrieve batches for all observables in this data store.
0073   virtual RooAbsData::RealSpans getBatches(std::size_t first, std::size_t len) const = 0;
0074   virtual RooAbsData::CategorySpans getCategoryBatches(std::size_t /*first*/, std::size_t /*len*/) const {
0075     std::cerr << "This functionality is not yet implemented for this data store." << std::endl;
0076     throw std::logic_error("getCategoryBatches() not implemented in RooAbsDataStore.");
0077     return {};
0078   }
0079   virtual std::span<const double> getWeightBatch(std::size_t first, std::size_t len) const = 0;
0080 
0081   // Change observable name
0082   virtual bool changeObservableName(const char* from, const char* to) =0 ;
0083 
0084   // Add one or more columns
0085   virtual RooAbsArg* addColumn(RooAbsArg& var, bool adjustRange=true) = 0 ;
0086 
0087   // Merge column-wise
0088   virtual RooAbsDataStore* merge(const RooArgSet& allvars, std::list<RooAbsDataStore*> dstoreList) = 0 ;
0089 
0090   // Add rows
0091   virtual void append(RooAbsDataStore& other)= 0 ;
0092 
0093   // General & bookkeeping methods
0094   virtual Int_t numEntries() const = 0 ;
0095   virtual double sumEntries() const { return 0 ; } ;
0096   virtual void reset() = 0 ;
0097 
0098   // Buffer redirection routines used in inside RooAbsOptTestStatistics
0099   virtual void attachBuffers(const RooArgSet& extObs) = 0 ;
0100   virtual void resetBuffers() = 0 ;
0101 
0102   virtual void setExternalWeightArray(const double* /*arrayWgt*/, const double* /*arrayWgtErrLo*/, const double* /*arrayWgtErrHi*/, const double* /*arraySumW2*/) {} ;
0103 
0104   // Printing interface (human readable)
0105   inline void Print(Option_t *options= nullptr) const override {
0106     // Print contents on stdout
0107     printStream(defaultPrintStream(),defaultPrintContents(options),defaultPrintStyle(options));
0108   }
0109 
0110   /// Print name of dataset
0111   void printName(std::ostream& os) const override { os << GetName(); }
0112   /// Print title of dataset
0113   void printTitle(std::ostream& os) const override { os << GetTitle(); }
0114   void printClassName(std::ostream& os) const override ;
0115   void printArgs(std::ostream& os) const override;
0116   /// Print value of the dataset, i.e. the sum of weights contained in the dataset
0117   void printValue(std::ostream& os) const override { os << numEntries() << " entries" ; }
0118   void printMultiline(std::ostream& os, Int_t content, bool verbose, TString indent) const override;
0119 
0120   /// Define default print options, for a given print style
0121   int defaultPrintContents(Option_t* /*opt*/) const override { return kName|kClassName|kArgs|kValue ; }
0122 
0123 
0124   // Constant term  optimizer interface
0125   virtual void cacheArgs(const RooAbsArg* cacheOwner, RooArgSet& varSet, const RooArgSet* nset=nullptr, bool skipZeroWeights=false) = 0 ;
0126   virtual const RooAbsArg* cacheOwner() = 0 ;
0127   virtual void attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVars) = 0 ;
0128   virtual void setArgStatus(const RooArgSet& set, bool active) = 0 ;
0129   const RooArgSet& cachedVars() const { return _cachedVars ; }
0130   virtual void resetCache() = 0 ;
0131   virtual void recalculateCache(const RooArgSet* /*proj*/, Int_t /*firstEvent*/, Int_t /*lastEvent*/, Int_t /*stepSize*/, bool /* skipZeroWeights*/) {} ;
0132 
0133   virtual void setDirtyProp(bool flag) { _doDirtyProp = flag ; }
0134   bool dirtyProp() const { return _doDirtyProp ; }
0135 
0136   virtual void checkInit() const {} ;
0137 
0138   virtual bool hasFilledCache() const { return false ; }
0139 
0140   virtual void dump() {}
0141 
0142   virtual void loadValues(const RooAbsDataStore *tds, const RooFormulaVar* select=nullptr, const char* rangeName=nullptr,
0143       std::size_t nStart=0, std::size_t nStop = std::numeric_limits<std::size_t>::max()) = 0 ;
0144 
0145   virtual void forceCacheUpdate() {} ;
0146 
0147  protected:
0148 
0149   RooArgSet _vars;
0150   RooArgSet _cachedVars;
0151 
0152   bool _doDirtyProp = true; ///< Switch do (de)activate dirty state propagation when loading a data point
0153 
0154   ClassDefOverride(RooAbsDataStore,1) // Abstract Data Storage class
0155 };
0156 
0157 
0158 #endif