CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OutputModule.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 
3 ----------------------------------------------------------------------*/
4 
13 
19 
22 
23 namespace edm {
24  // This grotesque little function exists just to allow calling of
25  // ConstProductRegistry::allBranchDescriptions in the context of
26  // OutputModule's initialization list, rather than in the body of
27  // the constructor.
28 
29  std::vector<BranchDescription const*>
32  return reg->allBranchDescriptions();
33  }
34 
35  std::vector<std::string> const& getAllTriggerNames() {
37  return tns->getTrigPaths();
38  }
39 }
40 
41 
42 namespace {
43  //--------------------------------------------------------
44  // Remove whitespace (spaces and tabs) from a std::string.
45  void remove_whitespace(std::string& s) {
46  s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
47  s.erase(std::remove(s.begin(), s.end(), '\t'), s.end());
48  }
49 
50  void test_remove_whitespace() {
51  std::string a("noblanks");
52  std::string b("\t no blanks \t");
53 
54  remove_whitespace(b);
55  assert(a == b);
56  }
57 
58  //--------------------------------------------------------
59  // Given a path-spec (std::string of the form "a:b", where the ":b" is
60  // optional), return a parsed_path_spec_t containing "a" and "b".
61 
62  typedef std::pair<std::string, std::string> parsed_path_spec_t;
63  void parse_path_spec(std::string const& path_spec,
64  parsed_path_spec_t& output) {
65  std::string trimmed_path_spec(path_spec);
66  remove_whitespace(trimmed_path_spec);
67 
68  std::string::size_type colon = trimmed_path_spec.find(":");
69  if (colon == std::string::npos) {
70  output.first = trimmed_path_spec;
71  } else {
72  output.first = trimmed_path_spec.substr(0, colon);
73  output.second = trimmed_path_spec.substr(colon + 1,
74  trimmed_path_spec.size());
75  }
76  }
77 
78  void test_parse_path_spec() {
79  std::vector<std::string> paths;
80  paths.push_back("a:p1");
81  paths.push_back("b:p2");
82  paths.push_back(" c");
83  paths.push_back("ddd\t:p3");
84  paths.push_back("eee: p4 ");
85 
86  std::vector<parsed_path_spec_t> parsed(paths.size());
87  for (size_t i = 0; i < paths.size(); ++i)
88  parse_path_spec(paths[i], parsed[i]);
89 
90  assert(parsed[0].first == "a");
91  assert(parsed[0].second == "p1");
92  assert(parsed[1].first == "b");
93  assert(parsed[1].second == "p2");
94  assert(parsed[2].first == "c");
95  assert(parsed[2].second == "");
96  assert(parsed[3].first == "ddd");
97  assert(parsed[3].second == "p3");
98  assert(parsed[4].first == "eee");
99  assert(parsed[4].second == "p4");
100  }
101 }
102 
103 namespace edm {
104  namespace test {
106  test_remove_whitespace();
107  test_parse_path_spec();
108  }
109  }
110 
111 
112  // -------------------------------------------------------
114  maxEvents_(-1),
115  remainingEvents_(maxEvents_),
116  keptProducts_(),
117  hasNewlyDroppedBranch_(),
118  process_name_(),
119  groupSelectorRules_(pset, "outputCommands", "OutputModule"),
120  groupSelector_(),
121  moduleDescription_(),
122  current_context_(0),
123  prodsValid_(false),
124  wantAllEvents_(false),
125  selectors_(),
126  selector_config_id_(),
127  branchParents_(),
128  branchChildren_() {
129 
130  hasNewlyDroppedBranch_.assign(false);
131 
133  process_name_ = tns->getProcessName();
134 
135  ParameterSet selectevents =
136  pset.getUntrackedParameter("SelectEvents", ParameterSet());
137 
138  selector_config_id_ = selectevents.id();
139  // If selectevents is an emtpy ParameterSet, then we are to write
140  // all events, or one which contains a vstrig 'SelectEvents' that
141  // is empty, we are to write all events. We have no need for any
142  // EventSelectors.
143  if (selectevents.empty()) {
144  wantAllEvents_ = true;
146  return;
147  }
148 
149  std::vector<std::string> path_specs =
150  selectevents.getParameter<std::vector<std::string> >("SelectEvents");
151 
152  if (path_specs.empty()) {
153  wantAllEvents_ = true;
155  return;
156  }
157 
158  // If we get here, we have the possibility of having to deal with
159  // path_specs that look at more than one process.
160  std::vector<parsed_path_spec_t> parsed_paths(path_specs.size());
161  for (size_t i = 0; i < path_specs.size(); ++i) {
162  parse_path_spec(path_specs[i], parsed_paths[i]);
163  }
165  }
166 
169  }
170 
172  if (groupSelector_.initialized()) return;
175 
176  // TODO: See if we can collapse keptProducts_ and groupSelector_ into a
177  // single object. See the notes in the header for GroupSelector
178  // for more information.
179 
180  ProductRegistry::ProductList::const_iterator it =
181  reg->productList().begin();
182  ProductRegistry::ProductList::const_iterator end =
183  reg->productList().end();
184 
185  for (; it != end; ++it) {
186  BranchDescription const& desc = it->second;
187  if(desc.transient()) {
188  // if the class of the branch is marked transient, output nothing
189  } else if(!desc.present() && !desc.produced()) {
190  // else if the branch containing the product has been previously dropped,
191  // output nothing
192  } else if (selected(desc)) {
193  // else if the branch has been selected, put it in the list of selected branches
194  keptProducts_[desc.branchType()].push_back(&desc);
195  } else {
196  // otherwise, output nothing,
197  // and mark the fact that there is a newly dropped branch of this type.
198  hasNewlyDroppedBranch_[desc.branchType()] = true;
199  }
200  }
201  }
202 
204 
206  selectProducts();
207  this->beginJob();
208  }
209 
211  endJob();
212  }
213 
214 
216  return selectors_.getOneTriggerResults(ev);
217  }
218 
220  // This is bad, because we're returning handles into an Event that
221  // is destructed before the return. It might not fail, because the
222  // actual EventPrincipal is not destroyed, but it still needs to
223  // be cleaned up.
224  Event ev(const_cast<EventPrincipal&>(ep),
226  return getTriggerResults(ev);
227  }
228 
229  namespace {
230  class PVSentry {
231  public:
232  PVSentry (detail::CachedProducts& prods, bool& valid) : p(prods), v(valid) {}
233  ~PVSentry() {
234  p.clear();
235  v = false;
236  }
237  private:
238  detail::CachedProducts& p;
239  bool& v;
240 
241  PVSentry(PVSentry const&); // not implemented
242  PVSentry& operator=(PVSentry const&); // not implemented
243  };
244  }
245 
246  bool
248  EventSetup const& c,
249  CurrentProcessingContext const* cpc) {
250  detail::CPCSentry sentry(current_context_, cpc);
251  PVSentry products_sentry(selectors_, prodsValid_);
252 
253  FDEBUG(2) << "writeEvent called\n";
254 
255  // This ugly little bit is here to prevent making the Event
256  // if we don't need it.
257  if (!wantAllEvents_) {
258  // use module description and const_cast unless interface to
259  // event is changed to just take a const EventPrincipal
260  Event e(const_cast<EventPrincipal&>(ep), moduleDescription_);
261  if (!selectors_.wantEvent(e)) {
262  return true;
263  }
264  }
265  write(ep);
267  if (remainingEvents_ > 0) {
269  }
270  return true;
271  }
272 
273 // bool OutputModule::wantEvent(Event const& ev)
274 // {
275 // getTriggerResults(ev);
276 // bool eventAccepted = false;
277 
278 // typedef std::vector<NamedEventSelector>::const_iterator iter;
279 // for (iter i = selectResult_.begin(), e = selectResult_.end();
280 // !eventAccepted && i != e; ++i)
281 // {
282 // eventAccepted = i->acceptEvent(*prods_);
283 // }
284 
285 // FDEBUG(2) << "Accept event " << ep.id() << " " << eventAccepted << "\n";
286 // return eventAccepted;
287 // }
288 
289  bool
291  EventSetup const& c,
292  CurrentProcessingContext const* cpc) {
293  detail::CPCSentry sentry(current_context_, cpc);
294  FDEBUG(2) << "beginRun called\n";
295  beginRun(rp);
296  return true;
297  }
298 
299  bool
301  EventSetup const& c,
302  CurrentProcessingContext const* cpc) {
303  detail::CPCSentry sentry(current_context_, cpc);
304  FDEBUG(2) << "endRun called\n";
305  endRun(rp);
306  return true;
307  }
308 
309  void
311  FDEBUG(2) << "writeRun called\n";
312  writeRun(rp);
313  }
314 
315  bool
317  EventSetup const& c,
318  CurrentProcessingContext const* cpc) {
319  detail::CPCSentry sentry(current_context_, cpc);
320  FDEBUG(2) << "beginLuminosityBlock called\n";
322  return true;
323  }
324 
325  bool
327  EventSetup const& c,
328  CurrentProcessingContext const* cpc) {
329  detail::CPCSentry sentry(current_context_, cpc);
330  FDEBUG(2) << "endLuminosityBlock called\n";
331  endLuminosityBlock(lbp);
332  return true;
333  }
334 
336  FDEBUG(2) << "writeLuminosityBlock called\n";
338  }
339 
341  openFile(fb);
342  }
343 
346  }
347 
350  }
351 
354  }
355 
358  }
359 
360  void
363  }
364 
365  void
366  OutputModule::doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren) {
367  postForkReacquireResources(iChildIndex, iNumberOfChildren);
368  }
369 
371  if (!isFileOpen()) doOpenFile();
372  }
373 
375  if (isFileOpen()) reallyCloseFile();
376  }
377 
380  startEndFile();
392  finishEndFile();
393  branchParents_.clear();
395  }
396 
399  return current_context_;
400  }
401 
402  ModuleDescription const&
404  return moduleDescription_;
405  }
406 
407  bool
409  return groupSelector_.selected(desc);
410  }
411 
412  void
415  desc.setUnknown();
416  descriptions.addDefault(desc);
417  }
418 
419  void
421  GroupSelectorRules::fillDescription(desc, "outputCommands");
423  }
424 
425  static const std::string kBaseType("OutputModule");
426  const std::string&
428  return kBaseType;
429  }
430 
431  void
433  for (EventPrincipal::const_iterator i = ep.begin(), iEnd = ep.end(); i != iEnd; ++i) {
434  if ((*i) && (*i)->productProvenancePtr() != 0) {
435  BranchID const& bid = (*i)->branchDescription().branchID();
436  BranchParents::iterator it = branchParents_.find(bid);
437  if (it == branchParents_.end()) {
438  it = branchParents_.insert(std::make_pair(bid, std::set<ParentageID>())).first;
439  }
440  it->second.insert((*i)->productProvenancePtr()->parentageID());
442  }
443  }
444  }
445 
446  void
448  for (BranchParents::const_iterator i = branchParents_.begin(), iEnd = branchParents_.end();
449  i != iEnd; ++i) {
450  BranchID const& child = i->first;
451  std::set<ParentageID> const& eIds = i->second;
452  for (std::set<ParentageID>::const_iterator it = eIds.begin(), itEnd = eIds.end();
453  it != itEnd; ++it) {
454  Parentage entryDesc;
455  ParentageRegistry::instance()->getMapped(*it, entryDesc);
456  std::vector<BranchID> const& parents = entryDesc.parents();
457  for (std::vector<BranchID>::const_iterator j = parents.begin(), jEnd = parents.end();
458  j != jEnd; ++j) {
459  branchChildren_.insertChild(*j, child);
460  }
461  }
462  }
463  }
464 }
virtual void respondToOpenInputFile(FileBlock const &fb)
Definition: OutputModule.h:187
nocap nocap const skelname & operator=(const skelname &)
void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
T getParameter(std::string const &) const
virtual void doOpenFile()
Definition: OutputModule.h:196
bool empty() const
Definition: ParameterSet.h:212
virtual void writeProductDependencies()
Definition: OutputModule.h:220
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< BranchDescription const * > getAllBranchDescriptions()
Definition: OutputModule.cc:30
bool initialized() const
Definition: GroupSelector.h:34
TPRegexp parents
Definition: eve_filter.cc:24
BranchType const & branchType() const
virtual void endLuminosityBlock(LuminosityBlockPrincipal const &lb)
Definition: OutputModule.h:184
ModuleDescription moduleDescription_
Definition: OutputModule.h:112
virtual void writeFileFormatVersion()
Definition: OutputModule.h:211
bool doEndLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, CurrentProcessingContext const *cpc)
const_iterator end() const
Definition: Principal.h:131
ModuleDescription const * moduleDescription() const
handle_t getOneTriggerResults(Event const &e)
ParameterSetID id() const
CurrentProcessingContext const * current_context_
Definition: OutputModule.h:115
detail::CachedProducts selectors_
Definition: OutputModule.h:122
virtual void writeIndexIntoFile()
Definition: OutputModule.h:213
bool & produced() const
virtual void beginLuminosityBlock(LuminosityBlockPrincipal const &lb)
Definition: OutputModule.h:183
boost::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
Definition: OutputModule.h:107
void insertEmpty(BranchID parent)
bool getMapped(key_type const &k, value_type &result) const
void insertChild(BranchID parent, BranchID child)
static const std::string & baseType()
virtual void respondToOpenOutputFiles(FileBlock const &fb)
Definition: OutputModule.h:189
void updateBranchParents(EventPrincipal const &ep)
virtual void finishEndFile()
Definition: OutputModule.h:222
static void fillDescription(ParameterSetDescription &desc, char const *parameterName)
bool selected(BranchDescription const &desc) const
#define FDEBUG(lev)
Definition: DebugMacros.h:18
virtual void beginRun(RunPrincipal const &r)
Definition: OutputModule.h:180
virtual void writeParentageRegistry()
Definition: OutputModule.h:218
uint16_t size_type
void doCloseFile()
Tell the OutputModule that is must end the current file.
std::vector< BranchID > const & parents() const
Definition: Parentage.h:39
U second(std::pair< T, U > const &p)
void run_all_output_module_tests()
std::string process_name_
Definition: OutputModule.h:109
virtual void writeProcessConfigurationRegistry()
Definition: OutputModule.h:214
void addDefault(ParameterSetDescription const &psetDescription)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
bool doEvent(EventPrincipal const &ep, EventSetup const &c, CurrentProcessingContext const *cpc)
SelectionsArray keptProducts_
Definition: OutputModule.h:106
void doWriteLuminosityBlock(LuminosityBlockPrincipal const &lbp)
void doPreForkReleaseResources()
int j
Definition: DBlmapReader.cc:9
virtual void writeLuminosityBlock(LuminosityBlockPrincipal const &lb)=0
GroupSelectorRules groupSelectorRules_
Definition: OutputModule.h:110
GroupSelector groupSelector_
Definition: OutputModule.h:111
void doRespondToCloseOutputFiles(FileBlock const &fb)
tuple pset
Definition: CrabTask.py:85
static void fillDescription(ParameterSetDescription &desc)
#define end
Definition: vmac.h:38
virtual void writeRun(RunPrincipal const &r)=0
bool first
Definition: L1TdeRCT.cc:79
virtual void write(EventPrincipal const &e)=0
virtual bool isFileOpen() const
Definition: OutputModule.h:194
bool & transient() const
virtual void respondToCloseOutputFiles(FileBlock const &fb)
Definition: OutputModule.h:190
void doRespondToCloseInputFile(FileBlock const &fb)
virtual void writeFileIdentifier()
Definition: OutputModule.h:212
void fillDependencyGraph()
void setup(std::vector< parsed_path_spec_t > const &path_specs, std::vector< std::string > const &triggernames, const std::string &process_name)
CurrentProcessingContext const * currentContext() const
const_iterator begin() const
Definition: Principal.h:130
double b
Definition: hdecay.h:120
void doWriteRun(RunPrincipal const &rp)
static void fillDescription(ParameterSetDescription &desc)
virtual void respondToCloseInputFile(FileBlock const &fb)
Definition: OutputModule.h:188
static const std::string kBaseType("EDAnalyzer")
bool doBeginLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, CurrentProcessingContext const *cpc)
boost::filter_iterator< FilledGroupPtr, GroupCollection::const_iterator > const_iterator
Definition: Principal.h:48
std::vector< std::string > const & getAllTriggerNames()
Definition: OutputModule.cc:35
BranchChildren branchChildren_
Definition: OutputModule.h:130
bool selected(BranchDescription const &desc) const
Trig getTriggerResults(Event const &ep) const
virtual void writeParameterSetRegistry()
Definition: OutputModule.h:216
double a
Definition: hdecay.h:121
Strings const & getTrigPaths() const
virtual void endJob()
Definition: OutputModule.h:179
virtual void beginJob()
Definition: OutputModule.h:178
virtual void endRun(RunPrincipal const &r)
Definition: OutputModule.h:181
static ThreadSafeRegistry * instance()
void doRespondToOpenInputFile(FileBlock const &fb)
string s
Definition: asciidump.py:422
virtual ~OutputModule()
bool doEndRun(RunPrincipal const &rp, EventSetup const &c, CurrentProcessingContext const *cpc)
void configure(OutputModuleDescription const &desc)
std::vector< BranchDescription const * > allBranchDescriptions() const
void setupDefault(std::vector< std::string > const &triggernames)
virtual void openFile(FileBlock const &fb)
Definition: OutputModule.h:186
bool doBeginRun(RunPrincipal const &rp, EventSetup const &c, CurrentProcessingContext const *cpc)
void initialize(GroupSelectorRules const &rules, std::vector< BranchDescription const * > const &branchDescriptions)
virtual void startEndFile()
Definition: OutputModule.h:210
virtual void writeBranchMapper()
Definition: OutputModule.h:221
ModuleDescription const & description() const
virtual void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
Definition: OutputModule.h:192
BranchParents branchParents_
Definition: OutputModule.h:128
mathSSE::Vec4< T > v
virtual void preForkReleaseResources()
Definition: OutputModule.h:191
OutputModule(ParameterSet const &pset)
bool wantEvent(Event const &e)
virtual void writeBranchIDListRegistry()
Definition: OutputModule.h:217
virtual void writeProcessHistoryRegistry()
Definition: OutputModule.h:215
void doRespondToOpenOutputFiles(FileBlock const &fb)
virtual void writeProductDescriptionRegistry()
Definition: OutputModule.h:219
ParameterSetID selector_config_id_
Definition: OutputModule.h:125