Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:21

0001 #include "CondFormats/L1TObjects/interface/L1TriggerKeyListExt.h"
0002 
0003 L1TriggerKeyListExt::L1TriggerKeyListExt() {}
0004 
0005 // L1TriggerKeyListExt::L1TriggerKeyListExt(const L1TriggerKeyListExt& rhs)
0006 // {
0007 //    // do actual copying here;
0008 // }
0009 
0010 L1TriggerKeyListExt::~L1TriggerKeyListExt() {}
0011 
0012 //
0013 // assignment operators
0014 //
0015 // const L1TriggerKeyListExt& L1TriggerKeyListExt::operator=(const L1TriggerKeyListExt& rhs)
0016 // {
0017 //   //An exception safe implementation is
0018 //   L1TriggerKeyListExt temp(rhs);
0019 //   swap(rhs);
0020 //
0021 //   return *this;
0022 // }
0023 
0024 //
0025 // member functions
0026 //
0027 
0028 bool L1TriggerKeyListExt::addKey(const std::string& tscKey, const std::string& payloadToken, bool overwriteKey) {
0029   std::pair<KeyToToken::iterator, bool> result = m_tscKeyToToken.insert(std::make_pair(tscKey, payloadToken));
0030 
0031   if (!result.second && overwriteKey) {
0032     // Erase previous entry
0033     m_tscKeyToToken.erase(result.first);
0034 
0035     // Try again
0036     result = m_tscKeyToToken.insert(std::make_pair(tscKey, payloadToken));
0037   }
0038 
0039   return result.second;
0040 }
0041 
0042 bool L1TriggerKeyListExt::addKey(const std::string& recordType,
0043                                  const std::string& key,
0044                                  const std::string& payloadToken,
0045                                  bool overwriteKey) {
0046   RecordToKeyToToken::iterator it = m_recordKeyToken.find(recordType);
0047 
0048   if (it == m_recordKeyToken.end()) {
0049     it = m_recordKeyToken.insert(std::make_pair(recordType, KeyToToken())).first;
0050   }
0051 
0052   std::pair<KeyToToken::iterator, bool> result = it->second.insert(std::make_pair(key, payloadToken));
0053 
0054   if (!result.second && overwriteKey) {
0055     // Erase previous entry
0056     it->second.erase(result.first);
0057 
0058     // Try again
0059     result = it->second.insert(std::make_pair(key, payloadToken));
0060   }
0061 
0062   return result.second;
0063 }
0064 
0065 //
0066 // const member functions
0067 //
0068 
0069 std::string L1TriggerKeyListExt::token(const std::string& tscKey) const {
0070   KeyToToken::const_iterator it = m_tscKeyToToken.find(tscKey);
0071 
0072   if (it == m_tscKeyToToken.end()) {
0073     return std::string();
0074   } else {
0075     return it->second;
0076   }
0077 }
0078 
0079 std::string L1TriggerKeyListExt::token(const std::string& recordName,
0080                                        const std::string& dataType,
0081                                        const std::string& key) const {
0082   std::string recordType = recordName + "@" + dataType;
0083   return token(recordType, key);
0084 }
0085 
0086 std::string L1TriggerKeyListExt::token(const std::string& recordType, const std::string& key) const {
0087   RecordToKeyToToken::const_iterator it = m_recordKeyToken.find(recordType);
0088 
0089   if (it == m_recordKeyToken.end()) {
0090     return std::string();
0091   } else {
0092     KeyToToken::const_iterator it2 = it->second.find(key);
0093 
0094     if (it2 == it->second.end()) {
0095       return std::string();
0096     } else {
0097       return it2->second;
0098     }
0099   }
0100 }
0101 
0102 // std::string
0103 // L1TriggerKeyListExt::objectKey( const std::string& recordName,
0104 //               const std::string& dataType,
0105 //               const std::string& payloadToken ) const
0106 // {
0107 //   return objectKey( recordName + "@" + dataType,
0108 //          payloadToken ) ;
0109 // }
0110 
0111 // std::string
0112 // L1TriggerKeyListExt::objectKey( const std::string& recordType,// "record@type"
0113 //               const std::string& payloadToken ) const
0114 // {
0115 //   RecordToKeyToToken::const_iterator keyTokenMap =
0116 //     m_recordKeyToken.find( recordType ) ;
0117 
0118 //   if( keyTokenMap != m_recordKeyToken.end() )
0119 //     {
0120 //       // Find object key with matching payload token.
0121 //       KeyToToken::const_iterator iKey = keyTokenMap.second.begin();
0122 //       KeyToToken::const_iterator eKey = keyTokenMap.second.end() ;
0123 //       for( ; iKey != eKey ; ++iKey )
0124 //  {
0125 //    if( iKey->second == payloadToken )
0126 //      {
0127 //        return iKey->first ;
0128 //      }
0129 //  }
0130 //     }
0131 
0132 //   return std::string() ;
0133 // }
0134 
0135 std::string L1TriggerKeyListExt::objectKey(const std::string& recordName, const std::string& payloadToken) const {
0136   RecordToKeyToToken::const_iterator iRecordType = m_recordKeyToken.begin();
0137   for (; iRecordType != m_recordKeyToken.end(); ++iRecordType) {
0138     // Extract record name from recordType
0139     std::string recordInMap(iRecordType->first, 0, iRecordType->first.find_first_of("@"));
0140     if (recordInMap == recordName) {
0141       // Find object key with matching payload token.
0142       KeyToToken::const_iterator iKey = iRecordType->second.begin();
0143       KeyToToken::const_iterator eKey = iRecordType->second.end();
0144       for (; iKey != eKey; ++iKey) {
0145         if (iKey->second == payloadToken) {
0146           return iKey->first;
0147         }
0148       }
0149     }
0150   }
0151 
0152   return std::string();
0153 }
0154 
0155 std::string L1TriggerKeyListExt::tscKey(const std::string& triggerKeyPayloadToken) const {
0156   // Find object key with matching payload token.
0157   KeyToToken::const_iterator iKey = m_tscKeyToToken.begin();
0158   KeyToToken::const_iterator eKey = m_tscKeyToToken.end();
0159   for (; iKey != eKey; ++iKey) {
0160     if (iKey->second == triggerKeyPayloadToken) {
0161       return iKey->first;
0162     }
0163   }
0164 
0165   return std::string();
0166 }
0167 
0168 //
0169 // static member functions
0170 //