Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:     L1TObjects
0004 // Class  :     L1TriggerKeyList
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:
0010 //         Created:  Fri Feb 29 21:00:24 CET 2008
0011 // $Id: L1TriggerKeyList.cc,v 1.2 2008/10/09 19:02:22 wsun Exp $
0012 //
0013 
0014 // system include files
0015 
0016 // user include files
0017 #include "CondFormats/L1TObjects/interface/L1TriggerKeyList.h"
0018 
0019 //
0020 // constants, enums and typedefs
0021 //
0022 
0023 //
0024 // static data member definitions
0025 //
0026 
0027 //
0028 // constructors and destructor
0029 //
0030 L1TriggerKeyList::L1TriggerKeyList() {}
0031 
0032 // L1TriggerKeyList::L1TriggerKeyList(const L1TriggerKeyList& rhs)
0033 // {
0034 //    // do actual copying here;
0035 // }
0036 
0037 L1TriggerKeyList::~L1TriggerKeyList() {}
0038 
0039 //
0040 // assignment operators
0041 //
0042 // const L1TriggerKeyList& L1TriggerKeyList::operator=(const L1TriggerKeyList& rhs)
0043 // {
0044 //   //An exception safe implementation is
0045 //   L1TriggerKeyList temp(rhs);
0046 //   swap(rhs);
0047 //
0048 //   return *this;
0049 // }
0050 
0051 //
0052 // member functions
0053 //
0054 
0055 bool L1TriggerKeyList::addKey(const std::string& tscKey, const std::string& payloadToken, bool overwriteKey) {
0056   std::pair<KeyToToken::iterator, bool> result = m_tscKeyToToken.insert(std::make_pair(tscKey, payloadToken));
0057 
0058   if (!result.second && overwriteKey) {
0059     // Erase previous entry
0060     m_tscKeyToToken.erase(result.first);
0061 
0062     // Try again
0063     result = m_tscKeyToToken.insert(std::make_pair(tscKey, payloadToken));
0064   }
0065 
0066   return result.second;
0067 }
0068 
0069 bool L1TriggerKeyList::addKey(const std::string& recordType,
0070                               const std::string& key,
0071                               const std::string& payloadToken,
0072                               bool overwriteKey) {
0073   RecordToKeyToToken::iterator it = m_recordKeyToken.find(recordType);
0074 
0075   if (it == m_recordKeyToken.end()) {
0076     it = m_recordKeyToken.insert(std::make_pair(recordType, KeyToToken())).first;
0077   }
0078 
0079   std::pair<KeyToToken::iterator, bool> result = it->second.insert(std::make_pair(key, payloadToken));
0080 
0081   if (!result.second && overwriteKey) {
0082     // Erase previous entry
0083     it->second.erase(result.first);
0084 
0085     // Try again
0086     result = it->second.insert(std::make_pair(key, payloadToken));
0087   }
0088 
0089   return result.second;
0090 }
0091 
0092 //
0093 // const member functions
0094 //
0095 
0096 std::string L1TriggerKeyList::token(const std::string& tscKey) const {
0097   KeyToToken::const_iterator it = m_tscKeyToToken.find(tscKey);
0098 
0099   if (it == m_tscKeyToToken.end()) {
0100     return std::string();
0101   } else {
0102     return it->second;
0103   }
0104 }
0105 
0106 std::string L1TriggerKeyList::token(const std::string& recordName,
0107                                     const std::string& dataType,
0108                                     const std::string& key) const {
0109   std::string recordType = recordName + "@" + dataType;
0110   return token(recordType, key);
0111 }
0112 
0113 std::string L1TriggerKeyList::token(const std::string& recordType, const std::string& key) const {
0114   RecordToKeyToToken::const_iterator it = m_recordKeyToken.find(recordType);
0115 
0116   if (it == m_recordKeyToken.end()) {
0117     return std::string();
0118   } else {
0119     KeyToToken::const_iterator it2 = it->second.find(key);
0120 
0121     if (it2 == it->second.end()) {
0122       return std::string();
0123     } else {
0124       return it2->second;
0125     }
0126   }
0127 }
0128 
0129 // std::string
0130 // L1TriggerKeyList::objectKey( const std::string& recordName,
0131 //               const std::string& dataType,
0132 //               const std::string& payloadToken ) const
0133 // {
0134 //   return objectKey( recordName + "@" + dataType,
0135 //          payloadToken ) ;
0136 // }
0137 
0138 // std::string
0139 // L1TriggerKeyList::objectKey( const std::string& recordType,// "record@type"
0140 //               const std::string& payloadToken ) const
0141 // {
0142 //   RecordToKeyToToken::const_iterator keyTokenMap =
0143 //     m_recordKeyToken.find( recordType ) ;
0144 
0145 //   if( keyTokenMap != m_recordKeyToken.end() )
0146 //     {
0147 //       // Find object key with matching payload token.
0148 //       KeyToToken::const_iterator iKey = keyTokenMap.second.begin();
0149 //       KeyToToken::const_iterator eKey = keyTokenMap.second.end() ;
0150 //       for( ; iKey != eKey ; ++iKey )
0151 //  {
0152 //    if( iKey->second == payloadToken )
0153 //      {
0154 //        return iKey->first ;
0155 //      }
0156 //  }
0157 //     }
0158 
0159 //   return std::string() ;
0160 // }
0161 
0162 std::string L1TriggerKeyList::objectKey(const std::string& recordName, const std::string& payloadToken) const {
0163   RecordToKeyToToken::const_iterator iRecordType = m_recordKeyToken.begin();
0164   for (; iRecordType != m_recordKeyToken.end(); ++iRecordType) {
0165     // Extract record name from recordType
0166     std::string recordInMap(iRecordType->first, 0, iRecordType->first.find_first_of("@"));
0167     if (recordInMap == recordName) {
0168       // Find object key with matching payload token.
0169       KeyToToken::const_iterator iKey = iRecordType->second.begin();
0170       KeyToToken::const_iterator eKey = iRecordType->second.end();
0171       for (; iKey != eKey; ++iKey) {
0172         if (iKey->second == payloadToken) {
0173           return iKey->first;
0174         }
0175       }
0176     }
0177   }
0178 
0179   return std::string();
0180 }
0181 
0182 std::string L1TriggerKeyList::tscKey(const std::string& triggerKeyPayloadToken) const {
0183   // Find object key with matching payload token.
0184   KeyToToken::const_iterator iKey = m_tscKeyToToken.begin();
0185   KeyToToken::const_iterator eKey = m_tscKeyToToken.end();
0186   for (; iKey != eKey; ++iKey) {
0187     if (iKey->second == triggerKeyPayloadToken) {
0188       return iKey->first;
0189     }
0190   }
0191 
0192   return std::string();
0193 }
0194 
0195 //
0196 // static member functions
0197 //