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 
36 
37 
38 namespace edm {
39  namespace one {
40 
41  // -------------------------------------------------------
43  maxEvents_(-1),
44  remainingEvents_(maxEvents_),
45  keptProducts_(),
46  hasNewlyDroppedBranch_(),
47  process_name_(),
48  productSelectorRules_(pset, "outputCommands", "OutputModule"),
49  productSelector_(),
50  moduleDescription_(),
51  wantAllEvents_(false),
52  selectors_(),
53  selector_config_id_(),
54  droppedBranchIDToKeptBranchID_(),
55  branchIDLists_(new BranchIDLists),
56  origBranchIDLists_(nullptr),
57  thinnedAssociationsHelper_(new ThinnedAssociationsHelper),
58  branchParents_(),
59  branchChildren_() {
60 
61  hasNewlyDroppedBranch_.fill(false);
62 
64  process_name_ = tns->getProcessName();
65 
66  ParameterSet selectevents =
67  pset.getUntrackedParameterSet("SelectEvents", ParameterSet());
68 
69  selectevents.registerIt(); // Just in case this PSet is not registered
70 
71  selector_config_id_ = selectevents.id();
75  selectors_);
76  }
77 
81  }
82 
84  ThinnedAssociationsHelper const& thinnedAssociationsHelper) {
85  if(productSelector_.initialized()) return;
87 
88  // TODO: See if we can collapse keptProducts_ and productSelector_ into a
89  // single object. See the notes in the header for ProductSelector
90  // for more information.
91 
92  std::map<BranchID, BranchDescription const*> trueBranchIDToKeptBranchDesc;
93  std::vector<BranchDescription const*> associationDescriptions;
94  std::set<BranchID> keptProductsInEvent;
95 
96  for(auto const& it : preg.productList()) {
97  BranchDescription const& desc = it.second;
98  if(desc.transient()) {
99  // if the class of the branch is marked transient, output nothing
100  } else if(!desc.present() && !desc.produced()) {
101  // else if the branch containing the product has been previously dropped,
102  // output nothing
103  } else if(desc.unwrappedType().typeInfo() == typeid(ThinnedAssociation)) {
104  associationDescriptions.push_back(&desc);
105  } else if(selected(desc)) {
106  keepThisBranch(desc, trueBranchIDToKeptBranchDesc, keptProductsInEvent);
107  } else {
108  // otherwise, output nothing,
109  // and mark the fact that there is a newly dropped branch of this type.
110  hasNewlyDroppedBranch_[desc.branchType()] = true;
111  }
112  }
113 
114  thinnedAssociationsHelper.selectAssociationProducts(associationDescriptions,
115  keptProductsInEvent,
117 
118  for(auto association : associationDescriptions) {
119  if(keepAssociation_[association->branchID()]) {
120  keepThisBranch(*association, trueBranchIDToKeptBranchDesc, keptProductsInEvent);
121  } else {
122  hasNewlyDroppedBranch_[association->branchType()] = true;
123  }
124  }
125 
126  // Now fill in a mapping needed in the case that a branch was dropped while its EDAlias was kept.
127  ProductSelector::fillDroppedToKept(preg, trueBranchIDToKeptBranchDesc, droppedBranchIDToKeptBranchID_);
128 
129  thinnedAssociationsHelper_->updateFromParentProcess(thinnedAssociationsHelper, keepAssociation_, droppedBranchIDToKeptBranchID_);
130  }
131 
133  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
134  std::set<BranchID>& keptProductsInEvent) {
135 
137  trueBranchIDToKeptBranchDesc);
138 
139  switch (desc.branchType()) {
140  case InEvent:
141  {
142  if(desc.produced()) {
143  keptProductsInEvent.insert(desc.originalBranchID());
144  } else {
145  keptProductsInEvent.insert(desc.branchID());
146  }
148  InputTag{desc.moduleLabel(),
149  desc.productInstanceName(),
150  desc.processName()});
151  break;
152  }
153  case InLumi:
154  {
155  consumes<InLumi>(TypeToGet{desc.unwrappedTypeID(),PRODUCT_TYPE},
156  InputTag(desc.moduleLabel(),
157  desc.productInstanceName(),
158  desc.processName()));
159  break;
160  }
161  case InRun:
162  {
163  consumes<InRun>(TypeToGet{desc.unwrappedTypeID(),PRODUCT_TYPE},
164  InputTag(desc.moduleLabel(),
165  desc.productInstanceName(),
166  desc.processName()));
167  break;
168  }
169  default:
170  assert(false);
171  break;
172  }
173  // Now put it in the list of selected branches.
174  keptProducts_[desc.branchType()].push_back(&desc);
175  }
176 
178 
180  return SharedResourcesAcquirer{};
181  }
182 
185  this->beginJob();
186  }
187 
189  endJob();
190  }
191 
192 
194  ModuleCallingContext const* mcc) const {
195  return selectors_.getOneTriggerResults(ep, mcc); }
196 
197  bool
199  EventSetup const&,
200  ActivityRegistry* act,
201  ModuleCallingContext const* mcc) {
202 
203  {
204  std::lock_guard<std::mutex> guard(mutex_);
205  detail::TRBESSentry products_sentry(selectors_);
206  if(!wantAllEvents_) {
207  if(!selectors_.wantEvent(ep, mcc)) {
208  return true;
209  }
210  }
211  {
212  std::lock_guard<SharedResourcesAcquirer> guard(resourcesAcquirer_);
213  EventSignalsSentry sentry(act,mcc);
214  write(ep, mcc);
215  }
217  }
218  if(remainingEvents_ > 0) {
220  }
221  return true;
222  }
223 
224  bool
226  EventSetup const&,
227  ModuleCallingContext const* mcc) {
228  doBeginRun_(rp, mcc);
229  return true;
230  }
231 
232  bool
234  EventSetup const&,
235  ModuleCallingContext const* mcc) {
236  doEndRun_(rp, mcc);
237  return true;
238  }
239 
240  void
242  ModuleCallingContext const* mcc) {
243  writeRun(rp, mcc);
244  }
245 
246  bool
248  EventSetup const&,
249  ModuleCallingContext const* mcc) {
250  doBeginLuminosityBlock_(lbp, mcc);
251  return true;
252  }
253 
254  bool
256  EventSetup const&,
257  ModuleCallingContext const* mcc) {
258  doEndLuminosityBlock_(lbp, mcc);
259  return true;
260  }
261 
263  ModuleCallingContext const* mcc) {
264  writeLuminosityBlock(lbp, mcc);
265  }
266 
268  openFile(fb);
269  }
270 
273  }
274 
277  }
278 
279  void
282  }
283 
284  void
285  OutputModuleBase::doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren) {
286  postForkReacquireResources(iChildIndex, iNumberOfChildren);
287  }
288 
289  void
291 
292  void
293  OutputModuleBase::postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/) {}
294 
295 
297  if(!isFileOpen()) reallyOpenFile();
298  }
299 
301  if(isFileOpen()) {
303  reallyCloseFile();
304  branchParents_.clear();
306  }
307  }
308 
310  }
311 
312  BranchIDLists const*
314  if(!droppedBranchIDToKeptBranchID_.empty()) {
315  // Make a private copy of the BranchIDLists.
317  // Check for branches dropped while an EDAlias was kept.
318  for(BranchIDList& branchIDList : *branchIDLists_) {
319  for(BranchID::value_type& branchID : branchIDList) {
320  // 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.
321  std::map<BranchID::value_type, BranchID::value_type>::const_iterator iter = droppedBranchIDToKeptBranchID_.find(branchID);
322  if(iter != droppedBranchIDToKeptBranchID_.end()) {
323  branchID = iter->second;
324  }
325  }
326  }
327  return branchIDLists_.get();
328  }
329  return origBranchIDLists_;
330  }
331 
334  return thinnedAssociationsHelper_.get();
335  }
336 
337  ModuleDescription const&
339  return moduleDescription_;
340  }
341 
342  bool
344  return productSelector_.selected(desc);
345  }
346 
347  void
350  desc.setUnknown();
351  descriptions.addDefault(desc);
352  }
353 
354  void
356  ProductSelectorRules::fillDescription(desc, "outputCommands");
358  }
359 
360  void
362  }
363 
364 
365  static const std::string kBaseType("OutputModule");
366  const std::string&
368  return kBaseType;
369  }
370 
371  void
372  OutputModuleBase::setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
373  bool anyProductProduced) {
375  description().moduleLabel(),
376  outputModulePathPositions,
377  anyProductProduced);
378  }
379 
380  void
382  for(EventPrincipal::const_iterator i = ep.begin(), iEnd = ep.end(); i != iEnd; ++i) {
383  if((*i) && (*i)->productProvenancePtr() != 0) {
384  BranchID const& bid = (*i)->branchDescription().branchID();
385  BranchParents::iterator it = branchParents_.find(bid);
386  if(it == branchParents_.end()) {
387  it = branchParents_.insert(std::make_pair(bid, std::set<ParentageID>())).first;
388  }
389  it->second.insert((*i)->productProvenancePtr()->parentageID());
391  }
392  }
393  }
394 
395  void
397  for(BranchParents::const_iterator i = branchParents_.begin(), iEnd = branchParents_.end();
398  i != iEnd; ++i) {
399  BranchID const& child = i->first;
400  std::set<ParentageID> const& eIds = i->second;
401  for(std::set<ParentageID>::const_iterator it = eIds.begin(), itEnd = eIds.end();
402  it != itEnd; ++it) {
403  Parentage entryDesc;
404  ParentageRegistry::instance()->getMapped(*it, entryDesc);
405  std::vector<BranchID> const& parents = entryDesc.parents();
406  for(std::vector<BranchID>::const_iterator j = parents.begin(), jEnd = parents.end();
407  j != jEnd; ++j) {
408  branchChildren_.insertChild(*j, child);
409  }
410  }
411  }
412  }
413 
414 
415  }
416 }
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 *)
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)
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)
Trig getTriggerResults(EventPrincipal const &ep, ModuleCallingContext const *) const
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
std::type_info const & typeInfo() const
static void fillDescription(ParameterSetDescription &desc)
std::unique_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper_
SharedResourcesAcquirer resourcesAcquirer_
virtual void doBeginLuminosityBlock_(LuminosityBlockPrincipal const &, ModuleCallingContext const *)
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
OutputModuleBase(ParameterSet const &pset)
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
handle_t getOneTriggerResults(EventPrincipal const &e, ModuleCallingContext const *)
void doRespondToOpenInputFile(FileBlock const &fb)
bool wantEvent(EventPrincipal const &e, ModuleCallingContext const *)
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 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()
detail::TriggerResultsBasedEventSelector selectors_
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_