CMS 3D CMS Logo

ESProductResolverProvider.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Framework
4 // Class : ESProductResolverProvider
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Author: Chris Jones
10 // Created: Mon Mar 28 15:07:54 EST 2005
11 //
12 
13 // system include files
14 #include <algorithm>
15 #include <cassert>
16 #include <cstring>
17 #include <limits>
18 
19 // user include files
25 
27 
28 namespace edm {
29  namespace eventsetup {
30 
32 
34 
36  unsigned int recordIndex)
37  : productResolverContainer_(productResolverContainer),
38  recordIndex_(recordIndex),
39  productResolversIndex_(kInvalidIndex) {}
40 
42  return productResolversIndex_ == kInvalidIndex;
43  }
44 
46  return productResolverContainer_->perRecordInfos_[recordIndex_].recordKey_;
47  }
48 
50  std::vector<std::pair<DataKey, std::shared_ptr<ESProductResolver>>>&& proxies,
52  PerRecordInfo& perRecordInfo = productResolverContainer_->perRecordInfos_[recordIndex_];
53  if (perRecordInfo.indexToDataKeys_ == kInvalidIndex) {
54  perRecordInfo.nDataKeys_ = proxies.size();
56  for (auto const& it : proxies) {
57  productResolverContainer_->dataKeys_.push_back(it.first);
58  }
59  } else {
60  assert(perRecordInfo.nDataKeys_ == proxies.size());
61  unsigned index = 0;
62  for (auto const& it : proxies) {
63  if (appendToDataLabel.empty()) {
65  } else {
66  assert(it.first.type() ==
68  auto lengthDataLabel = std::strlen(it.first.name().value());
69  assert(std::strncmp(
70  it.first.name().value(),
71  productResolverContainer_->dataKeys_[perRecordInfo.indexToDataKeys_ + index].name().value(),
72  lengthDataLabel) == 0);
73  }
74  ++index;
75  }
76  }
77  assert(unInitialized());
78  productResolversIndex_ = productResolverContainer_->productResolvers_.size();
79  for (auto const& it : proxies) {
80  productResolverContainer_->productResolvers_.emplace_back(it.second);
81  }
82  }
83 
85  PerRecordInfo const& perRecordInfo = productResolverContainer_->perRecordInfos_[recordIndex_];
86  auto iter = productResolverContainer_->dataKeys_.begin() + perRecordInfo.indexToDataKeys_;
87  auto iterEnd = iter + perRecordInfo.nDataKeys_;
88  for (; iter != iterEnd; ++iter) {
89  if (*iter == dataKey) {
90  return true;
91  }
92  }
93  return false;
94  }
95 
97  return productResolverContainer_->perRecordInfos_[recordIndex_].nDataKeys_;
98  }
99 
102  ++dataKeysIter_;
103  ++productResolversIter_;
104  return *this;
105  }
106 
108  std::vector<DataKey>::iterator dataKeysIter,
109  std::vector<edm::propagate_const<std::shared_ptr<ESProductResolver>>>::iterator productResolversIter)
110  : dataKeysIter_(dataKeysIter), productResolversIter_(productResolversIter) {}
111 
113  return Iterator(productResolverContainer_->dataKeys_.begin() +
114  productResolverContainer_->perRecordInfos_[recordIndex_].indexToDataKeys_,
115  productResolverContainer_->productResolvers_.begin() + productResolversIndex_);
116  }
117 
119  unsigned int nDataKeys = productResolverContainer_->perRecordInfos_[recordIndex_].nDataKeys_;
120  return Iterator(productResolverContainer_->dataKeys_.begin() +
121  productResolverContainer_->perRecordInfos_[recordIndex_].indexToDataKeys_ + nDataKeys,
122  productResolverContainer_->productResolvers_.begin() + productResolversIndex_ + nDataKeys);
123  }
124 
126  : recordKey_(key), indexToDataKeys_(kInvalidIndex) {}
127 
129  assert(keyedResolversCollection_.empty());
130  perRecordInfos_.emplace_back(iKey);
131  }
132 
134  auto lb = std::lower_bound(perRecordInfos_.begin(), perRecordInfos_.end(), PerRecordInfo(iKey));
135  return (lb != perRecordInfos_.end() && iKey == lb->recordKey_);
136  }
137 
139  std::set<EventSetupRecordKey> returnValue;
140  for (auto const& it : perRecordInfos_) {
141  returnValue.insert(returnValue.end(), it.recordKey_);
142  }
143  return returnValue;
144  }
145 
147  std::set<EventSetupRecordKey>& recordsNotAllowingConcurrentIOVs) const {
148  for (auto const& it : perRecordInfos_) {
149  const EventSetupRecordKey& key = it.recordKey_;
150  if (!allowConcurrentIOVs(key)) {
151  recordsNotAllowingConcurrentIOVs.insert(recordsNotAllowingConcurrentIOVs.end(), key);
152  }
153  }
154  }
155 
157  std::sort(perRecordInfos_.begin(), perRecordInfos_.end());
158  perRecordInfos_.erase(std::unique(perRecordInfos_.begin(), perRecordInfos_.end()), perRecordInfos_.end());
159  }
160 
162  unsigned int nConcurrentIOVs) {
163  if (keyedResolversCollection_.empty()) {
164  sortEventSetupRecordKeys();
165  }
166  assert(nConcurrentIOVs > 0U);
167  auto lb = std::lower_bound(perRecordInfos_.begin(), perRecordInfos_.end(), PerRecordInfo(key));
168  assert(lb != perRecordInfos_.end() && key == lb->recordKey_);
169  if (lb->nIOVs_ == 0) {
170  lb->nIOVs_ = nConcurrentIOVs;
171  auto recordIndex = std::distance(perRecordInfos_.begin(), lb);
172  lb->indexToKeyedResolvers_ = keyedResolversCollection_.size();
173  for (unsigned int i = 0; i < nConcurrentIOVs; ++i) {
174  keyedResolversCollection_.emplace_back(this, recordIndex);
175  }
176  }
177  }
178 
180  const EventSetupRecordKey& iRecordKey, unsigned int iovIndex) {
181  auto lb = std::lower_bound(perRecordInfos_.begin(), perRecordInfos_.end(), PerRecordInfo(iRecordKey));
182  assert(lb != perRecordInfos_.end() && iRecordKey == lb->recordKey_);
183  assert(iovIndex < lb->nIOVs_);
184  return keyedResolversCollection_[lb->indexToKeyedResolvers_ + iovIndex];
185  }
186 
188 
191  //this can only be changed once and the default value is the empty string
192  assert(oldValue.empty());
193 
194  const std::string kParamName("appendToDataLabel");
195  if (iToAppend.exists(kParamName)) {
196  appendToDataLabel_ = iToAppend.getParameter<std::string>(kParamName);
197  }
198  }
199 
201  const EventSetupRecordKey& iRecordKey, unsigned int iovIndex) {
203 
205  //delayed registration
206  std::vector<std::pair<DataKey, std::shared_ptr<ESProductResolver>>> keyedResolversVector =
207  registerResolvers(iRecordKey, iovIndex);
208  keyedResolvers.insert(std::move(keyedResolversVector), appendToDataLabel_);
209 
210  bool mustChangeLabels = (!appendToDataLabel_.empty());
211  for (auto keyedResolver : keyedResolvers) {
212  keyedResolver.productResolver_->setProviderDescription(&description());
213  if (mustChangeLabels) {
214  //Using swap is fine since
215  // 1) the data structure is not a map and so we have not sorted on the keys
216  // 2) this is the first time filling this so no outside agency has yet seen
217  // the label and therefore can not be dependent upon its value
218  std::string temp(std::string(keyedResolver.dataKey_.name().value()) + appendToDataLabel_);
219  DataKey newKey(keyedResolver.dataKey_.type(), temp.c_str());
220  swap(keyedResolver.dataKey_, newKey);
221  }
222  }
223  }
224  return keyedResolvers;
225  }
226 
227  static const std::string kAppendToDataLabel("appendToDataLabel");
228 
230  if (iDesc.defaultDescription()) {
233  }
234  }
235  for (auto& v : iDesc) {
236  if (v.second.isLabelUnused(kAppendToDataLabel)) {
237  v.second.add<std::string>(kAppendToDataLabel, std::string(""));
238  }
239  }
240  }
241 
242  } // namespace eventsetup
243 } // namespace edm
bool isLabelUnused(std::string const &label) const
const ComponentDescription & description() const
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void fillRecordsNotAllowingConcurrentIOVs(std::set< EventSetupRecordKey > &recordsNotAllowingConcurrentIOVs) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
constexpr auto kInvalidIndex
ParameterSetDescription * defaultDescription()
Returns 0 if no default has been assigned.
assert(be >=bs)
TGeoIterator Iterator
Iterator(std::vector< DataKey >::iterator dataKeysIter, std::vector< edm::propagate_const< std::shared_ptr< ESProductResolver >>>::iterator productResolversIter)
KeyedResolvers & keyedResolvers(const EventSetupRecordKey &iRecordKey, unsigned int iovIndex)
edm::propagate_const< ESProductResolverContainer * > productResolverContainer_
virtual KeyedResolversVector registerResolvers(const EventSetupRecordKey &, unsigned int iovIndex)=0
def unique(seq, keepstr=True)
Definition: tier0.py:24
void swap(DataKey &a, DataKey &b)
Definition: DataKey.h:85
void insert(std::vector< std::pair< DataKey, std::shared_ptr< ESProductResolver >>> &&, std::string const &appendToDataLabel)
key
prepare the HTCondor submission files and eventually submit them
static const std::string kAppendToDataLabel("appendToDataLabel")
bool allowConcurrentIOVs(EventSetupRecordKey const &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
virtual void updateLookup(ESRecordsToProductResolverIndices const &)
void createKeyedResolvers(EventSetupRecordKey const &key, unsigned int nConcurrentIOVs)
KeyedResolvers(ESProductResolverContainer *, unsigned int recordIndex)
void setAppendToDataLabel(const edm::ParameterSet &)
HLT enums.
static void prevalidate(ConfigurationDescriptions &)
def move(src, dest)
Definition: eostools.py:511
KeyedResolvers & keyedResolvers(const EventSetupRecordKey &iRecordKey, unsigned int iovIndex=0)
std::vector< edm::propagate_const< std::shared_ptr< ESProductResolver > > > productResolvers_