CMS 3D CMS Logo

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
ConfigurationDescriptions.h
AlignmentProducer_cff.appendToDataLabel
appendToDataLabel
Definition: AlignmentProducer_cff.py:82
edm::eventsetup::DataProxyProvider::registerProxies
virtual KeyedProxiesVector registerProxies(const EventSetupRecordKey &, unsigned int iovIndex)=0
edm::eventsetup::kAppendToDataLabel
static const std::string kAppendToDataLabel("appendToDataLabel")
edm::eventsetup::DataProxyProvider::KeyedProxies::contains
bool contains(DataKey const &dataKey) const
Definition: DataProxyProvider.cc:76
edm::eventsetup::DataProxyProvider::PerRecordInfo::indexToDataKeys_
unsigned int indexToDataKeys_
Definition: DataProxyProvider.h:132
mps_fire.i
i
Definition: mps_fire.py:428
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
edm::eventsetup::ESRecordsToProxyIndices
Definition: ESRecordsToProxyIndices.h:35
edm::eventsetup::DataProxyProvider::KeyedProxies::Iterator::Iterator
Iterator(std::vector< DataKey >::iterator dataKeysIter, std::vector< edm::propagate_const< std::shared_ptr< DataProxy >>>::iterator dataProxiesIter)
Definition: DataProxyProvider.cc:98
funct::false
false
Definition: Factorize.h:29
edm::eventsetup::DataProxyProvider::DataProxyContainer::dataProxies_
std::vector< edm::propagate_const< std::shared_ptr< DataProxy > > > dataProxies_
Definition: DataProxyProvider.h:155
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::eventsetup::DataProxyProvider::KeyedProxies::Iterator
Definition: DataProxyProvider.h:89
kInvalidIndex
constexpr auto kInvalidIndex
Definition: DataProxyProvider.cc:26
edm::eventsetup::DataProxyProvider::KeyedProxies::insert
void insert(std::vector< std::pair< DataKey, std::shared_ptr< DataProxy >>> &&, std::string const &appendToDataLabel)
Definition: DataProxyProvider.cc:44
edm::eventsetup::DataProxyProvider::DataProxyContainer::perRecordInfos_
std::vector< PerRecordInfo > perRecordInfos_
Definition: DataProxyProvider.h:152
edm::eventsetup::DataProxyProvider::KeyedProxies::unInitialized
bool unInitialized() const
Definition: DataProxyProvider.cc:38
cms::cuda::assert
assert(be >=bs)
edm::eventsetup::DataKey
Definition: DataKey.h:29
edm::eventsetup::DataProxyProvider::KeyedProxies
Definition: DataProxyProvider.h:73
findQualityFiles.v
v
Definition: findQualityFiles.py:179
edm::eventsetup::DataProxyProvider::KeyedProxies::size
unsigned int size() const
Definition: DataProxyProvider.cc:88
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::eventsetup::DataProxyProvider::DataProxyContainer::isUsingRecord
bool isUsingRecord(const EventSetupRecordKey &) const
Definition: DataProxyProvider.cc:124
edm::eventsetup::DataProxyProvider::DataProxyContainer::createKeyedProxies
void createKeyedProxies(EventSetupRecordKey const &key, unsigned int nConcurrentIOVs)
Definition: DataProxyProvider.cc:152
DataProxy.h
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
edm::eventsetup::DataProxyProvider::KeyedProxies::recordKey
EventSetupRecordKey const & recordKey() const
Definition: DataProxyProvider.cc:40
cms::Iterator
TGeoIterator Iterator
Definition: DDFilteredView.h:54
edm::propagate_const
Definition: propagate_const.h:32
DataProxyProvider.h
edm::eventsetup::DataProxyProvider::setAppendToDataLabel
void setAppendToDataLabel(const edm::ParameterSet &)
Definition: DataProxyProvider.cc:180
edm::eventsetup::DataProxyProvider::KeyedProxies::recordIndex_
unsigned int recordIndex_
Definition: DataProxyProvider.h:121
edm::eventsetup::DataProxyProvider::keyedProxies
KeyedProxies & keyedProxies(const EventSetupRecordKey &iRecordKey, unsigned int iovIndex=0)
Definition: DataProxyProvider.cc:191
RecordDependencyRegister.h
edm::eventsetup::DataProxyProvider::KeyedProxies::KeyedProxies
KeyedProxies(DataProxyContainer *, unsigned int recordIndex)
Definition: DataProxyProvider.cc:35
edm::eventsetup::DataProxyProvider::DataProxyProvider
DataProxyProvider()
Definition: DataProxyProvider.cc:31
edm::eventsetup::DataProxyProvider::updateLookup
virtual void updateLookup(ESRecordsToProxyIndices const &)
Definition: DataProxyProvider.cc:178
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:681
edm::eventsetup::DataProxyProvider::PerRecordInfo
Definition: DataProxyProvider.h:125
edm::eventsetup::DataProxyProvider::DataProxyContainer::fillRecordsNotAllowingConcurrentIOVs
void fillRecordsNotAllowingConcurrentIOVs(std::set< EventSetupRecordKey > &recordsNotAllowingConcurrentIOVs) const
Definition: DataProxyProvider.cc:137
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
edm::eventsetup::DataProxyProvider::DataProxyContainer::usingRecordWithKey
void usingRecordWithKey(const EventSetupRecordKey &)
Definition: DataProxyProvider.cc:119
edm::ParameterSet
Definition: ParameterSet.h:47
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
edm::eventsetup::DataProxyProvider::PerRecordInfo::nDataKeys_
unsigned int nDataKeys_
Definition: DataProxyProvider.h:131
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::eventsetup::DataProxyProvider::DataProxyContainer
Definition: DataProxyProvider.h:137
edm::eventsetup::DataProxyProvider::dataProxyContainer_
DataProxyContainer dataProxyContainer_
Definition: DataProxyProvider.h:201
edm::eventsetup::DataProxyProvider::prevalidate
static void prevalidate(ConfigurationDescriptions &)
Definition: DataProxyProvider.cc:220
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::eventsetup::DataProxyProvider::KeyedProxies::Iterator::operator++
Iterator & operator++()
Definition: DataProxyProvider.cc:92
edm::eventsetup::DataProxyProvider::appendToDataLabel_
std::string appendToDataLabel_
Definition: DataProxyProvider.h:203
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
edm::eventsetup::DataProxyProvider::KeyedProxies::end
Iterator end()
Definition: DataProxyProvider.cc:109
edm::eventsetup::DataProxyProvider::description
const ComponentDescription & description() const
Definition: DataProxyProvider.h:171
edm::ConfigurationDescriptions::defaultDescription
ParameterSetDescription * defaultDescription()
Returns 0 if no default has been assigned.
Definition: ConfigurationDescriptions.cc:112
edm::eventsetup::DataProxyProvider::DataProxyContainer::sortEventSetupRecordKeys
void sortEventSetupRecordKeys()
Definition: DataProxyProvider.cc:147
edm::eventsetup::DataProxyProvider::KeyedProxies::dataProxyContainer_
edm::propagate_const< DataProxyContainer * > dataProxyContainer_
Definition: DataProxyProvider.h:120
edm::eventsetup::swap
void swap(DataKey &a, DataKey &b)
Definition: DataKey.h:85
edm::ParameterSetDescription::isLabelUnused
bool isLabelUnused(std::string const &label) const
Definition: ParameterSetDescription.cc:191
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
ParameterSet.h
edm::eventsetup::DataProxyProvider::DataProxyContainer::usingRecords
std::set< EventSetupRecordKey > usingRecords() const
Definition: DataProxyProvider.cc:129
edm::eventsetup::DataProxyProvider::PerRecordInfo::PerRecordInfo
PerRecordInfo(const EventSetupRecordKey &)
Definition: DataProxyProvider.cc:116
edm::eventsetup::DataProxyProvider::KeyedProxies::begin
Iterator begin()
Definition: DataProxyProvider.cc:103
edm::eventsetup::DataProxyProvider::DataProxyContainer::keyedProxies
KeyedProxies & keyedProxies(const EventSetupRecordKey &iRecordKey, unsigned int iovIndex)
Definition: DataProxyProvider.cc:170
edm::eventsetup::DataProxyProvider::DataProxyContainer::dataKeys_
std::vector< DataKey > dataKeys_
Definition: DataProxyProvider.h:154
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7799
crabWrapper.key
key
Definition: crabWrapper.py:19
edm::eventsetup::allowConcurrentIOVs
bool allowConcurrentIOVs(EventSetupRecordKey const &)
Definition: RecordDependencyRegister.cc:46
edm::eventsetup::DataProxyProvider::KeyedProxies::dataProxiesIndex_
unsigned int dataProxiesIndex_
Definition: DataProxyProvider.h:122
edm::eventsetup::DataProxyProvider::~DataProxyProvider
virtual ~DataProxyProvider() noexcept(false)
Definition: DataProxyProvider.cc:33