CMS 3D CMS Logo

DaqProvenanceHelper.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <cassert>
3 #include <vector>
4 
6 
16 
17 namespace {
18  edm::BranchDescription makeDescriptionForDaqProvHelper(edm::TypeID const& rawDataType) {
20  "rawDataCollector",
21  // "source",
22  "LHC",
23  // "HLT",
24  "FEDRawDataCollection",
25  "FEDRawDataCollection",
26  "",
27  "FedRawDataInputSource",
29  edm::TypeWithDict(rawDataType.typeInfo()),
30  false);
31  desc.setIsProvenanceSetOnRead();
32  return desc;
33  }
34 } // namespace
35 
36 namespace edm {
38  : constBranchDescription_(makeDescriptionForDaqProvHelper(rawDataType)),
39  dummyProvenance_(constBranchDescription_.branchID()),
40  processParameterSet_(),
41  oldProcessName_(),
42  oldBranchID_(),
43  newBranchID_(),
44  oldProcessHistoryID_(nullptr),
45  phidMap_() {
46  // Now we create a process parameter set for the "LHC" process.
47  // We don't currently use the untracked parameters, However, we make them available, just in case.
51  typedef std::vector<std::string> vstring;
52  vstring empty;
53 
54  vstring modlbl;
55  modlbl.reserve(1);
56  modlbl.push_back(moduleLabel);
57  processParameterSet_.addParameter("@all_sources", modlbl);
58 
60  triggerPaths.addParameter<vstring>("@trigger_paths", empty);
62 
63  ParameterSet pseudoInput;
64  pseudoInput.addParameter<std::string>("@module_edm_type", "Source");
65  pseudoInput.addParameter<std::string>("@module_label", moduleLabel);
66  pseudoInput.addParameter<std::string>("@module_type", moduleName);
68 
69  processParameterSet_.addParameter<vstring>("@all_esmodules", empty);
70  processParameterSet_.addParameter<vstring>("@all_esprefers", empty);
71  processParameterSet_.addParameter<vstring>("@all_essources", empty);
77  // Now we register the process parameter set.
79 
80  //std::cerr << processParameterSet_.dump() << std::endl;
81  }
82 
84  ProcessHistoryRegistry& processHistoryRegistry) const {
85  // Now we need to set all the metadata
86  // Add the product to the product registry
87  productRegistry.copyProduct(constBranchDescription_);
88 
89  // Insert an entry for this process in the process history registry
90  ProcessHistory ph;
92  processHistoryRegistry.registerProcessHistory(ph);
93 
94  // Save the process history ID for use every event.
95  return ph.setProcessHistoryID();
96  }
97 
99  for (auto const& pc : ph) {
100  if (pc.processName() == oldProcessName_) {
101  return (pc.releaseVersion() == newPC.releaseVersion() && pc.passID() == newPC.passID());
102  }
103  }
104  return false;
105  }
106 
107  void DaqProvenanceHelper::fixMetaData(std::vector<ProcessConfiguration>& pcv, std::vector<ProcessHistory>& phv) {
108  phv.push_back(ProcessHistory()); // For new processHistory, containing only processConfiguration_
109  std::vector<ProcessConfiguration> newPCs;
110  for (auto const& pc : pcv) {
111  if (pc.processName() == oldProcessName_) {
112  newPCs.emplace_back(
113  constBranchDescription_.processName(), processParameterSet_.id(), pc.releaseVersion(), pc.passID());
114  }
115  }
116  assert(!newPCs.empty());
117  pcv.reserve(pcv.size() + newPCs.size());
118  pcv.insert(pcv.end(), newPCs.begin(), newPCs.end());
119  // update existing process histories
120  for (auto& ph : phv) {
121  for (auto const& newPC : newPCs) {
122  if (ph.empty() || matchProcesses(newPC, ph)) {
123  ProcessHistoryID oldPHID = ph.id();
124  ph.push_front(newPC);
125  ProcessHistoryID newPHID = ph.id();
126  phidMap_.insert(std::make_pair(oldPHID, newPHID));
127  break;
128  }
129  }
130  }
131  // For new process histories, containing only the new process configurations
132  phv.reserve(phv.size() + newPCs.size());
133  for (auto const& newPC : newPCs) {
134  phv.emplace_back();
135  phv.back().push_front(newPC);
136  }
137  }
138 
139  void DaqProvenanceHelper::fixMetaData(std::vector<BranchID>& branchID) const {
140  std::replace(branchID.begin(), branchID.end(), oldBranchID_, newBranchID_);
141  }
142 
143  void DaqProvenanceHelper::fixMetaData(BranchIDLists const& branchIDLists) const {
146  // The const_cast is ugly, but it beats the alternatives.
147  BranchIDLists& lists = const_cast<BranchIDLists&>(branchIDLists);
148  for (auto& list : lists) {
149  std::replace(list.begin(), list.end(), oldID, newID);
150  }
151  }
152 
153  void DaqProvenanceHelper::fixMetaData(BranchChildren& branchChildren) const {
154  typedef std::map<BranchID, std::set<BranchID> > BCMap;
155  // The const_cast is ugly, but it beats the alternatives.
156  BCMap& childLookup = const_cast<BCMap&>(branchChildren.childLookup());
157  // First fix any old branchID's in the key.
158  {
159  BCMap::iterator i = childLookup.find(oldBranchID_);
160  if (i != childLookup.end()) {
161  childLookup.insert(std::make_pair(newBranchID_, i->second));
162  childLookup.erase(i);
163  }
164  }
165  // Now fix any old branchID's in the sets;
166  for (auto& child : childLookup) {
167  if (child.second.erase(oldBranchID_) != 0) {
168  child.second.insert(newBranchID_);
169  }
170  }
171  }
172 
173  // Replace process history ID.
175  ProcessHistoryIDMap::const_iterator it = phidMap_.find(phid);
176  assert(it != phidMap_.end());
177  oldProcessHistoryID_ = &it->first;
178  return it->second;
179  }
180 
181  // Replace parentage ID.
183  ParentageIDMap::const_iterator it = parentageIDMap_.find(parentageID);
184  if (it == parentageIDMap_.end()) {
185  return parentageID;
186  }
187  return it->second;
188  }
189 
190  // Replace branch ID if necessary.
191  BranchID const& DaqProvenanceHelper::mapBranchID(BranchID const& branchID) const {
192  return (branchID == oldBranchID_ ? newBranchID_ : branchID);
193  }
194 
196  parentageIDMap_.insert(std::make_pair(iOld, iNew));
197  }
198 
199 } // namespace edm
edm::ParameterSet::registerIt
ParameterSet const & registerIt()
Definition: ParameterSet.cc:113
edm::DaqProvenanceHelper::oldBranchID_
BranchID oldBranchID_
Definition: DaqProvenanceHelper.h:58
edm::DaqProvenanceHelper::oldProcessName_
std::string oldProcessName_
Definition: DaqProvenanceHelper.h:57
edm::ProcessHistoryRegistry::registerProcessHistory
bool registerProcessHistory(ProcessHistory const &processHistory)
Definition: ProcessHistoryRegistry.cc:11
mps_fire.i
i
Definition: mps_fire.py:428
edm::ProcessConfiguration::releaseVersion
ReleaseVersion const & releaseVersion() const
Definition: ProcessConfiguration.h:27
edm::DaqProvenanceHelper::processParameterSet_
ParameterSet processParameterSet_
Definition: DaqProvenanceHelper.h:55
edm::DaqProvenanceHelper::mapParentageID
ParentageID const & mapParentageID(ParentageID const &phid) const
Definition: DaqProvenanceHelper.cc:182
ProducerES_cfi.ProcessHistory
ProcessHistory
Definition: ProducerES_cfi.py:14
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::DaqProvenanceHelper::matchProcesses
bool matchProcesses(ProcessConfiguration const &pc, ProcessHistory const &ph) const
Definition: DaqProvenanceHelper.cc:98
edm::DaqProvenanceHelper::oldProcessHistoryID_
ProcessHistoryID const * oldProcessHistoryID_
Definition: DaqProvenanceHelper.h:60
edm::TypeID::typeInfo
constexpr const std::type_info & typeInfo() const
Definition: TypeIDBase.h:50
cms::cuda::assert
assert(be >=bs)
edm::DaqProvenanceHelper::newBranchID_
BranchID newBranchID_
Definition: DaqProvenanceHelper.h:59
ProcessHistoryRegistry.h
TypeWithDict.h
ProductRegistry.h
edm::ParameterSet::id
ParameterSetID id() const
Definition: ParameterSet.cc:189
edm::getPassID
std::string getPassID()
Definition: GetPassID.h:7
edm::BranchID::id
unsigned int id() const
Definition: BranchID.h:21
edm::ProcessConfiguration::passID
PassID const & passID() const
Definition: ProcessConfiguration.h:28
edm::ProductRegistry
Definition: ProductRegistry.h:37
edm::vstring
std::vector< std::string > vstring
Definition: Schedule.cc:653
ProcessHistory.h
edm::BranchDescription::processName
std::string const & processName() const
Definition: BranchDescription.h:73
edm::BranchID
Definition: BranchID.h:14
edm::Hash< ParameterSetType >
edm::InEvent
Definition: BranchType.h:11
edm::BranchIDLists
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
edm::BranchID::value_type
unsigned int value_type
Definition: BranchID.h:16
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ProductRegistry::copyProduct
void copyProduct(BranchDescription const &productdesc)
Definition: ProductRegistry.cc:122
edm::TypeWithDict
Definition: TypeWithDict.h:38
edm::DaqProvenanceHelper::mapBranchID
BranchID const & mapBranchID(BranchID const &branchID) const
Definition: DaqProvenanceHelper.cc:191
edm::ParameterSet
Definition: ParameterSet.h:47
GetReleaseVersion.h
edm::DaqProvenanceHelper::daqInit
ProcessHistoryID daqInit(ProductRegistry &productRegistry, ProcessHistoryRegistry &processHistoryRegistry) const
Definition: DaqProvenanceHelper.cc:83
edm::DaqProvenanceHelper::setOldParentageIDToNew
void setOldParentageIDToNew(ParentageID const &iOld, ParentageID const &iNew)
Definition: DaqProvenanceHelper.cc:195
edm::ParameterSet::addParameter
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
edm::BranchChildren
Definition: BranchChildren.h:18
edm::BranchChildren::childLookup
map_t const & childLookup() const
Definition: BranchChildren.h:41
GetPassID.h
triggerPaths
static const std::string triggerPaths
Definition: EdmProvDump.cc:46
edm::DaqProvenanceHelper::parentageIDMap_
ParentageIDMap parentageIDMap_
Definition: DaqProvenanceHelper.h:62
BranchIDList.h
edm::ProcessHistory::emplace_back
void emplace_back(Args &&... args)
Definition: ProcessHistory.h:34
edm::DaqProvenanceHelper::DaqProvenanceHelper
DaqProvenanceHelper(TypeID const &rawDataType)
Definition: DaqProvenanceHelper.cc:37
SimL1EmulatorRepack_CalouGT_cff.processName
processName
Definition: SimL1EmulatorRepack_CalouGT_cff.py:17
edm::BranchDescription::moduleName
std::string const & moduleName() const
Definition: BranchDescription.h:115
edm::ProcessHistory::setProcessHistoryID
ProcessHistoryID setProcessHistoryID()
Definition: ProcessHistory.cc:27
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
edm::TypeID
Definition: TypeID.h:22
edm::ProcessHistoryID
Hash< ProcessHistoryType > ProcessHistoryID
Definition: ProcessHistoryID.h:8
edm::BranchDescription::moduleLabel
std::string const & moduleLabel() const
Definition: BranchDescription.h:72
edm::DaqProvenanceHelper::mapProcessHistoryID
ProcessHistoryID const & mapProcessHistoryID(ProcessHistoryID const &phid)
Definition: DaqProvenanceHelper.cc:174
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
edm::DaqProvenanceHelper::phidMap_
ProcessHistoryIDMap phidMap_
Definition: DaqProvenanceHelper.h:61
edm::getReleaseVersion
std::string getReleaseVersion()
Definition: GetReleaseVersion.cc:7
edm::ProcessHistoryRegistry
Definition: ProcessHistoryRegistry.h:18
edm::BranchDescription
Definition: BranchDescription.h:32
edm::DaqProvenanceHelper::fixMetaData
void fixMetaData(ProcessConfigurationVector &pcv, std::vector< ProcessHistory > &phv)
edm::ProcessHistory
Definition: ProcessHistory.h:13
ParameterSet.h
HerwigMaxPtPartonFilter_cfi.moduleLabel
moduleLabel
Definition: HerwigMaxPtPartonFilter_cfi.py:4
edm::moduleName
std::string moduleName(Provenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:27
child
Definition: simpleInheritance.h:11
DaqProvenanceHelper.h
edm::ProcessConfiguration
Definition: ProcessConfiguration.h:14
edm::DaqProvenanceHelper::constBranchDescription_
const BranchDescription constBranchDescription_
Definition: DaqProvenanceHelper.h:53
python.rootplot.root2matplotlib.replace
def replace(string, replacements)
Definition: root2matplotlib.py:444
BranchChildren.h