CMS 3D CMS Logo

OutputModuleBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FWCore/Framework
4 // Class : OutputModuleBase
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Chris Jones
10 // Created: Wed, 31 Jul 2013 15:59:19 GMT
11 //
12 
13 // system include files
14 #include <cassert>
15 
16 // user include files
18 
40 
41 namespace edm {
42  namespace one {
43 
44  // -------------------------------------------------------
46  : maxEvents_(-1),
47  remainingEvents_(maxEvents_),
48  keptProducts_(),
49  hasNewlyDroppedBranch_(),
50  process_name_(),
51  productSelectorRules_(pset, "outputCommands", "OutputModule"),
52  productSelector_(),
53  moduleDescription_(),
54  wantAllEvents_(false),
55  selectors_(),
56  selector_config_id_(),
57  droppedBranchIDToKeptBranchID_(),
58  branchIDLists_(new BranchIDLists),
59  origBranchIDLists_(nullptr),
60  thinnedAssociationsHelper_(new ThinnedAssociationsHelper) {
61  hasNewlyDroppedBranch_.fill(false);
62 
64  process_name_ = tns->getProcessName();
65 
66  selectEvents_ = pset.getUntrackedParameterSet("SelectEvents", ParameterSet());
67 
68  selectEvents_.registerIt(); // Just in case this PSet is not registered
69 
71 
72  //need to set wantAllEvents_ in constructor
73  // we will make the remaining selectors once we know how many streams
74  selectors_.resize(1);
77  }
78 
83  }
84 
88  return;
90 
91  // TODO: See if we can collapse keptProducts_ and productSelector_ into a
92  // single object. See the notes in the header for ProductSelector
93  // for more information.
94 
95  std::map<BranchID, BranchDescription const*> trueBranchIDToKeptBranchDesc;
96  std::vector<BranchDescription const*> associationDescriptions;
97  std::set<BranchID> keptProductsInEvent;
98  std::set<std::string> processesWithSelectedMergeableRunProducts;
99 
100  for (auto const& it : preg.productList()) {
101  BranchDescription const& desc = it.second;
102  if (desc.transient()) {
103  // if the class of the branch is marked transient, output nothing
104  } else if (!desc.present() && !desc.produced()) {
105  // else if the branch containing the product has been previously dropped,
106  // output nothing
107  } else if (desc.unwrappedType() == typeid(ThinnedAssociation)) {
108  associationDescriptions.push_back(&desc);
109  } else if (selected(desc)) {
110  keepThisBranch(desc, trueBranchIDToKeptBranchDesc, keptProductsInEvent);
111  insertSelectedProcesses(desc, processesWithSelectedMergeableRunProducts);
112  } else {
113  // otherwise, output nothing,
114  // and mark the fact that there is a newly dropped branch of this type.
115  hasNewlyDroppedBranch_[desc.branchType()] = true;
116  }
117  }
118 
119  setProcessesWithSelectedMergeableRunProducts(processesWithSelectedMergeableRunProducts);
120 
121  thinnedAssociationsHelper.selectAssociationProducts(
122  associationDescriptions, keptProductsInEvent, keepAssociation_);
123 
124  for (auto association : associationDescriptions) {
125  if (keepAssociation_[association->branchID()]) {
126  keepThisBranch(*association, trueBranchIDToKeptBranchDesc, keptProductsInEvent);
127  } else {
128  hasNewlyDroppedBranch_[association->branchType()] = true;
129  }
130  }
131 
132  // Now fill in a mapping needed in the case that a branch was dropped while its EDAlias was kept.
133  ProductSelector::fillDroppedToKept(preg, trueBranchIDToKeptBranchDesc, droppedBranchIDToKeptBranchID_);
134 
135  thinnedAssociationsHelper_->updateFromParentProcess(
136  thinnedAssociationsHelper, keepAssociation_, droppedBranchIDToKeptBranchID_);
137  }
138 
140  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
141  std::set<BranchID>& keptProductsInEvent) {
142  ProductSelector::checkForDuplicateKeptBranch(desc, trueBranchIDToKeptBranchDesc);
143 
144  EDGetToken token;
145 
146  std::vector<std::string> missingDictionaries;
147  if (!checkDictionary(missingDictionaries, desc.className(), desc.unwrappedType())) {
148  std::string context("Calling OutputModuleBase::keepThisBranch, checking dictionaries for kept types");
149  throwMissingDictionariesException(missingDictionaries, context);
150  }
151 
152  switch (desc.branchType()) {
153  case InEvent: {
154  if (desc.produced()) {
155  keptProductsInEvent.insert(desc.originalBranchID());
156  } else {
157  keptProductsInEvent.insert(desc.branchID());
158  }
160  InputTag{desc.moduleLabel(), desc.productInstanceName(), desc.processName()});
161  break;
162  }
163  case InLumi: {
164  token = consumes<InLumi>(TypeToGet{desc.unwrappedTypeID(), PRODUCT_TYPE},
165  InputTag(desc.moduleLabel(), desc.productInstanceName(), desc.processName()));
166  break;
167  }
168  case InRun: {
169  token = consumes<InRun>(TypeToGet{desc.unwrappedTypeID(), PRODUCT_TYPE},
170  InputTag(desc.moduleLabel(), desc.productInstanceName(), desc.processName()));
171  break;
172  }
173  default:
174  assert(false);
175  break;
176  }
177  // Now put it in the list of selected branches.
178  keptProducts_[desc.branchType()].push_back(std::make_pair(&desc, token));
179  }
180 
182 
185  std::vector<std::shared_ptr<SerialTaskQueue>>(1, std::make_shared<SerialTaskQueue>())};
186  }
187 
189  auto nstreams = iPC.numberOfStreams();
190  selectors_.resize(nstreams);
191 
193 
194  bool seenFirst = false;
195  for (auto& s : selectors_) {
196  if (seenFirst) {
198  } else {
199  seenFirst = true;
200  }
201  }
202  }
203 
204  void OutputModuleBase::preallocLumis(unsigned int) {}
205 
208  this->beginJob();
209  }
210 
212 
214 
215  std::vector<ProductResolverIndexAndSkipBit> OutputModuleBase::productsUsedBySelection() const {
216  std::vector<ProductResolverIndexAndSkipBit> returnValue;
217  auto const& s = selectors_[0];
218  auto const n = s.numberOfTokens();
219  returnValue.reserve(n);
220 
221  for (unsigned int i = 0; i < n; ++i) {
222  returnValue.emplace_back(uncheckedIndexFrom(s.token(i)));
223  }
224  return returnValue;
225  }
226 
228  EventPrincipal const& ep,
229  ModuleCallingContext const* mcc) {
230  if (wantAllEvents_)
231  return true;
232  auto& s = selectors_[id.value()];
234  e.setConsumer(this);
235  return s.wantEvent(e);
236  }
237 
239  EventSetupImpl const&,
240  ActivityRegistry* act,
241  ModuleCallingContext const* mcc) {
242  {
244  e.setConsumer(this);
245  EventSignalsSentry sentry(act, mcc);
246  write(e);
247  }
248  if (remainingEvents_ > 0) {
250  }
251  return true;
252  }
253 
255  RunForOutput r(rp, moduleDescription_, mcc, false);
256  r.setConsumer(this);
257  doBeginRun_(r);
258  return true;
259  }
260 
262  RunForOutput r(rp, moduleDescription_, mcc, true);
263  r.setConsumer(this);
264  doEndRun_(r);
265  return true;
266  }
267 
269  ModuleCallingContext const* mcc,
270  MergeableRunProductMetadata const* mrpm) {
271  RunForOutput r(rp, moduleDescription_, mcc, true, mrpm);
272  r.setConsumer(this);
273  writeRun(r);
274  }
275 
277  EventSetupImpl const&,
278  ModuleCallingContext const* mcc) {
279  LuminosityBlockForOutput lb(lbp, moduleDescription_, mcc, false);
280  lb.setConsumer(this);
282  return true;
283  }
284 
286  EventSetupImpl const&,
287  ModuleCallingContext const* mcc) {
288  LuminosityBlockForOutput lb(lbp, moduleDescription_, mcc, true);
289  lb.setConsumer(this);
291 
292  return true;
293  }
294 
296  ModuleCallingContext const* mcc) {
297  LuminosityBlockForOutput lb(lbp, moduleDescription_, mcc, true);
298  lb.setConsumer(this);
300  }
301 
303 
305 
307 
309  if (isFileOpen()) {
310  reallyCloseFile();
311  }
312  }
313 
315 
317  if (!droppedBranchIDToKeptBranchID_.empty()) {
318  // Make a private copy of the BranchIDLists.
320  // Check for branches dropped while an EDAlias was kept.
321  for (BranchIDList& branchIDList : *branchIDLists_) {
322  for (BranchID::value_type& branchID : branchIDList) {
323  // Replace BranchID of each dropped branch with that of the kept alias, so the alias branch will have the product ID of the original branch.
324  std::map<BranchID::value_type, BranchID::value_type>::const_iterator iter =
325  droppedBranchIDToKeptBranchID_.find(branchID);
326  if (iter != droppedBranchIDToKeptBranchID_.end()) {
327  branchID = iter->second;
328  }
329  }
330  }
331  return branchIDLists_.get();
332  }
333  return origBranchIDLists_;
334  }
335 
337  return thinnedAssociationsHelper_.get();
338  }
339 
341 
342  bool OutputModuleBase::selected(BranchDescription const& desc) const { return productSelector_.selected(desc); }
343 
346  desc.setUnknown();
347  descriptions.addDefault(desc);
348  }
349 
351  ProductSelectorRules::fillDescription(desc, "outputCommands");
353  }
354 
356 
357  static const std::string kBaseType("OutputModule");
359 
361  std::map<std::string, std::vector<std::pair<std::string, int>>> const& outputModulePathPositions,
362  bool anyProductProduced) {
364  description().moduleLabel(),
365  outputModulePathPositions,
366  anyProductProduced);
367  }
368  } // namespace one
369 } // namespace edm
static const std::string kBaseType("EDAnalyzer")
bool selected(BranchDescription const &desc) const
ModuleDescription const & description() const
BranchType const & branchType() const
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
void throwMissingDictionariesException(std::vector< std::string > &missingDictionaries, std::string const &context)
ThinnedAssociationsHelper const * thinnedAssociationsHelper() const
static void fillDroppedToKept(ProductRegistry const &preg, std::map< BranchID, BranchDescription const * > const &trueBranchIDToKeptBranchDesc, std::map< BranchID::value_type, BranchID::value_type > &droppedBranchIDToKeptBranchID_)
SelectedProductsForBranchType keptProducts_
void doWriteLuminosityBlock(LuminosityBlockPrincipal const &lbp, ModuleCallingContext const *)
ModuleDescription moduleDescription_
static void prevalidate(ConfigurationDescriptions &)
ParameterSetID id() const
SubProcessParentageHelper const * subProcessParentageHelper_
void configure(OutputModuleDescription const &desc)
ParameterSet const & getParameterSet(ParameterSetID const &id)
virtual void preallocLumis(unsigned int)
void keepThisBranch(BranchDescription const &desc, std::map< BranchID, BranchDescription const * > &trueBranchIDToKeptBranchDesc, std::set< BranchID > &keptProductsInEvent)
#define nullptr
std::string const & processName() const
static void fillDescription(ParameterSetDescription &desc, char const *parameterName, std::vector< std::string > const &defaultStrings=defaultSelectionStrings())
ParameterSet getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
void setEventSelectionInfo(std::map< std::string, std::vector< std::pair< std::string, int >>> const &outputModulePathPositions, bool anyProductProduced)
bool doEvent(EventPrincipal const &ep, EventSetupImpl const &c, ActivityRegistry *, ModuleCallingContext const *)
bool doEndLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetupImpl const &c, ModuleCallingContext const *)
bool doBeginRun(RunPrincipal const &rp, EventSetupImpl const &c, ModuleCallingContext const *)
virtual void doBeginLuminosityBlock_(LuminosityBlockForOutput const &)
ProductSelectorRules productSelectorRules_
void selectProducts(ProductRegistry const &preg, ThinnedAssociationsHelper const &)
BranchIDLists const * branchIDLists_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
virtual void doRespondToCloseInputFile_(FileBlock const &)
ProductList const & productList() const
virtual void doRespondToOpenInputFile_(FileBlock const &)
virtual void openFile(FileBlock const &)
void selectAssociationProducts(std::vector< BranchDescription const * > const &associationDescriptions, std::set< BranchID > const &keptProductsInEvent, std::map< BranchID, bool > &keepAssociation) const
virtual void doEndRun_(RunForOutput const &)
virtual void write(EventForOutput const &)=0
ProductResolverIndexAndSkipBit uncheckedIndexFrom(EDGetToken) const
void addDefault(ParameterSetDescription const &psetDescription)
std::string const & className() const
std::atomic< int > remainingEvents_
void doWriteRun(RunPrincipal const &rp, ModuleCallingContext const *, MergeableRunProductMetadata const *)
std::string const & moduleLabel() const
unsigned int value_type
Definition: BranchID.h:16
std::string const & productInstanceName() const
bool checkDictionary(std::vector< std::string > &missingDictionaries, TypeID const &typeID)
bool selected(BranchDescription const &desc) const
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
TypeID unwrappedTypeID() const
std::vector< BranchDescription const * > allBranchDescriptions() const
bool configureEventSelector(edm::ParameterSet const &iPSet, std::string const &iProcessName, std::vector< std::string > const &iAllTriggerNames, edm::detail::TriggerResultsBasedEventSelector &oSelector, ConsumesCollector &&iC)
BranchID const & branchID() const
TypeWithDict const & unwrappedType() const
bool doBeginLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetupImpl const &c, ModuleCallingContext const *)
static void fillDescription(ParameterSetDescription &desc)
SubProcessParentageHelper const * subProcessParentageHelper_
bool prePrefetchSelection(StreamID id, EventPrincipal const &, ModuleCallingContext const *)
edm::propagate_const< std::unique_ptr< ThinnedAssociationsHelper > > thinnedAssociationsHelper_
SharedResourcesAcquirer resourcesAcquirer_
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
OutputModuleBase(ParameterSet const &pset)
std::vector< detail::TriggerResultsBasedEventSelector > selectors_
virtual void writeRun(RunForOutput const &)=0
virtual void doEndLuminosityBlock_(LuminosityBlockForOutput const &)
void doRespondToCloseInputFile(FileBlock const &fb)
virtual SharedResourcesAcquirer createAcquirer()
bool doEndRun(RunPrincipal const &rp, EventSetupImpl const &c, ModuleCallingContext const *)
void doRespondToOpenInputFile(FileBlock const &fb)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
virtual void doBeginRun_(RunForOutput const &)
std::vector< BranchID::value_type > BranchIDList
Definition: BranchIDList.h:18
virtual void writeLuminosityBlock(LuminosityBlockForOutput const &)=0
HLT enums.
bool initialized() const
std::vector< std::string > const & getAllTriggerNames()
void initialize(ProductSelectorRules const &rules, std::vector< BranchDescription const * > const &branchDescriptions)
static const std::string & baseType()
void doPreallocate(PreallocationConfiguration const &)
void setConsumer(EDConsumerBase const *iConsumer)
void doOpenFile(FileBlock const &fb)
BranchIDLists const * origBranchIDLists_
BranchID const & originalBranchID() const
void insertSelectedProcesses(BranchDescription const &desc, std::set< std::string > &processes)
virtual void setProcessesWithSelectedMergeableRunProducts(std::set< std::string > const &)
ParameterSetID registerProperSelectionInfo(edm::ParameterSet const &iInitial, std::string const &iLabel, std::map< std::string, std::vector< std::pair< std::string, int > > > const &outputModulePathPositions, bool anyProductProduced)
void doCloseFile()
Tell the OutputModule that is must end the current file.
static void fillDescription(ParameterSetDescription &desc)
virtual bool isFileOpen() const
std::map< BranchID::value_type, BranchID::value_type > droppedBranchIDToKeptBranchID_
ProductSelector productSelector_
std::vector< ProductResolverIndexAndSkipBit > productsUsedBySelection() const
ParameterSet const & registerIt()
ParameterSetID selector_config_id_
edm::propagate_const< std::unique_ptr< BranchIDLists > > branchIDLists_
static void checkForDuplicateKeptBranch(BranchDescription const &desc, std::map< BranchID, BranchDescription const * > &trueBranchIDToKeptBranchDesc)
BranchIDLists const * branchIDLists()
std::map< BranchID, bool > keepAssociation_