CMS 3D CMS Logo

WorkerT.cc
Go to the documentation of this file.
3 
16 
20 
25 
26 #include <type_traits>
27 
28 namespace edm{
29  namespace workerimpl {
30  template<typename T>
32  static bool constexpr value = false;
33  };
34 
35  template<>
37  static bool constexpr value = true;
38  };
39 
40  template<>
42  static bool constexpr value = true;
43  };
44 
45  template<>
47  static bool constexpr value = true;
48  };
49 
50  template<>
52  static bool constexpr value = true;
53  };
54 
55  template<>
57  static bool constexpr value = true;
58  };
59 
60  template<>
62  static bool constexpr value = true;
63  };
64 
65  template<>
67  static bool constexpr value = true;
68  };
69 
70  template<>
72  static bool constexpr value = true;
73  };
74 
75  template<>
77  static bool constexpr value = true;
78  };
79 
80  struct DoNothing {
81  template< typename... T>
82  inline void operator()(const T&...) {}
83  };
84 
85  template<typename T>
86  struct DoBeginStream {
87  inline void operator()(WorkerT<T>* iWorker, StreamID id) {
88  iWorker->callWorkerBeginStream(0,id);
89  }
90  };
91 
92  template<typename T>
93  struct DoEndStream {
94  inline void operator()(WorkerT<T>* iWorker, StreamID id) {
95  iWorker->callWorkerEndStream(0,id);
96  }
97  };
98 
99  template<typename T, typename P>
101  inline void operator() (WorkerT<T>* iWorker, StreamID id, P const& rp,
102  EventSetup const& c,
103  ModuleCallingContext const* mcc) {
104  iWorker->callWorkerStreamBegin(0,id,rp,c, mcc);
105  }
106  };
107 
108  template<typename T, typename P>
110  inline void operator() (WorkerT<T>* iWorker, StreamID id, P const& rp,
111  EventSetup const& c,
112  ModuleCallingContext const* mcc) {
113  iWorker->callWorkerStreamEnd(0,id,rp,c, mcc);
114  }
115  };
116  }
117 
118  template<typename T>
119  inline
120  WorkerT<T>::WorkerT(std::shared_ptr<T> ed, ModuleDescription const& md, ExceptionToActionTable const* actions) :
121  Worker(md, actions),
122  module_(ed) {
123  assert(module_ != nullptr);
124  }
125 
126  template<typename T>
128  }
129 
130 
131  template<typename T>
133  return module_->wantsGlobalRuns();
134  }
135 
136  template<typename T>
138  return module_->wantsGlobalLuminosityBlocks();
139  }
140 
141  template<typename T>
143  return module_->wantsStreamRuns();
144  }
145 
146  template<typename T>
148  return module_->wantsStreamLuminosityBlocks();
149  }
150 
151  template<typename T>
153  return nullptr;
154  }
155  template<typename T>
157  return nullptr;
158  }
159  template<>
161  return module_->globalRunsQueue();
162  }
163  template<>
165  return module_->globalLuminosityBlocksQueue();
166  }
167  template<>
169  return module_->globalRunsQueue();
170  }
171  template<>
173  return module_->globalLuminosityBlocksQueue();
174  }
175  template<>
177  return module_->globalRunsQueue();
178  }
179  template<>
181  return module_->globalLuminosityBlocksQueue();
182  }
183  template<>
185  return module_->globalRunsQueue();
186  }
187  template<>
189  return module_->globalLuminosityBlocksQueue();
190  }
191  //one
192  template<>
194  return module_->globalRunsQueue();
195  }
196  template<>
198  return module_->globalLuminosityBlocksQueue();
199  }
200  template<>
202  return module_->globalRunsQueue();
203  }
204  template<>
206  return module_->globalLuminosityBlocksQueue();
207  }
208  template<>
210  return module_->globalRunsQueue();
211  }
212  template<>
214  return module_->globalLuminosityBlocksQueue();
215  }
216  template<>
218  return module_->globalRunsQueue();
219  }
220  template<>
222  return module_->globalLuminosityBlocksQueue();
223  }
224 
225 
226  template<typename T>
227  inline
228  bool
230  std::shared_ptr<Worker> sentry(this,[&ep](Worker* obj) {obj->postDoEvent(ep);});
231  return module_->doEvent(ep, c, activityRegistry(), mcc);
232  }
233 
234  template<typename T>
235  inline
236  void
238  ModuleCallingContext const*,
240  }
241 
242  template<>
243  inline
244  void
246  ModuleCallingContext const* mcc,
247  WaitingTaskWithArenaHolder& holder) {
248  module_->doAcquire(ep, c, activityRegistry(), mcc, holder);
249  }
250 
251  template<>
252  inline
253  void
255  ModuleCallingContext const* mcc,
256  WaitingTaskWithArenaHolder& holder) {
257  module_->doAcquire(ep, c, activityRegistry(), mcc, holder);
258  }
259 
260  template<>
261  inline
262  void
264  ModuleCallingContext const* mcc,
265  WaitingTaskWithArenaHolder& holder) {
266  module_->doAcquire(ep, c, activityRegistry(), mcc, holder);
267  }
268 
269  template<>
270  inline
271  void
273  ModuleCallingContext const* mcc,
274  WaitingTaskWithArenaHolder& holder) {
275  module_->doAcquire(ep, c, activityRegistry(), mcc, holder);
276  }
277 
278  template<typename T>
279  inline
280  bool
281  WorkerT<T>::implNeedToRunSelection() const { return false;}
282 
283  template<typename T>
284  inline
285  bool
287  EventPrincipal const& ep,
288  ModuleCallingContext const* mcc) {
289  return true;
290  }
291  template<typename T>
292  inline
293  void
294  WorkerT<T>::itemsToGetForSelection(std::vector<ProductResolverIndexAndSkipBit>&) const {}
295 
296 
297  template<>
298  inline
299  bool
301  template<>
302  inline
303  bool
305  EventPrincipal const& ep,
306  ModuleCallingContext const* mcc) {
307  return module_->prePrefetchSelection(id,ep,mcc);
308  }
309  template<>
310  inline
311  void
312  WorkerT<OutputModule>::itemsToGetForSelection(std::vector<ProductResolverIndexAndSkipBit>& iItems) const {
313  iItems = module_->productsUsedBySelection();
314  }
315 
316  template<>
317  inline
318  bool
320 
321  template<>
322  inline
323  bool
325  EventPrincipal const& ep,
326  ModuleCallingContext const* mcc) {
327  return module_->prePrefetchSelection(id,ep,mcc);
328  }
329  template<>
330  inline
331  void
332  WorkerT<edm::one::OutputModuleBase>::itemsToGetForSelection(std::vector<ProductResolverIndexAndSkipBit>& iItems) const {
333  iItems = module_->productsUsedBySelection();
334  }
335 
336  template<>
337  inline
338  bool
340  template<>
341  inline
342  bool
344  EventPrincipal const& ep,
345  ModuleCallingContext const* mcc) {
346  return module_->prePrefetchSelection(id,ep,mcc);
347  }
348  template<>
349  inline
350  void
351  WorkerT<edm::global::OutputModuleBase>::itemsToGetForSelection(std::vector<ProductResolverIndexAndSkipBit>& iItems) const {
352  iItems = module_->productsUsedBySelection();
353  }
354 
355  template<>
356  inline
357  bool
359  template<>
360  inline
361  bool
363  EventPrincipal const& ep,
364  ModuleCallingContext const* mcc) {
365  return module_->prePrefetchSelection(id,ep,mcc);
366  }
367  template<>
368  inline
369  void
370  WorkerT<edm::limited::OutputModuleBase>::itemsToGetForSelection(std::vector<ProductResolverIndexAndSkipBit>& iItems) const {
371  iItems = module_->productsUsedBySelection();
372  }
373 
374  template<typename T>
375  inline
376  bool
378  module_->doBeginRun(rp, c, mcc);
379  return true;
380  }
381 
382  template<typename T>
383  template<typename D>
384  void
386  EventSetup const& c,
387  ModuleCallingContext const* mcc) {
388  module_->doStreamBeginRun(id, rp, c, mcc);
389  }
390 
391  template<typename T>
392  template<typename D>
393  void
395  EventSetup const& c,
396  ModuleCallingContext const* mcc) {
397  module_->doStreamEndRun(id, rp, c, mcc);
398  }
399 
400 
401  template<typename T>
402  inline
403  bool
405  ModuleCallingContext const* mcc) {
408  workerimpl::DoNothing> might_call;
409  might_call(this,id,rp,c, mcc);
410  return true;
411  }
412 
413  template<typename T>
414  inline
415  bool
417  ModuleCallingContext const* mcc) {
420  workerimpl::DoNothing> might_call;
421  might_call(this,id,rp,c, mcc);
422  return true;
423  }
424 
425  template<typename T>
426  inline
427  bool
429  ModuleCallingContext const* mcc) {
430  module_->doEndRun(rp, c, mcc);
431  return true;
432  }
433 
434  template<typename T>
435  inline
436  bool
438  ModuleCallingContext const* mcc) {
439  module_->doBeginLuminosityBlock(lbp, c, mcc);
440  return true;
441  }
442 
443  template<typename T>
444  template<typename D>
445  void
447  EventSetup const& c,
448  ModuleCallingContext const* mcc) {
449  module_->doStreamBeginLuminosityBlock(id, rp, c, mcc);
450  }
451 
452  template<typename T>
453  template<typename D>
454  void
456  EventSetup const& c,
457  ModuleCallingContext const* mcc) {
458  module_->doStreamEndLuminosityBlock(id, rp, c, mcc);
459  }
460 
461 
462  template<typename T>
463  inline
464  bool
466  ModuleCallingContext const* mcc) {
469  workerimpl::DoNothing> might_call;
470  might_call(this,id,lbp,c, mcc);
471  return true;
472  }
473 
474  template<typename T>
475  inline
476  bool
478  ModuleCallingContext const* mcc) {
481  workerimpl::DoNothing> might_call;
482  might_call(this,id,lbp,c,mcc);
483 
484  return true;
485  }
486 
487  template<typename T>
488  inline
489  bool
491  ModuleCallingContext const* mcc) {
492  module_->doEndLuminosityBlock(lbp, c, mcc);
493  return true;
494  }
495 
496  template<typename T>
497  inline
500  return module_->workerType();
501  }
502 
503  template<typename T>
504  inline
505  void
507  module_->doBeginJob();
508  }
509 
510  template<typename T>
511  inline
512  void
514  module_->doEndJob();
515  }
516 
517  template<typename T>
518  template<typename D>
520  module_->doBeginStream(id);
521  }
522 
523  template<typename T>
524  inline
525  void
529  workerimpl::DoNothing> might_call;
530  might_call(this,id);
531  }
532 
533  template<typename T>
534  template<typename D>
536  module_->doEndStream(id);
537  }
538 
539  template<typename T>
540  inline
541  void
545  workerimpl::DoNothing> might_call;
546  might_call(this,id);
547  }
548 
549  template<typename T>
550  inline
551  void
553  module_->doRespondToOpenInputFile(fb);
554  }
555 
556  template<typename T>
557  inline
558  void
560  module_->doRespondToCloseInputFile(fb);
561  }
562 
563  template<typename T>
564  inline
565  void
568  module_->doRegisterThinnedAssociations(registry, helper);
569  }
570 
571  template<typename T>
572  inline
574  return Worker::TaskQueueAdaptor{};
575  }
577  return &(module_->sharedResourcesAcquirer().serialQueueChain());
578  }
580  return &(module_->sharedResourcesAcquirer().serialQueueChain());
581  }
583  return &(module_->sharedResourcesAcquirer().serialQueueChain());
584  }
586  return &(module_->sharedResourcesAcquirer().serialQueueChain());
587  }
589  return &(module_->sharedResourcesAcquirer().serialQueueChain());
590  }
592  return &(module_->sharedResourcesAcquirer().serialQueueChain());
593  }
595  return &(module_->sharedResourcesAcquirer().serialQueueChain());
596  }
598  return &(module_->sharedResourcesAcquirer().serialQueueChain());
599  }
601  return &(module_->queue());
602  }
604  return &(module_->queue());
605  }
607  return &(module_->queue());
608  }
610  return &(module_->queue());
611  }
612 
613 
614  namespace {
615  template <typename T> bool mustPrefetchMayGet();
616 
617  template<> bool mustPrefetchMayGet<EDAnalyzer>() { return true;}
618  template<> bool mustPrefetchMayGet<EDProducer>() { return true;}
619  template<> bool mustPrefetchMayGet<EDFilter>() { return true;}
620  template<> bool mustPrefetchMayGet<OutputModule>() { return true;}
621 
622  template<> bool mustPrefetchMayGet<edm::one::EDProducerBase>() { return true;}
623  template<> bool mustPrefetchMayGet<edm::one::EDFilterBase>() { return true;}
624  template<> bool mustPrefetchMayGet<edm::one::EDAnalyzerBase>() { return true;}
625  template<> bool mustPrefetchMayGet<edm::one::OutputModuleBase>() { return true;}
626 
627  template<> bool mustPrefetchMayGet<edm::global::EDProducerBase>() { return true;}
628  template<> bool mustPrefetchMayGet<edm::global::EDFilterBase>() { return true;}
629  template<> bool mustPrefetchMayGet<edm::global::EDAnalyzerBase>() { return true;}
630  template<> bool mustPrefetchMayGet<edm::global::OutputModuleBase>() { return true;}
631 
632  template<> bool mustPrefetchMayGet<edm::limited::EDProducerBase>() { return true;}
633  template<> bool mustPrefetchMayGet<edm::limited::EDFilterBase>() { return true;}
634  template<> bool mustPrefetchMayGet<edm::limited::EDAnalyzerBase>() { return true;}
635  template<> bool mustPrefetchMayGet<edm::limited::OutputModuleBase>() { return true;}
636 
637  template<> bool mustPrefetchMayGet<edm::stream::EDProducerAdaptorBase>() { return true;}
638  template<> bool mustPrefetchMayGet<edm::stream::EDFilterAdaptorBase>() { return true;}
639  template<> bool mustPrefetchMayGet<edm::stream::EDAnalyzerAdaptorBase>() { return true;}
640 
641  }
642 
643 
644  template<typename T>
646  ProductResolverIndexHelper const& iHelper) {
647  module_->updateLookup(iBranchType,iHelper,mustPrefetchMayGet<T>());
648  }
649 
650  namespace {
651  using ModuleToResolverIndicies = std::unordered_multimap<std::string,
652  std::tuple<edm::TypeID const*, const char*, edm::ProductResolverIndex>>;
653  void resolvePutIndiciesImpl(void*,
654  BranchType iBranchType,
655  ModuleToResolverIndicies const& iIndicies,
656  std::string const& iModuleLabel) {
657  //Do nothing
658  }
659 
660  void resolvePutIndiciesImpl(ProducerBase* iProd,
661  BranchType iBranchType,
662  ModuleToResolverIndicies const& iIndicies,
663  std::string const& iModuleLabel) {
664  iProd->resolvePutIndicies(iBranchType, iIndicies, iModuleLabel);
665  }
666 
667  void resolvePutIndiciesImpl(edm::stream::EDProducerAdaptorBase* iProd,
668  BranchType iBranchType,
669  ModuleToResolverIndicies const& iIndicies,
670  std::string const& iModuleLabel) {
671  iProd->resolvePutIndicies(iBranchType, iIndicies, iModuleLabel);
672  }
673  void resolvePutIndiciesImpl(edm::stream::EDFilterAdaptorBase* iProd,
674  BranchType iBranchType,
675  ModuleToResolverIndicies const& iIndicies,
676  std::string const& iModuleLabel) {
677  iProd->resolvePutIndicies(iBranchType, iIndicies, iModuleLabel);
678  }
679 
680  std::vector<ProductResolverIndex> s_emptyIndexList;
681 
682  std::vector<ProductResolverIndex> const& itemsShouldPutInEventImpl(void const*) {
683  return s_emptyIndexList;
684  }
685 
686  std::vector<ProductResolverIndex> const& itemsShouldPutInEventImpl(ProducerBase const* iProd) {
687  return iProd->indiciesForPutProducts(edm::InEvent);
688  }
689 
690  std::vector<ProductResolverIndex> const& itemsShouldPutInEventImpl(edm::stream::EDProducerAdaptorBase const* iProd) {
691  return iProd->indiciesForPutProducts(edm::InEvent);
692  }
693 
694  std::vector<ProductResolverIndex> const& itemsShouldPutInEventImpl(edm::stream::EDFilterAdaptorBase const* iProd) {
695  return iProd->indiciesForPutProducts(edm::InEvent);
696  }
697 
698  }
699 
700  template<typename T>
702  std::unordered_multimap<std::string,
703  std::tuple<TypeID const*, const char*, edm::ProductResolverIndex>> const& iIndicies) {
704  resolvePutIndiciesImpl(&module(), iBranchType,iIndicies, description().moduleLabel());
705  }
706 
707 
708  template<typename T>
709  std::vector<ProductResolverIndex> const&
711  return itemsShouldPutInEventImpl(&module());
712  }
713 
714 
715  template<>
717  template<>
719  template<>
721  template<>
723  template<>
725  template<>
727  template<>
729  template<>
731 
732  template<>
734  template<>
736  template<>
738  template<>
740 
741  template<>
743  template<>
745  template<>
747  template<>
749 
750 
751  template<>
753  template<>
755  template<>
757 
758  //Explicitly instantiate our needed templates to avoid having the compiler
759  // instantiate them in all of our libraries
760  template class WorkerT<EDProducer>;
761  template class WorkerT<EDFilter>;
762  template class WorkerT<EDAnalyzer>;
763  template class WorkerT<OutputModule>;
764  template class WorkerT<one::EDProducerBase>;
765  template class WorkerT<one::EDFilterBase>;
766  template class WorkerT<one::EDAnalyzerBase>;
767  template class WorkerT<one::OutputModuleBase>;
768  template class WorkerT<global::EDProducerBase>;
769  template class WorkerT<global::EDFilterBase>;
770  template class WorkerT<global::EDAnalyzerBase>;
771  template class WorkerT<global::OutputModuleBase>;
775  template class WorkerT<limited::EDProducerBase>;
776  template class WorkerT<limited::EDFilterBase>;
777  template class WorkerT<limited::EDAnalyzerBase>;
778  template class WorkerT<limited::OutputModuleBase>;
779 }
bool implDoStreamEnd(StreamID id, RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *mcc) override
Definition: WorkerT.cc:416
static const char module_[]
bool wantsStreamLuminosityBlocks() const final
Definition: WorkerT.cc:147
ModuleDescription const & description() const
Definition: Worker.h:188
SerialTaskQueue * globalRunsQueue() final
Definition: WorkerT.cc:152
Definition: helper.py:1
roAction_t actions[nactions]
Definition: GenABIO.cc:187
void callWorkerStreamEnd(D, StreamID id, RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *mcc)
Definition: WorkerT.cc:394
SerialTaskQueue * globalLuminosityBlocksQueue() final
Definition: WorkerT.cc:156
void implEndJob() override
Definition: WorkerT.cc:513
bool wantsGlobalRuns() const final
Definition: WorkerT.cc:132
void updateLookup(BranchType iBranchType, ProductResolverIndexHelper const &) override
Definition: WorkerT.cc:645
T & module()
Definition: WorkerT.h:84
bool implDoStreamBegin(StreamID id, RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *mcc) override
Definition: WorkerT.cc:404
ActivityRegistry * activityRegistry()
Definition: Worker.h:274
bool implDo(EventPrincipal const &ep, EventSetup const &c, ModuleCallingContext const *mcc) override
Definition: WorkerT.cc:229
#define constexpr
BranchType
Definition: BranchType.h:11
Types moduleType() const override
void resolvePutIndicies(BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
Definition: ProducerBase.cc:85
edm::propagate_const< std::shared_ptr< T > > module_
Definition: WorkerT.h:166
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts(BranchType iBranchType) const
Definition: ProducerBase.h:86
void implRespondToOpenInputFile(FileBlock const &fb) override
Definition: WorkerT.cc:552
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts(BranchType iBranchType) const
bool implDoPrePrefetchSelection(StreamID id, EventPrincipal const &ep, ModuleCallingContext const *mcc) override
Definition: WorkerT.cc:286
bool wantsGlobalLuminosityBlocks() const final
Definition: WorkerT.cc:137
void callWorkerEndStream(D, StreamID)
Definition: WorkerT.cc:535
void operator()(WorkerT< T > *iWorker, StreamID id)
Definition: WorkerT.cc:87
void operator()(const T &...)
Definition: WorkerT.cc:82
void implBeginStream(StreamID) override
Definition: WorkerT.cc:526
Definition: value.py:1
TaskQueueAdaptor serializeRunModule() override
Definition: WorkerT.cc:573
void resolvePutIndicies(BranchType iBranchType, std::unordered_multimap< std::string, std::tuple< TypeID const *, const char *, edm::ProductResolverIndex >> const &iIndicies) override
Definition: WorkerT.cc:701
void operator()(WorkerT< T > *iWorker, StreamID id)
Definition: WorkerT.cc:94
void callWorkerStreamBegin(D, StreamID id, RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *mcc)
Definition: WorkerT.cc:385
bool implDoBegin(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *mcc) override
Definition: WorkerT.cc:377
~WorkerT() override
Definition: WorkerT.cc:127
std::vector< ProductResolverIndex > const & itemsShouldPutInEvent() const override
Definition: WorkerT.cc:710
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:151
bool implNeedToRunSelection() const final
Definition: WorkerT.cc:281
void implEndStream(StreamID) override
Definition: WorkerT.cc:542
void implBeginJob() override
Definition: WorkerT.cc:506
void implRespondToCloseInputFile(FileBlock const &fb) override
Definition: WorkerT.cc:559
std::pair< OmniClusterRef, TrackingParticleRef > P
void resolvePutIndicies(BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
void callWorkerBeginStream(D, StreamID)
Definition: WorkerT.cc:519
void implDoAcquire(EventPrincipal const &ep, EventSetup const &c, ModuleCallingContext const *mcc, WaitingTaskWithArenaHolder &holder) final
Definition: WorkerT.cc:237
HLT enums.
void itemsToGetForSelection(std::vector< ProductResolverIndexAndSkipBit > &) const final
Definition: WorkerT.cc:294
void postDoEvent(EventPrincipal const &)
Definition: Worker.cc:375
void implRegisterThinnedAssociations(ProductRegistry const &, ThinnedAssociationsHelper &) override
Definition: WorkerT.cc:566
bool implDoEnd(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *mcc) override
Definition: WorkerT.cc:428
bool wantsStreamRuns() const final
Definition: WorkerT.cc:142
static Interceptor::Registry registry("Interceptor")
long double T
std::string workerType() const override
Definition: WorkerT.cc:499
WorkerT(std::shared_ptr< T >, ModuleDescription const &, ExceptionToActionTable const *actions)
Definition: WorkerT.cc:120