ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 * @(#)root/roofitcore:$Id: RooAbsStudy.cxx 30333 2009-09-21 15:39:17Z wouter $
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/

//////////////////////////////////////////////////////////////////////////////
//
// BEGIN_HTML
// RooAbsStudy is an abstract base class for RooStudyManager modules
//
// END_HTML
//



#include "RooFit.h"
#include "Riostream.h"

#include "RooAbsStudy.h"
#include "RooMsgService.h"
#include "RooDataSet.h"
#include "TList.h"
#include "TClass.h"

using namespace std ;

ClassImp(RooAbsStudy)
  ;


//_____________________________________________________________________________
RooAbsStudy::RooAbsStudy(const char* name, const char* title) : TNamed(name,title), _storeDetails(0), _summaryData(0), _detailData(0), _ownDetailData(kTRUE)
{  
  // Constructor
}



//_____________________________________________________________________________
RooAbsStudy::RooAbsStudy(const RooAbsStudy& other) : TNamed(other), _storeDetails(other._storeDetails), _summaryData(other._summaryData), 
						     _detailData(0), _ownDetailData(other._ownDetailData)
{  
  // Copy constructor
}



//_____________________________________________________________________________
RooAbsStudy::~RooAbsStudy() 
{
  // Destructor
  if (_summaryData) delete _summaryData ;
  if (_ownDetailData && _detailData) {
    _detailData->Delete() ;
    delete _detailData ;
  }
}




//_____________________________________________________________________________
void RooAbsStudy::registerSummaryOutput(const RooArgSet& allVars, const RooArgSet& varsWithError, const RooArgSet& varsWithAsymError) 
{
  if (_summaryData) {
    coutW(ObjectHandling) << "RooAbsStudy::registerSummaryOutput(" << GetName() << ") WARNING summary output already registered" << endl ;
    return ;
  }

  string name = Form("%s_summary_data",GetName()) ;
  string title = Form("%s Summary Data",GetTitle()) ;
  _summaryData = new RooDataSet(name.c_str(),title.c_str(),allVars,RooFit::StoreError(varsWithError),RooFit::StoreAsymError(varsWithAsymError)) ;  
}


//_____________________________________________________________________________
void RooAbsStudy::storeSummaryOutput(const RooArgSet& vars) 
{
  if (!_summaryData) {
    coutE(ObjectHandling) << "RooAbsStudy::storeSummaryOutput(" << GetName() << ") ERROR: no summary output data configuration registered" << endl ;
    return ;
  }
  _summaryData->add(vars) ;
}



//_____________________________________________________________________________
void RooAbsStudy::storeDetailedOutput(TNamed& object) 
{
  if (_storeDetails) {

    if (!_detailData) {
      _detailData = new RooLinkedList ;
      _detailData->SetName(Form("%s_detailed_data",GetName())) ;
      //cout << "RooAbsStudy::ctor() detailData name = " << _detailData->GetName() << endl ;
    }

    object.SetName(Form("%s_detailed_data_%d",GetName(),_detailData->GetSize())) ;    
    //cout << "storing detailed data with name " << object.GetName() << endl ;
    _detailData->Add(&object) ;
  } else {
    delete &object ;
  }
}



//_____________________________________________________________________________
void RooAbsStudy::aggregateSummaryOutput(TList* chunkList)
{
  if (!chunkList) return ;

  TIterator* iter = chunkList->MakeIterator() ;
  TObject* obj ;
  while((obj=iter->Next())) {

    //cout << "RooAbsStudy::aggregateSummaryOutput(" << GetName() << ") processing object " << obj->GetName() << endl ;

    RooDataSet* data = dynamic_cast<RooDataSet*>(obj) ;
    if (data) {
      if (TString(data->GetName()).BeginsWith(Form("%s_summary_data",GetName()))) {
	//cout << "RooAbsStudy::aggregateSummaryOutput(" << GetName() << ") found summary block " << data->GetName() << endl ;
	if (!_summaryData) {
	  _summaryData = (RooDataSet*) data->Clone(Form("%s_summary_data",GetName())) ;
	} else {
	  _summaryData->append(*data) ;
	}
      }
    }

    RooLinkedList* dlist = dynamic_cast<RooLinkedList*>(obj) ;
    if (dlist) {
      if (TString(dlist->GetName()).BeginsWith(Form("%s_detailed_data",GetName()))) {
	//cout << "RooAbsStudy::aggregateSummaryOutput(" << GetName() << ") found detail block " <<dlist->GetName() << " with " << dlist->GetSize() << " entries" << endl ;
	TIterator* diter = dlist->MakeIterator() ;
	TNamed* dobj ;
	while((dobj=(TNamed*)diter->Next())) {	  
	  storeDetailedOutput(*dobj) ;
	}
	delete diter ;
      }
    }
  }
}
 RooAbsStudy.cxx:1
 RooAbsStudy.cxx:2
 RooAbsStudy.cxx:3
 RooAbsStudy.cxx:4
 RooAbsStudy.cxx:5
 RooAbsStudy.cxx:6
 RooAbsStudy.cxx:7
 RooAbsStudy.cxx:8
 RooAbsStudy.cxx:9
 RooAbsStudy.cxx:10
 RooAbsStudy.cxx:11
 RooAbsStudy.cxx:12
 RooAbsStudy.cxx:13
 RooAbsStudy.cxx:14
 RooAbsStudy.cxx:15
 RooAbsStudy.cxx:16
 RooAbsStudy.cxx:17
 RooAbsStudy.cxx:18
 RooAbsStudy.cxx:19
 RooAbsStudy.cxx:20
 RooAbsStudy.cxx:21
 RooAbsStudy.cxx:22
 RooAbsStudy.cxx:23
 RooAbsStudy.cxx:24
 RooAbsStudy.cxx:25
 RooAbsStudy.cxx:26
 RooAbsStudy.cxx:27
 RooAbsStudy.cxx:28
 RooAbsStudy.cxx:29
 RooAbsStudy.cxx:30
 RooAbsStudy.cxx:31
 RooAbsStudy.cxx:32
 RooAbsStudy.cxx:33
 RooAbsStudy.cxx:34
 RooAbsStudy.cxx:35
 RooAbsStudy.cxx:36
 RooAbsStudy.cxx:37
 RooAbsStudy.cxx:38
 RooAbsStudy.cxx:39
 RooAbsStudy.cxx:40
 RooAbsStudy.cxx:41
 RooAbsStudy.cxx:42
 RooAbsStudy.cxx:43
 RooAbsStudy.cxx:44
 RooAbsStudy.cxx:45
 RooAbsStudy.cxx:46
 RooAbsStudy.cxx:47
 RooAbsStudy.cxx:48
 RooAbsStudy.cxx:49
 RooAbsStudy.cxx:50
 RooAbsStudy.cxx:51
 RooAbsStudy.cxx:52
 RooAbsStudy.cxx:53
 RooAbsStudy.cxx:54
 RooAbsStudy.cxx:55
 RooAbsStudy.cxx:56
 RooAbsStudy.cxx:57
 RooAbsStudy.cxx:58
 RooAbsStudy.cxx:59
 RooAbsStudy.cxx:60
 RooAbsStudy.cxx:61
 RooAbsStudy.cxx:62
 RooAbsStudy.cxx:63
 RooAbsStudy.cxx:64
 RooAbsStudy.cxx:65
 RooAbsStudy.cxx:66
 RooAbsStudy.cxx:67
 RooAbsStudy.cxx:68
 RooAbsStudy.cxx:69
 RooAbsStudy.cxx:70
 RooAbsStudy.cxx:71
 RooAbsStudy.cxx:72
 RooAbsStudy.cxx:73
 RooAbsStudy.cxx:74
 RooAbsStudy.cxx:75
 RooAbsStudy.cxx:76
 RooAbsStudy.cxx:77
 RooAbsStudy.cxx:78
 RooAbsStudy.cxx:79
 RooAbsStudy.cxx:80
 RooAbsStudy.cxx:81
 RooAbsStudy.cxx:82
 RooAbsStudy.cxx:83
 RooAbsStudy.cxx:84
 RooAbsStudy.cxx:85
 RooAbsStudy.cxx:86
 RooAbsStudy.cxx:87
 RooAbsStudy.cxx:88
 RooAbsStudy.cxx:89
 RooAbsStudy.cxx:90
 RooAbsStudy.cxx:91
 RooAbsStudy.cxx:92
 RooAbsStudy.cxx:93
 RooAbsStudy.cxx:94
 RooAbsStudy.cxx:95
 RooAbsStudy.cxx:96
 RooAbsStudy.cxx:97
 RooAbsStudy.cxx:98
 RooAbsStudy.cxx:99
 RooAbsStudy.cxx:100
 RooAbsStudy.cxx:101
 RooAbsStudy.cxx:102
 RooAbsStudy.cxx:103
 RooAbsStudy.cxx:104
 RooAbsStudy.cxx:105
 RooAbsStudy.cxx:106
 RooAbsStudy.cxx:107
 RooAbsStudy.cxx:108
 RooAbsStudy.cxx:109
 RooAbsStudy.cxx:110
 RooAbsStudy.cxx:111
 RooAbsStudy.cxx:112
 RooAbsStudy.cxx:113
 RooAbsStudy.cxx:114
 RooAbsStudy.cxx:115
 RooAbsStudy.cxx:116
 RooAbsStudy.cxx:117
 RooAbsStudy.cxx:118
 RooAbsStudy.cxx:119
 RooAbsStudy.cxx:120
 RooAbsStudy.cxx:121
 RooAbsStudy.cxx:122
 RooAbsStudy.cxx:123
 RooAbsStudy.cxx:124
 RooAbsStudy.cxx:125
 RooAbsStudy.cxx:126
 RooAbsStudy.cxx:127
 RooAbsStudy.cxx:128
 RooAbsStudy.cxx:129
 RooAbsStudy.cxx:130
 RooAbsStudy.cxx:131
 RooAbsStudy.cxx:132
 RooAbsStudy.cxx:133
 RooAbsStudy.cxx:134
 RooAbsStudy.cxx:135
 RooAbsStudy.cxx:136
 RooAbsStudy.cxx:137
 RooAbsStudy.cxx:138
 RooAbsStudy.cxx:139
 RooAbsStudy.cxx:140
 RooAbsStudy.cxx:141
 RooAbsStudy.cxx:142
 RooAbsStudy.cxx:143
 RooAbsStudy.cxx:144
 RooAbsStudy.cxx:145
 RooAbsStudy.cxx:146
 RooAbsStudy.cxx:147
 RooAbsStudy.cxx:148
 RooAbsStudy.cxx:149
 RooAbsStudy.cxx:150
 RooAbsStudy.cxx:151
 RooAbsStudy.cxx:152
 RooAbsStudy.cxx:153
 RooAbsStudy.cxx:154
 RooAbsStudy.cxx:155
 RooAbsStudy.cxx:156