CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DataFormats/PatCandidates/src/Flags.cc

Go to the documentation of this file.
00001 #include "DataFormats/PatCandidates/interface/Flags.h"
00002 
00003 using pat::Flags;
00004 
00005 const std::string & 
00006 Flags::bitToString(uint32_t bit) {
00007     static const std::string UNDEFINED_UNDEFINED = "Undefined/Undefined";
00008     if      (bit & CoreBits      ) return Core::bitToString( Core::Bits(bit) );
00009     else if (bit & SelectionBits ) return Selection::bitToString( Selection::Bits(bit) );
00010     else if (bit & OverlapBits   ) return Overlap::bitToString( Overlap::Bits(bit) );
00011     else if (bit & IsolationBits ) return Isolation::bitToString( Isolation::Bits(bit) );
00012     else return UNDEFINED_UNDEFINED;
00013 }
00014 
00015 std::string Flags::maskToString ( uint32_t mask ) {
00016     std::string ret;
00017     bool first = false;
00018     for (uint32_t i = 1; i != 0; i <<= 1) {
00019         if ( mask & i ) {
00020             if (first) { first = false;  } else { ret += " + "; }
00021             ret += bitToString ( mask & i );
00022         }
00023     }
00024     return ret;
00025 }
00026 
00027 uint32_t
00028 Flags::get( const std::string & str ) {
00029     size_t idx = str.find_first_of("/");
00030     if (idx != std::string::npos) {
00031         std::string set = str.substr(0, idx);
00032         if (set == "Core")      return Core::get(     str.substr(idx+1));
00033         if (set == "Overlap")   return Overlap::get(  str.substr(idx+1));
00034         if (set == "Isolation") return Isolation::get(str.substr(idx+1));
00035         if (set == "Selection") return Selection::get(str.substr(idx+1)); 
00036     }
00037     return 0;
00038 }
00039 
00040 uint32_t
00041 Flags::get( const std::vector<std::string> & strs ) {
00042     uint32_t ret = 0;
00043     for (std::vector<std::string>::const_iterator it = strs.begin(), ed = strs.end(); it != ed; ++it) {
00044         ret |= get( *it );
00045     }
00046     return ret;
00047 }
00048 
00049 const std::string & 
00050 Flags::Core:: bitToString( Core::Bits bit ) {
00051     static const std::string STR_All           = "Core/All", 
00052                              STR_Duplicate     = "Core/Duplicate",
00053                              STR_Preselection  = "Core/Preselection",
00054                              STR_Vertexing     = "Core/Vertexing",
00055                              STR_Overflow      = "Core/Overflow",
00056                              STR_Undefined     = "Core/Undefined";
00057                               
00058     switch (bit) {
00059         case All:           return STR_All;
00060         case Duplicate:     return STR_Duplicate;
00061         case Preselection:  return STR_Preselection;
00062         case Vertexing:     return STR_Vertexing;
00063         case Overflow:      return STR_Overflow;
00064         default:            return STR_Undefined;
00065     }
00066 }
00067 
00068 Flags::Core::Bits 
00069 Flags::Core::get ( const std::string & instr ) {
00070     size_t idx = instr.find_first_of("/");
00071     const std::string &str  = (idx == std::string::npos) ? instr : instr.substr(idx+1);
00072     if      (str == "All")           return All;
00073     else if (str == "Duplicate"    ) return Duplicate;
00074     else if (str == "Preselection" ) return Preselection;
00075     else if (str == "Vertexing"    ) return Vertexing;
00076     else if (str == "Overlfow"     ) return Overflow;
00077     return Undefined;
00078 }
00079 
00080 uint32_t
00081 Flags::Core::get ( const std::vector<std::string> & strs ) {
00082     uint32_t ret = 0;
00083     for (std::vector<std::string>::const_iterator it = strs.begin(), ed = strs.end(); it != ed; ++it) {
00084         ret |= get( *it );
00085     }
00086     return ret;
00087 }
00088 
00089 const std::string & 
00090 Flags::Selection:: bitToString( Selection::Bits bit ) {
00091     static const std::string    STR_All =       "Selection/All",
00092                                 STR_Bit0 =      "Selection/Bit0",
00093                                 STR_Bit1 =      "Selection/Bit1",
00094                                 STR_Bit2 =      "Selection/Bit2",
00095                                 STR_Bit3 =      "Selection/Bit3",
00096                                 STR_Bit4 =      "Selection/Bit4",
00097                                 STR_Bit5 =      "Selection/Bit5",
00098                                 STR_Bit6 =      "Selection/Bit6",
00099                                 STR_Bit7 =      "Selection/Bit7",
00100                                 STR_Bit8 =      "Selection/Bit8",
00101                                 STR_Bit9 =      "Selection/Bit9",
00102                                 STR_Bit10 =     "Selection/Bit10",
00103                                 STR_Bit11 =     "Selection/Bit11",
00104                                 STR_Undefined = "Selection/Undefined";
00105     switch (bit) {
00106         case All:   return STR_All;
00107         case Bit0:  return STR_Bit0;
00108         case Bit1:  return STR_Bit1;
00109         case Bit2:  return STR_Bit2;
00110         case Bit3:  return STR_Bit3;
00111         case Bit4:  return STR_Bit4;
00112         case Bit5:  return STR_Bit5;
00113         case Bit6:  return STR_Bit6;
00114         case Bit7:  return STR_Bit7;
00115         case Bit8:  return STR_Bit8;
00116         case Bit9:  return STR_Bit9;
00117         case Bit10: return STR_Bit10;
00118         case Bit11: return STR_Bit11;
00119         default:
00120             return STR_Undefined;
00121     }
00122 }
00123 
00124 Flags::Selection::Bits 
00125 Flags::Selection::get ( int8_t bit) {
00126     if (bit == -1) return All;
00127     if (bit <= 11) return Bits((1 << bit) << 8);
00128     return Undefined;
00129 }
00130 
00131 Flags::Selection::Bits 
00132 Flags::Selection::get ( const std::string & instr ) {
00133     size_t idx = instr.find_first_of("/");
00134     const std::string &str  = (idx == std::string::npos) ? instr : instr.substr(idx+1);
00135     if      (str == "All"   ) return All;
00136     else if (str == "Bit0"  ) return Bit0;
00137     else if (str == "Bit1"  ) return Bit1;
00138     else if (str == "Bit2"  ) return Bit2;
00139     else if (str == "Bit3"  ) return Bit3;
00140     else if (str == "Bit4"  ) return Bit4;
00141     else if (str == "Bit5"  ) return Bit5;
00142     else if (str == "Bit6"  ) return Bit6;
00143     else if (str == "Bit7"  ) return Bit7;
00144     else if (str == "Bit8"  ) return Bit8;
00145     else if (str == "Bit9"  ) return Bit9;
00146     else if (str == "Bit10" ) return Bit10;
00147     else if (str == "Bit11" ) return Bit11;
00148     return Undefined;
00149 }
00150 
00151 uint32_t
00152 Flags::Selection::get ( const std::vector<std::string> & strs ) {
00153     uint32_t ret = 0;
00154     for (std::vector<std::string>::const_iterator it = strs.begin(), ed = strs.end(); it != ed; ++it) {
00155         ret |= get( *it );
00156     }
00157     return ret;
00158 }
00159 
00160 const std::string & 
00161 Flags::Overlap:: bitToString( Overlap::Bits bit ) {
00162     static const std::string STR_All =       "Overlap/All",
00163                              STR_Jets =      "Overlap/Jets",
00164                              STR_Electrons = "Overlap/Electrons",
00165                              STR_Muons =     "Overlap/Muons",
00166                              STR_Taus =      "Overlap/Taus",
00167                              STR_Photons =   "Overlap/Photons",
00168                              STR_User =     "Overlap/User",
00169                              STR_User1 =     "Overlap/User1",
00170                              STR_User2 =     "Overlap/User2",
00171                              STR_User3 =     "Overlap/User3",
00172                              STR_Undefined = "Overlap/Undefined";
00173     switch (bit) {
00174         case All:       return STR_All;
00175         case Jets:      return STR_Jets;
00176         case Electrons: return STR_Electrons;
00177         case Muons:     return STR_Muons;
00178         case Taus:      return STR_Taus;
00179         case Photons:   return STR_Photons;
00180         case User:      return STR_User;
00181         case User1:     return STR_User1;
00182         case User2:     return STR_User2;
00183         case User3:     return STR_User3;
00184         default:
00185             return STR_Undefined;
00186     }
00187 }
00188 
00189 Flags::Overlap::Bits 
00190 Flags::Overlap::get ( const std::string & instr ) {
00191     size_t idx = instr.find_first_of("/");
00192     const std::string &str  = (idx == std::string::npos) ? instr : instr.substr(idx+1);
00193     if      (str == "All"      ) return All;
00194     else if (str == "Jets"     ) return Jets;
00195     else if (str == "Electrons") return Electrons;
00196     else if (str == "Muons"    ) return Muons;
00197     else if (str == "Taus"     ) return Taus;
00198     else if (str == "Photons"  ) return Photons;
00199     else if (str == "User"    )  return User;
00200     else if (str == "User1"    ) return User1;
00201     else if (str == "User2"    ) return User2;
00202     else if (str == "User3"    ) return User3;
00203     return Undefined;
00204 }
00205 
00206 uint32_t
00207 Flags::Overlap::get ( const std::vector<std::string> & strs ) {
00208     uint32_t ret = 0;
00209     for (std::vector<std::string>::const_iterator it = strs.begin(), ed = strs.end(); it != ed; ++it) {
00210         ret |= get( *it );
00211     }
00212     return ret;
00213 }
00214 
00215 const std::string & 
00216 Flags::Isolation:: bitToString( Isolation::Bits bit ) {
00217     static const std::string    STR_All =     "Isolation/All",
00218                                 STR_Tracker = "Isolation/Tracker",
00219                                 STR_ECal =    "Isolation/ECal",
00220                                 STR_HCal =    "Isolation/HCal",
00221                                 STR_Calo =    "Isolation/Calo",
00222                                 STR_User =    "Isolation/User",
00223                                 STR_User1 =   "Isolation/User1",
00224                                 STR_User2 =   "Isolation/User2",
00225                                 STR_User3 =   "Isolation/User3",
00226                                 STR_User4 =   "Isolation/User4",
00227                                 STR_User5 =   "Isolation/User5",
00228                                 STR_Undefined="Isolation/Undefined";
00229     switch (bit) {
00230         case All:       return STR_All;
00231         case Tracker:   return STR_Tracker;
00232         case ECal:      return STR_ECal;
00233         case HCal:      return STR_HCal;
00234         case Calo:      return STR_Calo;
00235         case User:      return STR_User;
00236         case User1:     return STR_User1;
00237         case User2:     return STR_User2;
00238         case User3:     return STR_User3;
00239         case User4:     return STR_User4;
00240         case User5:     return STR_User5;
00241         default:
00242             return STR_Undefined;
00243     }
00244 }
00245 
00246 Flags::Isolation::Bits 
00247 Flags::Isolation::get ( const std::string & instr ) {
00248     size_t idx = instr.find_first_of("/");
00249     const std::string &str  = (idx == std::string::npos) ? instr : instr.substr(idx+1);
00250     if      (str == "All"      ) return All;
00251     else if (str == "Tracker"  ) return Tracker;
00252     else if (str == "ECal"     ) return ECal;
00253     else if (str == "HCal"     ) return HCal;
00254     else if (str == "Calo"     ) return Calo;
00255     else if (str == "User"     ) return User1;
00256     else if (str == "User1"    ) return User1;
00257     else if (str == "User2"    ) return User2;
00258     else if (str == "User3"    ) return User3;
00259     else if (str == "User4"    ) return User4;
00260     else if (str == "User5"    ) return User5;
00261     return Undefined;
00262 }
00263 
00264 uint32_t
00265 Flags::Isolation::get ( const std::vector<std::string> & strs ) {
00266     uint32_t ret = 0;
00267     for (std::vector<std::string>::const_iterator it = strs.begin(), ed = strs.end(); it != ed; ++it) {
00268         ret |= get( *it );
00269     }
00270     return ret;
00271 }
00272 
00273