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 
22 namespace edm {
23 
24  void
26  ProcessHistoryVector& pHistVector) {
27  assert (pHistMap.empty() != pHistVector.empty());
28  for (ProcessHistoryVector::const_iterator i = pHistVector.begin(), e = pHistVector.end(); i != e; ++i) {
29  pHistMap.insert(std::make_pair(i->id(), *i));
30  }
31  pHistVector.clear();
32  for (ProcessHistoryMap::const_iterator i = pHistMap.begin(), e = pHistMap.end(); i != e; ++i) {
33  ProcessHistory newHist;
34  ProcessHistoryID const& oldphID = i->first;
35  for (ProcessHistory::const_iterator it = i->second.begin(), et = i->second.end(); it != et; ++it) {
36  ParameterSetID const& newPsetID = convertID(it->parameterSetID());
37  newHist.push_back(ProcessConfiguration(it->processName(), newPsetID, it->releaseVersion(), it->passID()));
38  }
39  assert(newHist.size() == i->second.size());
40  ProcessHistoryID newphID = newHist.id();
41  pHistVector.push_back(newHist);
42  if (newphID != oldphID) {
43  processHistoryIdConverter_.insert(std::make_pair(oldphID, newphID));
44  }
45  }
46  assert(pHistVector.size() == pHistMap.size());
47  }
48 
49  namespace {
50  typedef StringVector OneHistory;
51  typedef std::set<OneHistory> Histories;
52  typedef std::pair<std::string, BranchID> Product;
53  typedef std::vector<Product> OrderedProducts;
54  struct Sorter {
55  explicit Sorter(Histories const& histories) : histories_(histories) {}
56  bool operator()(Product const& a, Product const& b) const;
57  Histories const histories_;
58  };
59  bool Sorter::operator()(Product const& a, Product const& b) const {
60  assert (a != b);
61  if (a.first == b.first) 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()) continue;
66  OneHistory::const_iterator itB = find_in_all(*it, b.first);
67  if (itB == it->end()) 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
80  fillProcessConfiguration(ProcessHistoryVector const& pHistVec, ProcessConfigurationVector& procConfigVector) {
81  procConfigVector.clear();
82  std::set<ProcessConfiguration> pcset;
83  for (ProcessHistoryVector::const_iterator it = pHistVec.begin(), itEnd = pHistVec.end();
84  it != itEnd; ++it) {
85  for (ProcessConfigurationVector::const_iterator i = it->begin(), iEnd = it->end();
86  i != iEnd; ++i) {
87  if (pcset.insert(*i).second) {
88  procConfigVector.push_back(*i);
89  }
90  }
91  }
92  }
93 
94  void
95  fillListsAndIndexes(ProductRegistry const& productRegistry,
96  ProcessHistoryMap const& pHistMap,
97  boost::shared_ptr<BranchIDLists const>& branchIDLists,
98  std::vector<BranchListIndex>& branchListIndexes) {
99  OrderedProducts orderedProducts;
100  std::set<std::string> processNamesThatProduced;
101  ProductRegistry::ProductList const& prodList = productRegistry.productList();
102  for (ProductRegistry::ProductList::const_iterator it = prodList.begin(), itEnd = prodList.end();
103  it != itEnd; ++it) {
104  if (it->second.branchType() == InEvent) {
105  it->second.init();
106  processNamesThatProduced.insert(it->second.processName());
107  orderedProducts.push_back(std::make_pair(it->second.processName(), it->second.branchID()));
108  }
109  }
110  assert (!orderedProducts.empty());
111  Histories processHistories;
112  size_t max = 0;
113  for(ProcessHistoryMap::const_iterator it = pHistMap.begin(), itEnd = pHistMap.end(); it != itEnd; ++it) {
114  ProcessHistory const& pHist = it->second;
115  OneHistory processHistory;
116  for(ProcessHistory::const_iterator i = pHist.begin(), iEnd = pHist.end(); i != iEnd; ++i) {
117  if (processNamesThatProduced.find(i->processName()) != processNamesThatProduced.end()) {
118  processHistory.push_back(i->processName());
119  }
120  }
121  max = (processHistory.size() > max ? processHistory.size() : max);
122  assert(max <= processNamesThatProduced.size());
123  if (processHistory.size() > 1) {
124  processHistories.insert(processHistory);
125  }
126  }
127  stable_sort_all(orderedProducts, Sorter(processHistories));
128 
129  std::auto_ptr<BranchIDLists> pv(new BranchIDLists);
130  std::auto_ptr<BranchIDList> p(new BranchIDList);
131  std::string processName;
132  BranchListIndex blix = 0;
133  for (OrderedProducts::const_iterator it = orderedProducts.begin(), itEnd = orderedProducts.end(); it != itEnd; ++it) {
134  if (it->first != processName) {
135  if (!processName.empty()) {
136  pv->push_back(*p);
137  branchListIndexes.push_back(blix);
138  ++blix;
139  p.reset(new BranchIDList);
140  }
141  processName = it->first;
142  }
143  p->push_back(it->second.id());
144  }
145  pv->push_back(*p);
146  branchListIndexes.push_back(blix);
147  branchIDLists.reset(pv.release());
148  }
149  }
150 
152  ProductRegistry& productRegistry,
153  ProcessHistoryMap& pHistMap,
154  ProcessHistoryVector& pHistVector,
155  ProcessConfigurationVector& procConfigVector,
156  ParameterSetIdConverter const& parameterSetIdConverter,
157  bool fullConversion) :
158  parameterSetIdConverter_(parameterSetIdConverter),
159  processHistoryIdConverter_(),
160  branchIDLists_(),
161  branchListIndexes_() {
162  fixProcessHistory(pHistMap, pHistVector);
163  fillProcessConfiguration(pHistVector, procConfigVector);
164  if (fullConversion) {
165  fillListsAndIndexes(productRegistry, pHistMap, branchIDLists_, branchListIndexes_);
166  }
167  }
168 
170 
171  ParameterSetID const&
173  ParameterSetIdConverter::const_iterator it = parameterSetIdConverter_.find(oldID);
174  if (it == parameterSetIdConverter_.end()) {
175  return oldID;
176  }
177  return it->second;
178  }
179 
180  ProcessHistoryID const&
182  ProcessHistoryIdConverter::const_iterator it = processHistoryIdConverter_.find(oldID);
183  if (it == processHistoryIdConverter_.end()) {
184  return oldID;
185  }
186  return it->second;
187  }
188 
189  boost::shared_ptr<BranchIDLists const>
191  return branchIDLists_;
192  }
193 
194  void
196  indexes = branchListIndexes_;
197  }
198 }
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_
boost::shared_ptr< BranchIDLists const > branchIDLists() const
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
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
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
void push_back(const_reference t)
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
author Stefano ARGIRO author Bill Tanenbaum
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