CMS 3D CMS Logo

OutputModuleCommunicatorT.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 
17 
19 
24 
25 namespace {
26  template <typename F>
27  void async( edm::OutputModule& iMod, F&& iFunc ) {
29  }
30 
31  template <typename F>
32  void async( edm::one::OutputModuleBase& iMod, F&& iFunc ) {
34  }
35 
36  template <typename F>
37  void async( edm::limited::OutputModuleBase& iMod, F&& iFunc ) {
38  iMod.queue().push(std::move(iFunc));
39  }
40 
41  template <typename F>
42  void async( edm::global::OutputModuleBase&, F iFunc ) {
43  auto t = edm::make_functor_task(tbb::task::allocate_root(), iFunc);
44  tbb::task::spawn(*t);
45  }
46 }
47 
48 namespace edm {
49 
50  template<typename T>
51  void
53  module().doCloseFile();
54  }
55 
56  template<typename T>
57  bool
59  return module().shouldWeCloseFile();
60  }
61 
62  template<typename T>
63  void
65  module().doOpenFile(fb);
66  }
67 
68  template<typename T>
69  void
71  edm::RunPrincipal const& rp,
72  ProcessContext const* processContext,
73  ActivityRegistry* activityRegistry,
74  MergeableRunProductMetadata const* mergeableRunProductMetadata) {
75  auto token = ServiceRegistry::instance().presentToken();
77  LuminosityBlockID(rp.run(), 0),
78  rp.index(),
80  rp.endTime(),
81  processContext);
82  auto t = [&mod = module(), &rp, globalContext, token, desc = &description(), activityRegistry, mergeableRunProductMetadata, iTask]() mutable {
83  std::exception_ptr ex;
84  try {
85  ServiceRegistry::Operate op(token);
86  ParentContext parentContext(&globalContext);
87  ModuleCallingContext mcc(desc);
88  ModuleContextSentry moduleContextSentry(&mcc, parentContext);
89  activityRegistry->preModuleWriteRunSignal_(globalContext, mcc);
90  auto sentry( make_sentry(activityRegistry,
91  [&globalContext, &mcc](ActivityRegistry* activityRegistry) {
92  activityRegistry->postModuleWriteRunSignal_(globalContext, mcc);
93  }));
94  mod.doWriteRun(rp, &mcc, mergeableRunProductMetadata);
95  } catch(...) {
96  ex = std::current_exception();
97  }
98  iTask.doneWaiting(ex);
99  };
100  async(module(), std::move(t));
101  }
102 
103  template<typename T>
104  void
107  ProcessContext const* processContext,
108  ActivityRegistry* activityRegistry) {
109  auto token = ServiceRegistry::instance().presentToken();
111  lbp.id(),
112  lbp.runPrincipal().index(),
113  lbp.index(),
114  lbp.beginTime(),
115  processContext);
116  auto t=[&mod = module(), &lbp, activityRegistry, token, globalContext,desc = &description(),iTask]() mutable {
117  std::exception_ptr ex;
118  try {
119  ServiceRegistry::Operate op(token);
120 
121  ParentContext parentContext(&globalContext);
122  ModuleCallingContext mcc(desc);
123  ModuleContextSentry moduleContextSentry(&mcc, parentContext);
124  activityRegistry->preModuleWriteLumiSignal_(globalContext, mcc);
125  auto sentry( make_sentry(activityRegistry,
126  [&globalContext, &mcc](ActivityRegistry* activityRegistry) {
127  activityRegistry->postModuleWriteLumiSignal_(globalContext, mcc);
128  }));
129  mod.doWriteLuminosityBlock(lbp, &mcc);
130  } catch(...) {
131  ex = std::current_exception();
132  }
133  iTask.doneWaiting(ex);
134  };
135  async(module(), std::move(t));
136  }
137 
138  template<typename T>
139  bool OutputModuleCommunicatorT<T>::wantAllEvents() const {return module().wantAllEvents();}
140 
141  template<typename T>
142  bool OutputModuleCommunicatorT<T>::limitReached() const {return module().limitReached();}
143 
144  template<typename T>
146 
147  template<typename T>
149  return module().keptProducts();
150  }
151 
152  template<typename T>
154  module().selectProducts(preg, helper);
155  }
156 
157  template<typename T>
158  void OutputModuleCommunicatorT<T>::setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
159  bool anyProductProduced) {
160  module().setEventSelectionInfo(outputModulePathPositions, anyProductProduced);
161  }
162 
163  template<typename T>
165  return module().description();
166  }
167 
168  namespace impl {
169  std::unique_ptr<edm::OutputModuleCommunicator> createCommunicatorIfNeeded(void *) {
170  return std::unique_ptr<edm::OutputModuleCommunicator>{};
171  }
172  std::unique_ptr<edm::OutputModuleCommunicator> createCommunicatorIfNeeded(::edm::OutputModule * iMod){
173  return std::make_unique<OutputModuleCommunicatorT<edm::OutputModule>>(iMod);
174  }
175  std::unique_ptr<edm::OutputModuleCommunicator> createCommunicatorIfNeeded(::edm::global::OutputModuleBase * iMod){
176  return std::make_unique<OutputModuleCommunicatorT<edm::global::OutputModuleBase>>(iMod);
177  }
178  std::unique_ptr<edm::OutputModuleCommunicator> createCommunicatorIfNeeded(::edm::one::OutputModuleBase * iMod){
179  return std::make_unique<OutputModuleCommunicatorT<edm::one::OutputModuleBase>>(iMod);
180  }
181  std::unique_ptr<edm::OutputModuleCommunicator> createCommunicatorIfNeeded(::edm::limited::OutputModuleBase * iMod){
182  return std::make_unique<OutputModuleCommunicatorT<edm::limited::OutputModuleBase>>(iMod);
183  }
184  }
185 }
186 
187 namespace edm {
192 }
RunPrincipal const & runPrincipal() const
void push(T &&iAction)
asynchronously pushes functor iAction into queue
SharedResourcesAcquirer & sharedResourcesAcquirer()
std::unique_ptr< T, F > make_sentry(T *iObject, F iFunc)
NOTE: if iObject is null, then iFunc will not be called.
Definition: make_sentry.h:29
Definition: helper.py:1
Timestamp const & beginTime() const
std::array< SelectedProducts, NumBranchTypes > SelectedProductsForBranchType
FunctorTask< F > * make_functor_task(ALLOC &&iAlloc, F f)
Definition: FunctorTask.h:47
void selectProducts(edm::ProductRegistry const &preg, ThinnedAssociationsHelper const &) override
SharedResourcesAcquirer & sharedResourcesAcquirer()
Definition: OutputModule.h:93
PostModuleWriteLumi postModuleWriteLumiSignal_
void configure(edm::OutputModuleDescription const &desc) override
LuminosityBlockIndex index() const
void push(T &&iAction)
asynchronously pushes functor iAction into queue
RunNumber_t run() const
Definition: RunPrincipal.h:65
ServiceToken presentToken() const
ModuleDescription const & description() const override
edm::SelectedProductsForBranchType const & keptProducts() const override
void writeRunAsync(WaitingTaskHolder iTask, edm::RunPrincipal const &rp, ProcessContext const *, ActivityRegistry *, MergeableRunProductMetadata const *) override
void doneWaiting(std::exception_ptr iExcept)
static ServiceRegistry & instance()
Timestamp const & endTime() const
Definition: RunPrincipal.h:81
std::unique_ptr< edm::OutputModuleCommunicator > createCommunicatorIfNeeded(void *)
PostModuleWriteRun postModuleWriteRunSignal_
static LuminosityBlockIndex invalidLuminosityBlockIndex()
SerialTaskQueueChain & serialQueueChain() const
void writeLumiAsync(WaitingTaskHolder iTask, edm::LuminosityBlockPrincipal const &lbp, ProcessContext const *, ActivityRegistry *) override
void setEventSelectionInfo(std::map< std::string, std::vector< std::pair< std::string, int > > > const &outputModulePathPositions, bool anyProductProduced) override
PreModuleWriteRun preModuleWriteRunSignal_
RunIndex index() const
Definition: RunPrincipal.h:57
HLT enums.
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
Definition: vlib.h:208
void openFile(edm::FileBlock const &fb) override
def move(src, dest)
Definition: eostools.py:511