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 
34 
35 
36 namespace edm {
37  namespace one {
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  branchParents_(),
56  branchChildren_() {
57 
58  hasNewlyDroppedBranch_.fill(false);
59 
61  process_name_ = tns->getProcessName();
62 
63  ParameterSet selectevents =
64  pset.getUntrackedParameterSet("SelectEvents", ParameterSet());
65 
66  selectevents.registerIt(); // Just in case this PSet is not registered
67 
68  selector_config_id_ = selectevents.id();
72  selectors_);
73  }
74 
78  }
79 
81  if(productSelector_.initialized()) return;
83 
84  // TODO: See if we can collapse keptProducts_ and productSelector_ into a
85  // single object. See the notes in the header for ProductSelector
86  // for more information.
87 
88  std::map<BranchID, BranchDescription const*> trueBranchIDToKeptBranchDesc;
89 
90  for(auto const& it : preg.productList()) {
91  BranchDescription const& desc = it.second;
92  if(desc.transient()) {
93  // if the class of the branch is marked transient, output nothing
94  } else if(!desc.present() && !desc.produced()) {
95  // else if the branch containing the product has been previously dropped,
96  // output nothing
97  } else if(selected(desc)) {
98  // else if the branch has been selected, put it in the list of selected branches.
99  if(desc.produced()) {
100  // First we check if an equivalent branch has already been selected due to an EDAlias.
101  // We only need the check for products produced in this process.
102  BranchID const& trueBranchID = desc.originalBranchID();
103  std::map<BranchID, BranchDescription const*>::const_iterator iter = trueBranchIDToKeptBranchDesc.find(trueBranchID);
104  if(iter != trueBranchIDToKeptBranchDesc.end()) {
105  throw edm::Exception(errors::Configuration, "Duplicate Output Selection")
106  << "Two (or more) equivalent branches have been selected for output.\n"
107  << "#1: " << BranchKey(desc) << "\n"
108  << "#2: " << BranchKey(*iter->second) << "\n"
109  << "Please drop at least one of them.\n";
110  }
111  trueBranchIDToKeptBranchDesc.insert(std::make_pair(trueBranchID, &desc));
112  }
113  switch (desc.branchType()) {
114  case InEvent:
115  {
117  InputTag{desc.moduleLabel(),
118  desc.productInstanceName(),
119  desc.processName()});
120  break;
121  }
122  case InLumi:
123  {
124  consumes<InLumi>(TypeToGet{desc.unwrappedTypeID(),PRODUCT_TYPE},
125  InputTag(desc.moduleLabel(),
126  desc.productInstanceName(),
127  desc.processName()));
128  break;
129  }
130  case InRun:
131  {
132  consumes<InRun>(TypeToGet{desc.unwrappedTypeID(),PRODUCT_TYPE},
133  InputTag(desc.moduleLabel(),
134  desc.productInstanceName(),
135  desc.processName()));
136  break;
137  }
138  default:
139  assert(false);
140  break;
141  }
142  // Now put it in the list of selected branches.
143  keptProducts_[desc.branchType()].push_back(&desc);
144  } else {
145  // otherwise, output nothing,
146  // and mark the fact that there is a newly dropped branch of this type.
147  hasNewlyDroppedBranch_[desc.branchType()] = true;
148  }
149  }
150  // Now fill in a mapping needed in the case that a branch was dropped while its EDAlias was kept.
151  for(auto const& it : preg.productList()) {
152  BranchDescription const& desc = it.second;
153  if(!desc.produced() || desc.isAlias()) continue;
154  BranchID const& branchID = desc.branchID();
155  std::map<BranchID, BranchDescription const*>::const_iterator iter = trueBranchIDToKeptBranchDesc.find(branchID);
156  if(iter != trueBranchIDToKeptBranchDesc.end()) {
157  // This branch, produced in this process, or an alias of it, was persisted.
158  BranchID const& keptBranchID = iter->second->branchID();
159  if(keptBranchID != branchID) {
160  // An EDAlias branch was persisted.
161  droppedBranchIDToKeptBranchID_.insert(std::make_pair(branchID.id(), keptBranchID.id()));
162  }
163  }
164  }
165  }
166 
168 
170  return SharedResourcesAcquirer{};
171  }
172 
175  this->beginJob();
176  }
177 
179  endJob();
180  }
181 
182 
184  ModuleCallingContext const* mcc) const {
185  return selectors_.getOneTriggerResults(ep, mcc); }
186 
187  bool
189  EventSetup const&,
190  ActivityRegistry* act,
191  ModuleCallingContext const* mcc) {
192 
193  {
194  std::lock_guard<std::mutex> guard(mutex_);
195  detail::TRBESSentry products_sentry(selectors_);
196  if(!wantAllEvents_) {
197  if(!selectors_.wantEvent(ep, mcc)) {
198  return true;
199  }
200  }
201  {
202  std::lock_guard<SharedResourcesAcquirer> guard(resourcesAcquirer_);
203  EventSignalsSentry sentry(act,mcc);
204  write(ep, mcc);
205  }
207  }
208  if(remainingEvents_ > 0) {
210  }
211  return true;
212  }
213 
214  bool
216  EventSetup const&,
217  ModuleCallingContext const* mcc) {
218  doBeginRun_(rp, mcc);
219  return true;
220  }
221 
222  bool
224  EventSetup const&,
225  ModuleCallingContext const* mcc) {
226  doEndRun_(rp, mcc);
227  return true;
228  }
229 
230  void
232  ModuleCallingContext const* mcc) {
233  writeRun(rp, mcc);
234  }
235 
236  bool
238  EventSetup const&,
239  ModuleCallingContext const* mcc) {
240  doBeginLuminosityBlock_(lbp, mcc);
241  return true;
242  }
243 
244  bool
246  EventSetup const&,
247  ModuleCallingContext const* mcc) {
248  doEndLuminosityBlock_(lbp, mcc);
249  return true;
250  }
251 
253  ModuleCallingContext const* mcc) {
254  writeLuminosityBlock(lbp, mcc);
255  }
256 
258  openFile(fb);
259  }
260 
263  }
264 
267  }
268 
269  void
272  }
273 
274  void
275  OutputModuleBase::doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren) {
276  postForkReacquireResources(iChildIndex, iNumberOfChildren);
277  }
278 
279  void
281 
282  void
283  OutputModuleBase::postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/) {}
284 
285 
287  if(!isFileOpen()) reallyOpenFile();
288  }
289 
291  if(isFileOpen()) {
293  reallyCloseFile();
294  branchParents_.clear();
296  }
297  }
298 
300  }
301 
302  BranchIDLists const*
304  if(!droppedBranchIDToKeptBranchID_.empty()) {
305  // Make a private copy of the BranchIDLists.
307  // Check for branches dropped while an EDAlias was kept.
308  for(BranchIDList& branchIDList : *branchIDLists_) {
309  for(BranchID::value_type& branchID : branchIDList) {
310  // 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.
311  std::map<BranchID::value_type, BranchID::value_type>::const_iterator iter = droppedBranchIDToKeptBranchID_.find(branchID);
312  if(iter != droppedBranchIDToKeptBranchID_.end()) {
313  branchID = iter->second;
314  }
315  }
316  }
317  return branchIDLists_.get();
318  }
319  return origBranchIDLists_;
320  }
321 
322  ModuleDescription const&
324  return moduleDescription_;
325  }
326 
327  bool
329  return productSelector_.selected(desc);
330  }
331 
332  void
335  desc.setUnknown();
336  descriptions.addDefault(desc);
337  }
338 
339  void
341  ProductSelectorRules::fillDescription(desc, "outputCommands");
343  }
344 
345  void
347  }
348 
349 
350  static const std::string kBaseType("OutputModule");
351  const std::string&
353  return kBaseType;
354  }
355 
356  void
357  OutputModuleBase::setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
358  bool anyProductProduced) {
360  description().moduleLabel(),
361  outputModulePathPositions,
362  anyProductProduced);
363  }
364 
365  void
367  for(EventPrincipal::const_iterator i = ep.begin(), iEnd = ep.end(); i != iEnd; ++i) {
368  if((*i) && (*i)->productProvenancePtr() != 0) {
369  BranchID const& bid = (*i)->branchDescription().branchID();
370  BranchParents::iterator it = branchParents_.find(bid);
371  if(it == branchParents_.end()) {
372  it = branchParents_.insert(std::make_pair(bid, std::set<ParentageID>())).first;
373  }
374  it->second.insert((*i)->productProvenancePtr()->parentageID());
376  }
377  }
378  }
379 
380  void
382  for(BranchParents::const_iterator i = branchParents_.begin(), iEnd = branchParents_.end();
383  i != iEnd; ++i) {
384  BranchID const& child = i->first;
385  std::set<ParentageID> const& eIds = i->second;
386  for(std::set<ParentageID>::const_iterator it = eIds.begin(), itEnd = eIds.end();
387  it != itEnd; ++it) {
388  Parentage entryDesc;
389  ParentageRegistry::instance()->getMapped(*it, entryDesc);
390  std::vector<BranchID> const& parents = entryDesc.parents();
391  for(std::vector<BranchID>::const_iterator j = parents.begin(), jEnd = parents.end();
392  j != jEnd; ++j) {
393  branchChildren_.insertChild(*j, child);
394  }
395  }
396  }
397  }
398 
399 
400  }
401 }
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
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:160
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)
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
void selectProducts(ProductRegistry const &preg)
#define nullptr
ProductSelectorRules productSelectorRules_
unsigned int id() const
Definition: BranchID.h:23
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 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()
static void fillDescription(ParameterSetDescription &desc)
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:159
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:58
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:369
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_
bool doEndLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *)