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 (ProcessHistoryVector::const_iterator it = pHistVec.begin(), itEnd = pHistVec.end();
83  it != itEnd; ++it) {
84  for (ProcessConfigurationVector::const_iterator i = it->begin(), iEnd = it->end();
85  i != iEnd; ++i) {
86  if (pcset.insert(*i).second) {
87  procConfigVector.push_back(*i);
88  }
89  }
90  }
91  }
92 
93  void
94  fillListsAndIndexes(ProductRegistry const& productRegistry,
95  ProcessHistoryMap const& pHistMap,
96  boost::shared_ptr<BranchIDLists const>& branchIDLists,
97  std::vector<BranchListIndex>& branchListIndexes) {
98  OrderedProducts orderedProducts;
99  std::set<std::string> processNamesThatProduced;
100  ProductRegistry::ProductList const& prodList = productRegistry.productList();
101  for (ProductRegistry::ProductList::const_iterator it = prodList.begin(), itEnd = prodList.end();
102  it != itEnd; ++it) {
103  if (it->second.branchType() == InEvent) {
104  it->second.init();
105  processNamesThatProduced.insert(it->second.processName());
106  orderedProducts.emplace_back(it->second.processName(), it->second.branchID());
107  }
108  }
109  assert (!orderedProducts.empty());
110  Histories processHistories;
111  size_t max = 0;
112  for(ProcessHistoryMap::const_iterator it = pHistMap.begin(), itEnd = pHistMap.end(); it != itEnd; ++it) {
113  ProcessHistory const& pHist = it->second;
114  OneHistory processHistory;
115  for(ProcessHistory::const_iterator i = pHist.begin(), iEnd = pHist.end(); i != iEnd; ++i) {
116  if (processNamesThatProduced.find(i->processName()) != processNamesThatProduced.end()) {
117  processHistory.push_back(i->processName());
118  }
119  }
120  max = (processHistory.size() > max ? processHistory.size() : max);
121  assert(max <= processNamesThatProduced.size());
122  if (processHistory.size() > 1) {
123  processHistories.insert(processHistory);
124  }
125  }
126  stable_sort_all(orderedProducts, Sorter(processHistories));
127 
128  std::unique_ptr<BranchIDLists> pv(new BranchIDLists);
129  std::unique_ptr<BranchIDList> p(new BranchIDList);
130  std::string processName;
131  BranchListIndex blix = 0;
132  for (OrderedProducts::const_iterator it = orderedProducts.begin(), itEnd = orderedProducts.end(); it != itEnd; ++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.reset(new 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  }
149 
151  ProductRegistry& productRegistry,
152  ProcessHistoryMap& pHistMap,
153  ProcessHistoryVector& pHistVector,
154  ProcessConfigurationVector& procConfigVector,
155  ParameterSetIdConverter const& parameterSetIdConverter,
156  bool fullConversion) :
157  parameterSetIdConverter_(parameterSetIdConverter),
158  processHistoryIdConverter_(),
159  branchIDLists_(),
160  branchListIndexes_() {
161  fixProcessHistory(pHistMap, pHistVector);
162  fillProcessConfiguration(pHistVector, procConfigVector);
163  if (fullConversion) {
164  fillListsAndIndexes(productRegistry, pHistMap, branchIDLists_, branchListIndexes_);
165  }
166  }
167 
169 
170  ParameterSetID const&
172  ParameterSetIdConverter::const_iterator it = parameterSetIdConverter_.find(oldID);
173  if (it == parameterSetIdConverter_.end()) {
174  return oldID;
175  }
176  return it->second;
177  }
178 
179  ProcessHistoryID const&
181  ProcessHistoryIdConverter::const_iterator it = processHistoryIdConverter_.find(oldID);
182  if (it == processHistoryIdConverter_.end()) {
183  return oldID;
184  }
185  return it->second;
186  }
187 
188  boost::shared_ptr<BranchIDLists const>
190  return branchIDLists_;
191  }
192 
193  void
195  indexes = branchListIndexes_;
196  }
197 }
collection_type::const_iterator const_iterator
boost::shared_ptr< BranchIDLists const > branchIDLists_
int i
Definition: DBlmapReader.cc:9
unsigned short BranchListIndex
size_type size() const
ProcessHistoryIdConverter processHistoryIdConverter_
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
boost::shared_ptr< BranchIDLists const > branchIDLists() const
std::map< BranchKey, BranchDescription > ProductList
std::vector< std::string > StringVector
ProcessHistoryRegistry::collection_type ProcessHistoryMap
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)
ProcessConfigurationRegistry::vector_type ProcessConfigurationVector
ParameterSetIdConverter parameterSetIdConverter_
std::vector< BranchListIndex > BranchListIndexes
ProcessHistoryRegistry::vector_type ProcessHistoryVector
std::vector< BranchListIndex > branchListIndexes_
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
ProcessHistoryID id() const
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:137
void branchListIndexes(BranchListIndexes &indexes) const