CMS 3D CMS Logo

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 // constants, enums and typedefs
21 //
22 
23 //
24 // static data member definitions
25 //
26 
27 //
28 // constructors and destructor
29 //
31 
32 // L1TriggerKeyList::L1TriggerKeyList(const L1TriggerKeyList& rhs)
33 // {
34 // // do actual copying here;
35 // }
36 
38 
39 //
40 // assignment operators
41 //
42 // const L1TriggerKeyList& L1TriggerKeyList::operator=(const L1TriggerKeyList& rhs)
43 // {
44 // //An exception safe implementation is
45 // L1TriggerKeyList temp(rhs);
46 // swap(rhs);
47 //
48 // return *this;
49 // }
50 
51 //
52 // member functions
53 //
54 
55 bool L1TriggerKeyList::addKey(const std::string& tscKey, const std::string& payloadToken, bool overwriteKey) {
56  std::pair<KeyToToken::iterator, bool> result = m_tscKeyToToken.insert(std::make_pair(tscKey, payloadToken));
57 
58  if (!result.second && overwriteKey) {
59  // Erase previous entry
60  m_tscKeyToToken.erase(result.first);
61 
62  // Try again
63  result = m_tscKeyToToken.insert(std::make_pair(tscKey, payloadToken));
64  }
65 
66  return result.second;
67 }
68 
69 bool L1TriggerKeyList::addKey(const std::string& recordType,
70  const std::string& key,
71  const std::string& payloadToken,
72  bool overwriteKey) {
73  RecordToKeyToToken::iterator it = m_recordKeyToken.find(recordType);
74 
75  if (it == m_recordKeyToken.end()) {
76  it = m_recordKeyToken.insert(std::make_pair(recordType, KeyToToken())).first;
77  }
78 
79  std::pair<KeyToToken::iterator, bool> result = it->second.insert(std::make_pair(key, payloadToken));
80 
81  if (!result.second && overwriteKey) {
82  // Erase previous entry
83  it->second.erase(result.first);
84 
85  // Try again
86  result = it->second.insert(std::make_pair(key, payloadToken));
87  }
88 
89  return result.second;
90 }
91 
92 //
93 // const member functions
94 //
95 
97  KeyToToken::const_iterator it = m_tscKeyToToken.find(tscKey);
98 
99  if (it == m_tscKeyToToken.end()) {
100  return std::string();
101  } else {
102  return it->second;
103  }
104 }
105 
107  const std::string& dataType,
108  const std::string& key) const {
109  std::string recordType = recordName + "@" + dataType;
110  return token(recordType, key);
111 }
112 
114  RecordToKeyToToken::const_iterator it = m_recordKeyToken.find(recordType);
115 
116  if (it == m_recordKeyToken.end()) {
117  return std::string();
118  } else {
119  KeyToToken::const_iterator it2 = it->second.find(key);
120 
121  if (it2 == it->second.end()) {
122  return std::string();
123  } else {
124  return it2->second;
125  }
126  }
127 }
128 
129 // std::string
130 // L1TriggerKeyList::objectKey( const std::string& recordName,
131 // const std::string& dataType,
132 // const std::string& payloadToken ) const
133 // {
134 // return objectKey( recordName + "@" + dataType,
135 // payloadToken ) ;
136 // }
137 
138 // std::string
139 // L1TriggerKeyList::objectKey( const std::string& recordType,// "record@type"
140 // const std::string& payloadToken ) const
141 // {
142 // RecordToKeyToToken::const_iterator keyTokenMap =
143 // m_recordKeyToken.find( recordType ) ;
144 
145 // if( keyTokenMap != m_recordKeyToken.end() )
146 // {
147 // // Find object key with matching payload token.
148 // KeyToToken::const_iterator iKey = keyTokenMap.second.begin();
149 // KeyToToken::const_iterator eKey = keyTokenMap.second.end() ;
150 // for( ; iKey != eKey ; ++iKey )
151 // {
152 // if( iKey->second == payloadToken )
153 // {
154 // return iKey->first ;
155 // }
156 // }
157 // }
158 
159 // return std::string() ;
160 // }
161 
163  RecordToKeyToToken::const_iterator iRecordType = m_recordKeyToken.begin();
164  for (; iRecordType != m_recordKeyToken.end(); ++iRecordType) {
165  // Extract record name from recordType
166  std::string recordInMap(iRecordType->first, 0, iRecordType->first.find_first_of("@"));
167  if (recordInMap == recordName) {
168  // Find object key with matching payload token.
169  KeyToToken::const_iterator iKey = iRecordType->second.begin();
170  KeyToToken::const_iterator eKey = iRecordType->second.end();
171  for (; iKey != eKey; ++iKey) {
172  if (iKey->second == payloadToken) {
173  return iKey->first;
174  }
175  }
176  }
177  }
178 
179  return std::string();
180 }
181 
182 std::string L1TriggerKeyList::tscKey(const std::string& triggerKeyPayloadToken) const {
183  // Find object key with matching payload token.
184  KeyToToken::const_iterator iKey = m_tscKeyToToken.begin();
185  KeyToToken::const_iterator eKey = m_tscKeyToToken.end();
186  for (; iKey != eKey; ++iKey) {
187  if (iKey->second == triggerKeyPayloadToken) {
188  return iKey->first;
189  }
190  }
191 
192  return std::string();
193 }
194 
195 //
196 // static member functions
197 //
RecordToKeyToToken m_recordKeyToken
KeyToToken m_tscKeyToToken
std::map< std::string, std::string > KeyToToken
std::string token(const std::string &tscKey) const
key
prepare the HTCondor submission files and eventually submit them
std::string objectKey(const std::string &recordName, const std::string &payloadToken) const
virtual ~L1TriggerKeyList()
std::string tscKey(const std::string &triggerKeyPayloadToken) const
bool addKey(const std::string &tscKey, const std::string &payloadToken, bool overwriteKey=false)