CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
37 
38 
39 namespace edm {
40  namespace one {
41 
42  // -------------------------------------------------------
44  maxEvents_(-1),
45  remainingEvents_(maxEvents_),
46  keptProducts_(),
47  hasNewlyDroppedBranch_(),
48  process_name_(),
49  productSelectorRules_(pset, "outputCommands", "OutputModule"),
50  productSelector_(),
51  moduleDescription_(),
52  wantAllEvents_(false),
53  selectors_(),
54  selector_config_id_(),
55  droppedBranchIDToKeptBranchID_(),
56  branchIDLists_(new BranchIDLists),
57  origBranchIDLists_(nullptr),
58  thinnedAssociationsHelper_(new ThinnedAssociationsHelper),
59  branchParents_(),
60  branchChildren_() {
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]);
81 
82  }
83 
87  }
88 
90  ThinnedAssociationsHelper const& thinnedAssociationsHelper) {
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  switch (desc.branchType()) {
146  case InEvent:
147  {
148  if(desc.produced()) {
149  keptProductsInEvent.insert(desc.originalBranchID());
150  } else {
151  keptProductsInEvent.insert(desc.branchID());
152  }
154  InputTag{desc.moduleLabel(),
155  desc.productInstanceName(),
156  desc.processName()});
157  break;
158  }
159  case InLumi:
160  {
161  consumes<InLumi>(TypeToGet{desc.unwrappedTypeID(),PRODUCT_TYPE},
162  InputTag(desc.moduleLabel(),
163  desc.productInstanceName(),
164  desc.processName()));
165  break;
166  }
167  case InRun:
168  {
169  consumes<InRun>(TypeToGet{desc.unwrappedTypeID(),PRODUCT_TYPE},
170  InputTag(desc.moduleLabel(),
171  desc.productInstanceName(),
172  desc.processName()));
173  break;
174  }
175  default:
176  assert(false);
177  break;
178  }
179  // Now put it in the list of selected branches.
180  keptProducts_[desc.branchType()].push_back(&desc);
181  }
182 
184 
186  return SharedResourcesAcquirer{};
187  }
188 
190  auto nstreams = iPC.numberOfStreams();
191  selectors_.resize(nstreams);
192 
193  bool seenFirst = false;
194  for(auto& s : selectors_) {
195  if(seenFirst) {
199  s);
200  } else {
201  seenFirst = true;
202  }
203  }
204  }
205 
208  this->beginJob();
209  }
210 
212  endJob();
213  }
214 
216 
217  auto& s = selectors_[id.value()];
218  detail::TRBESSentry products_sentry(s);
219 
220  return wantAllEvents_ or s.wantEvent(ep,mcc);
221  }
222 
223  bool
225  EventSetup const&,
226  ActivityRegistry* act,
227  ModuleCallingContext const* mcc) {
228 
229  {
230  std::lock_guard<std::mutex> guard(mutex_);
231  {
232  std::lock_guard<SharedResourcesAcquirer> guard(resourcesAcquirer_);
233  EventSignalsSentry sentry(act,mcc);
234  write(ep, mcc);
235  }
237  }
238  if(remainingEvents_ > 0) {
240  }
241  return true;
242  }
243 
244  bool
246  EventSetup const&,
247  ModuleCallingContext const* mcc) {
248  doBeginRun_(rp, mcc);
249  return true;
250  }
251 
252  bool
254  EventSetup const&,
255  ModuleCallingContext const* mcc) {
256  doEndRun_(rp, mcc);
257  return true;
258  }
259 
260  void
262  ModuleCallingContext const* mcc) {
263  writeRun(rp, mcc);
264  }
265 
266  bool
268  EventSetup const&,
269  ModuleCallingContext const* mcc) {
270  doBeginLuminosityBlock_(lbp, mcc);
271  return true;
272  }
273 
274  bool
276  EventSetup const&,
277  ModuleCallingContext const* mcc) {
278  doEndLuminosityBlock_(lbp, mcc);
279  return true;
280  }
281 
283  ModuleCallingContext const* mcc) {
284  writeLuminosityBlock(lbp, mcc);
285  }
286 
288  openFile(fb);
289  }
290 
293  }
294 
297  }
298 
299  void
302  }
303 
304  void
305  OutputModuleBase::doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren) {
306  postForkReacquireResources(iChildIndex, iNumberOfChildren);
307  }
308 
309  void
311 
312  void
313  OutputModuleBase::postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/) {}
314 
315 
317  if(!isFileOpen()) reallyOpenFile();
318  }
319 
321  if(isFileOpen()) {
323  reallyCloseFile();
324  branchParents_.clear();
326  }
327  }
328 
330  }
331 
332  BranchIDLists const*
334  if(!droppedBranchIDToKeptBranchID_.empty()) {
335  // Make a private copy of the BranchIDLists.
337  // Check for branches dropped while an EDAlias was kept.
338  for(BranchIDList& branchIDList : *branchIDLists_) {
339  for(BranchID::value_type& branchID : branchIDList) {
340  // 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.
341  std::map<BranchID::value_type, BranchID::value_type>::const_iterator iter = droppedBranchIDToKeptBranchID_.find(branchID);
342  if(iter != droppedBranchIDToKeptBranchID_.end()) {
343  branchID = iter->second;
344  }
345  }
346  }
347  return branchIDLists_.get();
348  }
349  return origBranchIDLists_;
350  }
351 
354  return thinnedAssociationsHelper_.get();
355  }
356 
357  ModuleDescription const&
359  return moduleDescription_;
360  }
361 
362  bool
364  return productSelector_.selected(desc);
365  }
366 
367  void
370  desc.setUnknown();
371  descriptions.addDefault(desc);
372  }
373 
374  void
376  ProductSelectorRules::fillDescription(desc, "outputCommands");
378  }
379 
380  void
382  }
383 
384 
385  static const std::string kBaseType("OutputModule");
386  const std::string&
388  return kBaseType;
389  }
390 
391  void
392  OutputModuleBase::setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
393  bool anyProductProduced) {
395  description().moduleLabel(),
396  outputModulePathPositions,
397  anyProductProduced);
398  }
399 
400  void
402  for(EventPrincipal::const_iterator i = ep.begin(), iEnd = ep.end(); i != iEnd; ++i) {
403  if((*i) && (*i)->productProvenancePtr() != 0) {
404  BranchID const& bid = (*i)->branchDescription().branchID();
405  BranchParents::iterator it = branchParents_.find(bid);
406  if(it == branchParents_.end()) {
407  it = branchParents_.insert(std::make_pair(bid, std::set<ParentageID>())).first;
408  }
409  it->second.insert((*i)->productProvenancePtr()->parentageID());
411  }
412  }
413  }
414 
415  void
417  for(BranchParents::const_iterator i = branchParents_.begin(), iEnd = branchParents_.end();
418  i != iEnd; ++i) {
419  BranchID const& child = i->first;
420  std::set<ParentageID> const& eIds = i->second;
421  for(std::set<ParentageID>::const_iterator it = eIds.begin(), itEnd = eIds.end();
422  it != itEnd; ++it) {
423  Parentage entryDesc;
424  ParentageRegistry::instance()->getMapped(*it, entryDesc);
425  std::vector<BranchID> const& parents = entryDesc.parents();
426  for(std::vector<BranchID>::const_iterator j = parents.begin(), jEnd = parents.end();
427  j != jEnd; ++j) {
428  branchChildren_.insertChild(*j, child);
429  }
430  }
431  }
432  }
433 
434 
435  }
436 }
BranchIDLists const * branchIDLists() const
static const std::string kBaseType("EDAnalyzer")
std::unique_ptr< BranchIDLists > branchIDLists_
int i
Definition: DBlmapReader.cc:9
bool selected(BranchDescription const &desc) const
static void fillDescription(ParameterSetDescription &desc, char const *parameterName)
ModuleDescription const & description() const
TPRegexp parents
Definition: eve_filter.cc:24
BranchType const & branchType() const
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
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 *)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
ModuleDescription moduleDescription_
void doWriteRun(RunPrincipal const &rp, ModuleCallingContext const *)
static void prevalidate(ConfigurationDescriptions &)
const_iterator end() const
Definition: Principal.h:158
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)
assert(m_qm.get())
void keepThisBranch(BranchDescription const &desc, std::map< BranchID, BranchDescription const * > &trueBranchIDToKeptBranchDesc, std::set< BranchID > &keptProductsInEvent)
virtual void doEndRun_(RunPrincipal const &, ModuleCallingContext const *)
void insertEmpty(BranchID parent)
void insertChild(BranchID parent, BranchID child)
bool doBeginRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *)
std::string const & processName() const
ParameterSet getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
#define nullptr
ProductSelectorRules productSelectorRules_
void selectProducts(ProductRegistry const &preg, ThinnedAssociationsHelper const &)
virtual void doBeginRun_(RunPrincipal const &, ModuleCallingContext const *)
BranchIDLists const * branchIDLists_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< BranchID > const & parents() const
Definition: Parentage.h:37
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
void addDefault(ParameterSetDescription const &psetDescription)
std::atomic< int > remainingEvents_
bool getMapped(key_type const &k, value_type &result) const
std::string const & moduleLabel() const
unsigned int value_type
Definition: BranchID.h:16
std::string const & productInstanceName() const
bool selected(BranchDescription const &desc) const
TypeID unwrappedTypeID() const
void setEventSelectionInfo(std::map< std::string, std::vector< std::pair< std::string, int > > > const &outputModulePathPositions, bool anyProductProduced)
int j
Definition: DBlmapReader.cc:9
std::vector< BranchDescription const * > allBranchDescriptions() const
virtual void writeRun(RunPrincipal const &, ModuleCallingContext const *)=0
BranchID const & branchID() const
virtual void preForkReleaseResources()
TypeWithDict const & unwrappedType() const
static void fillDescription(ParameterSetDescription &desc)
bool prePrefetchSelection(StreamID id, EventPrincipal const &, ModuleCallingContext const *)
std::unique_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper_
SharedResourcesAcquirer resourcesAcquirer_
virtual void doBeginLuminosityBlock_(LuminosityBlockPrincipal const &, ModuleCallingContext const *)
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
OutputModuleBase(ParameterSet const &pset)
std::vector< detail::TriggerResultsBasedEventSelector > selectors_
virtual void doEndLuminosityBlock_(LuminosityBlockPrincipal const &, ModuleCallingContext const *)
void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
void doRespondToCloseInputFile(FileBlock const &fb)
virtual SharedResourcesAcquirer createAcquirer()
const_iterator begin() const
Definition: Principal.h:157
void doRespondToOpenInputFile(FileBlock const &fb)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
virtual void write(EventPrincipal const &e, ModuleCallingContext const *)=0
std::vector< BranchID::value_type > BranchIDList
Definition: BranchIDList.h:18
bool doEndRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *)
bool initialized() const
std::vector< std::string > const & getAllTriggerNames()
boost::filter_iterator< FilledProductPtr, ProductHolderCollection::const_iterator > const_iterator
Definition: Principal.h:56
void initialize(ProductSelectorRules const &rules, std::vector< BranchDescription const * > const &branchDescriptions)
static const std::string & baseType()
void doPreallocate(PreallocationConfiguration const &)
void doOpenFile(FileBlock const &fb)
virtual void writeLuminosityBlock(LuminosityBlockPrincipal const &, ModuleCallingContext const *)=0
virtual void postForkReacquireResources(unsigned int, unsigned int)
BranchIDLists const * origBranchIDLists_
BranchID const & originalBranchID() const
bool doBeginLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *)
volatile std::atomic< bool > shutdown_flag false
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_
preg
Definition: Schedule.cc:370
void updateBranchParents(EventPrincipal const &ep)
static ParentageRegistry * instance()
ProductSelector productSelector_
bool configureEventSelector(edm::ParameterSet const &iPSet, std::string const &iProcessName, std::vector< std::string > const &iAllTriggerNames, edm::detail::TriggerResultsBasedEventSelector &oSelector)
ParameterSet const & registerIt()
ParameterSetID selector_config_id_
static void checkForDuplicateKeptBranch(BranchDescription const &desc, std::map< BranchID, BranchDescription const * > &trueBranchIDToKeptBranchDesc)
bool doEndLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *)
std::map< BranchID, bool > keepAssociation_