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
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
std::string getPassID()
Definition: GetPassID.h:7
DaqProvenanceHelper(TypeID const &rawDataType)
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
ReleaseVersion const & releaseVersion() const
bool registerProcessHistory(ProcessHistory const &processHistory)
def replace(string, replacements)
std::string const & moduleName() const
std::string const & processName() const
assert(be >=bs)
ProcessHistoryID daqInit(ProductRegistry &productRegistry, ProcessHistoryRegistry &processHistoryRegistry) const
void fixMetaData(ProcessConfigurationVector &pcv, std::vector< ProcessHistory > &phv)
ParameterSetID id() const
PassID const & passID() const
ParameterSet const & registerIt()
BranchID const & mapBranchID(BranchID const &branchID) const
unsigned int value_type
Definition: BranchID.h:16
bool matchProcesses(ProcessConfiguration const &pc, ProcessHistory const &ph) const
void setOldParentageIDToNew(ParentageID const &iOld, ParentageID const &iNew)
ProcessHistoryIDMap phidMap_
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
unsigned int id() const
Definition: BranchID.h:21
map_t const & childLookup() const
ParentageID const & mapParentageID(ParentageID const &phid) const
Hash< ProcessHistoryType > ProcessHistoryID
std::string getReleaseVersion()
ProcessHistoryID const & mapProcessHistoryID(ProcessHistoryID const &phid)
std::string moduleName(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:27
HLT enums.
BranchDescription const constBranchDescription_
constexpr const std::type_info & typeInfo() const
Definition: TypeIDBase.h:50
static std::string const triggerPaths
Definition: EdmProvDump.cc:48
std::string const & moduleLabel() const
std::vector< std::string > vstring
Definition: Schedule.cc:475
void copyProduct(BranchDescription const &productdesc)
ProcessHistoryID const * oldProcessHistoryID_