CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DaqProvenanceHelper.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <vector>
3 
5 
15 
16 namespace edm {
18  : constBranchDescription_(BranchDescription(InEvent
19  , "rawDataCollector"
20  //, "source"
21  , "LHC"
22  // , "HLT"
23  , "FEDRawDataCollection"
24  , "FEDRawDataCollection"
25  , ""
26  , "DaqSource"
27  , ParameterSetID()
28  , rawDataType
29  , false))
30  , dummyProvenance_(constBranchDescription_.branchID())
31  , processParameterSet_()
32  , oldProcessName_()
33  , oldBranchID_()
34  , newBranchID_()
35  , oldProcessHistoryID_(0)
36  , processConfiguration_()
37  , phidMap_() {
38 
39  // Now we create a process parameter set for the "LHC" process.
40  // We don't currently use the untracked parameters, However, we make them available, just in case.
41  std::string const& moduleLabel = constBranchDescription_.moduleLabel();
42  std::string const& processName = constBranchDescription_.processName();
43  std::string const& moduleName = constBranchDescription_.moduleName();
44  typedef std::vector<std::string> vstring;
45  vstring empty;
46 
47  vstring modlbl;
48  modlbl.reserve(1);
49  modlbl.push_back(moduleLabel);
50  processParameterSet_.addParameter("@all_sources", modlbl);
51 
52  ParameterSet triggerPaths;
53  triggerPaths.addParameter<vstring>("@trigger_paths", empty);
54  processParameterSet_.addParameter<ParameterSet>("@trigger_paths", triggerPaths);
55 
56  ParameterSet pseudoInput;
57  pseudoInput.addParameter<std::string>("@module_edm_type", "Source");
58  pseudoInput.addParameter<std::string>("@module_label", moduleLabel);
59  pseudoInput.addParameter<std::string>("@module_type", moduleName);
60  processParameterSet_.addParameter<ParameterSet>(moduleLabel, pseudoInput);
61 
62  processParameterSet_.addParameter<vstring>("@all_esmodules", empty);
63  processParameterSet_.addParameter<vstring>("@all_esprefers", empty);
64  processParameterSet_.addParameter<vstring>("@all_essources", empty);
65  processParameterSet_.addParameter<vstring>("@all_loopers", empty);
66  processParameterSet_.addParameter<vstring>("@all_modules", empty);
67  processParameterSet_.addParameter<vstring>("@end_paths", empty);
68  processParameterSet_.addParameter<vstring>("@paths", empty);
69  processParameterSet_.addParameter<std::string>("@process_name", processName);
70  // Now we register the process parameter set.
72 
73  //std::cerr << processParameterSet_.dump() << std::endl;
74  }
75 
78  // Now we need to set all the metadata
79  // Add the product to the product registry
80  productRegistry.copyProduct(constBranchDescription_.me());
81 
82  // Insert an entry for this process in the process configuration registry
85 
86  // Insert an entry for this process in the process history registry
87  ProcessHistory ph;
88  ph.push_back(pc);
90 
91  // Save the process history ID for use every event.
92  return ph.id();
93  }
94 
95  void
96  DaqProvenanceHelper::fixMetaData(std::vector<ProcessConfiguration>& pcv) {
97  bool found = false;
98  for(std::vector<ProcessConfiguration>::const_iterator it = pcv.begin(), itEnd = pcv.end(); it != itEnd; ++it) {
99  if(it->processName() == oldProcessName_) {
102  it->releaseVersion(), it->passID());
103  pcv.push_back(processConfiguration_);
104  found = true;
105  break;
106  }
107  }
108  assert(found);
109  }
110 
111  void
112  DaqProvenanceHelper::fixMetaData(std::vector<ProcessHistory>& phv) {
113  phv.reserve(phv.size() + 1);
114  phv.push_back(ProcessHistory()); // For new processHistory, containing only processConfiguration_.
115  for(std::vector<ProcessHistory>::iterator it = phv.begin(), itEnd = phv.end(); it != itEnd; ++it) {
116  ProcessHistoryID oldPHID = it->id();
117  it->push_front(processConfiguration_);
118  ProcessHistoryID newPHID = it->id();
119  phidMap_.insert(std::make_pair(oldPHID, newPHID));
120  }
121  }
122 
123  void
124  DaqProvenanceHelper::fixMetaData(std::vector<BranchID>& branchID) const {
125  std::replace(branchID.begin(), branchID.end(), oldBranchID_, newBranchID_);
126  }
127 
128  void
129  DaqProvenanceHelper::fixMetaData(BranchIDLists const& branchIDLists) const {
132  // The const_cast is ugly, but it beats the alternatives.
133  BranchIDLists& lists = const_cast<BranchIDLists&>(branchIDLists);
134  for(BranchIDLists::iterator it = lists.begin(), itEnd = lists.end(); it != itEnd; ++it) {
135  std::replace(it->begin(), it->end(), oldID, newID);
136  }
137  }
138 
139  void
141  typedef std::map<BranchID, std::set<BranchID> > BCMap;
142  // The const_cast is ugly, but it beats the alternatives.
143  BCMap& childLookup = const_cast<BCMap&>(branchChildren.childLookup());
144  // First fix any old branchID's in the key.
145  {
146  BCMap::iterator i = childLookup.find(oldBranchID_);
147  if(i != childLookup.end()) {
148  childLookup.insert(std::make_pair(newBranchID_, i->second));
149  childLookup.erase(i);
150  }
151  }
152  // Now fix any old branchID's in the sets;
153  for(BCMap::iterator it = childLookup.begin(), itEnd = childLookup.end(); it != itEnd; ++it) {
154  if(it->second.erase(oldBranchID_) != 0) {
155  it->second.insert(newBranchID_);
156  }
157  }
158  }
159 
160  // Replace process history ID.
161  ProcessHistoryID const&
163  ProcessHistoryIDMap::const_iterator it = phidMap_.find(phid);
164  assert(it != phidMap_.end());
165  oldProcessHistoryID_ = &it->first;
166  return it->second;
167  }
168 
169  // Replace parentage ID.
170  ParentageID const&
172  ParentageIDMap::const_iterator it = parentageIDMap_.find(parentageID);
173  if(it == parentageIDMap_.end()) {
174  return parentageID;
175  }
176  return it->second;
177  }
178 
179  // Replace branch ID if necessary.
180  BranchID const&
182  return(branchID == oldBranchID_ ? newBranchID_ : branchID);
183  }
184 }
std::string const & processName() const
std::string getPassID()
Definition: GetPassID.h:8
int i
Definition: DBlmapReader.cc:9
DaqProvenanceHelper(TypeID const &rawDataType)
BranchDescription const & me() const
std::vector< std::string > vstring
Definition: Schedule.cc:147
ParameterSetID id() const
static ThreadSafeRegistry * instance()
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
BranchID const & mapBranchID(BranchID const &branchID) const
def replace
Definition: linker.py:10
bool insertMapped(value_type const &v)
unsigned int id() const
Definition: BranchID.h:23
ProcessHistoryID daqInit(ProductRegistry &productRegistry) const
std::string const & moduleName() const
ProcessHistoryID const & mapProcessHistoryID(ProcessHistoryID const &phid)
ConstBranchDescription constBranchDescription_
map_t const & childLookup() const
unsigned int value_type
Definition: BranchID.h:16
ProcessHistoryIDMap phidMap_
ProcessConfiguration processConfiguration_
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:145
std::string getReleaseVersion()
void push_back(const_reference t)
author Stefano ARGIRO author Bill Tanenbaum
ParentageID const & mapParentageID(ParentageID const &phid) const
ProcessHistoryID id() const
ParameterSet const & registerIt()
void copyProduct(BranchDescription const &productdesc)
std::string const & moduleLabel() const
ProcessHistoryID const * oldProcessHistoryID_
void fixMetaData(std::vector< ProcessConfiguration > &pcv)