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 edm {
19  : constBranchDescription_(BranchDescription(InEvent,
20  "rawDataCollector"
21  //, "source"
22  ,
23  "LHC"
24  // , "HLT"
25  ,
26  "FEDRawDataCollection",
27  "FEDRawDataCollection",
28  "",
29  "FedRawDataInputSource",
31  TypeWithDict(rawDataType.typeInfo()),
32  false)),
33  dummyProvenance_(constBranchDescription_.branchID()),
34  processParameterSet_(),
35  oldProcessName_(),
36  oldBranchID_(),
37  newBranchID_(),
38  oldProcessHistoryID_(nullptr),
39  phidMap_() {
40  // Now we create a process parameter set for the "LHC" process.
41  // We don't currently use the untracked parameters, However, we make them available, just in case.
42  std::string const& moduleLabel = constBranchDescription_.moduleLabel();
45  typedef std::vector<std::string> vstring;
46  vstring empty;
47 
48  vstring modlbl;
49  modlbl.reserve(1);
50  modlbl.push_back(moduleLabel);
51  processParameterSet_.addParameter("@all_sources", modlbl);
52 
54  triggerPaths.addParameter<vstring>("@trigger_paths", empty);
56 
57  ParameterSet pseudoInput;
58  pseudoInput.addParameter<std::string>("@module_edm_type", "Source");
59  pseudoInput.addParameter<std::string>("@module_label", moduleLabel);
60  pseudoInput.addParameter<std::string>("@module_type", moduleName);
61  processParameterSet_.addParameter<ParameterSet>(moduleLabel, pseudoInput);
62 
63  processParameterSet_.addParameter<vstring>("@all_esmodules", empty);
64  processParameterSet_.addParameter<vstring>("@all_esprefers", empty);
65  processParameterSet_.addParameter<vstring>("@all_essources", empty);
66  processParameterSet_.addParameter<vstring>("@all_loopers", empty);
67  processParameterSet_.addParameter<vstring>("@all_modules", empty);
68  processParameterSet_.addParameter<vstring>("@end_paths", empty);
69  processParameterSet_.addParameter<vstring>("@paths", empty);
71  // Now we register the process parameter set.
73 
74  //std::cerr << processParameterSet_.dump() << std::endl;
75  }
76 
78  ProcessHistoryRegistry& processHistoryRegistry) const {
79  // Now we need to set all the metadata
80  // Add the product to the product registry
81  productRegistry.copyProduct(constBranchDescription_);
82 
83  // Insert an entry for this process in the process history registry
84  ProcessHistory ph;
86  processHistoryRegistry.registerProcessHistory(ph);
87 
88  // Save the process history ID for use every event.
89  return ph.setProcessHistoryID();
90  }
91 
93  for (auto const& pc : ph) {
94  if (pc.processName() == oldProcessName_) {
95  return (pc.releaseVersion() == newPC.releaseVersion() && pc.passID() == newPC.passID());
96  }
97  }
98  return false;
99  }
100 
101  void DaqProvenanceHelper::fixMetaData(std::vector<ProcessConfiguration>& pcv, std::vector<ProcessHistory>& phv) {
102  phv.push_back(ProcessHistory()); // For new processHistory, containing only processConfiguration_
103  std::vector<ProcessConfiguration> newPCs;
104  for (auto const& pc : pcv) {
105  if (pc.processName() == oldProcessName_) {
106  newPCs.emplace_back(
107  constBranchDescription_.processName(), processParameterSet_.id(), pc.releaseVersion(), pc.passID());
108  }
109  }
110  assert(!newPCs.empty());
111  pcv.reserve(pcv.size() + newPCs.size());
112  pcv.insert(pcv.end(), newPCs.begin(), newPCs.end());
113  // update existing process histories
114  for (auto& ph : phv) {
115  for (auto const& newPC : newPCs) {
116  if (ph.empty() || matchProcesses(newPC, ph)) {
117  ProcessHistoryID oldPHID = ph.id();
118  ph.push_front(newPC);
119  ProcessHistoryID newPHID = ph.id();
120  phidMap_.insert(std::make_pair(oldPHID, newPHID));
121  break;
122  }
123  }
124  }
125  // For new process histories, containing only the new process configurations
126  phv.reserve(phv.size() + newPCs.size());
127  for (auto const& newPC : newPCs) {
128  phv.emplace_back();
129  phv.back().push_front(newPC);
130  }
131  }
132 
133  void DaqProvenanceHelper::fixMetaData(std::vector<BranchID>& branchID) const {
134  std::replace(branchID.begin(), branchID.end(), oldBranchID_, newBranchID_);
135  }
136 
137  void DaqProvenanceHelper::fixMetaData(BranchIDLists const& branchIDLists) const {
140  // The const_cast is ugly, but it beats the alternatives.
141  BranchIDLists& lists = const_cast<BranchIDLists&>(branchIDLists);
142  for (auto& list : lists) {
143  std::replace(list.begin(), list.end(), oldID, newID);
144  }
145  }
146 
147  void DaqProvenanceHelper::fixMetaData(BranchChildren& branchChildren) const {
148  typedef std::map<BranchID, std::set<BranchID> > BCMap;
149  // The const_cast is ugly, but it beats the alternatives.
150  BCMap& childLookup = const_cast<BCMap&>(branchChildren.childLookup());
151  // First fix any old branchID's in the key.
152  {
153  BCMap::iterator i = childLookup.find(oldBranchID_);
154  if (i != childLookup.end()) {
155  childLookup.insert(std::make_pair(newBranchID_, i->second));
156  childLookup.erase(i);
157  }
158  }
159  // Now fix any old branchID's in the sets;
160  for (auto& child : childLookup) {
161  if (child.second.erase(oldBranchID_) != 0) {
162  child.second.insert(newBranchID_);
163  }
164  }
165  }
166 
167  // Replace process history ID.
169  ProcessHistoryIDMap::const_iterator it = phidMap_.find(phid);
170  assert(it != phidMap_.end());
171  oldProcessHistoryID_ = &it->first;
172  return it->second;
173  }
174 
175  // Replace parentage ID.
177  ParentageIDMap::const_iterator it = parentageIDMap_.find(parentageID);
178  if (it == parentageIDMap_.end()) {
179  return parentageID;
180  }
181  return it->second;
182  }
183 
184  // Replace branch ID if necessary.
185  BranchID const& DaqProvenanceHelper::mapBranchID(BranchID const& branchID) const {
186  return (branchID == oldBranchID_ ? newBranchID_ : branchID);
187  }
188 
190  parentageIDMap_.insert(std::make_pair(iOld, iNew));
191  }
192 
193 } // namespace edm
std::string getPassID()
Definition: GetPassID.h:7
DaqProvenanceHelper(TypeID const &rawDataType)
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
ParameterSetID id() const
BranchID const & mapBranchID(BranchID const &branchID) const
#define nullptr
bool registerProcessHistory(ProcessHistory const &processHistory)
def replace(string, replacements)
std::string const & processName() const
ProcessHistoryID setProcessHistoryID()
PassID const & passID() const
unsigned int id() const
Definition: BranchID.h:23
void emplace_back(Args &&...args)
ProcessHistoryID const & mapProcessHistoryID(ProcessHistoryID const &phid)
void fixMetaData(ProcessConfigurationVector &pcv, std::vector< ProcessHistory > &phv)
std::string moduleName(Provenance const &provenance)
Definition: Provenance.cc:27
std::string const & moduleLabel() const
map_t const & childLookup() const
unsigned int value_type
Definition: BranchID.h:16
void setOldParentageIDToNew(ParentageID const &iOld, ParentageID const &iNew)
ProcessHistoryIDMap phidMap_
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:125
std::string const & moduleName() const
ProcessHistoryID daqInit(ProductRegistry &productRegistry, ProcessHistoryRegistry &processHistoryRegistry) const
std::string getReleaseVersion()
ReleaseVersion const & releaseVersion() const
HLT enums.
BranchDescription const constBranchDescription_
ParentageID const & mapParentageID(ParentageID const &phid) const
static std::string const triggerPaths
Definition: EdmProvDump.cc:46
ParameterSet const & registerIt()
std::vector< std::string > vstring
Definition: Schedule.cc:565
void copyProduct(BranchDescription const &productdesc)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
ProcessHistoryID const * oldProcessHistoryID_
bool matchProcesses(ProcessConfiguration const &pc, ProcessHistory const &ph) const