CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ProvenanceAdaptor.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 
3 ProvenanceAdaptor.cc
4 
5 ----------------------------------------------------------------------*/
6 //------------------------------------------------------------
7 // Class ProvenanceAdaptor: adapts old provenance (fileFormatVersion_.value() < 11) to new provenance.
8 
10 
11 #include <cassert>
12 #include <memory>
13 
14 #include <set>
15 #include <utility>
16 #include <string>
17 #include <memory>
23 namespace edm {
24 
26  assert(pHistMap.empty() != pHistVector.empty());
27  for (ProcessHistoryVector::const_iterator i = pHistVector.begin(), e = pHistVector.end(); i != e; ++i) {
28  pHistMap.insert(std::make_pair(i->id(), *i));
29  }
30  pHistVector.clear();
31  for (ProcessHistoryMap::const_iterator i = pHistMap.begin(), e = pHistMap.end(); i != e; ++i) {
32  ProcessHistory newHist;
33  ProcessHistoryID const& oldphID = i->first;
34  for (ProcessHistory::const_iterator it = i->second.begin(), et = i->second.end(); it != et; ++it) {
35  ParameterSetID const& newPsetID = convertID(it->parameterSetID());
36  newHist.emplace_back(it->processName(), newPsetID, it->releaseVersion(), it->passID());
37  }
38  assert(newHist.size() == i->second.size());
39  ProcessHistoryID newphID = newHist.id();
40  pHistVector.push_back(std::move(newHist));
41  if (newphID != oldphID) {
42  processHistoryIdConverter_.insert(std::make_pair(oldphID, newphID));
43  }
44  }
45  assert(pHistVector.size() == pHistMap.size());
46  }
47 
48  namespace {
49  typedef StringVector OneHistory;
50  typedef std::set<OneHistory> Histories;
51  typedef std::pair<std::string, BranchID> Product;
52  typedef std::vector<Product> OrderedProducts;
53  struct Sorter {
54  explicit Sorter(Histories const& histories) : histories_(histories) {}
55  bool operator()(Product const& a, Product const& b) const;
56  Histories const histories_;
57  };
58  bool Sorter::operator()(Product const& a, Product const& b) const {
59  assert(a != b);
60  if (a.first == b.first)
61  return false;
62  bool mayBeTrue = false;
63  for (Histories::const_iterator it = histories_.begin(), itEnd = histories_.end(); it != itEnd; ++it) {
64  OneHistory::const_iterator itA = find_in_all(*it, a.first);
65  if (itA == it->end())
66  continue;
67  OneHistory::const_iterator itB = find_in_all(*it, b.first);
68  if (itB == it->end())
69  continue;
70  assert(itA != itB);
71  if (itB < itA) {
72  // process b precedes process a;
73  return false;
74  }
75  // process a precedes process b;
76  mayBeTrue = true;
77  }
78  return mayBeTrue;
79  }
80 
81  void fillProcessConfiguration(ProcessHistoryVector const& pHistVec, ProcessConfigurationVector& procConfigVector) {
82  procConfigVector.clear();
83  std::set<ProcessConfiguration> pcset;
84  for (auto const& history : pHistVec) {
85  for (auto const& process : history) {
86  if (pcset.insert(process).second) {
87  procConfigVector.push_back(process);
88  }
89  }
90  }
91  }
92 
93  void fillListsAndIndexes(ProductRegistry& productRegistry,
94  ProcessHistoryMap const& pHistMap,
95  std::shared_ptr<BranchIDLists const>& branchIDLists,
96  std::vector<BranchListIndex>& branchListIndexes) {
97  OrderedProducts orderedProducts;
98  std::set<std::string> processNamesThatProduced;
99  ProductRegistry::ProductList& prodList = productRegistry.productListUpdator();
100  for (auto& item : prodList) {
101  BranchDescription& prod = item.second;
102  if (prod.branchType() == InEvent) {
103  prod.init();
104  processNamesThatProduced.insert(prod.processName());
105  orderedProducts.emplace_back(prod.processName(), prod.branchID());
106  }
107  }
108  assert(!orderedProducts.empty());
109  Histories processHistories;
110  size_t max = 0;
111  for (ProcessHistoryMap::const_iterator it = pHistMap.begin(), itEnd = pHistMap.end(); it != itEnd; ++it) {
112  ProcessHistory const& pHist = it->second;
113  OneHistory processHistory;
114  for (ProcessHistory::const_iterator i = pHist.begin(), iEnd = pHist.end(); i != iEnd; ++i) {
115  if (processNamesThatProduced.find(i->processName()) != processNamesThatProduced.end()) {
116  processHistory.push_back(i->processName());
117  }
118  }
119  max = (processHistory.size() > max ? processHistory.size() : max);
120  assert(max <= processNamesThatProduced.size());
121  if (processHistory.size() > 1) {
122  processHistories.insert(processHistory);
123  }
124  }
125  stable_sort_all(orderedProducts, Sorter(processHistories));
126 
127  auto pv = std::make_unique<BranchIDLists>();
128  auto p = std::make_unique<BranchIDList>();
130  BranchListIndex blix = 0;
131  for (OrderedProducts::const_iterator it = orderedProducts.begin(), itEnd = orderedProducts.end(); it != itEnd;
132  ++it) {
133  if (it->first != processName) {
134  if (!processName.empty()) {
135  branchListIndexes.push_back(blix);
136  ++blix;
137  pv->push_back(std::move(*p));
138  p = std::make_unique<BranchIDList>();
139  }
140  processName = it->first;
141  }
142  p->push_back(it->second.id());
143  }
144  branchListIndexes.push_back(blix);
145  pv->push_back(std::move(*p));
146  branchIDLists.reset(pv.release());
147  }
148  } // namespace
149 
151  ProcessHistoryMap& pHistMap,
152  ProcessHistoryVector& pHistVector,
153  ProcessConfigurationVector& procConfigVector,
154  ParameterSetIdConverter const& parameterSetIdConverter,
155  bool fullConversion)
156  : parameterSetIdConverter_(parameterSetIdConverter),
157  processHistoryIdConverter_(),
158  branchIDLists_(),
159  branchListIndexes_() {
160  fixProcessHistory(pHistMap, pHistVector);
161  fillProcessConfiguration(pHistVector, procConfigVector);
162  if (fullConversion) {
163  fillListsAndIndexes(productRegistry, pHistMap, branchIDLists_, branchListIndexes_);
164  }
165  }
166 
168 
170  ParameterSetIdConverter::const_iterator it = parameterSetIdConverter_.find(oldID);
171  if (it == parameterSetIdConverter_.end()) {
172  return oldID;
173  }
174  return it->second;
175  }
176 
178  ProcessHistoryIdConverter::const_iterator it = processHistoryIdConverter_.find(oldID);
179  if (it == processHistoryIdConverter_.end()) {
180  return oldID;
181  }
182  return it->second;
183  }
184 
185  std::shared_ptr<BranchIDLists const> ProvenanceAdaptor::branchIDLists() const { return branchIDLists_; }
186 
188 } // namespace edm
std::vector< ProcessHistory > ProcessHistoryVector
collection_type::const_iterator const_iterator
std::vector< ProcessConfiguration > ProcessConfigurationVector
unsigned short BranchListIndex
size_type size() const
ProcessHistoryIdConverter processHistoryIdConverter_
std::shared_ptr< BranchIDLists const > branchIDLists_
std::map< BranchKey, BranchDescription > ProductList
std::vector< std::string > StringVector
ProvenanceAdaptor(ProductRegistry &productRegistry, ProcessHistoryMap &pHistMap, ProcessHistoryVector &pHistVector, ProcessConfigurationVector &procConfigVector, ParameterSetIdConverter const &parameterSetIdConverter, bool fullConversion)
void stable_sort_all(RandomAccessSequence &s)
wrappers for std::stable_sort
Definition: Algorithms.h:103
assert(be >=bs)
void emplace_back(Args &&...args)
ParameterSetIdConverter parameterSetIdConverter_
std::vector< BranchListIndex > BranchListIndexes
def move
Definition: eostools.py:511
tuple ProcessHistory
std::vector< BranchListIndex > branchListIndexes_
std::shared_ptr< BranchIDLists const > branchIDLists() const
ForwardSequence::const_iterator find_in_all(ForwardSequence const &s, Datum const &d)
wrappers for std::find
Definition: Algorithms.h:26
ParameterSetConverter::ParameterSetIdConverter ParameterSetIdConverter
void fixProcessHistory(ProcessHistoryMap &pHistMap, ProcessHistoryVector &pHistVector)
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
ParameterSetID const & convertID(ParameterSetID const &oldID) const
tuple process
Definition: LaserDQM_cfg.py:3
ProcessHistoryID id() const
std::map< ProcessHistoryID, ProcessHistory > ProcessHistoryMap
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:118
void branchListIndexes(BranchListIndexes &indexes) const