00001
00002
00003 #ifndef __TACCEPT__
00004 #define __TACCEPT__
00005
00015 #include <TString.h>
00016 #include <map>
00017 #include <bitset>
00018
00019
00021 static const unsigned int m_nBits=32;
00022
00023
00024
00025 namespace Root {
00026 class TAccept
00027 {
00028
00029 public:
00031 TAccept(const char* name="TAccept");
00032
00034 TAccept( const TAccept& parent );
00035
00037 TAccept& operator= ( const TAccept& rhs );
00038
00040 virtual ~TAccept();
00041
00042 public:
00044 inline operator bool() const
00045 {
00046 return (m_accept.count() == m_cutMap.size()) ? true : false ;
00047 };
00048
00049
00051 inline const char* getName() const { return m_name; };
00052
00053
00055 inline void clear() { m_accept.reset(); }
00056
00058 inline void clearPositive()
00059 {
00060 for ( unsigned int i=0; i<m_cutMap.size(); ++i ) m_accept[i] = true;
00061 }
00062
00063
00065 inline unsigned int getNCuts() const { return m_cutMap.size(); };
00066
00067
00069 int addCut( const TString& cutName, const TString& cutDescription );
00070
00071
00073 inline unsigned int getCutPosition( const TString& cutName ) const
00074 {
00075 std::map< TString, std::pair< TString, unsigned int > >::const_iterator it = m_cutMap.find(cutName);
00076 return (it != m_cutMap.end()) ? (it->second).second : 999999;
00077 }
00078
00079
00081 const TString& getCutName( unsigned int cutPosition ) const;
00082
00083
00085 inline const TString& getCutDescription( const TString& cutName ) const
00086 {
00087 std::map< TString, std::pair< TString, unsigned int > >::const_iterator it = m_cutMap.find(cutName);
00088 return (it != m_cutMap.end()) ? (it->second).first : m_emptyString;
00089 }
00090
00092 const TString& getCutDescription( unsigned int cutPosition ) const;
00093
00094
00096 inline bool getCutResult( const TString& cutName ) const
00097 {
00098 unsigned int cutPosition = getCutPosition(cutName);
00099 return getCutResult(cutPosition);
00100 }
00101
00103 inline bool getCutResult( unsigned int cutPosition ) const
00104 {
00105 return m_accept[cutPosition];
00106 }
00107
00108
00110 inline std::bitset<m_nBits> getCutResultBitSet() const
00111 {
00112 return m_accept;
00113 }
00114
00117 inline std::bitset<m_nBits> getCutResultInvertedBitSet() const
00118 {
00119 std::bitset<m_nBits> inverted;
00120
00121 for ( std::size_t i=0; i<m_cutMap.size(); ++i )
00122 {
00123 inverted[i] = !(m_accept.test(i));
00124 }
00125 return inverted;
00126 }
00127
00130 inline unsigned int getCutResultInverted() const
00131 {
00132 std::bitset<m_nBits> inverted;
00133
00134 for ( std::size_t i=0; i<m_cutMap.size(); ++i )
00135 {
00136 inverted[i] = !(m_accept.test(i));
00137 }
00138 return inverted.to_ulong();
00139 }
00140
00141
00142
00144 inline void setCutResult( const TString& cutName, bool cutResult )
00145 {
00146 unsigned int cutPosition = getCutPosition(cutName);
00147 return setCutResult( cutPosition, cutResult );
00148 }
00149
00151 inline void setCutResult( unsigned int cutPosition, bool cutResult )
00152 {
00153 m_accept[cutPosition] = cutResult;
00154 return;
00155 }
00156
00157
00159 inline void setCutDescription( const TString& cutName, const TString& cutDescription )
00160 {
00161 unsigned int cutPosition = getCutPosition(cutName);
00162 return setCutDescription( cutPosition, cutDescription );
00163 }
00164
00166 void setCutDescription( unsigned int cutPosition, const TString& cutDescription );
00167
00168
00169 #ifdef ROOTCORE
00170
00171 ClassDef(TAccept,1);
00172 #endif
00173
00174
00175
00176 protected:
00178 TString m_name;
00179
00180
00181
00182 private:
00184 std::bitset<m_nBits> m_accept;
00185
00187 std::map< TString, std::pair< TString, unsigned int > > m_cutMap;
00188
00190 TString m_emptyString;
00191
00192
00193 };
00194
00195 }
00196
00197
00198 #endif