// @(#)root/roostats:$Id$
// Author: Sven Kreiss, Kyle Cranmer   Nov 2010
/*************************************************************************
 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOSTATS_DetailedOutputAggregator
#define ROOSTATS_DetailedOutputAggregator

#ifndef ROOT_TString
#include "TString.h"
#endif


/**

This class is designed to aid in the construction of RooDataSets and RooArgSets, particularly those naturally arising in fitting operations. Typically, the usage of this class is as follows:

1.  create DetailedOutputAggregator instance
2.  use AppendArgSet to add value sets to be stored as one row of the dataset
3.  call CommitSet when an entire row's worth of values has been added
4.  repeat steps 2 and 3 until all rows have been added
5.  call GetAsDataSet to extract result RooDataSet

\ingroup Roostats

*/

class RooAbsCollection; 
class RooFitResult;
class RooDataSet;
class RooArgList;
class RooArgSet; 

namespace RooStats {

   class DetailedOutputAggregator {

   public:

      // Translate the given fit result to a RooArgSet in a generic way.
      // Prefix is prepended to all variable names.
      // Note that the returned set is managed by the user and the user must 
      // explicitly delete all the set content (the returned set does not own the content)
      static RooArgSet *GetAsArgSet(RooFitResult *result, TString prefix="", bool withErrorsAndPulls=false);
      
      DetailedOutputAggregator() {
         fResult = NULL;
         fBuiltSet = NULL;
      }

      // For each variable in aset, prepend prefix to its name and add
      // to the internal store. Note this will not appear in the produced
      // dataset unless CommitSet is called.
      void AppendArgSet(const RooAbsCollection *aset, TString prefix="");

      const RooArgList* GetAsArgList() const {
         // Returns this set of detailed output.
         // Note that the ownership of the returned list is not transfered
         // It is managed by the DetailedOutputAggregator class 
         return fBuiltSet;
      }
      
      // Commit to the result RooDataSet.
      void CommitSet(double weight=1.0);

      RooDataSet *GetAsDataSet(TString name, TString title);

      virtual ~DetailedOutputAggregator();

   private:

      RooDataSet *fResult;
      RooArgList *fBuiltSet;
      
   protected:
      ClassDef(DetailedOutputAggregator,1)
   };
}

#endif
 DetailedOutputAggregator.h:1
 DetailedOutputAggregator.h:2
 DetailedOutputAggregator.h:3
 DetailedOutputAggregator.h:4
 DetailedOutputAggregator.h:5
 DetailedOutputAggregator.h:6
 DetailedOutputAggregator.h:7
 DetailedOutputAggregator.h:8
 DetailedOutputAggregator.h:9
 DetailedOutputAggregator.h:10
 DetailedOutputAggregator.h:11
 DetailedOutputAggregator.h:12
 DetailedOutputAggregator.h:13
 DetailedOutputAggregator.h:14
 DetailedOutputAggregator.h:15
 DetailedOutputAggregator.h:16
 DetailedOutputAggregator.h:17
 DetailedOutputAggregator.h:18
 DetailedOutputAggregator.h:19
 DetailedOutputAggregator.h:20
 DetailedOutputAggregator.h:21
 DetailedOutputAggregator.h:22
 DetailedOutputAggregator.h:23
 DetailedOutputAggregator.h:24
 DetailedOutputAggregator.h:25
 DetailedOutputAggregator.h:26
 DetailedOutputAggregator.h:27
 DetailedOutputAggregator.h:28
 DetailedOutputAggregator.h:29
 DetailedOutputAggregator.h:30
 DetailedOutputAggregator.h:31
 DetailedOutputAggregator.h:32
 DetailedOutputAggregator.h:33
 DetailedOutputAggregator.h:34
 DetailedOutputAggregator.h:35
 DetailedOutputAggregator.h:36
 DetailedOutputAggregator.h:37
 DetailedOutputAggregator.h:38
 DetailedOutputAggregator.h:39
 DetailedOutputAggregator.h:40
 DetailedOutputAggregator.h:41
 DetailedOutputAggregator.h:42
 DetailedOutputAggregator.h:43
 DetailedOutputAggregator.h:44
 DetailedOutputAggregator.h:45
 DetailedOutputAggregator.h:46
 DetailedOutputAggregator.h:47
 DetailedOutputAggregator.h:48
 DetailedOutputAggregator.h:49
 DetailedOutputAggregator.h:50
 DetailedOutputAggregator.h:51
 DetailedOutputAggregator.h:52
 DetailedOutputAggregator.h:53
 DetailedOutputAggregator.h:54
 DetailedOutputAggregator.h:55
 DetailedOutputAggregator.h:56
 DetailedOutputAggregator.h:57
 DetailedOutputAggregator.h:58
 DetailedOutputAggregator.h:59
 DetailedOutputAggregator.h:60
 DetailedOutputAggregator.h:61
 DetailedOutputAggregator.h:62
 DetailedOutputAggregator.h:63
 DetailedOutputAggregator.h:64
 DetailedOutputAggregator.h:65
 DetailedOutputAggregator.h:66
 DetailedOutputAggregator.h:67
 DetailedOutputAggregator.h:68
 DetailedOutputAggregator.h:69
 DetailedOutputAggregator.h:70
 DetailedOutputAggregator.h:71
 DetailedOutputAggregator.h:72
 DetailedOutputAggregator.h:73
 DetailedOutputAggregator.h:74
 DetailedOutputAggregator.h:75
 DetailedOutputAggregator.h:76
 DetailedOutputAggregator.h:77
 DetailedOutputAggregator.h:78
 DetailedOutputAggregator.h:79
 DetailedOutputAggregator.h:80
 DetailedOutputAggregator.h:81
 DetailedOutputAggregator.h:82
 DetailedOutputAggregator.h:83
 DetailedOutputAggregator.h:84
 DetailedOutputAggregator.h:85