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 
39 
40 namespace edm {
41  namespace one {
42 
43  // -------------------------------------------------------
45  maxEvents_(-1),
46  remainingEvents_(maxEvents_),
47  keptProducts_(),
48  hasNewlyDroppedBranch_(),
49  process_name_(),
50  productSelectorRules_(pset, "outputCommands", "OutputModule"),
51  productSelector_(),
52  moduleDescription_(),
53  wantAllEvents_(false),
54  selectors_(),
55  selector_config_id_(),
56  droppedBranchIDToKeptBranchID_(),
57  branchIDLists_(new BranchIDLists),
58  origBranchIDLists_(nullptr),
59  thinnedAssociationsHelper_(new ThinnedAssociationsHelper) {
60 
61  hasNewlyDroppedBranch_.fill(false);
62 
64  process_name_ = tns->getProcessName();
65 
67  pset.getUntrackedParameterSet("SelectEvents", ParameterSet());
68 
69  selectEvents_.registerIt(); // Just in case this PSet is not registered
70 
72 
73  //need to set wantAllEvents_ in constructor
74  // we will make the remaining selectors once we know how many streams
75  selectors_.resize(1);
79  selectors_[0],
81 
82  }
83 
88  }
89 
92  if(productSelector_.initialized()) return;
94 
95  // TODO: See if we can collapse keptProducts_ and productSelector_ into a
96  // single object. See the notes in the header for ProductSelector
97  // for more information.
98 
99  std::map<BranchID, BranchDescription const*> trueBranchIDToKeptBranchDesc;
100  std::vector<BranchDescription const*> associationDescriptions;
101  std::set<BranchID> keptProductsInEvent;
102 
103  for(auto const& it : preg.productList()) {
104  BranchDescription const& desc = it.second;
105  if(desc.transient()) {
106  // if the class of the branch is marked transient, output nothing
107  } else if(!desc.present() && !desc.produced()) {
108  // else if the branch containing the product has been previously dropped,
109  // output nothing
110  } else if(desc.unwrappedType() == typeid(ThinnedAssociation)) {
111  associationDescriptions.push_back(&desc);
112  } else if(selected(desc)) {
113  keepThisBranch(desc, trueBranchIDToKeptBranchDesc, keptProductsInEvent);
114  } else {
115  // otherwise, output nothing,
116  // and mark the fact that there is a newly dropped branch of this type.
117  hasNewlyDroppedBranch_[desc.branchType()] = true;
118  }
119  }
120 
121  thinnedAssociationsHelper.selectAssociationProducts(associationDescriptions,
122  keptProductsInEvent,
124 
125  for(auto association : associationDescriptions) {
126  if(keepAssociation_[association->branchID()]) {
127  keepThisBranch(*association, trueBranchIDToKeptBranchDesc, keptProductsInEvent);
128  } else {
129  hasNewlyDroppedBranch_[association->branchType()] = true;
130  }
131  }
132 
133  // Now fill in a mapping needed in the case that a branch was dropped while its EDAlias was kept.
134  ProductSelector::fillDroppedToKept(preg, trueBranchIDToKeptBranchDesc, droppedBranchIDToKeptBranchID_);
135 
136  thinnedAssociationsHelper_->updateFromParentProcess(thinnedAssociationsHelper, keepAssociation_, droppedBranchIDToKeptBranchID_);
137  }
138 
140  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
141  std::set<BranchID>& keptProductsInEvent) {
142 
144  trueBranchIDToKeptBranchDesc);
145 
146  EDGetToken token;
147 
148  std::vector<std::string> missingDictionaries;
149  if (!checkDictionary(missingDictionaries, desc.className(), desc.unwrappedType())) {
150  std::string context("Calling OutputModuleBase::keepThisBranch, checking dictionaries for kept types");
151  throwMissingDictionariesException(missingDictionaries, context);
152  }
153 
154  switch (desc.branchType()) {
155  case InEvent:
156  {
157  if(desc.produced()) {
158  keptProductsInEvent.insert(desc.originalBranchID());
159  } else {
160  keptProductsInEvent.insert(desc.branchID());
161  }
163  InputTag{desc.moduleLabel(),
164  desc.productInstanceName(),
165  desc.processName()});
166  break;
167  }
168  case InLumi:
169  {
170  token = consumes<InLumi>(TypeToGet{desc.unwrappedTypeID(),PRODUCT_TYPE},
171  InputTag(desc.moduleLabel(),
172  desc.productInstanceName(),
173  desc.processName()));
174  break;
175  }
176  case InRun:
177  {
178  token = consumes<InRun>(TypeToGet{desc.unwrappedTypeID(),PRODUCT_TYPE},
179  InputTag(desc.moduleLabel(),
180  desc.productInstanceName(),
181  desc.processName()));
182  break;
183  }
184  default:
185  assert(false);
186  break;
187  }
188  // Now put it in the list of selected branches.
189  keptProducts_[desc.branchType()].push_back(std::make_pair(&desc, token));
190  }
191 
193 
196  std::vector<std::shared_ptr<SerialTaskQueue>>(1, std::make_shared<SerialTaskQueue>())};
197  }
198 
200  auto nstreams = iPC.numberOfStreams();
201  selectors_.resize(nstreams);
202 
203  bool seenFirst = false;
204  for(auto& s : selectors_) {
205  if(seenFirst) {
209  s,
211  } else {
212  seenFirst = true;
213  }
214  }
215  }
216 
219  this->beginJob();
220  }
221 
223  endJob();
224  }
225 
227  if(wantAllEvents_) return true;
228  auto& s = selectors_[id.value()];
230  e.setConsumer(this);
231  return s.wantEvent(e);
232  }
233 
234  bool
236  EventSetup const&,
237  ActivityRegistry* act,
238  ModuleCallingContext const* mcc) {
239 
240  {
242  e.setConsumer(this);
243  EventSignalsSentry sentry(act,mcc);
244  write(e);
245  }
246  if(remainingEvents_ > 0) {
248  }
249  return true;
250  }
251 
252  bool
254  EventSetup const&,
255  ModuleCallingContext const* mcc) {
257  r.setConsumer(this);
258  doBeginRun_(r);
259  return true;
260  }
261 
262  bool
264  EventSetup const&,
265  ModuleCallingContext const* mcc) {
267  r.setConsumer(this);
268  doEndRun_(r);
269  return true;
270  }
271 
272  void
274  ModuleCallingContext const* mcc) {
276  r.setConsumer(this);
277  writeRun(r);
278  }
279 
280  bool
282  EventSetup const&,
283  ModuleCallingContext const* mcc) {
285  lb.setConsumer(this);
287  return true;
288  }
289 
290  bool
292  EventSetup const&,
293  ModuleCallingContext const* mcc) {
295  lb.setConsumer(this);
297 
298  return true;
299  }
300 
302  ModuleCallingContext const* mcc) {
304  lb.setConsumer(this);
306  }
307 
309  openFile(fb);
310  }
311 
314  }
315 
318  }
319 
321  if(isFileOpen()) {
322  reallyCloseFile();
323  }
324  }
325 
327  }
328 
329  BranchIDLists const*
331  if(!droppedBranchIDToKeptBranchID_.empty()) {
332  // Make a private copy of the BranchIDLists.
334  // Check for branches dropped while an EDAlias was kept.
335  for(BranchIDList& branchIDList : *branchIDLists_) {
336  for(BranchID::value_type& branchID : branchIDList) {
337  // 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.
338  std::map<BranchID::value_type, BranchID::value_type>::const_iterator iter = droppedBranchIDToKeptBranchID_.find(branchID);
339  if(iter != droppedBranchIDToKeptBranchID_.end()) {
340  branchID = iter->second;
341  }
342  }
343  }
344  return branchIDLists_.get();
345  }
346  return origBranchIDLists_;
347  }
348 
351  return thinnedAssociationsHelper_.get();
352  }
353 
354  ModuleDescription const&
356  return moduleDescription_;
357  }
358 
359  bool
361  return productSelector_.selected(desc);
362  }
363 
364  void
367  desc.setUnknown();
368  descriptions.addDefault(desc);
369  }
370 
371  void
373  ProductSelectorRules::fillDescription(desc, "outputCommands");
375  }
376 
377  void
379  }
380 
381 
382  static const std::string kBaseType("OutputModule");
383  const std::string&
385  return kBaseType;
386  }
387 
388  void
389  OutputModuleBase::setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
390  bool anyProductProduced) {
392  description().moduleLabel(),
393  outputModulePathPositions,
394  anyProductProduced);
395  }
396  }
397 }
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_
void doWriteRun(RunPrincipal const &rp, ModuleCallingContext const *)
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
void addDefault(ParameterSetDescription const &psetDescription)
std::string const & className() const
std::atomic< int > remainingEvents_
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
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_
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_