CMS 3D CMS Logo

DaqProvenanceHelper.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <cassert>
3 #include <vector>
4 
6 
17 
18 namespace {
19  edm::BranchDescription makeDescriptionForDaqProvHelper(edm::TypeID const& rawDataType,
22  std::string const& sourceLabel) {
24  "rawDataCollector",
25  // "source",
26  "LHC",
27  // "HLT",
30  "",
31  sourceLabel,
33  edm::TypeWithDict(rawDataType.typeInfo()),
34  false);
35  desc.setIsProvenanceSetOnRead();
36  return desc;
37  }
38 } // namespace
39 
40 namespace edm {
44  std::string const& sourceLabel)
45  : constBranchDescription_(
46  makeDescriptionForDaqProvHelper(rawDataType, collectionName, friendlyName, sourceLabel)),
47  dummyProvenance_(constBranchDescription_.branchID()),
48  processParameterSet_(),
49  oldProcessName_(),
50  oldBranchID_(),
51  newBranchID_(),
52  oldProcessHistoryID_(nullptr),
53  phidMap_() {
54  // Now we create a process parameter set for the "LHC" process.
55  // We don't currently use the untracked parameters, However, we make them available, just in case.
59  typedef std::vector<std::string> vstring;
60  vstring empty;
61 
62  vstring modlbl;
63  modlbl.reserve(1);
64  modlbl.push_back(moduleLabel);
65  processParameterSet_.addParameter("@all_sources", modlbl);
66 
68  triggerPaths.addParameter<vstring>("@trigger_paths", empty);
70 
71  ParameterSet pseudoInput;
72  pseudoInput.addParameter<std::string>("@module_edm_type", "Source");
73  pseudoInput.addParameter<std::string>("@module_label", moduleLabel);
74  pseudoInput.addParameter<std::string>("@module_type", moduleName);
76 
77  processParameterSet_.addParameter<vstring>("@all_esmodules", empty);
78  processParameterSet_.addParameter<vstring>("@all_esprefers", empty);
79  processParameterSet_.addParameter<vstring>("@all_essources", empty);
85  // Now we register the process parameter set.
87 
88  //std::cerr << processParameterSet_.dump() << std::endl;
89  }
90 
91  //default
93  : DaqProvenanceHelper(rawDataType, "FEDRawDataCollection", "FEDRawDataCollection", "FedRawDataInputSource") {}
94 
96  ProcessHistoryRegistry& processHistoryRegistry) const {
97  // Now we need to set all the metadata
98  // Add the product to the product registry
99  productRegistry.copyProduct(constBranchDescription_);
100 
101  // Insert an entry for this process in the process history registry
104  processHistoryRegistry.registerProcessHistory(ph);
105 
106  // Save the process history ID for use every event.
107  return ph.setProcessHistoryID();
108  }
109 
111  for (auto const& pc : ph) {
112  if (pc.processName() == oldProcessName_) {
113  return (pc.releaseVersion() == newPC.releaseVersion() && pc.passID() == newPC.passID());
114  }
115  }
116  return false;
117  }
118 
119  void DaqProvenanceHelper::fixMetaData(std::vector<ProcessConfiguration>& pcv, std::vector<ProcessHistory>& phv) {
120  phv.push_back(ProcessHistory()); // For new processHistory, containing only processConfiguration_
121  std::vector<ProcessConfiguration> newPCs;
122  for (auto const& pc : pcv) {
123  if (pc.processName() == oldProcessName_) {
124  newPCs.emplace_back(
125  constBranchDescription_.processName(), processParameterSet_.id(), pc.releaseVersion(), pc.passID());
126  }
127  }
128  if (newPCs.empty()) {
129  throw Exception(errors::LogicError) << "\nFatal error in RootFile constructor. Most likely this is because\n"
130  << "the input file contains a FEDRawDataCollection with module label\n"
131  << "\"source\". This is against CMS naming conventions.\n"
132  << "See GitHub Issue 45137 for related details.\n";
133  }
134  pcv.reserve(pcv.size() + newPCs.size());
135  pcv.insert(pcv.end(), newPCs.begin(), newPCs.end());
136  // update existing process histories
137  for (auto& ph : phv) {
138  for (auto const& newPC : newPCs) {
139  if (ph.empty() || matchProcesses(newPC, ph)) {
140  ProcessHistoryID oldPHID = ph.id();
141  ph.push_front(newPC);
142  ProcessHistoryID newPHID = ph.id();
143  phidMap_.insert(std::make_pair(oldPHID, newPHID));
144  break;
145  }
146  }
147  }
148  // For new process histories, containing only the new process configurations
149  phv.reserve(phv.size() + newPCs.size());
150  for (auto const& newPC : newPCs) {
151  phv.emplace_back();
152  phv.back().push_front(newPC);
153  }
154  }
155 
156  void DaqProvenanceHelper::fixMetaData(std::vector<BranchID>& branchID) const {
157  std::replace(branchID.begin(), branchID.end(), oldBranchID_, newBranchID_);
158  }
159 
160  void DaqProvenanceHelper::fixMetaData(BranchIDLists const& branchIDLists) const {
163  // The const_cast is ugly, but it beats the alternatives.
164  BranchIDLists& lists = const_cast<BranchIDLists&>(branchIDLists);
165  for (auto& list : lists) {
166  std::replace(list.begin(), list.end(), oldID, newID);
167  }
168  }
169 
170  void DaqProvenanceHelper::fixMetaData(BranchChildren& branchChildren) const {
171  typedef std::map<BranchID, std::set<BranchID> > BCMap;
172  // The const_cast is ugly, but it beats the alternatives.
173  BCMap& childLookup = const_cast<BCMap&>(branchChildren.childLookup());
174  // First fix any old branchID's in the key.
175  {
176  BCMap::iterator i = childLookup.find(oldBranchID_);
177  if (i != childLookup.end()) {
178  childLookup.insert(std::make_pair(newBranchID_, i->second));
179  childLookup.erase(i);
180  }
181  }
182  // Now fix any old branchID's in the sets;
183  for (auto& child : childLookup) {
184  if (child.second.erase(oldBranchID_) != 0) {
185  child.second.insert(newBranchID_);
186  }
187  }
188  }
189 
190  // Replace process history ID.
192  ProcessHistoryIDMap::const_iterator it = phidMap_.find(phid);
193  assert(it != phidMap_.end());
194  oldProcessHistoryID_ = &it->first;
195  return it->second;
196  }
197 
198  // Replace parentage ID.
200  ParentageIDMap::const_iterator it = parentageIDMap_.find(parentageID);
201  if (it == parentageIDMap_.end()) {
202  return parentageID;
203  }
204  return it->second;
205  }
206 
207  // Replace branch ID if necessary.
208  BranchID const& DaqProvenanceHelper::mapBranchID(BranchID const& branchID) const {
209  return (branchID == oldBranchID_ ? newBranchID_ : branchID);
210  }
211 
213  parentageIDMap_.insert(std::make_pair(iOld, iNew));
214  }
215 
216 } // 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_