00001
00002
00003 #include "PhysicsTools/StatPatternRecognition/interface/SprExperiment.hh"
00004 #include "PhysicsTools/StatPatternRecognition/interface/SprClass.hh"
00005
00006 #include <algorithm>
00007 #include <sstream>
00008
00009 using namespace std;
00010
00011
00012 bool SprClass::operator==(int cls) const
00013 {
00014 if( negate_ ) {
00015 for( int i=0;i<classes_.size();i++ )
00016 if( cls == classes_[i] ) return false;
00017 return true;
00018 }
00019 else {
00020 for( int i=0;i<classes_.size();i++ )
00021 if( cls == classes_[i] ) return true;
00022 return false;
00023 }
00024 return false;
00025 }
00026
00027
00028 bool SprClass::operator==(const SprClass& other) const
00029 {
00030 if( negate_ != other.negate_ ) return false;
00031 if( classes_.size() != other.classes_.size() ) return false;
00032 for( int i=0;i<classes_.size();i++ ) {
00033 if( find(other.classes_.begin(),other.classes_.end(),classes_[i])
00034 == other.classes_.end() ) return false;
00035 }
00036 for( int i=0;i<other.classes_.size();i++ ) {
00037 if( find(classes_.begin(),classes_.end(),other.classes_[i])
00038 == classes_.end() ) return false;
00039 }
00040 return true;
00041 }
00042
00043
00044 bool SprClass::checkClasses() const
00045 {
00046 for( vector<int>::const_iterator iter=classes_.begin();
00047 iter!=classes_.end();iter++ ) {
00048 if( find(iter+1,classes_.end(),*iter) != classes_.end() ) {
00049 cerr << "Class " << *iter << " has been entered twice." << endl;
00050 return false;
00051 }
00052 }
00053 return true;
00054 }
00055
00056
00057 int SprClass::overlap(const SprClass& other) const
00058 {
00059 if( negate_ || other.negate_ ) return -1;
00060 for( int i=0;i<classes_.size();i++ ) {
00061 if( find(other.classes_.begin(),other.classes_.end(),classes_[i])
00062 != other.classes_.end() ) return 1;
00063 }
00064 for( int i=0;i<other.classes_.size();i++ ) {
00065 if( find(classes_.begin(),classes_.end(),other.classes_[i])
00066 != classes_.end() ) return 1;
00067 }
00068 return 0;
00069 }
00070
00071
00072 std::string SprClass::toString() const
00073 {
00074 ostringstream os;
00075 os << *this;
00076 return os.str();
00077 }