/**********************************************************************************
 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
 * Package: TMVA                                                                  *
 * Class  : BDTEventWrapper                                                       *
 * Web    : http://tmva.sourceforge.net                                           *
 *                                                                                *
 * Description:                                                                   *
 *                                                                                *
 *                                                                                *
 * Author: Doug Schouten (dschoute@sfu.ca)                                        *
 *                                                                                *
 * Copyright (c) 2007:                                                            *
 *      CERN, Switzerland                                                         *
 *      U. of Texas at Austin, USA                                                *
 *                                                                                *
 * Redistribution and use in source and binary forms, with or without             *
 * modification, are permitted according to the terms listed in LICENSE           *
 * (http://tmva.sourceforge.net/LICENSE)                                          *
 **********************************************************************************/

#ifndef ROOT_TMVA_BDTEventWrapper
#define ROOT_TMVA_BDTEventWrapper

#ifndef ROOT_Event
#include "Event.h"
#endif

namespace TMVA {

   class BDTEventWrapper{

   public:

      BDTEventWrapper( const Event* );
      ~BDTEventWrapper();

      // Require '<' operator to use std::sort algorithms on collection of Events
      Bool_t operator <( const BDTEventWrapper& other ) const;

      // Set the accumulated weight, for sorted signal/background events
      /**
       * @param fType - true for signal, false for background
       * @param weight - the total weight
       */
      void SetCumulativeWeight( Bool_t type, Double_t weight );

      // Get the accumulated weight
      /**
       * @param fType - true for signal, false for background
       * @return the cumulative weight for sorted signal/background events
       */
      Double_t GetCumulativeWeight( Bool_t type ) const;

      // Set the index of the variable to compare on
      /**
       * @param iVar - index of the variable in fEvent to use
       */
      inline static void SetVarIndex( Int_t iVar ) { if (iVar >= 0) GetVarIndex() = iVar; }

      // Return the value of variable fVarIndex for this event
      /**
       * @return value of variable fVarIndex for this event
       */
      inline Double_t GetVal() const { return fEvent->GetValue(GetVarIndex()); }
      const Event* operator*() const { return fEvent; }

   private:

      // This is a workaround for OSx where static thread_local data members are
      // not supported. The C++ solution would indeed be the following:
      static Int_t& GetVarIndex(){TTHREAD_TLS(Int_t) fVarIndex(0); return fVarIndex;}; // index of the variable to sort on

      const Event* fEvent;     // pointer to the event

      Double_t     fBkgWeight; // cumulative background weight for splitting
      Double_t     fSigWeight; // same for the signal weights
   };
}

inline Bool_t TMVA::BDTEventWrapper::operator<( const BDTEventWrapper& other ) const
{
   return GetVal() < other.GetVal();
}

#endif

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