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),
155  processHistoryIdConverter_(),
156  branchIDLists_(),
157  branchListIndexes_() {
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
mps_fire.i
i
Definition: mps_fire.py:355
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:185
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:183
edm::ProvenanceAdaptor::parameterSetIdConverter_
ParameterSetIdConverter parameterSetIdConverter_
Definition: ProvenanceAdaptor.h:52
edm::ProductRegistry
Definition: ProductRegistry.h:34
edm::ProcessHistoryMap
std::map< ProcessHistoryID, ProcessHistory > ProcessHistoryMap
Definition: ProcessHistoryRegistry.h:15
edm::ProvenanceAdaptor::~ProvenanceAdaptor
~ProvenanceAdaptor()
Definition: ProvenanceAdaptor.cc:165
ProcessHistory.h
ProcessConfiguration.h
edm::BranchIDList
std::vector< BranchID::value_type > BranchIDList
Definition: BranchIDList.h:18
dumpMFGeometry_cfg.prod
prod
Definition: dumpMFGeometry_cfg.py:24
edm::ProvenanceAdaptor::convertID
ParameterSetID const & convertID(ParameterSetID const &oldID) const
Definition: ProvenanceAdaptor.cc:167
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:36
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:17
edm::ProvenanceAdaptor::fixProcessHistory
void fixProcessHistory(ProcessHistoryMap &pHistMap, ProcessHistoryVector &pHistVector)
Definition: ProvenanceAdaptor.cc:23
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:148
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