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 
62  hasNewlyDroppedBranch_.fill(false);
63 
65  process_name_ = tns->getProcessName();
66 
68  pset.getUntrackedParameterSet("SelectEvents", ParameterSet());
69 
70  selectEvents_.registerIt(); // Just in case this PSet is not registered
71 
73 
74  //need to set wantAllEvents_ in constructor
75  // we will make the remaining selectors once we know how many streams
76  selectors_.resize(1);
80  selectors_[0],
82 
83  }
84 
89  }
90 
93  if(productSelector_.initialized()) return;
95 
96  // TODO: See if we can collapse keptProducts_ and productSelector_ into a
97  // single object. See the notes in the header for ProductSelector
98  // for more information.
99 
100  std::map<BranchID, BranchDescription const*> trueBranchIDToKeptBranchDesc;
101  std::vector<BranchDescription const*> associationDescriptions;
102  std::set<BranchID> keptProductsInEvent;
103  std::set<std::string> processesWithSelectedMergeableRunProducts;
104 
105  for(auto const& it : preg.productList()) {
106  BranchDescription const& desc = it.second;
107  if(desc.transient()) {
108  // if the class of the branch is marked transient, output nothing
109  } else if(!desc.present() && !desc.produced()) {
110  // else if the branch containing the product has been previously dropped,
111  // output nothing
112  } else if(desc.unwrappedType() == typeid(ThinnedAssociation)) {
113  associationDescriptions.push_back(&desc);
114  } else if(selected(desc)) {
115  keepThisBranch(desc, trueBranchIDToKeptBranchDesc, keptProductsInEvent);
117  processesWithSelectedMergeableRunProducts);
118  } else {
119  // otherwise, output nothing,
120  // and mark the fact that there is a newly dropped branch of this type.
121  hasNewlyDroppedBranch_[desc.branchType()] = true;
122  }
123  }
124 
125  setProcessesWithSelectedMergeableRunProducts(processesWithSelectedMergeableRunProducts);
126 
127  thinnedAssociationsHelper.selectAssociationProducts(associationDescriptions,
128  keptProductsInEvent,
130 
131  for(auto association : associationDescriptions) {
132  if(keepAssociation_[association->branchID()]) {
133  keepThisBranch(*association, trueBranchIDToKeptBranchDesc, keptProductsInEvent);
134  } else {
135  hasNewlyDroppedBranch_[association->branchType()] = true;
136  }
137  }
138 
139  // Now fill in a mapping needed in the case that a branch was dropped while its EDAlias was kept.
140  ProductSelector::fillDroppedToKept(preg, trueBranchIDToKeptBranchDesc, droppedBranchIDToKeptBranchID_);
141 
142  thinnedAssociationsHelper_->updateFromParentProcess(thinnedAssociationsHelper, keepAssociation_, droppedBranchIDToKeptBranchID_);
143  }
144 
146  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
147  std::set<BranchID>& keptProductsInEvent) {
148 
150  trueBranchIDToKeptBranchDesc);
151 
152  EDGetToken token;
153 
154  std::vector<std::string> missingDictionaries;
155  if (!checkDictionary(missingDictionaries, desc.className(), desc.unwrappedType())) {
156  std::string context("Calling OutputModuleBase::keepThisBranch, checking dictionaries for kept types");
157  throwMissingDictionariesException(missingDictionaries, context);
158  }
159 
160  switch (desc.branchType()) {
161  case InEvent:
162  {
163  if(desc.produced()) {
164  keptProductsInEvent.insert(desc.originalBranchID());
165  } else {
166  keptProductsInEvent.insert(desc.branchID());
167  }
169  InputTag{desc.moduleLabel(),
170  desc.productInstanceName(),
171  desc.processName()});
172  break;
173  }
174  case InLumi:
175  {
176  token = consumes<InLumi>(TypeToGet{desc.unwrappedTypeID(),PRODUCT_TYPE},
177  InputTag(desc.moduleLabel(),
178  desc.productInstanceName(),
179  desc.processName()));
180  break;
181  }
182  case InRun:
183  {
184  token = consumes<InRun>(TypeToGet{desc.unwrappedTypeID(),PRODUCT_TYPE},
185  InputTag(desc.moduleLabel(),
186  desc.productInstanceName(),
187  desc.processName()));
188  break;
189  }
190  default:
191  assert(false);
192  break;
193  }
194  // Now put it in the list of selected branches.
195  keptProducts_[desc.branchType()].push_back(std::make_pair(&desc, token));
196  }
197 
199 
202  std::vector<std::shared_ptr<SerialTaskQueue>>(1, std::make_shared<SerialTaskQueue>())};
203  }
204 
206  auto nstreams = iPC.numberOfStreams();
207  selectors_.resize(nstreams);
208 
209  bool seenFirst = false;
210  for(auto& s : selectors_) {
211  if(seenFirst) {
215  s,
217  } else {
218  seenFirst = true;
219  }
220  }
221  }
222 
225  this->beginJob();
226  }
227 
229  endJob();
230  }
231 
233  return !wantAllEvents_;
234  }
235 
236  std::vector<ProductResolverIndexAndSkipBit>
238  std::vector<ProductResolverIndexAndSkipBit> returnValue;
239  auto const& s = selectors_[0];
240  auto const n = s.numberOfTokens();
241  returnValue.reserve(n);
242 
243  for(unsigned int i=0; i< n;++i) {
244  returnValue.emplace_back(uncheckedIndexFrom(s.token(i)));
245  }
246  return returnValue;
247  }
248 
250  if(wantAllEvents_) return true;
251  auto& s = selectors_[id.value()];
253  e.setConsumer(this);
254  return s.wantEvent(e);
255  }
256 
257  bool
259  EventSetup const&,
260  ActivityRegistry* act,
261  ModuleCallingContext const* mcc) {
262 
263  {
265  e.setConsumer(this);
266  EventSignalsSentry sentry(act,mcc);
267  write(e);
268  }
269  if(remainingEvents_ > 0) {
271  }
272  return true;
273  }
274 
275  bool
277  EventSetup const&,
278  ModuleCallingContext const* mcc) {
279  RunForOutput r(rp, moduleDescription_, mcc, false);
280  r.setConsumer(this);
281  doBeginRun_(r);
282  return true;
283  }
284 
285  bool
287  EventSetup const&,
288  ModuleCallingContext const* mcc) {
289  RunForOutput r(rp, moduleDescription_, mcc, true);
290  r.setConsumer(this);
291  doEndRun_(r);
292  return true;
293  }
294 
295  void
297  ModuleCallingContext const* mcc,
298  MergeableRunProductMetadata const* mrpm) {
299  RunForOutput r(rp, moduleDescription_, mcc, true, mrpm);
300  r.setConsumer(this);
301  writeRun(r);
302  }
303 
304  bool
306  EventSetup const&,
307  ModuleCallingContext const* mcc) {
308  LuminosityBlockForOutput lb(lbp, moduleDescription_, mcc, false);
309  lb.setConsumer(this);
311  return true;
312  }
313 
314  bool
316  EventSetup const&,
317  ModuleCallingContext const* mcc) {
318  LuminosityBlockForOutput lb(lbp, moduleDescription_, mcc, true);
319  lb.setConsumer(this);
321 
322  return true;
323  }
324 
326  ModuleCallingContext const* mcc) {
327  LuminosityBlockForOutput lb(lbp, moduleDescription_, mcc, true);
328  lb.setConsumer(this);
330  }
331 
333  openFile(fb);
334  }
335 
338  }
339 
342  }
343 
345  if(isFileOpen()) {
346  reallyCloseFile();
347  }
348  }
349 
351  }
352 
353  BranchIDLists const*
355  if(!droppedBranchIDToKeptBranchID_.empty()) {
356  // Make a private copy of the BranchIDLists.
358  // Check for branches dropped while an EDAlias was kept.
359  for(BranchIDList& branchIDList : *branchIDLists_) {
360  for(BranchID::value_type& branchID : branchIDList) {
361  // 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.
362  std::map<BranchID::value_type, BranchID::value_type>::const_iterator iter = droppedBranchIDToKeptBranchID_.find(branchID);
363  if(iter != droppedBranchIDToKeptBranchID_.end()) {
364  branchID = iter->second;
365  }
366  }
367  }
368  return branchIDLists_.get();
369  }
370  return origBranchIDLists_;
371  }
372 
375  return thinnedAssociationsHelper_.get();
376  }
377 
378  ModuleDescription const&
380  return moduleDescription_;
381  }
382 
383  bool
385  return productSelector_.selected(desc);
386  }
387 
388  void
391  desc.setUnknown();
392  descriptions.addDefault(desc);
393  }
394 
395  void
397  ProductSelectorRules::fillDescription(desc, "outputCommands");
399  }
400 
401  void
403  }
404 
405 
406  static const std::string kBaseType("OutputModule");
407  const std::string&
409  return kBaseType;
410  }
411 
412  void
413  OutputModuleBase::setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
414  bool anyProductProduced) {
416  description().moduleLabel(),
417  outputModulePathPositions,
418  anyProductProduced);
419  }
420  }
421 }
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 &)
bool doEvent(EventPrincipal const &ep, EventSetup const &c, ActivityRegistry *, ModuleCallingContext const *)
ParameterSetID id() const
SubProcessParentageHelper const * subProcessParentageHelper_
void configure(OutputModuleDescription const &desc)
ParameterSet const & getParameterSet(ParameterSetID const &id)
void keepThisBranch(BranchDescription const &desc, std::map< BranchID, BranchDescription const * > &trueBranchIDToKeptBranchDesc, std::set< BranchID > &keptProductsInEvent)
bool doBeginRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *)
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
#define nullptr
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
void setEventSelectionInfo(std::map< std::string, std::vector< std::pair< std::string, int > > > const &outputModulePathPositions, bool anyProductProduced)
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
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()
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
bool doEndRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *)
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 &)
bool doBeginLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext 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()
bool doEndLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *)
std::map< BranchID, bool > keepAssociation_