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 //
10 
11 // system include files
12 #include <cassert>
13 
14 // user include files
16 
34 
35 
36 namespace edm {
37  namespace global {
38 
39  // -------------------------------------------------------
41  maxEvents_(-1),
42  remainingEvents_(maxEvents_),
43  keptProducts_(),
44  hasNewlyDroppedBranch_(),
45  process_name_(),
46  productSelectorRules_(pset, "outputCommands", "OutputModule"),
47  productSelector_(),
48  moduleDescription_(),
49  wantAllEvents_(false),
50  selectors_(),
51  selector_config_id_(),
52  droppedBranchIDToKeptBranchID_(),
53  branchIDLists_(new BranchIDLists),
54  origBranchIDLists_(nullptr),
55  thinnedAssociationsHelper_(new ThinnedAssociationsHelper) {
56 
57  hasNewlyDroppedBranch_.fill(false);
58 
60  process_name_ = tns->getProcessName();
61 
63  pset.getUntrackedParameterSet("SelectEvents", ParameterSet());
64 
65  selectEvents_.registerIt(); // Just in case this PSet is not registered
66 
68 
69  //need to set wantAllEvents_ in constructor
70  // we will make the remaining selectors once we know how many streams
71  selectors_.resize(1);
75  selectors_[0]);
76 
77  }
78 
82  }
83 
85  ThinnedAssociationsHelper const& thinnedAssociationsHelper) {
86  if(productSelector_.initialized()) return;
88 
89  // TODO: See if we can collapse keptProducts_ and productSelector_ into a
90  // single object. See the notes in the header for ProductSelector
91  // for more information.
92 
93  std::map<BranchID, BranchDescription const*> trueBranchIDToKeptBranchDesc;
94  std::vector<BranchDescription const*> associationDescriptions;
95  std::set<BranchID> keptProductsInEvent;
96 
97  for(auto const& it : preg.productList()) {
98  BranchDescription const& desc = it.second;
99  if(desc.transient()) {
100  // if the class of the branch is marked transient, output nothing
101  } else if(!desc.present() && !desc.produced()) {
102  // else if the branch containing the product has been previously dropped,
103  // output nothing
104  } else if(desc.unwrappedType() == typeid(ThinnedAssociation)) {
105  associationDescriptions.push_back(&desc);
106  } else if(selected(desc)) {
107  keepThisBranch(desc, trueBranchIDToKeptBranchDesc, keptProductsInEvent);
108  } else {
109  // otherwise, output nothing,
110  // and mark the fact that there is a newly dropped branch of this type.
111  hasNewlyDroppedBranch_[desc.branchType()] = true;
112  }
113  }
114 
115  thinnedAssociationsHelper.selectAssociationProducts(associationDescriptions,
116  keptProductsInEvent,
118 
119  for(auto association : associationDescriptions) {
120  if(keepAssociation_[association->branchID()]) {
121  keepThisBranch(*association, trueBranchIDToKeptBranchDesc, keptProductsInEvent);
122  } else {
123  hasNewlyDroppedBranch_[association->branchType()] = true;
124  }
125  }
126 
127  // Now fill in a mapping needed in the case that a branch was dropped while its EDAlias was kept.
128  ProductSelector::fillDroppedToKept(preg, trueBranchIDToKeptBranchDesc, droppedBranchIDToKeptBranchID_);
129 
130  thinnedAssociationsHelper_->updateFromParentProcess(thinnedAssociationsHelper, keepAssociation_, droppedBranchIDToKeptBranchID_);
131  }
132 
134  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
135  std::set<BranchID>& keptProductsInEvent) {
136 
138  trueBranchIDToKeptBranchDesc);
139 
140  switch (desc.branchType()) {
141  case InEvent:
142  {
143  if(desc.produced()) {
144  keptProductsInEvent.insert(desc.originalBranchID());
145  } else {
146  keptProductsInEvent.insert(desc.branchID());
147  }
149  InputTag{desc.moduleLabel(),
150  desc.productInstanceName(),
151  desc.processName()});
152  break;
153  }
154  case InLumi:
155  {
156  consumes<InLumi>(TypeToGet{desc.unwrappedTypeID(),PRODUCT_TYPE},
157  InputTag(desc.moduleLabel(),
158  desc.productInstanceName(),
159  desc.processName()));
160  break;
161  }
162  case InRun:
163  {
164  consumes<InRun>(TypeToGet{desc.unwrappedTypeID(),PRODUCT_TYPE},
165  InputTag(desc.moduleLabel(),
166  desc.productInstanceName(),
167  desc.processName()));
168  break;
169  }
170  default:
171  assert(false);
172  break;
173  }
174  // Now put it in the list of selected branches.
175  keptProducts_[desc.branchType()].push_back(&desc);
176  }
177 
179 
181  auto nstreams = iPC.numberOfStreams();
182  selectors_.resize(nstreams);
183 
184  bool seenFirst = false;
185  for(auto& s : selectors_) {
186  if(seenFirst) {
190  s);
191  } else {
192  seenFirst = true;
193  }
194  }
195  }
196 
198  this->beginJob();
199  }
200 
202  endJob();
203  }
204 
206 
207  auto& s = selectors_[id.value()];
208  return wantAllEvents_ or s.wantEvent(ep,mcc);
209  }
210 
211  bool
213  EventSetup const&,
214  ActivityRegistry* act,
215  ModuleCallingContext const* mcc) {
216 
217  {
218  EventSignalsSentry sentry(act,mcc);
219  write(ep, mcc);
220  }
221 
222  auto remainingEvents = remainingEvents_.load();
223  bool keepTrying = remainingEvents > 0;
224  while(keepTrying) {
225  auto newValue = remainingEvents - 1;
226  keepTrying = !remainingEvents_.compare_exchange_strong(remainingEvents, newValue);
227  if(keepTrying) {
228  // the exchange failed because the value was changed by another thread.
229  // remainingEvents was changed to be the new value of remainingEvents_;
230  keepTrying = remainingEvents > 0;
231  }
232  }
233  return true;
234  }
235 
236  bool
238  EventSetup const&,
239  ModuleCallingContext const* mcc) {
240  doBeginRun_(rp, mcc);
241  return true;
242  }
243 
244  bool
246  EventSetup const&,
247  ModuleCallingContext const* mcc) {
248  doEndRun_(rp, mcc);
249  return true;
250  }
251 
252  void
254  ModuleCallingContext const* mcc) {
255  writeRun(rp, mcc);
256  }
257 
258  bool
260  EventSetup const&,
261  ModuleCallingContext const* mcc) {
262  doBeginLuminosityBlock_(lbp, mcc);
263  return true;
264  }
265 
266  bool
268  EventSetup const&,
269  ModuleCallingContext const* mcc) {
270  doEndLuminosityBlock_(lbp, mcc);
271  return true;
272  }
273 
275  ModuleCallingContext const* mcc) {
276  writeLuminosityBlock(lbp, mcc);
277  }
278 
280  openFile(fb);
281  }
282 
285  }
286 
289  }
290 
291  void
294  }
295 
296  void
297  OutputModuleBase::doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren) {
298  postForkReacquireResources(iChildIndex, iNumberOfChildren);
299  }
300 
301  void
303 
304  void
305  OutputModuleBase::postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/) {}
306 
307 
309  if(!isFileOpen()) reallyOpenFile();
310  }
311 
313  if(isFileOpen()) {
314  reallyCloseFile();
315  }
316  }
317 
319  }
320 
321  BranchIDLists const*
323  if(!droppedBranchIDToKeptBranchID_.empty()) {
324  // Make a private copy of the BranchIDLists.
326  // Check for branches dropped while an EDAlias was kept.
327  for(BranchIDList& branchIDList : *branchIDLists_) {
328  for(BranchID::value_type& branchID : branchIDList) {
329  // 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.
330  std::map<BranchID::value_type, BranchID::value_type>::const_iterator iter = droppedBranchIDToKeptBranchID_.find(branchID);
331  if(iter != droppedBranchIDToKeptBranchID_.end()) {
332  branchID = iter->second;
333  }
334  }
335  }
336  return branchIDLists_.get();
337  }
338  return origBranchIDLists_;
339  }
340 
343  return thinnedAssociationsHelper_.get();
344  }
345 
346  ModuleDescription const&
348  return moduleDescription_;
349  }
350 
351  bool
353  return productSelector_.selected(desc);
354  }
355 
356  void
359  desc.setUnknown();
360  descriptions.addDefault(desc);
361  }
362 
363  void
365  ProductSelectorRules::fillDescription(desc, "outputCommands");
367  }
368 
369  void
371  }
372 
373 
374  static const std::string kBaseType("OutputModule");
375  const std::string&
377  return kBaseType;
378  }
379 
380  void
381  OutputModuleBase::setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
382  bool anyProductProduced) {
384  description().moduleLabel(),
385  outputModulePathPositions,
386  anyProductProduced);
387  }
388  }
389 }
static const std::string kBaseType("EDAnalyzer")
virtual void writeLuminosityBlock(LuminosityBlockPrincipal const &, ModuleCallingContext const *)=0
bool selected(BranchDescription const &desc) const
virtual void postForkReacquireResources(unsigned int, unsigned int)
void doCloseFile()
Tell the OutputModule that is must end the current file.
void keepThisBranch(BranchDescription const &desc, std::map< BranchID, BranchDescription const * > &trueBranchIDToKeptBranchDesc, std::set< BranchID > &keptProductsInEvent)
ModuleDescription const & description() const
BranchIDLists const * origBranchIDLists_
static void fillDescription(ParameterSetDescription &desc, char const *parameterName)
void doRespondToOpenInputFile(FileBlock const &fb)
void selectProducts(ProductRegistry const &preg, ThinnedAssociationsHelper const &)
BranchType const & branchType() const
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
void doWriteLuminosityBlock(LuminosityBlockPrincipal const &lbp, ModuleCallingContext const *)
static void fillDroppedToKept(ProductRegistry const &preg, std::map< BranchID, BranchDescription const * > const &trueBranchIDToKeptBranchDesc, std::map< BranchID::value_type, BranchID::value_type > &droppedBranchIDToKeptBranchID_)
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
virtual bool isFileOpen() const
OutputModuleBase(ParameterSet const &pset)
ParameterSetID id() const
ParameterSet const & getParameterSet(ParameterSetID const &id)
assert(m_qm.get())
std::map< BranchID::value_type, BranchID::value_type > droppedBranchIDToKeptBranchID_
std::vector< detail::TriggerResultsBasedEventSelector > selectors_
virtual void openFile(FileBlock const &)
virtual void doRespondToOpenInputFile_(FileBlock const &)
std::string const & processName() const
ParameterSet getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
SelectedProductsForBranchType keptProducts_
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
BranchIDLists const * branchIDLists()
#define nullptr
bool doEvent(EventPrincipal const &ep, EventSetup const &c, ActivityRegistry *, ModuleCallingContext const *)
BranchIDLists const * branchIDLists_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
ThinnedAssociationsHelper const * thinnedAssociationsHelper() const
ModuleDescription moduleDescription_
ProductList const & productList() const
void selectAssociationProducts(std::vector< BranchDescription const * > const &associationDescriptions, std::set< BranchID > const &keptProductsInEvent, std::map< BranchID, bool > &keepAssociation) const
edm::propagate_const< std::unique_ptr< ThinnedAssociationsHelper > > thinnedAssociationsHelper_
bool prePrefetchSelection(StreamID id, EventPrincipal const &, ModuleCallingContext const *)
void addDefault(ParameterSetDescription const &psetDescription)
virtual void doEndRun_(RunPrincipal const &, ModuleCallingContext const *)
void setEventSelectionInfo(std::map< std::string, std::vector< std::pair< std::string, int > > > const &outputModulePathPositions, bool anyProductProduced)
std::string const & moduleLabel() const
unsigned int value_type
Definition: BranchID.h:16
std::string const & productInstanceName() const
void doPreallocate(PreallocationConfiguration const &)
std::map< BranchID, bool > keepAssociation_
bool selected(BranchDescription const &desc) const
TypeID unwrappedTypeID() const
edm::propagate_const< std::unique_ptr< BranchIDLists > > branchIDLists_
static void prevalidate(ConfigurationDescriptions &)
std::vector< BranchDescription const * > allBranchDescriptions() const
static const std::string & baseType()
BranchID const & branchID() const
TypeWithDict const & unwrappedType() const
void configure(OutputModuleDescription const &desc)
static void fillDescription(ParameterSetDescription &desc)
static void fillDescription(ParameterSetDescription &desc)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
virtual void doBeginRun_(RunPrincipal const &, ModuleCallingContext const *)
ProductSelectorRules productSelectorRules_
void doRespondToCloseInputFile(FileBlock const &fb)
std::atomic< int > remainingEvents_
virtual void write(EventPrincipal const &e, ModuleCallingContext const *)=0
bool doBeginRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *)
bool doEndRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *)
std::vector< BranchID::value_type > BranchIDList
Definition: BranchIDList.h:18
bool initialized() const
std::vector< std::string > const & getAllTriggerNames()
void initialize(ProductSelectorRules const &rules, std::vector< BranchDescription const * > const &branchDescriptions)
void doWriteRun(RunPrincipal const &rp, ModuleCallingContext const *)
bool doEndLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *)
BranchID const & originalBranchID() const
volatile std::atomic< bool > shutdown_flag false
virtual void doRespondToCloseInputFile_(FileBlock 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)
preg
Definition: Schedule.cc:374
bool doBeginLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *)
void doOpenFile(FileBlock const &fb)
bool configureEventSelector(edm::ParameterSet const &iPSet, std::string const &iProcessName, std::vector< std::string > const &iAllTriggerNames, edm::detail::TriggerResultsBasedEventSelector &oSelector)
ParameterSet const & registerIt()
virtual void doBeginLuminosityBlock_(LuminosityBlockPrincipal const &, ModuleCallingContext const *)
void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
virtual void writeRun(RunPrincipal const &, ModuleCallingContext const *)=0
static void checkForDuplicateKeptBranch(BranchDescription const &desc, std::map< BranchID, BranchDescription const * > &trueBranchIDToKeptBranchDesc)
virtual void doEndLuminosityBlock_(LuminosityBlockPrincipal const &, ModuleCallingContext const *)