CMS 3D CMS Logo

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 
24  assert(pHistMap.empty() != pHistVector.empty());
25  for (ProcessHistoryVector::const_iterator i = pHistVector.begin(), e = pHistVector.end(); i != e; ++i) {
26  pHistMap.insert(std::make_pair(i->id(), *i));
27  }
28  pHistVector.clear();
29  for (ProcessHistoryMap::const_iterator i = pHistMap.begin(), e = pHistMap.end(); i != e; ++i) {
30  ProcessHistory newHist;
31  ProcessHistoryID const& oldphID = i->first;
32  for (ProcessHistory::const_iterator it = i->second.begin(), et = i->second.end(); it != et; ++it) {
33  ParameterSetID const& newPsetID = convertID(it->parameterSetID());
34  newHist.emplace_back(it->processName(), newPsetID, it->releaseVersion(), it->passID());
35  }
36  assert(newHist.size() == i->second.size());
37  ProcessHistoryID newphID = newHist.id();
38  pHistVector.push_back(std::move(newHist));
39  if (newphID != oldphID) {
40  processHistoryIdConverter_.insert(std::make_pair(oldphID, newphID));
41  }
42  }
43  assert(pHistVector.size() == pHistMap.size());
44  }
45 
46  namespace {
47  typedef StringVector OneHistory;
48  typedef std::set<OneHistory> Histories;
49  typedef std::pair<std::string, BranchID> Product;
50  typedef std::vector<Product> OrderedProducts;
51  struct Sorter {
52  explicit Sorter(Histories const& histories) : histories_(histories) {}
53  bool operator()(Product const& a, Product const& b) const;
54  Histories const histories_;
55  };
56  bool Sorter::operator()(Product const& a, Product const& b) const {
57  assert(a != b);
58  if (a.first == b.first)
59  return false;
60  bool mayBeTrue = false;
61  for (Histories::const_iterator it = histories_.begin(), itEnd = histories_.end(); it != itEnd; ++it) {
62  OneHistory::const_iterator itA = find_in_all(*it, a.first);
63  if (itA == it->end())
64  continue;
65  OneHistory::const_iterator itB = find_in_all(*it, b.first);
66  if (itB == it->end())
67  continue;
68  assert(itA != itB);
69  if (itB < itA) {
70  // process b precedes process a;
71  return false;
72  }
73  // process a precedes process b;
74  mayBeTrue = true;
75  }
76  return mayBeTrue;
77  }
78 
79  void 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 fillListsAndIndexes(ProductRegistry& productRegistry,
92  ProcessHistoryMap const& pHistMap,
93  std::shared_ptr<BranchIDLists const>& branchIDLists,
94  std::vector<BranchListIndex>& branchListIndexes) {
95  OrderedProducts orderedProducts;
96  std::set<std::string> processNamesThatProduced;
97  ProductRegistry::ProductList& prodList = productRegistry.productListUpdator();
98  for (auto& item : prodList) {
99  BranchDescription& prod = item.second;
100  if (prod.branchType() == InEvent) {
101  prod.init();
102  processNamesThatProduced.insert(prod.processName());
103  orderedProducts.emplace_back(prod.processName(), prod.branchID());
104  }
105  }
106  assert(!orderedProducts.empty());
107  Histories processHistories;
108  size_t max = 0;
109  for (ProcessHistoryMap::const_iterator it = pHistMap.begin(), itEnd = pHistMap.end(); it != itEnd; ++it) {
110  ProcessHistory const& pHist = it->second;
111  OneHistory processHistory;
112  for (ProcessHistory::const_iterator i = pHist.begin(), iEnd = pHist.end(); i != iEnd; ++i) {
113  if (processNamesThatProduced.find(i->processName()) != processNamesThatProduced.end()) {
114  processHistory.push_back(i->processName());
115  }
116  }
117  max = (processHistory.size() > max ? processHistory.size() : max);
118  assert(max <= processNamesThatProduced.size());
119  if (processHistory.size() > 1) {
120  processHistories.insert(processHistory);
121  }
122  }
123  stable_sort_all(orderedProducts, Sorter(processHistories));
124 
125  auto pv = std::make_unique<BranchIDLists>();
126  auto p = std::make_unique<BranchIDList>();
128  BranchListIndex blix = 0;
129  for (OrderedProducts::const_iterator it = orderedProducts.begin(), itEnd = orderedProducts.end(); it != itEnd;
130  ++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  } // namespace
147 
149  ProcessHistoryMap& pHistMap,
150  ProcessHistoryVector& pHistVector,
151  ProcessConfigurationVector& procConfigVector,
152  ParameterSetIdConverter const& parameterSetIdConverter,
153  bool fullConversion)
154  : parameterSetIdConverter_(parameterSetIdConverter),
156  branchIDLists_(),
158  fixProcessHistory(pHistMap, pHistVector);
159  fillProcessConfiguration(pHistVector, procConfigVector);
160  if (fullConversion) {
161  fillListsAndIndexes(productRegistry, pHistMap, branchIDLists_, branchListIndexes_);
162  }
163  }
164 
166 
168  ParameterSetIdConverter::const_iterator it = parameterSetIdConverter_.find(oldID);
169  if (it == parameterSetIdConverter_.end()) {
170  return oldID;
171  }
172  return it->second;
173  }
174 
176  ProcessHistoryIdConverter::const_iterator it = processHistoryIdConverter_.find(oldID);
177  if (it == processHistoryIdConverter_.end()) {
178  return oldID;
179  }
180  return it->second;
181  }
182 
183  std::shared_ptr<BranchIDLists const> ProvenanceAdaptor::branchIDLists() const { return branchIDLists_; }
184 
186 } // namespace edm
std::vector< ProcessHistory > ProcessHistoryVector
collection_type::const_iterator const_iterator
const_iterator begin() const
std::vector< ProcessConfiguration > ProcessConfigurationVector
unsigned short BranchListIndex
size_type size() const
ProcessHistoryIdConverter processHistoryIdConverter_
BranchType const & branchType() const
std::shared_ptr< BranchIDLists const > branchIDLists_
std::map< BranchKey, BranchDescription > ProductList
std::vector< std::string > StringVector
std::string const & processName() const
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
void emplace_back(Args &&...args)
ParameterSetIdConverter parameterSetIdConverter_
std::vector< BranchListIndex > BranchListIndexes
def pv(vc)
Definition: MetAnalyzer.py:7
BranchID const & branchID() const
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
void push_back(const_reference t)
ParameterSetConverter::ParameterSetIdConverter ParameterSetIdConverter
void fixProcessHistory(ProcessHistoryMap &pHistMap, ProcessHistoryVector &pHistVector)
double b
Definition: hdecay.h:120
ProductList & productListUpdator()
et
define resolution functions of each parameter
const_iterator end() const
std::vector< BranchID::value_type > BranchIDList
Definition: BranchIDList.h:18
HLT enums.
double a
Definition: hdecay.h:121
ParameterSetID const & convertID(ParameterSetID const &oldID) const
ProcessHistoryID id() const
std::map< ProcessHistoryID, ProcessHistory > ProcessHistoryMap
def move(src, dest)
Definition: eostools.py:511
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:142
void branchListIndexes(BranchListIndexes &indexes) const