CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 <set>
13 #include <utility>
14 #include <string>
15 #include <memory>
21 namespace edm {
22 
23  void
25  ProcessHistoryVector& pHistVector) {
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) return false;
61  bool mayBeTrue = false;
62  for (Histories::const_iterator it = histories_.begin(), itEnd = histories_.end(); it != itEnd; ++it) {
63  OneHistory::const_iterator itA = find_in_all(*it, a.first);
64  if (itA == it->end()) continue;
65  OneHistory::const_iterator itB = find_in_all(*it, b.first);
66  if (itB == it->end()) continue;
67  assert (itA != itB);
68  if (itB < itA) {
69  // process b precedes process a;
70  return false;
71  }
72  // process a precedes process b;
73  mayBeTrue = true;
74  }
75  return mayBeTrue;
76  }
77 
78  void
79  fillProcessConfiguration(ProcessHistoryVector const& pHistVec, ProcessConfigurationVector& procConfigVector) {
80  procConfigVector.clear();
81  std::set<ProcessConfiguration> pcset;
82  for (auto const& history : pHistVec) {
83  for (auto const& process : history) {
84  if (pcset.insert(process).second) {
85  procConfigVector.push_back(process);
86  }
87  }
88  }
89  }
90 
91  void
92  fillListsAndIndexes(ProductRegistry& productRegistry,
93  ProcessHistoryMap const& pHistMap,
94  std::shared_ptr<BranchIDLists const>& branchIDLists,
95  std::vector<BranchListIndex>& branchListIndexes) {
96  OrderedProducts orderedProducts;
97  std::set<std::string> processNamesThatProduced;
98  ProductRegistry::ProductList& prodList = productRegistry.productListUpdator();
99  for (auto& item : prodList) {
100  BranchDescription& prod = item.second;
101  if (prod.branchType() == InEvent) {
102  prod.init();
103  processNamesThatProduced.insert(prod.processName());
104  orderedProducts.emplace_back(prod.processName(), prod.branchID());
105  }
106  }
107  assert (!orderedProducts.empty());
108  Histories processHistories;
109  size_t max = 0;
110  for(ProcessHistoryMap::const_iterator it = pHistMap.begin(), itEnd = pHistMap.end(); it != itEnd; ++it) {
111  ProcessHistory const& pHist = it->second;
112  OneHistory processHistory;
113  for(ProcessHistory::const_iterator i = pHist.begin(), iEnd = pHist.end(); i != iEnd; ++i) {
114  if (processNamesThatProduced.find(i->processName()) != processNamesThatProduced.end()) {
115  processHistory.push_back(i->processName());
116  }
117  }
118  max = (processHistory.size() > max ? processHistory.size() : max);
119  assert(max <= processNamesThatProduced.size());
120  if (processHistory.size() > 1) {
121  processHistories.insert(processHistory);
122  }
123  }
124  stable_sort_all(orderedProducts, Sorter(processHistories));
125 
126  std::unique_ptr<BranchIDLists> pv(new BranchIDLists);
127  std::unique_ptr<BranchIDList> p(new BranchIDList);
129  BranchListIndex blix = 0;
130  for (OrderedProducts::const_iterator it = orderedProducts.begin(), itEnd = orderedProducts.end(); it != itEnd; ++it) {
131  if (it->first != processName) {
132  if (!processName.empty()) {
133  branchListIndexes.push_back(blix);
134  ++blix;
135  pv->push_back(std::move(*p));
136  p.reset(new BranchIDList);
137  }
138  processName = it->first;
139  }
140  p->push_back(it->second.id());
141  }
142  branchListIndexes.push_back(blix);
143  pv->push_back(std::move(*p));
144  branchIDLists.reset(pv.release());
145  }
146  }
147 
149  ProductRegistry& productRegistry,
150  ProcessHistoryMap& pHistMap,
151  ProcessHistoryVector& pHistVector,
152  ProcessConfigurationVector& procConfigVector,
153  ParameterSetIdConverter const& parameterSetIdConverter,
154  bool fullConversion) :
155  parameterSetIdConverter_(parameterSetIdConverter),
156  processHistoryIdConverter_(),
157  branchIDLists_(),
158  branchListIndexes_() {
159  fixProcessHistory(pHistMap, pHistVector);
160  fillProcessConfiguration(pHistVector, procConfigVector);
161  if (fullConversion) {
162  fillListsAndIndexes(productRegistry, pHistMap, branchIDLists_, branchListIndexes_);
163  }
164  }
165 
167 
168  ParameterSetID const&
170  ParameterSetIdConverter::const_iterator it = parameterSetIdConverter_.find(oldID);
171  if (it == parameterSetIdConverter_.end()) {
172  return oldID;
173  }
174  return it->second;
175  }
176 
177  ProcessHistoryID const&
179  ProcessHistoryIdConverter::const_iterator it = processHistoryIdConverter_.find(oldID);
180  if (it == processHistoryIdConverter_.end()) {
181  return oldID;
182  }
183  return it->second;
184  }
185 
186  std::shared_ptr<BranchIDLists const>
188  return branchIDLists_;
189  }
190 
191  void
193  indexes = branchListIndexes_;
194  }
195 }
std::vector< ProcessHistory > ProcessHistoryVector
collection_type::const_iterator const_iterator
std::vector< ProcessConfiguration > ProcessConfigurationVector
int i
Definition: DBlmapReader.cc:9
unsigned short BranchListIndex
size_type size() const
ProcessHistoryIdConverter processHistoryIdConverter_
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
std::shared_ptr< BranchIDLists const > branchIDLists_
std::map< BranchKey, BranchDescription > ProductList
assert(m_qm.get())
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:135
void emplace_back(Args &&...args)
ParameterSetIdConverter parameterSetIdConverter_
std::vector< BranchListIndex > BranchListIndexes
def move
Definition: eostools.py:510
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:32
ParameterSetConverter::ParameterSetIdConverter ParameterSetIdConverter
void fixProcessHistory(ProcessHistoryMap &pHistMap, ProcessHistoryVector &pHistVector)
double b
Definition: hdecay.h:120
std::vector< BranchID::value_type > BranchIDList
Definition: BranchIDList.h:18
double a
Definition: hdecay.h:121
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:142
void branchListIndexes(BranchListIndexes &indexes) const