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 <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
mps_fire.i
i
Definition: mps_fire.py:428
edm::find_in_all
ForwardSequence::const_iterator find_in_all(ForwardSequence const &s, Datum const &d)
wrappers for std::find
Definition: Algorithms.h:26
ProducerES_cfi.ProcessHistory
ProcessHistory
Definition: ProducerES_cfi.py:14
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::max
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:118
edm::ProvenanceAdaptor::branchListIndexes
void branchListIndexes(BranchListIndexes &indexes) const
Definition: ProvenanceAdaptor.cc:187
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
BranchID.h
edm::BranchListIndexes
std::vector< BranchListIndex > BranchListIndexes
Definition: BranchListIndex.h:18
Algorithms.h
edm::ProcessHistory::id
ProcessHistoryID id() const
Definition: ProcessHistory.cc:10
cms::cuda::assert
assert(be >=bs)
edm::ProvenanceAdaptor::branchIDLists_
std::shared_ptr< BranchIDLists const > branchIDLists_
Definition: ProvenanceAdaptor.h:54
ProductRegistry.h
edm::ProvenanceAdaptor::branchIDLists
std::shared_ptr< BranchIDLists const > branchIDLists() const
Definition: ProvenanceAdaptor.cc:185
edm::ProvenanceAdaptor::parameterSetIdConverter_
ParameterSetIdConverter parameterSetIdConverter_
Definition: ProvenanceAdaptor.h:52
edm::ProductRegistry
Definition: ProductRegistry.h:37
edm::ProcessHistoryMap
std::map< ProcessHistoryID, ProcessHistory > ProcessHistoryMap
Definition: ProcessHistoryRegistry.h:15
edm::ProvenanceAdaptor::~ProvenanceAdaptor
~ProvenanceAdaptor()
Definition: ProvenanceAdaptor.cc:167
ProcessHistory.h
ProcessConfiguration.h
dumpMFGeometry_cfg.prod
prod
Definition: dumpMFGeometry_cfg.py:24
edm::ProvenanceAdaptor::convertID
ParameterSetID const & convertID(ParameterSetID const &oldID) const
Definition: ProvenanceAdaptor.cc:169
edm::Hash< ProcessHistoryType >
edm::BranchListIndex
unsigned short BranchListIndex
Definition: BranchListIndex.h:17
edm::InEvent
Definition: BranchType.h:11
b
double b
Definition: hdecay.h:118
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ProcessHistory::size
size_type size() const
Definition: ProcessHistory.h:52
edm::ProductRegistry::ProductList
std::map< BranchKey, BranchDescription > ProductList
Definition: ProductRegistry.h:39
edm::ProvenanceAdaptor::branchListIndexes_
std::vector< BranchListIndex > branchListIndexes_
Definition: ProvenanceAdaptor.h:55
a
double a
Definition: hdecay.h:119
edm::ProcessHistory::const_iterator
collection_type::const_iterator const_iterator
Definition: ProcessHistory.h:19
LaserDQM_cfg.process
process
Definition: LaserDQM_cfg.py:3
edm::ProcessConfigurationVector
std::vector< ProcessConfiguration > ProcessConfigurationVector
Definition: ProcessConfiguration.h:62
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
edm::ProcessHistoryVector
std::vector< ProcessHistory > ProcessHistoryVector
Definition: ProcessHistoryRegistry.h:16
edm::StringVector
std::vector< std::string > StringVector
Definition: ParameterSetConverter.h:16
edm::ProvenanceAdaptor::fixProcessHistory
void fixProcessHistory(ProcessHistoryMap &pHistMap, ProcessHistoryVector &pHistVector)
Definition: ProvenanceAdaptor.cc:25
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
edm::ProcessHistory::emplace_back
void emplace_back(Args &&... args)
Definition: ProcessHistory.h:34
SimL1EmulatorRepack_CalouGT_cff.processName
processName
Definition: SimL1EmulatorRepack_CalouGT_cff.py:17
edm::ProvenanceAdaptor::ProvenanceAdaptor
ProvenanceAdaptor(ProductRegistry &productRegistry, ProcessHistoryMap &pHistMap, ProcessHistoryVector &pHistVector, ProcessConfigurationVector &procConfigVector, ParameterSetIdConverter const &parameterSetIdConverter, bool fullConversion)
Definition: ProvenanceAdaptor.cc:150
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::ProvenanceAdaptor::ParameterSetIdConverter
ParameterSetConverter::ParameterSetIdConverter ParameterSetIdConverter
Definition: ProvenanceAdaptor.h:28
ProvenanceAdaptor.h
edm::ProcessHistory
Definition: ProcessHistory.h:13
edm::stable_sort_all
void stable_sort_all(RandomAccessSequence &s)
wrappers for std::stable_sort
Definition: Algorithms.h:103
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::ProvenanceAdaptor::processHistoryIdConverter_
ProcessHistoryIdConverter processHistoryIdConverter_
Definition: ProvenanceAdaptor.h:53