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,
21  std::string const& sourceLabel) {
23  "rawDataCollector",
24  // "source",
25  "LHC",
26  // "HLT",
29  "",
30  sourceLabel,
32  edm::TypeWithDict(rawDataType.typeInfo()),
33  false);
34  desc.setIsProvenanceSetOnRead();
35  return desc;
36  }
37 } // namespace
38 
39 namespace edm {
43  std::string const& sourceLabel)
44  : constBranchDescription_(
45  makeDescriptionForDaqProvHelper(rawDataType, collectionName, friendlyName, sourceLabel)),
46  dummyProvenance_(constBranchDescription_.branchID()),
47  processParameterSet_(),
48  oldProcessName_(),
49  oldBranchID_(),
50  newBranchID_(),
51  oldProcessHistoryID_(nullptr),
52  phidMap_() {
53  // Now we create a process parameter set for the "LHC" process.
54  // We don't currently use the untracked parameters, However, we make them available, just in case.
58  typedef std::vector<std::string> vstring;
59  vstring empty;
60 
61  vstring modlbl;
62  modlbl.reserve(1);
63  modlbl.push_back(moduleLabel);
64  processParameterSet_.addParameter("@all_sources", modlbl);
65 
67  triggerPaths.addParameter<vstring>("@trigger_paths", empty);
69 
70  ParameterSet pseudoInput;
71  pseudoInput.addParameter<std::string>("@module_edm_type", "Source");
72  pseudoInput.addParameter<std::string>("@module_label", moduleLabel);
73  pseudoInput.addParameter<std::string>("@module_type", moduleName);
75 
76  processParameterSet_.addParameter<vstring>("@all_esmodules", empty);
77  processParameterSet_.addParameter<vstring>("@all_esprefers", empty);
78  processParameterSet_.addParameter<vstring>("@all_essources", empty);
84  // Now we register the process parameter set.
86 
87  //std::cerr << processParameterSet_.dump() << std::endl;
88  }
89 
90  //default
92  : DaqProvenanceHelper(rawDataType, "FEDRawDataCollection", "FEDRawDataCollection", "FedRawDataInputSource") {}
93 
95  ProcessHistoryRegistry& processHistoryRegistry) const {
96  // Now we need to set all the metadata
97  // Add the product to the product registry
98  productRegistry.copyProduct(constBranchDescription_);
99 
100  // Insert an entry for this process in the process history registry
103  processHistoryRegistry.registerProcessHistory(ph);
104 
105  // Save the process history ID for use every event.
106  return ph.setProcessHistoryID();
107  }
108 
110  for (auto const& pc : ph) {
111  if (pc.processName() == oldProcessName_) {
112  return (pc.releaseVersion() == newPC.releaseVersion() && pc.passID() == newPC.passID());
113  }
114  }
115  return false;
116  }
117 
118  void DaqProvenanceHelper::fixMetaData(std::vector<ProcessConfiguration>& pcv, std::vector<ProcessHistory>& phv) {
119  phv.push_back(ProcessHistory()); // For new processHistory, containing only processConfiguration_
120  std::vector<ProcessConfiguration> newPCs;
121  for (auto const& pc : pcv) {
122  if (pc.processName() == oldProcessName_) {
123  newPCs.emplace_back(
124  constBranchDescription_.processName(), processParameterSet_.id(), pc.releaseVersion(), pc.passID());
125  }
126  }
127  assert(!newPCs.empty());
128  pcv.reserve(pcv.size() + newPCs.size());
129  pcv.insert(pcv.end(), newPCs.begin(), newPCs.end());
130  // update existing process histories
131  for (auto& ph : phv) {
132  for (auto const& newPC : newPCs) {
133  if (ph.empty() || matchProcesses(newPC, ph)) {
134  ProcessHistoryID oldPHID = ph.id();
135  ph.push_front(newPC);
136  ProcessHistoryID newPHID = ph.id();
137  phidMap_.insert(std::make_pair(oldPHID, newPHID));
138  break;
139  }
140  }
141  }
142  // For new process histories, containing only the new process configurations
143  phv.reserve(phv.size() + newPCs.size());
144  for (auto const& newPC : newPCs) {
145  phv.emplace_back();
146  phv.back().push_front(newPC);
147  }
148  }
149 
150  void DaqProvenanceHelper::fixMetaData(std::vector<BranchID>& branchID) const {
151  std::replace(branchID.begin(), branchID.end(), oldBranchID_, newBranchID_);
152  }
153 
154  void DaqProvenanceHelper::fixMetaData(BranchIDLists const& branchIDLists) const {
157  // The const_cast is ugly, but it beats the alternatives.
158  BranchIDLists& lists = const_cast<BranchIDLists&>(branchIDLists);
159  for (auto& list : lists) {
160  std::replace(list.begin(), list.end(), oldID, newID);
161  }
162  }
163 
164  void DaqProvenanceHelper::fixMetaData(BranchChildren& branchChildren) const {
165  typedef std::map<BranchID, std::set<BranchID> > BCMap;
166  // The const_cast is ugly, but it beats the alternatives.
167  BCMap& childLookup = const_cast<BCMap&>(branchChildren.childLookup());
168  // First fix any old branchID's in the key.
169  {
170  BCMap::iterator i = childLookup.find(oldBranchID_);
171  if (i != childLookup.end()) {
172  childLookup.insert(std::make_pair(newBranchID_, i->second));
173  childLookup.erase(i);
174  }
175  }
176  // Now fix any old branchID's in the sets;
177  for (auto& child : childLookup) {
178  if (child.second.erase(oldBranchID_) != 0) {
179  child.second.insert(newBranchID_);
180  }
181  }
182  }
183 
184  // Replace process history ID.
186  ProcessHistoryIDMap::const_iterator it = phidMap_.find(phid);
187  assert(it != phidMap_.end());
188  oldProcessHistoryID_ = &it->first;
189  return it->second;
190  }
191 
192  // Replace parentage ID.
194  ParentageIDMap::const_iterator it = parentageIDMap_.find(parentageID);
195  if (it == parentageIDMap_.end()) {
196  return parentageID;
197  }
198  return it->second;
199  }
200 
201  // Replace branch ID if necessary.
202  BranchID const& DaqProvenanceHelper::mapBranchID(BranchID const& branchID) const {
203  return (branchID == oldBranchID_ ? newBranchID_ : branchID);
204  }
205 
207  parentageIDMap_.insert(std::make_pair(iOld, iNew));
208  }
209 
210 } // 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
std::string friendlyName(std::string const &iFullName)
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:136
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:482
void copyProduct(BranchDescription const &productdesc)
ProcessHistoryID const * oldProcessHistoryID_