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 
87  }
88 
91  if(productSelector_.initialized()) return;
93 
94  // TODO: See if we can collapse keptProducts_ and productSelector_ into a
95  // single object. See the notes in the header for ProductSelector
96  // for more information.
97 
98  std::map<BranchID, BranchDescription const*> trueBranchIDToKeptBranchDesc;
99  std::vector<BranchDescription const*> associationDescriptions;
100  std::set<BranchID> keptProductsInEvent;
101 
102  for(auto const& it : preg.productList()) {
103  BranchDescription const& desc = it.second;
104  if(desc.transient()) {
105  // if the class of the branch is marked transient, output nothing
106  } else if(!desc.present() && !desc.produced()) {
107  // else if the branch containing the product has been previously dropped,
108  // output nothing
109  } else if(desc.unwrappedType() == typeid(ThinnedAssociation)) {
110  associationDescriptions.push_back(&desc);
111  } else if(selected(desc)) {
112  keepThisBranch(desc, trueBranchIDToKeptBranchDesc, keptProductsInEvent);
113  } else {
114  // otherwise, output nothing,
115  // and mark the fact that there is a newly dropped branch of this type.
116  hasNewlyDroppedBranch_[desc.branchType()] = true;
117  }
118  }
119 
120  thinnedAssociationsHelper.selectAssociationProducts(associationDescriptions,
121  keptProductsInEvent,
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(thinnedAssociationsHelper, keepAssociation_, droppedBranchIDToKeptBranchID_);
136  }
137 
139  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
140  std::set<BranchID>& keptProductsInEvent) {
141 
143  trueBranchIDToKeptBranchDesc);
144 
145  EDGetToken token;
146 
147  std::vector<std::string> missingDictionaries;
148  if (!checkDictionary(missingDictionaries, desc.className(), desc.unwrappedType())) {
149  std::string context("Calling OutputModuleBase::keepThisBranch, checking dictionaries for kept types");
150  throwMissingDictionariesException(missingDictionaries, context);
151  }
152 
153  switch (desc.branchType()) {
154  case InEvent:
155  {
156  if(desc.produced()) {
157  keptProductsInEvent.insert(desc.originalBranchID());
158  } else {
159  keptProductsInEvent.insert(desc.branchID());
160  }
162  InputTag{desc.moduleLabel(),
163  desc.productInstanceName(),
164  desc.processName()});
165  break;
166  }
167  case InLumi:
168  {
169  token = consumes<InLumi>(TypeToGet{desc.unwrappedTypeID(),PRODUCT_TYPE},
170  InputTag(desc.moduleLabel(),
171  desc.productInstanceName(),
172  desc.processName()));
173  break;
174  }
175  case InRun:
176  {
177  token = consumes<InRun>(TypeToGet{desc.unwrappedTypeID(),PRODUCT_TYPE},
178  InputTag(desc.moduleLabel(),
179  desc.productInstanceName(),
180  desc.processName()));
181  break;
182  }
183  default:
184  assert(false);
185  break;
186  }
187  // Now put it in the list of selected branches.
188  keptProducts_[desc.branchType()].push_back(std::make_pair(&desc, token));
189  }
190 
192 
195  std::vector<std::shared_ptr<SerialTaskQueue>>(1, std::make_shared<SerialTaskQueue>())};
196  }
197 
199  auto nstreams = iPC.numberOfStreams();
200  selectors_.resize(nstreams);
201 
202  bool seenFirst = false;
203  for(auto& s : selectors_) {
204  if(seenFirst) {
208  s,
210  } else {
211  seenFirst = true;
212  }
213  }
214  }
215 
218  this->beginJob();
219  }
220 
222  endJob();
223  }
224 
226  if(wantAllEvents_) return true;
227  auto& s = selectors_[id.value()];
229  e.setConsumer(this);
230  return s.wantEvent(e);
231  }
232 
233  bool
235  EventSetup const&,
236  ActivityRegistry* act,
237  ModuleCallingContext const* mcc) {
238 
239  {
241  e.setConsumer(this);
242  EventSignalsSentry sentry(act,mcc);
243  write(e);
244  }
245  if(remainingEvents_ > 0) {
247  }
248  return true;
249  }
250 
251  bool
253  EventSetup const&,
254  ModuleCallingContext const* mcc) {
256  r.setConsumer(this);
257  doBeginRun_(r);
258  return true;
259  }
260 
261  bool
263  EventSetup const&,
264  ModuleCallingContext const* mcc) {
266  r.setConsumer(this);
267  doEndRun_(r);
268  return true;
269  }
270 
271  void
273  ModuleCallingContext const* mcc) {
275  r.setConsumer(this);
276  writeRun(r);
277  }
278 
279  bool
281  EventSetup const&,
282  ModuleCallingContext const* mcc) {
284  lb.setConsumer(this);
286  return true;
287  }
288 
289  bool
291  EventSetup const&,
292  ModuleCallingContext const* mcc) {
294  lb.setConsumer(this);
296 
297  return true;
298  }
299 
301  ModuleCallingContext const* mcc) {
303  lb.setConsumer(this);
305  }
306 
308  openFile(fb);
309  }
310 
313  }
314 
317  }
318 
319  void
322  }
323 
324  void
325  OutputModuleBase::doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren) {
326  postForkReacquireResources(iChildIndex, iNumberOfChildren);
327  }
328 
329  void
331 
332  void
333  OutputModuleBase::postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/) {}
334 
335 
337  if(!isFileOpen()) reallyOpenFile();
338  }
339 
341  if(isFileOpen()) {
342  reallyCloseFile();
343  }
344  }
345 
347  }
348 
349  BranchIDLists const*
351  if(!droppedBranchIDToKeptBranchID_.empty()) {
352  // Make a private copy of the BranchIDLists.
354  // Check for branches dropped while an EDAlias was kept.
355  for(BranchIDList& branchIDList : *branchIDLists_) {
356  for(BranchID::value_type& branchID : branchIDList) {
357  // 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.
358  std::map<BranchID::value_type, BranchID::value_type>::const_iterator iter = droppedBranchIDToKeptBranchID_.find(branchID);
359  if(iter != droppedBranchIDToKeptBranchID_.end()) {
360  branchID = iter->second;
361  }
362  }
363  }
364  return branchIDLists_.get();
365  }
366  return origBranchIDLists_;
367  }
368 
371  return thinnedAssociationsHelper_.get();
372  }
373 
374  ModuleDescription const&
376  return moduleDescription_;
377  }
378 
379  bool
381  return productSelector_.selected(desc);
382  }
383 
384  void
387  desc.setUnknown();
388  descriptions.addDefault(desc);
389  }
390 
391  void
393  ProductSelectorRules::fillDescription(desc, "outputCommands");
395  }
396 
397  void
399  }
400 
401 
402  static const std::string kBaseType("OutputModule");
403  const std::string&
405  return kBaseType;
406  }
407 
408  void
409  OutputModuleBase::setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
410  bool anyProductProduced) {
412  description().moduleLabel(),
413  outputModulePathPositions,
414  anyProductProduced);
415  }
416  }
417 }
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
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
virtual void preForkReleaseResources()
TypeWithDict const & unwrappedType() const
static void fillDescription(ParameterSetDescription &desc)
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_
void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
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)
virtual void postForkReacquireResources(unsigned int, unsigned int)
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_