CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/CondFormats/L1TObjects/src/L1TriggerKeyList.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     L1TObjects
00004 // Class  :     L1TriggerKeyList
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  
00010 //         Created:  Fri Feb 29 21:00:24 CET 2008
00011 // $Id: L1TriggerKeyList.cc,v 1.3 2009/04/06 01:58:49 wsun Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include "CondFormats/L1TObjects/interface/L1TriggerKeyList.h"
00018 
00019 
00020 //
00021 // constants, enums and typedefs
00022 //
00023 
00024 //
00025 // static data member definitions
00026 //
00027 
00028 //
00029 // constructors and destructor
00030 //
00031 L1TriggerKeyList::L1TriggerKeyList()
00032 {
00033 }
00034 
00035 // L1TriggerKeyList::L1TriggerKeyList(const L1TriggerKeyList& rhs)
00036 // {
00037 //    // do actual copying here;
00038 // }
00039 
00040 L1TriggerKeyList::~L1TriggerKeyList()
00041 {
00042 }
00043 
00044 //
00045 // assignment operators
00046 //
00047 // const L1TriggerKeyList& L1TriggerKeyList::operator=(const L1TriggerKeyList& rhs)
00048 // {
00049 //   //An exception safe implementation is
00050 //   L1TriggerKeyList temp(rhs);
00051 //   swap(rhs);
00052 //
00053 //   return *this;
00054 // }
00055 
00056 //
00057 // member functions
00058 //
00059 
00060 bool
00061 L1TriggerKeyList::addKey( const std::string& tscKey,
00062                           const std::string& payloadToken,
00063                           bool overwriteKey )
00064 {
00065   std::pair< KeyToToken::iterator, bool > result =
00066     m_tscKeyToToken.insert( std::make_pair( tscKey, payloadToken ) ) ;
00067 
00068   if( !result.second && overwriteKey )
00069     {
00070       // Erase previous entry
00071       m_tscKeyToToken.erase( result.first ) ;
00072 
00073       // Try again
00074       result = m_tscKeyToToken.insert( std::make_pair( tscKey,
00075                                                        payloadToken ) ) ;
00076     }
00077 
00078   return result.second ;
00079 }
00080 
00081 bool
00082 L1TriggerKeyList::addKey( const std::string& recordType,
00083                           const std::string& key,
00084                           const std::string& payloadToken,
00085                           bool overwriteKey )
00086 {
00087   RecordToKeyToToken::iterator it = m_recordKeyToken.find( recordType ) ;
00088 
00089   if( it == m_recordKeyToken.end() )
00090     {
00091       it = m_recordKeyToken.insert( std::make_pair( recordType,
00092                                                     KeyToToken() ) ).first ;
00093     } 
00094 
00095   std::pair< KeyToToken::iterator, bool > result =
00096     it->second.insert( std::make_pair( key, payloadToken ) ) ;
00097 
00098   if( !result.second && overwriteKey )
00099     {
00100       // Erase previous entry
00101       it->second.erase( result.first ) ;
00102 
00103       // Try again
00104       result = it->second.insert( std::make_pair( key, payloadToken ) ) ;
00105     }
00106 
00107   return result.second ;
00108 }
00109 
00110 //
00111 // const member functions
00112 //
00113 
00114 std::string
00115 L1TriggerKeyList::token( const std::string& tscKey ) const
00116 {
00117   KeyToToken::const_iterator it = m_tscKeyToToken.find( tscKey ) ;
00118 
00119   if( it == m_tscKeyToToken.end() )
00120     {
00121       return std::string() ;
00122     }
00123   else
00124     {
00125       return it->second;
00126     }
00127 }
00128 
00129 std::string
00130 L1TriggerKeyList::token( const std::string& recordName,
00131                          const std::string& dataType,
00132                          const std::string& key ) const
00133 {
00134   std::string recordType = recordName + "@" + dataType ;
00135   return token( recordType, key ) ;
00136 }
00137 
00138 std::string
00139 L1TriggerKeyList::token( const std::string& recordType,
00140                          const std::string& key ) const
00141 {
00142   RecordToKeyToToken::const_iterator it = m_recordKeyToken.find( recordType ) ;
00143 
00144   if( it == m_recordKeyToken.end() )
00145     {
00146       return std::string() ;
00147     } 
00148   else
00149     {
00150       KeyToToken::const_iterator it2 = it->second.find( key ) ;
00151 
00152       if( it2 == it->second.end() )
00153         {
00154           return std::string() ;
00155         }
00156       else
00157         {
00158           return it2->second ;
00159         }
00160     }
00161 }
00162 
00163 // std::string
00164 // L1TriggerKeyList::objectKey( const std::string& recordName,
00165 //                           const std::string& dataType,
00166 //                           const std::string& payloadToken ) const
00167 // {
00168 //   return objectKey( recordName + "@" + dataType,
00169 //                  payloadToken ) ;
00170 // }
00171 
00172 // std::string
00173 // L1TriggerKeyList::objectKey( const std::string& recordType,// "record@type"
00174 //                           const std::string& payloadToken ) const
00175 // {
00176 //   RecordToKeyToToken::const_iterator keyTokenMap =
00177 //     m_recordKeyToken.find( recordType ) ;
00178 
00179 //   if( keyTokenMap != m_recordKeyToken.end() )
00180 //     {
00181 //       // Find object key with matching payload token.
00182 //       KeyToToken::const_iterator iKey = keyTokenMap.second.begin();
00183 //       KeyToToken::const_iterator eKey = keyTokenMap.second.end() ;
00184 //       for( ; iKey != eKey ; ++iKey )
00185 //      {
00186 //        if( iKey->second == payloadToken )
00187 //          {
00188 //            return iKey->first ;
00189 //          }
00190 //      }
00191 //     }
00192 
00193 //   return std::string() ;
00194 // }
00195 
00196 std::string
00197 L1TriggerKeyList::objectKey( const std::string& recordName,
00198                              const std::string& payloadToken ) const
00199 {
00200   RecordToKeyToToken::const_iterator iRecordType = m_recordKeyToken.begin() ;
00201   for( ; iRecordType != m_recordKeyToken.end() ; ++iRecordType )
00202     {
00203       // Extract record name from recordType
00204       std::string recordInMap( iRecordType->first, 0,
00205                                iRecordType->first.find_first_of("@") ) ;
00206       if( recordInMap == recordName )
00207         {
00208           // Find object key with matching payload token.
00209           KeyToToken::const_iterator iKey = iRecordType->second.begin();
00210           KeyToToken::const_iterator eKey = iRecordType->second.end() ;
00211           for( ; iKey != eKey ; ++iKey )
00212             {
00213               if( iKey->second == payloadToken )
00214                 {
00215                   return iKey->first ;
00216                 }
00217             }
00218         }
00219     }
00220 
00221   return std::string() ;
00222 }
00223 
00224 std::string
00225 L1TriggerKeyList::tscKey( const std::string& triggerKeyPayloadToken ) const
00226 {
00227   // Find object key with matching payload token.
00228   KeyToToken::const_iterator iKey = m_tscKeyToToken.begin();
00229   KeyToToken::const_iterator eKey = m_tscKeyToToken.end() ;
00230   for( ; iKey != eKey ; ++iKey )
00231     {
00232       if( iKey->second == triggerKeyPayloadToken )
00233         {
00234           return iKey->first ;
00235         }
00236     }
00237 
00238   return std::string() ;
00239 }
00240 
00241 //
00242 // static member functions
00243 //