CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataProxyProvider.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Framework
4 // Class : DataProxyProvider
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 
35  DataProxyProvider::KeyedProxies::KeyedProxies(DataProxyContainer* dataProxyContainer, unsigned int recordIndex)
36  : dataProxyContainer_(dataProxyContainer), recordIndex_(recordIndex), dataProxiesIndex_(kInvalidIndex) {}
37 
38  bool DataProxyProvider::KeyedProxies::unInitialized() const { return dataProxiesIndex_ == kInvalidIndex; }
39 
41  return dataProxyContainer_->perRecordInfos_[recordIndex_].recordKey_;
42  }
43 
44  void DataProxyProvider::KeyedProxies::insert(std::vector<std::pair<DataKey, std::shared_ptr<DataProxy>>>&& proxies,
46  PerRecordInfo& perRecordInfo = dataProxyContainer_->perRecordInfos_[recordIndex_];
47  if (perRecordInfo.indexToDataKeys_ == kInvalidIndex) {
48  perRecordInfo.nDataKeys_ = proxies.size();
49  perRecordInfo.indexToDataKeys_ = dataProxyContainer_->dataKeys_.size();
50  for (auto const& it : proxies) {
51  dataProxyContainer_->dataKeys_.push_back(it.first);
52  }
53  } else {
54  assert(perRecordInfo.nDataKeys_ == proxies.size());
55  unsigned index = 0;
56  for (auto const& it : proxies) {
57  if (appendToDataLabel.empty()) {
58  assert(it.first == dataProxyContainer_->dataKeys_[perRecordInfo.indexToDataKeys_ + index]);
59  } else {
60  assert(it.first.type() == dataProxyContainer_->dataKeys_[perRecordInfo.indexToDataKeys_ + index].type());
61  auto lengthDataLabel = std::strlen(it.first.name().value());
62  assert(std::strncmp(it.first.name().value(),
63  dataProxyContainer_->dataKeys_[perRecordInfo.indexToDataKeys_ + index].name().value(),
64  lengthDataLabel) == 0);
65  }
66  ++index;
67  }
68  }
69  assert(unInitialized());
70  dataProxiesIndex_ = dataProxyContainer_->dataProxies_.size();
71  for (auto const& it : proxies) {
72  dataProxyContainer_->dataProxies_.emplace_back(it.second);
73  }
74  }
75 
77  PerRecordInfo const& perRecordInfo = dataProxyContainer_->perRecordInfos_[recordIndex_];
78  auto iter = dataProxyContainer_->dataKeys_.begin() + perRecordInfo.indexToDataKeys_;
79  auto iterEnd = iter + perRecordInfo.nDataKeys_;
80  for (; iter != iterEnd; ++iter) {
81  if (*iter == dataKey) {
82  return true;
83  }
84  }
85  return false;
86  }
87 
89  return dataProxyContainer_->perRecordInfos_[recordIndex_].nDataKeys_;
90  }
91 
93  ++dataKeysIter_;
94  ++dataProxiesIter_;
95  return *this;
96  }
97 
99  std::vector<DataKey>::iterator dataKeysIter,
100  std::vector<edm::propagate_const<std::shared_ptr<DataProxy>>>::iterator dataProxiesIter)
101  : dataKeysIter_(dataKeysIter), dataProxiesIter_(dataProxiesIter) {}
102 
104  return Iterator(
105  dataProxyContainer_->dataKeys_.begin() + dataProxyContainer_->perRecordInfos_[recordIndex_].indexToDataKeys_,
106  dataProxyContainer_->dataProxies_.begin() + dataProxiesIndex_);
107  }
108 
110  unsigned int nDataKeys = dataProxyContainer_->perRecordInfos_[recordIndex_].nDataKeys_;
111  return Iterator(dataProxyContainer_->dataKeys_.begin() +
112  dataProxyContainer_->perRecordInfos_[recordIndex_].indexToDataKeys_ + nDataKeys,
113  dataProxyContainer_->dataProxies_.begin() + dataProxiesIndex_ + nDataKeys);
114  }
115 
117  : recordKey_(key), indexToDataKeys_(kInvalidIndex) {}
118 
120  assert(keyedProxiesCollection_.empty());
121  perRecordInfos_.emplace_back(iKey);
122  }
123 
125  auto lb = std::lower_bound(perRecordInfos_.begin(), perRecordInfos_.end(), PerRecordInfo(iKey));
126  return (lb != perRecordInfos_.end() && iKey == lb->recordKey_);
127  }
128 
129  std::set<EventSetupRecordKey> DataProxyProvider::DataProxyContainer::usingRecords() const {
130  std::set<EventSetupRecordKey> returnValue;
131  for (auto const& it : perRecordInfos_) {
132  returnValue.insert(returnValue.end(), it.recordKey_);
133  }
134  return returnValue;
135  }
136 
138  std::set<EventSetupRecordKey>& recordsNotAllowingConcurrentIOVs) const {
139  for (auto const& it : perRecordInfos_) {
140  const EventSetupRecordKey& key = it.recordKey_;
141  if (!allowConcurrentIOVs(key)) {
142  recordsNotAllowingConcurrentIOVs.insert(recordsNotAllowingConcurrentIOVs.end(), key);
143  }
144  }
145  }
146 
148  std::sort(perRecordInfos_.begin(), perRecordInfos_.end());
149  perRecordInfos_.erase(std::unique(perRecordInfos_.begin(), perRecordInfos_.end()), perRecordInfos_.end());
150  }
151 
153  unsigned int nConcurrentIOVs) {
154  if (keyedProxiesCollection_.empty()) {
155  sortEventSetupRecordKeys();
156  }
157  assert(nConcurrentIOVs > 0U);
158  auto lb = std::lower_bound(perRecordInfos_.begin(), perRecordInfos_.end(), PerRecordInfo(key));
159  assert(lb != perRecordInfos_.end() && key == lb->recordKey_);
160  if (lb->nIOVs_ == 0) {
161  lb->nIOVs_ = nConcurrentIOVs;
162  auto recordIndex = std::distance(perRecordInfos_.begin(), lb);
163  lb->indexToKeyedProxies_ = keyedProxiesCollection_.size();
164  for (unsigned int i = 0; i < nConcurrentIOVs; ++i) {
165  keyedProxiesCollection_.emplace_back(this, recordIndex);
166  }
167  }
168  }
169 
171  const EventSetupRecordKey& iRecordKey, unsigned int iovIndex) {
172  auto lb = std::lower_bound(perRecordInfos_.begin(), perRecordInfos_.end(), PerRecordInfo(iRecordKey));
173  assert(lb != perRecordInfos_.end() && iRecordKey == lb->recordKey_);
174  assert(iovIndex < lb->nIOVs_);
175  return keyedProxiesCollection_[lb->indexToKeyedProxies_ + iovIndex];
176  }
177 
179 
182  //this can only be changed once and the default value is the empty string
183  assert(oldValue.empty());
184 
185  const std::string kParamName("appendToDataLabel");
186  if (iToAppend.exists(kParamName)) {
187  appendToDataLabel_ = iToAppend.getParameter<std::string>(kParamName);
188  }
189  }
190 
192  unsigned int iovIndex) {
194 
195  if (keyedProxies.unInitialized()) {
196  //delayed registration
197  std::vector<std::pair<DataKey, std::shared_ptr<DataProxy>>> keyedProxiesVector =
198  registerProxies(iRecordKey, iovIndex);
199  keyedProxies.insert(std::move(keyedProxiesVector), appendToDataLabel_);
200 
201  bool mustChangeLabels = (!appendToDataLabel_.empty());
202  for (auto keyedProxy : keyedProxies) {
203  keyedProxy.dataProxy_->setProviderDescription(&description());
204  if (mustChangeLabels) {
205  //Using swap is fine since
206  // 1) the data structure is not a map and so we have not sorted on the keys
207  // 2) this is the first time filling this so no outside agency has yet seen
208  // the label and therefore can not be dependent upon its value
209  std::string temp(std::string(keyedProxy.dataKey_.name().value()) + appendToDataLabel_);
210  DataKey newKey(keyedProxy.dataKey_.type(), temp.c_str());
211  swap(keyedProxy.dataKey_, newKey);
212  }
213  }
214  }
215  return keyedProxies;
216  }
217 
218  static const std::string kAppendToDataLabel("appendToDataLabel");
219 
221  if (iDesc.defaultDescription()) {
224  }
225  }
226  for (auto& v : iDesc) {
227  if (v.second.isLabelUnused(kAppendToDataLabel)) {
228  v.second.add<std::string>(kAppendToDataLabel, std::string(""));
229  }
230  }
231  }
232 
233  } // namespace eventsetup
234 } // namespace edm
def unique
Definition: tier0.py:24
bool exists(std::string const &parameterName) const
checks if a parameter exists
ParameterSetDescription * defaultDescription()
Returns 0 if no default has been assigned.
assert(be >=bs)
TGeoIterator Iterator
EventSetupRecordKey const & recordKey() const
virtual KeyedProxiesVector registerProxies(const EventSetupRecordKey &, unsigned int iovIndex)=0
def move
Definition: eostools.py:511
tuple key
prepare the HTCondor submission files and eventually submit them
std::vector< edm::propagate_const< std::shared_ptr< DataProxy > > > dataProxies_
KeyedProxies & keyedProxies(const EventSetupRecordKey &iRecordKey, unsigned int iovIndex)
const ComponentDescription & description() const
void swap(DataKey &a, DataKey &b)
Definition: DataKey.h:85
bool isLabelUnused(std::string const &label) const
static const std::string kAppendToDataLabel("appendToDataLabel")
virtual void updateLookup(ESRecordsToProxyIndices const &)
bool allowConcurrentIOVs(EventSetupRecordKey const &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool contains(DataKey const &dataKey) const
edm::propagate_const< DataProxyContainer * > dataProxyContainer_
static void prevalidate(ConfigurationDescriptions &)
bool isUsingRecord(const EventSetupRecordKey &) const
void setAppendToDataLabel(const edm::ParameterSet &)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void fillRecordsNotAllowingConcurrentIOVs(std::set< EventSetupRecordKey > &recordsNotAllowingConcurrentIOVs) const
void insert(std::vector< std::pair< DataKey, std::shared_ptr< DataProxy >>> &&, std::string const &appendToDataLabel)
KeyedProxies & keyedProxies(const EventSetupRecordKey &iRecordKey, unsigned int iovIndex=0)
void createKeyedProxies(EventSetupRecordKey const &key, unsigned int nConcurrentIOVs)
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Iterator(std::vector< DataKey >::iterator dataKeysIter, std::vector< edm::propagate_const< std::shared_ptr< DataProxy >>>::iterator dataProxiesIter)
constexpr auto kInvalidIndex
std::set< EventSetupRecordKey > usingRecords() const
virtual ~DataProxyProvider() noexcept(false)
KeyedProxies(DataProxyContainer *, unsigned int recordIndex)