CMS 3D CMS Logo

L1TriggerKeyListExt.cc
Go to the documentation of this file.
2 
4 {
5 }
6 
7 // L1TriggerKeyListExt::L1TriggerKeyListExt(const L1TriggerKeyListExt& rhs)
8 // {
9 // // do actual copying here;
10 // }
11 
13 {
14 }
15 
16 //
17 // assignment operators
18 //
19 // const L1TriggerKeyListExt& L1TriggerKeyListExt::operator=(const L1TriggerKeyListExt& rhs)
20 // {
21 // //An exception safe implementation is
22 // L1TriggerKeyListExt temp(rhs);
23 // swap(rhs);
24 //
25 // return *this;
26 // }
27 
28 //
29 // member functions
30 //
31 
32 bool
34  const std::string& payloadToken,
35  bool overwriteKey )
36 {
37  std::pair< KeyToToken::iterator, bool > result =
38  m_tscKeyToToken.insert( std::make_pair( tscKey, payloadToken ) ) ;
39 
40  if( !result.second && overwriteKey )
41  {
42  // Erase previous entry
43  m_tscKeyToToken.erase( result.first ) ;
44 
45  // Try again
46  result = m_tscKeyToToken.insert( std::make_pair( tscKey,
47  payloadToken ) ) ;
48  }
49 
50  return result.second ;
51 }
52 
53 bool
55  const std::string& key,
56  const std::string& payloadToken,
57  bool overwriteKey )
58 {
59  RecordToKeyToToken::iterator it = m_recordKeyToken.find( recordType ) ;
60 
61  if( it == m_recordKeyToken.end() )
62  {
63  it = m_recordKeyToken.insert( std::make_pair( recordType,
64  KeyToToken() ) ).first ;
65  }
66 
67  std::pair< KeyToToken::iterator, bool > result =
68  it->second.insert( std::make_pair( key, payloadToken ) ) ;
69 
70  if( !result.second && overwriteKey )
71  {
72  // Erase previous entry
73  it->second.erase( result.first ) ;
74 
75  // Try again
76  result = it->second.insert( std::make_pair( key, payloadToken ) ) ;
77  }
78 
79  return result.second ;
80 }
81 
82 //
83 // const member functions
84 //
85 
88 {
89  KeyToToken::const_iterator it = m_tscKeyToToken.find( tscKey ) ;
90 
91  if( it == m_tscKeyToToken.end() )
92  {
93  return std::string() ;
94  }
95  else
96  {
97  return it->second;
98  }
99 }
100 
103  const std::string& dataType,
104  const std::string& key ) const
105 {
106  std::string recordType = recordName + "@" + dataType ;
107  return token( recordType, key ) ;
108 }
109 
112  const std::string& key ) const
113 {
114  RecordToKeyToToken::const_iterator it = m_recordKeyToken.find( recordType ) ;
115 
116  if( it == m_recordKeyToken.end() )
117  {
118  return std::string() ;
119  }
120  else
121  {
122  KeyToToken::const_iterator it2 = it->second.find( key ) ;
123 
124  if( it2 == it->second.end() )
125  {
126  return std::string() ;
127  }
128  else
129  {
130  return it2->second ;
131  }
132  }
133 }
134 
135 // std::string
136 // L1TriggerKeyListExt::objectKey( const std::string& recordName,
137 // const std::string& dataType,
138 // const std::string& payloadToken ) const
139 // {
140 // return objectKey( recordName + "@" + dataType,
141 // payloadToken ) ;
142 // }
143 
144 // std::string
145 // L1TriggerKeyListExt::objectKey( const std::string& recordType,// "record@type"
146 // const std::string& payloadToken ) const
147 // {
148 // RecordToKeyToToken::const_iterator keyTokenMap =
149 // m_recordKeyToken.find( recordType ) ;
150 
151 // if( keyTokenMap != m_recordKeyToken.end() )
152 // {
153 // // Find object key with matching payload token.
154 // KeyToToken::const_iterator iKey = keyTokenMap.second.begin();
155 // KeyToToken::const_iterator eKey = keyTokenMap.second.end() ;
156 // for( ; iKey != eKey ; ++iKey )
157 // {
158 // if( iKey->second == payloadToken )
159 // {
160 // return iKey->first ;
161 // }
162 // }
163 // }
164 
165 // return std::string() ;
166 // }
167 
170  const std::string& payloadToken ) const
171 {
172  RecordToKeyToToken::const_iterator iRecordType = m_recordKeyToken.begin() ;
173  for( ; iRecordType != m_recordKeyToken.end() ; ++iRecordType )
174  {
175  // Extract record name from recordType
176  std::string recordInMap( iRecordType->first, 0,
177  iRecordType->first.find_first_of("@") ) ;
178  if( recordInMap == recordName )
179  {
180  // Find object key with matching payload token.
181  KeyToToken::const_iterator iKey = iRecordType->second.begin();
182  KeyToToken::const_iterator eKey = iRecordType->second.end() ;
183  for( ; iKey != eKey ; ++iKey )
184  {
185  if( iKey->second == payloadToken )
186  {
187  return iKey->first ;
188  }
189  }
190  }
191  }
192 
193  return std::string() ;
194 }
195 
197 L1TriggerKeyListExt::tscKey( const std::string& triggerKeyPayloadToken ) const
198 {
199  // Find object key with matching payload token.
200  KeyToToken::const_iterator iKey = m_tscKeyToToken.begin();
201  KeyToToken::const_iterator eKey = m_tscKeyToToken.end() ;
202  for( ; iKey != eKey ; ++iKey )
203  {
204  if( iKey->second == triggerKeyPayloadToken )
205  {
206  return iKey->first ;
207  }
208  }
209 
210  return std::string() ;
211 }
212 
213 //
214 // static member functions
215 //
RecordToKeyToToken m_recordKeyToken
std::map< std::string, std::string > KeyToToken
std::string tscKey(const std::string &triggerKeyPayloadToken) const
std::string objectKey(const std::string &recordName, const std::string &payloadToken) const
bool addKey(const std::string &tscKey, const std::string &payloadToken, bool overwriteKey=false)
std::string token(const std::string &tscKey) const