test
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 
59  hasNewlyDroppedBranch_.fill(false);
60 
62  process_name_ = tns->getProcessName();
63 
65  pset.getUntrackedParameterSet("SelectEvents", ParameterSet());
66 
67  selectEvents_.registerIt(); // Just in case this PSet is not registered
68 
70 
71  //need to set wantAllEvents_ in constructor
72  // we will make the remaining selectors once we know how many streams
73  selectors_.resize(1);
77  selectors_[0]);
78 
79  }
80 
84  }
85 
87  ThinnedAssociationsHelper const& thinnedAssociationsHelper) {
88  if(productSelector_.initialized()) return;
90 
91  // TODO: See if we can collapse keptProducts_ and productSelector_ into a
92  // single object. See the notes in the header for ProductSelector
93  // for more information.
94 
95  std::map<BranchID, BranchDescription const*> trueBranchIDToKeptBranchDesc;
96  std::vector<BranchDescription const*> associationDescriptions;
97  std::set<BranchID> keptProductsInEvent;
98 
99  for(auto const& it : preg.productList()) {
100  BranchDescription const& desc = it.second;
101  if(desc.transient()) {
102  // if the class of the branch is marked transient, output nothing
103  } else if(!desc.present() && !desc.produced()) {
104  // else if the branch containing the product has been previously dropped,
105  // output nothing
106  } else if(desc.unwrappedType() == typeid(ThinnedAssociation)) {
107  associationDescriptions.push_back(&desc);
108  } else if(selected(desc)) {
109  keepThisBranch(desc, trueBranchIDToKeptBranchDesc, keptProductsInEvent);
110  } else {
111  // otherwise, output nothing,
112  // and mark the fact that there is a newly dropped branch of this type.
113  hasNewlyDroppedBranch_[desc.branchType()] = true;
114  }
115  }
116 
117  thinnedAssociationsHelper.selectAssociationProducts(associationDescriptions,
118  keptProductsInEvent,
120 
121  for(auto association : associationDescriptions) {
122  if(keepAssociation_[association->branchID()]) {
123  keepThisBranch(*association, trueBranchIDToKeptBranchDesc, keptProductsInEvent);
124  } else {
125  hasNewlyDroppedBranch_[association->branchType()] = true;
126  }
127  }
128 
129  // Now fill in a mapping needed in the case that a branch was dropped while its EDAlias was kept.
130  ProductSelector::fillDroppedToKept(preg, trueBranchIDToKeptBranchDesc, droppedBranchIDToKeptBranchID_);
131 
132  thinnedAssociationsHelper_->updateFromParentProcess(thinnedAssociationsHelper, keepAssociation_, droppedBranchIDToKeptBranchID_);
133  }
134 
136  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
137  std::set<BranchID>& keptProductsInEvent) {
138 
140  trueBranchIDToKeptBranchDesc);
141 
142  switch (desc.branchType()) {
143  case InEvent:
144  {
145  if(desc.produced()) {
146  keptProductsInEvent.insert(desc.originalBranchID());
147  } else {
148  keptProductsInEvent.insert(desc.branchID());
149  }
151  InputTag{desc.moduleLabel(),
152  desc.productInstanceName(),
153  desc.processName()});
154  break;
155  }
156  case InLumi:
157  {
158  consumes<InLumi>(TypeToGet{desc.unwrappedTypeID(),PRODUCT_TYPE},
159  InputTag(desc.moduleLabel(),
160  desc.productInstanceName(),
161  desc.processName()));
162  break;
163  }
164  case InRun:
165  {
166  consumes<InRun>(TypeToGet{desc.unwrappedTypeID(),PRODUCT_TYPE},
167  InputTag(desc.moduleLabel(),
168  desc.productInstanceName(),
169  desc.processName()));
170  break;
171  }
172  default:
173  assert(false);
174  break;
175  }
176  // Now put it in the list of selected branches.
177  keptProducts_[desc.branchType()].push_back(&desc);
178  }
179 
181 
183  return SharedResourcesAcquirer{};
184  }
185 
187  auto nstreams = iPC.numberOfStreams();
188  selectors_.resize(nstreams);
189 
190  bool seenFirst = false;
191  for(auto& s : selectors_) {
192  if(seenFirst) {
196  s);
197  } else {
198  seenFirst = true;
199  }
200  }
201  }
202 
205  this->beginJob();
206  }
207 
209  endJob();
210  }
211 
213 
214  auto& s = selectors_[id.value()];
215  return wantAllEvents_ or s.wantEvent(ep,mcc);
216  }
217 
218  bool
220  EventSetup const&,
221  ActivityRegistry* act,
222  ModuleCallingContext const* mcc) {
223 
224  {
225  std::lock_guard<std::mutex> guard(mutex_);
226  {
227  std::lock_guard<SharedResourcesAcquirer> guard(resourcesAcquirer_);
228  EventSignalsSentry sentry(act,mcc);
229  write(ep, mcc);
230  }
231  }
232  if(remainingEvents_ > 0) {
234  }
235  return true;
236  }
237 
238  bool
240  EventSetup const&,
241  ModuleCallingContext const* mcc) {
242  doBeginRun_(rp, mcc);
243  return true;
244  }
245 
246  bool
248  EventSetup const&,
249  ModuleCallingContext const* mcc) {
250  doEndRun_(rp, mcc);
251  return true;
252  }
253 
254  void
256  ModuleCallingContext const* mcc) {
257  writeRun(rp, mcc);
258  }
259 
260  bool
262  EventSetup const&,
263  ModuleCallingContext const* mcc) {
264  doBeginLuminosityBlock_(lbp, mcc);
265  return true;
266  }
267 
268  bool
270  EventSetup const&,
271  ModuleCallingContext const* mcc) {
272  doEndLuminosityBlock_(lbp, mcc);
273  return true;
274  }
275 
277  ModuleCallingContext const* mcc) {
278  writeLuminosityBlock(lbp, mcc);
279  }
280 
282  openFile(fb);
283  }
284 
287  }
288 
291  }
292 
293  void
296  }
297 
298  void
299  OutputModuleBase::doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren) {
300  postForkReacquireResources(iChildIndex, iNumberOfChildren);
301  }
302 
303  void
305 
306  void
307  OutputModuleBase::postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/) {}
308 
309 
311  if(!isFileOpen()) reallyOpenFile();
312  }
313 
315  if(isFileOpen()) {
316  reallyCloseFile();
317  }
318  }
319 
321  }
322 
323  BranchIDLists const*
325  if(!droppedBranchIDToKeptBranchID_.empty()) {
326  // Make a private copy of the BranchIDLists.
328  // Check for branches dropped while an EDAlias was kept.
329  for(BranchIDList& branchIDList : *branchIDLists_) {
330  for(BranchID::value_type& branchID : branchIDList) {
331  // 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.
332  std::map<BranchID::value_type, BranchID::value_type>::const_iterator iter = droppedBranchIDToKeptBranchID_.find(branchID);
333  if(iter != droppedBranchIDToKeptBranchID_.end()) {
334  branchID = iter->second;
335  }
336  }
337  }
338  return branchIDLists_.get();
339  }
340  return origBranchIDLists_;
341  }
342 
345  return thinnedAssociationsHelper_.get();
346  }
347 
348  ModuleDescription const&
350  return moduleDescription_;
351  }
352 
353  bool
355  return productSelector_.selected(desc);
356  }
357 
358  void
361  desc.setUnknown();
362  descriptions.addDefault(desc);
363  }
364 
365  void
367  ProductSelectorRules::fillDescription(desc, "outputCommands");
369  }
370 
371  void
373  }
374 
375 
376  static const std::string kBaseType("OutputModule");
377  const std::string&
379  return kBaseType;
380  }
381 
382  void
383  OutputModuleBase::setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
384  bool anyProductProduced) {
386  description().moduleLabel(),
387  outputModulePathPositions,
388  anyProductProduced);
389  }
390  }
391 }
static const std::string kBaseType("EDAnalyzer")
bool selected(BranchDescription const &desc) const
static void fillDescription(ParameterSetDescription &desc, char const *parameterName)
ModuleDescription const & description() const
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 &)
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 *)
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)
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_
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)
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 *)
edm::propagate_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()
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()
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:374
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_
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_