Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:50:58

0001 #include "DataFormats/PatCandidates/interface/Flags.h"
0002 
0003 using pat::Flags;
0004 
0005 const std::string &Flags::bitToString(uint32_t bit) {
0006   static const std::string UNDEFINED_UNDEFINED = "Undefined/Undefined";
0007   if (bit & CoreBits)
0008     return Core::bitToString(Core::Bits(bit));
0009   else if (bit & SelectionBits)
0010     return Selection::bitToString(Selection::Bits(bit));
0011   else if (bit & OverlapBits)
0012     return Overlap::bitToString(Overlap::Bits(bit));
0013   else if (bit & IsolationBits)
0014     return Isolation::bitToString(Isolation::Bits(bit));
0015   else
0016     return UNDEFINED_UNDEFINED;
0017 }
0018 
0019 std::string Flags::maskToString(uint32_t mask) {
0020   std::string ret;
0021   bool first = false;
0022   for (uint32_t i = 1; i != 0; i <<= 1) {
0023     if (mask & i) {
0024       if (first) {
0025         first = false;
0026       } else {
0027         ret += " + ";
0028       }
0029       ret += bitToString(mask & i);
0030     }
0031   }
0032   return ret;
0033 }
0034 
0035 uint32_t Flags::get(const std::string &str) {
0036   size_t idx = str.find_first_of('/');
0037   if (idx != std::string::npos) {
0038     std::string set = str.substr(0, idx);
0039     if (set == "Core")
0040       return Core::get(str.substr(idx + 1));
0041     if (set == "Overlap")
0042       return Overlap::get(str.substr(idx + 1));
0043     if (set == "Isolation")
0044       return Isolation::get(str.substr(idx + 1));
0045     if (set == "Selection")
0046       return Selection::get(str.substr(idx + 1));
0047   }
0048   return 0;
0049 }
0050 
0051 uint32_t Flags::get(const std::vector<std::string> &strs) {
0052   uint32_t ret = 0;
0053   for (std::vector<std::string>::const_iterator it = strs.begin(), ed = strs.end(); it != ed; ++it) {
0054     ret |= get(*it);
0055   }
0056   return ret;
0057 }
0058 
0059 const std::string &Flags::Core::bitToString(Core::Bits bit) {
0060   static const std::string STR_All = "Core/All", STR_Duplicate = "Core/Duplicate",
0061                            STR_Preselection = "Core/Preselection", STR_Vertexing = "Core/Vertexing",
0062                            STR_Overflow = "Core/Overflow", STR_Undefined = "Core/Undefined";
0063 
0064   switch (bit) {
0065     case All:
0066       return STR_All;
0067     case Duplicate:
0068       return STR_Duplicate;
0069     case Preselection:
0070       return STR_Preselection;
0071     case Vertexing:
0072       return STR_Vertexing;
0073     case Overflow:
0074       return STR_Overflow;
0075     default:
0076       return STR_Undefined;
0077   }
0078 }
0079 
0080 Flags::Core::Bits Flags::Core::get(const std::string &instr) {
0081   size_t idx = instr.find_first_of('/');
0082   const std::string &str = (idx == std::string::npos) ? instr : instr.substr(idx + 1);
0083   if (str == "All")
0084     return All;
0085   else if (str == "Duplicate")
0086     return Duplicate;
0087   else if (str == "Preselection")
0088     return Preselection;
0089   else if (str == "Vertexing")
0090     return Vertexing;
0091   else if (str == "Overlfow")
0092     return Overflow;
0093   return Undefined;
0094 }
0095 
0096 uint32_t Flags::Core::get(const std::vector<std::string> &strs) {
0097   uint32_t ret = 0;
0098   for (std::vector<std::string>::const_iterator it = strs.begin(), ed = strs.end(); it != ed; ++it) {
0099     ret |= get(*it);
0100   }
0101   return ret;
0102 }
0103 
0104 const std::string &Flags::Selection::bitToString(Selection::Bits bit) {
0105   static const std::string STR_All = "Selection/All", STR_Bit0 = "Selection/Bit0", STR_Bit1 = "Selection/Bit1",
0106                            STR_Bit2 = "Selection/Bit2", STR_Bit3 = "Selection/Bit3", STR_Bit4 = "Selection/Bit4",
0107                            STR_Bit5 = "Selection/Bit5", STR_Bit6 = "Selection/Bit6", STR_Bit7 = "Selection/Bit7",
0108                            STR_Bit8 = "Selection/Bit8", STR_Bit9 = "Selection/Bit9", STR_Bit10 = "Selection/Bit10",
0109                            STR_Bit11 = "Selection/Bit11", STR_Undefined = "Selection/Undefined";
0110   switch (bit) {
0111     case All:
0112       return STR_All;
0113     case Bit0:
0114       return STR_Bit0;
0115     case Bit1:
0116       return STR_Bit1;
0117     case Bit2:
0118       return STR_Bit2;
0119     case Bit3:
0120       return STR_Bit3;
0121     case Bit4:
0122       return STR_Bit4;
0123     case Bit5:
0124       return STR_Bit5;
0125     case Bit6:
0126       return STR_Bit6;
0127     case Bit7:
0128       return STR_Bit7;
0129     case Bit8:
0130       return STR_Bit8;
0131     case Bit9:
0132       return STR_Bit9;
0133     case Bit10:
0134       return STR_Bit10;
0135     case Bit11:
0136       return STR_Bit11;
0137     default:
0138       return STR_Undefined;
0139   }
0140 }
0141 
0142 Flags::Selection::Bits Flags::Selection::get(int8_t bit) {
0143   if (bit == -1)
0144     return All;
0145   if (bit <= 11)
0146     return Bits((1 << bit) << 8);
0147   return Undefined;
0148 }
0149 
0150 Flags::Selection::Bits Flags::Selection::get(const std::string &instr) {
0151   size_t idx = instr.find_first_of('/');
0152   const std::string &str = (idx == std::string::npos) ? instr : instr.substr(idx + 1);
0153   if (str == "All")
0154     return All;
0155   else if (str == "Bit0")
0156     return Bit0;
0157   else if (str == "Bit1")
0158     return Bit1;
0159   else if (str == "Bit2")
0160     return Bit2;
0161   else if (str == "Bit3")
0162     return Bit3;
0163   else if (str == "Bit4")
0164     return Bit4;
0165   else if (str == "Bit5")
0166     return Bit5;
0167   else if (str == "Bit6")
0168     return Bit6;
0169   else if (str == "Bit7")
0170     return Bit7;
0171   else if (str == "Bit8")
0172     return Bit8;
0173   else if (str == "Bit9")
0174     return Bit9;
0175   else if (str == "Bit10")
0176     return Bit10;
0177   else if (str == "Bit11")
0178     return Bit11;
0179   return Undefined;
0180 }
0181 
0182 uint32_t Flags::Selection::get(const std::vector<std::string> &strs) {
0183   uint32_t ret = 0;
0184   for (std::vector<std::string>::const_iterator it = strs.begin(), ed = strs.end(); it != ed; ++it) {
0185     ret |= get(*it);
0186   }
0187   return ret;
0188 }
0189 
0190 const std::string &Flags::Overlap::bitToString(Overlap::Bits bit) {
0191   static const std::string STR_All = "Overlap/All", STR_Jets = "Overlap/Jets", STR_Electrons = "Overlap/Electrons",
0192                            STR_Muons = "Overlap/Muons", STR_Taus = "Overlap/Taus", STR_Photons = "Overlap/Photons",
0193                            STR_User = "Overlap/User", STR_User1 = "Overlap/User1", STR_User2 = "Overlap/User2",
0194                            STR_User3 = "Overlap/User3", STR_Undefined = "Overlap/Undefined";
0195   switch (bit) {
0196     case All:
0197       return STR_All;
0198     case Jets:
0199       return STR_Jets;
0200     case Electrons:
0201       return STR_Electrons;
0202     case Muons:
0203       return STR_Muons;
0204     case Taus:
0205       return STR_Taus;
0206     case Photons:
0207       return STR_Photons;
0208     case User:
0209       return STR_User;
0210     case User1:
0211       return STR_User1;
0212     case User2:
0213       return STR_User2;
0214     case User3:
0215       return STR_User3;
0216     default:
0217       return STR_Undefined;
0218   }
0219 }
0220 
0221 Flags::Overlap::Bits Flags::Overlap::get(const std::string &instr) {
0222   size_t idx = instr.find_first_of('/');
0223   const std::string &str = (idx == std::string::npos) ? instr : instr.substr(idx + 1);
0224   if (str == "All")
0225     return All;
0226   else if (str == "Jets")
0227     return Jets;
0228   else if (str == "Electrons")
0229     return Electrons;
0230   else if (str == "Muons")
0231     return Muons;
0232   else if (str == "Taus")
0233     return Taus;
0234   else if (str == "Photons")
0235     return Photons;
0236   else if (str == "User")
0237     return User;
0238   else if (str == "User1")
0239     return User1;
0240   else if (str == "User2")
0241     return User2;
0242   else if (str == "User3")
0243     return User3;
0244   return Undefined;
0245 }
0246 
0247 uint32_t Flags::Overlap::get(const std::vector<std::string> &strs) {
0248   uint32_t ret = 0;
0249   for (std::vector<std::string>::const_iterator it = strs.begin(), ed = strs.end(); it != ed; ++it) {
0250     ret |= get(*it);
0251   }
0252   return ret;
0253 }
0254 
0255 const std::string &Flags::Isolation::bitToString(Isolation::Bits bit) {
0256   static const std::string STR_All = "Isolation/All", STR_Tracker = "Isolation/Tracker", STR_ECal = "Isolation/ECal",
0257                            STR_HCal = "Isolation/HCal", STR_Calo = "Isolation/Calo", STR_User = "Isolation/User",
0258                            STR_User1 = "Isolation/User1", STR_User2 = "Isolation/User2", STR_User3 = "Isolation/User3",
0259                            STR_User4 = "Isolation/User4", STR_User5 = "Isolation/User5",
0260                            STR_Undefined = "Isolation/Undefined";
0261   switch (bit) {
0262     case All:
0263       return STR_All;
0264     case Tracker:
0265       return STR_Tracker;
0266     case ECal:
0267       return STR_ECal;
0268     case HCal:
0269       return STR_HCal;
0270     case Calo:
0271       return STR_Calo;
0272     case User:
0273       return STR_User;
0274     case User1:
0275       return STR_User1;
0276     case User2:
0277       return STR_User2;
0278     case User3:
0279       return STR_User3;
0280     case User4:
0281       return STR_User4;
0282     case User5:
0283       return STR_User5;
0284     default:
0285       return STR_Undefined;
0286   }
0287 }
0288 
0289 Flags::Isolation::Bits Flags::Isolation::get(const std::string &instr) {
0290   size_t idx = instr.find_first_of('/');
0291   const std::string &str = (idx == std::string::npos) ? instr : instr.substr(idx + 1);
0292   if (str == "All")
0293     return All;
0294   else if (str == "Tracker")
0295     return Tracker;
0296   else if (str == "ECal")
0297     return ECal;
0298   else if (str == "HCal")
0299     return HCal;
0300   else if (str == "Calo")
0301     return Calo;
0302   else if (str == "User")
0303     return User1;
0304   else if (str == "User1")
0305     return User1;
0306   else if (str == "User2")
0307     return User2;
0308   else if (str == "User3")
0309     return User3;
0310   else if (str == "User4")
0311     return User4;
0312   else if (str == "User5")
0313     return User5;
0314   return Undefined;
0315 }
0316 
0317 uint32_t Flags::Isolation::get(const std::vector<std::string> &strs) {
0318   uint32_t ret = 0;
0319   for (std::vector<std::string>::const_iterator it = strs.begin(), ed = strs.end(); it != ed; ++it) {
0320     ret |= get(*it);
0321   }
0322   return ret;
0323 }