CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TriggerKeyList.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1TObjects
4 // Class : L1TriggerKeyList
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author:
10 // Created: Fri Feb 29 21:00:24 CET 2008
11 // $Id: L1TriggerKeyList.cc,v 1.2 2008/10/09 19:02:22 wsun Exp $
12 //
13 
14 // system include files
15 
16 // user include files
18 
19 
20 //
21 // constants, enums and typedefs
22 //
23 
24 //
25 // static data member definitions
26 //
27 
28 //
29 // constructors and destructor
30 //
32 {
33 }
34 
35 // L1TriggerKeyList::L1TriggerKeyList(const L1TriggerKeyList& rhs)
36 // {
37 // // do actual copying here;
38 // }
39 
41 {
42 }
43 
44 //
45 // assignment operators
46 //
47 // const L1TriggerKeyList& L1TriggerKeyList::operator=(const L1TriggerKeyList& rhs)
48 // {
49 // //An exception safe implementation is
50 // L1TriggerKeyList temp(rhs);
51 // swap(rhs);
52 //
53 // return *this;
54 // }
55 
56 //
57 // member functions
58 //
59 
60 bool
62  const std::string& payloadToken,
63  bool overwriteKey )
64 {
65  std::pair< KeyToToken::iterator, bool > result =
66  m_tscKeyToToken.insert( std::make_pair( tscKey, payloadToken ) ) ;
67 
68  if( !result.second && overwriteKey )
69  {
70  // Erase previous entry
71  m_tscKeyToToken.erase( result.first ) ;
72 
73  // Try again
74  result = m_tscKeyToToken.insert( std::make_pair( tscKey,
75  payloadToken ) ) ;
76  }
77 
78  return result.second ;
79 }
80 
81 bool
83  const std::string& key,
84  const std::string& payloadToken,
85  bool overwriteKey )
86 {
87  RecordToKeyToToken::iterator it = m_recordKeyToken.find( recordType ) ;
88 
89  if( it == m_recordKeyToken.end() )
90  {
91  it = m_recordKeyToken.insert( std::make_pair( recordType,
92  KeyToToken() ) ).first ;
93  }
94 
95  std::pair< KeyToToken::iterator, bool > result =
96  it->second.insert( std::make_pair( key, payloadToken ) ) ;
97 
98  if( !result.second && overwriteKey )
99  {
100  // Erase previous entry
101  it->second.erase( result.first ) ;
102 
103  // Try again
104  result = it->second.insert( std::make_pair( key, payloadToken ) ) ;
105  }
106 
107  return result.second ;
108 }
109 
110 //
111 // const member functions
112 //
113 
115 L1TriggerKeyList::token( const std::string& tscKey ) const
116 {
117  KeyToToken::const_iterator it = m_tscKeyToToken.find( tscKey ) ;
118 
119  if( it == m_tscKeyToToken.end() )
120  {
121  return std::string() ;
122  }
123  else
124  {
125  return it->second;
126  }
127 }
128 
131  const std::string& dataType,
132  const std::string& key ) const
133 {
134  std::string recordType = recordName + "@" + dataType ;
135  return token( recordType, key ) ;
136 }
137 
140  const std::string& key ) const
141 {
142  RecordToKeyToToken::const_iterator it = m_recordKeyToken.find( recordType ) ;
143 
144  if( it == m_recordKeyToken.end() )
145  {
146  return std::string() ;
147  }
148  else
149  {
150  KeyToToken::const_iterator it2 = it->second.find( key ) ;
151 
152  if( it2 == it->second.end() )
153  {
154  return std::string() ;
155  }
156  else
157  {
158  return it2->second ;
159  }
160  }
161 }
162 
163 // std::string
164 // L1TriggerKeyList::objectKey( const std::string& recordName,
165 // const std::string& dataType,
166 // const std::string& payloadToken ) const
167 // {
168 // return objectKey( recordName + "@" + dataType,
169 // payloadToken ) ;
170 // }
171 
172 // std::string
173 // L1TriggerKeyList::objectKey( const std::string& recordType,// "record@type"
174 // const std::string& payloadToken ) const
175 // {
176 // RecordToKeyToToken::const_iterator keyTokenMap =
177 // m_recordKeyToken.find( recordType ) ;
178 
179 // if( keyTokenMap != m_recordKeyToken.end() )
180 // {
181 // // Find object key with matching payload token.
182 // KeyToToken::const_iterator iKey = keyTokenMap.second.begin();
183 // KeyToToken::const_iterator eKey = keyTokenMap.second.end() ;
184 // for( ; iKey != eKey ; ++iKey )
185 // {
186 // if( iKey->second == payloadToken )
187 // {
188 // return iKey->first ;
189 // }
190 // }
191 // }
192 
193 // return std::string() ;
194 // }
195 
198  const std::string& payloadToken ) const
199 {
200  RecordToKeyToToken::const_iterator iRecordType = m_recordKeyToken.begin() ;
201  for( ; iRecordType != m_recordKeyToken.end() ; ++iRecordType )
202  {
203  // Extract record name from recordType
204  std::string recordInMap( iRecordType->first, 0,
205  iRecordType->first.find_first_of("@") ) ;
206  if( recordInMap == recordName )
207  {
208  // Find object key with matching payload token.
209  KeyToToken::const_iterator iKey = iRecordType->second.begin();
210  KeyToToken::const_iterator eKey = iRecordType->second.end() ;
211  for( ; iKey != eKey ; ++iKey )
212  {
213  if( iKey->second == payloadToken )
214  {
215  return iKey->first ;
216  }
217  }
218  }
219  }
220 
221  return std::string() ;
222 }
223 
225 L1TriggerKeyList::tscKey( const std::string& triggerKeyPayloadToken ) const
226 {
227  // Find object key with matching payload token.
228  KeyToToken::const_iterator iKey = m_tscKeyToToken.begin();
229  KeyToToken::const_iterator eKey = m_tscKeyToToken.end() ;
230  for( ; iKey != eKey ; ++iKey )
231  {
232  if( iKey->second == triggerKeyPayloadToken )
233  {
234  return iKey->first ;
235  }
236  }
237 
238  return std::string() ;
239 }
240 
241 //
242 // static member functions
243 //
RecordToKeyToToken m_recordKeyToken
std::map< std::string, std::string > KeyToToken
KeyToToken m_tscKeyToToken
tuple recordName
Definition: align_cfg.py:66
tuple result
Definition: mps_fire.py:95
std::string tscKey(const std::string &triggerKeyPayloadToken) const
std::string objectKey(const std::string &recordName, const std::string &payloadToken) const
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
virtual ~L1TriggerKeyList()
std::string token(const std::string &tscKey) const
bool addKey(const std::string &tscKey, const std::string &payloadToken, bool overwriteKey=false)