CMS 3D CMS Logo

OutputModuleCommunicatorT.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 
17 
19 
24 
25 namespace {
26 
27  template <typename F>
28  void async(edm::one::OutputModuleBase& iMod, F&& iFunc) {
30  }
31 
32  template <typename F>
33  void async(edm::limited::OutputModuleBase& iMod, F&& iFunc) {
34  iMod.queue().push(std::move(iFunc));
35  }
36 
37  template <typename F>
38  void async(edm::global::OutputModuleBase&, F iFunc) {
39  auto t = edm::make_functor_task(tbb::task::allocate_root(), iFunc);
40  tbb::task::spawn(*t);
41  }
42 } // namespace
43 
44 namespace edm {
45 
46  template <typename T>
48  module().doCloseFile();
49  }
50 
51  template <typename T>
53  return module().shouldWeCloseFile();
54  }
55 
56  template <typename T>
58  module().doOpenFile(fb);
59  }
60 
61  template <typename T>
63  ProcessBlockPrincipal const& processBlockPrincipal,
64  ProcessContext const* processContext,
65  ActivityRegistry* activityRegistry) {
72  processContext);
73  auto t = [&mod = module(),
74  &processBlockPrincipal,
75  globalContext,
76  token,
77  desc = &description(),
78  activityRegistry,
79  iTask]() mutable {
80  std::exception_ptr ex;
81  // Caught exception is propagated via WaitingTaskHolder
82  CMS_SA_ALLOW try {
84  ParentContext parentContext(&globalContext);
86  ModuleContextSentry moduleContextSentry(&mcc, parentContext);
87  activityRegistry->preModuleWriteProcessBlockSignal_(globalContext, mcc);
88  auto sentry(make_sentry(activityRegistry, [&globalContext, &mcc](ActivityRegistry* ar) {
89  ar->postModuleWriteProcessBlockSignal_(globalContext, mcc);
90  }));
91  mod.doWriteProcessBlock(processBlockPrincipal, &mcc);
92  } catch (...) {
93  ex = std::current_exception();
94  }
95  iTask.doneWaiting(ex);
96  };
97  async(module(), std::move(t));
98  }
99 
100  template <typename T>
102  edm::RunPrincipal const& rp,
103  ProcessContext const* processContext,
104  ActivityRegistry* activityRegistry,
105  MergeableRunProductMetadata const* mergeableRunProductMetadata) {
108  LuminosityBlockID(rp.run(), 0),
109  rp.index(),
111  rp.endTime(),
112  processContext);
113  auto t = [&mod = module(),
114  &rp,
115  globalContext,
116  token,
117  desc = &description(),
118  activityRegistry,
119  mergeableRunProductMetadata,
120  iTask]() mutable {
121  std::exception_ptr ex;
122  // Caught exception is propagated via WaitingTaskHolder
123  CMS_SA_ALLOW try {
125  ParentContext parentContext(&globalContext);
127  ModuleContextSentry moduleContextSentry(&mcc, parentContext);
128  activityRegistry->preModuleWriteRunSignal_(globalContext, mcc);
129  auto sentry(make_sentry(activityRegistry, [&globalContext, &mcc](ActivityRegistry* ar) {
130  ar->postModuleWriteRunSignal_(globalContext, mcc);
131  }));
132  mod.doWriteRun(rp, &mcc, mergeableRunProductMetadata);
133  } catch (...) {
134  ex = std::current_exception();
135  }
136  iTask.doneWaiting(ex);
137  };
138  async(module(), std::move(t));
139  }
140 
141  template <typename T>
144  ProcessContext const* processContext,
145  ActivityRegistry* activityRegistry) {
148  lbp.id(),
149  lbp.runPrincipal().index(),
150  lbp.index(),
151  lbp.beginTime(),
152  processContext);
153  auto t = [&mod = module(), &lbp, activityRegistry, token, globalContext, desc = &description(), iTask]() mutable {
154  std::exception_ptr ex;
155  // Caught exception is propagated via WaitingTaskHolder
156  CMS_SA_ALLOW try {
158 
159  ParentContext parentContext(&globalContext);
161  ModuleContextSentry moduleContextSentry(&mcc, parentContext);
162  activityRegistry->preModuleWriteLumiSignal_(globalContext, mcc);
163  auto sentry(make_sentry(activityRegistry, [&globalContext, &mcc](ActivityRegistry* ar) {
164  ar->postModuleWriteLumiSignal_(globalContext, mcc);
165  }));
166  mod.doWriteLuminosityBlock(lbp, &mcc);
167  } catch (...) {
168  ex = std::current_exception();
169  }
170  iTask.doneWaiting(ex);
171  };
172  async(module(), std::move(t));
173  }
174 
175  template <typename T>
177  return module().wantAllEvents();
178  }
179 
180  template <typename T>
182  return module().limitReached();
183  }
184 
185  template <typename T>
187  module().configure(desc);
188  }
189 
190  template <typename T>
192  return module().keptProducts();
193  }
194 
195  template <typename T>
198  module().selectProducts(preg, helper);
199  }
200 
201  template <typename T>
203  std::map<std::string, std::vector<std::pair<std::string, int>>> const& outputModulePathPositions,
204  bool anyProductProduced) {
205  module().setEventSelectionInfo(outputModulePathPositions, anyProductProduced);
206  }
207 
208  template <typename T>
210  return module().description();
211  }
212 
213  namespace impl {
214  std::unique_ptr<edm::OutputModuleCommunicator> createCommunicatorIfNeeded(void*) {
215  return std::unique_ptr<edm::OutputModuleCommunicator>{};
216  }
217  std::unique_ptr<edm::OutputModuleCommunicator> createCommunicatorIfNeeded(::edm::global::OutputModuleBase* iMod) {
218  return std::make_unique<OutputModuleCommunicatorT<edm::global::OutputModuleBase>>(iMod);
219  }
220  std::unique_ptr<edm::OutputModuleCommunicator> createCommunicatorIfNeeded(::edm::one::OutputModuleBase* iMod) {
221  return std::make_unique<OutputModuleCommunicatorT<edm::one::OutputModuleBase>>(iMod);
222  }
223  std::unique_ptr<edm::OutputModuleCommunicator> createCommunicatorIfNeeded(::edm::limited::OutputModuleBase* iMod) {
224  return std::make_unique<OutputModuleCommunicatorT<edm::limited::OutputModuleBase>>(iMod);
225  }
226  } // namespace impl
227 } // namespace edm
228 
229 namespace edm {
230  template class OutputModuleCommunicatorT<one::OutputModuleBase>;
231  template class OutputModuleCommunicatorT<global::OutputModuleBase>;
232  template class OutputModuleCommunicatorT<limited::OutputModuleBase>;
233 } // namespace edm
edm::SharedResourcesAcquirer::serialQueueChain
SerialTaskQueueChain & serialQueueChain() const
Definition: SharedResourcesAcquirer.h:54
edm::limited::OutputModuleBase::queue
LimitedTaskQueue & queue()
Definition: OutputModuleBase.h:119
edm::RunPrincipal::endTime
Timestamp const & endTime() const
Definition: RunPrincipal.h:69
edm::LuminosityBlockPrincipal::runPrincipal
RunPrincipal const & runPrincipal() const
Definition: LuminosityBlockPrincipal.h:45
ModuleCallingContext.h
edm::OutputModuleCommunicatorT::writeRunAsync
void writeRunAsync(WaitingTaskHolder iTask, edm::RunPrincipal const &rp, ProcessContext const *, ActivityRegistry *, MergeableRunProductMetadata const *) override
Definition: OutputModuleCommunicatorT.cc:101
ServiceRegistry.h
edm::ModuleContextSentry
Definition: ModuleContextSentry.h:11
WaitingTaskHolder.h
edm::global::OutputModuleBase
Definition: OutputModuleBase.h:64
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ActivityRegistry::preModuleWriteRunSignal_
PreModuleWriteRun preModuleWriteRunSignal_
Definition: ActivityRegistry.h:955
edm::ProcessContext
Definition: ProcessContext.h:27
edmLumisInFiles.description
description
Definition: edmLumisInFiles.py:11
mod
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
FunctorTask.h
edm::LuminosityBlockPrincipal
Definition: LuminosityBlockPrincipal.h:31
edm::make_functor_task
FunctorTask< F > * make_functor_task(ALLOC &&iAlloc, F f)
Definition: FunctorTask.h:47
edm::GlobalContext::Transition::kWriteProcessBlock
edm::OutputModuleCommunicatorT::selectProducts
void selectProducts(edm::ProductRegistry const &preg, ThinnedAssociationsHelper const &) override
Definition: OutputModuleCommunicatorT.cc:196
edm::WaitingTaskHolder::doneWaiting
void doneWaiting(std::exception_ptr iExcept)
Definition: WaitingTaskHolder.h:75
edm::ActivityRegistry::postModuleWriteLumiSignal_
PostModuleWriteLumi postModuleWriteLumiSignal_
Definition: ActivityRegistry.h:974
edm::ProcessBlockPrincipal
Definition: ProcessBlockPrincipal.h:22
LuminosityBlockID.h
CMS_SA_ALLOW
#define CMS_SA_ALLOW
Definition: thread_safety_macros.h:5
edm::ModuleDescription
Definition: ModuleDescription.h:21
edm::one::OutputModuleBase::sharedResourcesAcquirer
SharedResourcesAcquirer & sharedResourcesAcquirer()
Definition: OutputModuleBase.h:115
F
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
edm::ProductRegistry
Definition: ProductRegistry.h:37
ActivityRegistry.h
edm::ActivityRegistry::postModuleWriteRunSignal_
PostModuleWriteRun postModuleWriteRunSignal_
Definition: ActivityRegistry.h:960
edm::FileBlock
Definition: FileBlock.h:20
edm::OutputModuleCommunicatorT::configure
void configure(edm::OutputModuleDescription const &desc) override
Definition: OutputModuleCommunicatorT.cc:186
edm::OutputModuleCommunicatorT::description
ModuleDescription const & description() const override
Definition: OutputModuleCommunicatorT.cc:209
edm::OutputModuleCommunicatorT::writeProcessBlockAsync
void writeProcessBlockAsync(WaitingTaskHolder iTask, ProcessBlockPrincipal const &, ProcessContext const *, ActivityRegistry *) override
Definition: OutputModuleCommunicatorT.cc:62
edm::SerialTaskQueueChain::push
void push(T &&iAction)
asynchronously pushes functor iAction into queue
Definition: SerialTaskQueueChain.h:86
edm::ActivityRegistry
Definition: ActivityRegistry.h:133
edm::MergeableRunProductMetadata
Definition: MergeableRunProductMetadata.h:52
make_sentry.h
edm::OutputModuleCommunicatorT::writeLumiAsync
void writeLumiAsync(WaitingTaskHolder iTask, edm::LuminosityBlockPrincipal const &lbp, ProcessContext const *, ActivityRegistry *) override
Definition: OutputModuleCommunicatorT.cc:142
edm::one::OutputModuleBase
Definition: OutputModuleBase.h:67
edm::LuminosityBlockID
Definition: LuminosityBlockID.h:31
edm::OutputModuleCommunicatorT::closeFile
void closeFile() override
Definition: OutputModuleCommunicatorT.cc:47
edm::OutputModuleCommunicatorT::limitReached
bool limitReached() const override
Definition: OutputModuleCommunicatorT.cc:181
edm::ParentContext
Definition: ParentContext.h:27
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::RunPrincipal::index
RunIndex index() const
Definition: RunPrincipal.h:57
edm::GlobalContext::Transition::kWriteLuminosityBlock
edm::ThinnedAssociationsHelper
Definition: ThinnedAssociationsHelper.h:37
edm::GlobalContext
Definition: GlobalContext.h:29
edm::impl::createCommunicatorIfNeeded
std::unique_ptr< edm::OutputModuleCommunicator > createCommunicatorIfNeeded(void *)
Definition: OutputModuleCommunicatorT.cc:214
GlobalContext.h
edm::LuminosityBlockIndex::invalidLuminosityBlockIndex
static LuminosityBlockIndex invalidLuminosityBlockIndex()
Definition: LuminosityBlockIndex.cc:9
edm::WaitingTaskHolder
Definition: WaitingTaskHolder.h:30
edm::ActivityRegistry::postModuleWriteProcessBlockSignal_
PostModuleWriteProcessBlock postModuleWriteProcessBlockSignal_
Definition: ActivityRegistry.h:948
edm::ServiceRegistry::presentToken
ServiceToken presentToken() const
Definition: ServiceRegistry.cc:63
edm::OutputModuleCommunicatorT::keptProducts
edm::SelectedProductsForBranchType const & keptProducts() const override
Definition: OutputModuleCommunicatorT.cc:191
thread_safety_macros.h
RunPrincipal.h
helper
Definition: helper.py:1
edm::RunPrincipal::run
RunNumber_t run() const
Definition: RunPrincipal.h:61
edm::limited::OutputModuleBase
Definition: OutputModuleBase.h:65
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::GlobalContext::Transition::kWriteRun
OutputModuleCommunicatorT.h
edm::OutputModuleCommunicatorT::wantAllEvents
bool wantAllEvents() const override
Definition: OutputModuleCommunicatorT.cc:176
edm::ServiceRegistry::instance
static ServiceRegistry & instance()
Definition: ServiceRegistry.cc:90
edm::RunIndex::invalidRunIndex
static RunIndex invalidRunIndex()
Definition: RunIndex.cc:9
edm::OutputModuleCommunicatorT::setEventSelectionInfo
void setEventSelectionInfo(std::map< std::string, std::vector< std::pair< std::string, int > > > const &outputModulePathPositions, bool anyProductProduced) override
Definition: OutputModuleCommunicatorT.cc:202
LuminosityBlockPrincipal.h
OutputModuleBase.h
edm::Timestamp::invalidTimestamp
static Timestamp invalidTimestamp()
Definition: Timestamp.h:82
ParentContext.h
edm::OutputModuleCommunicatorT::shouldWeCloseFile
bool shouldWeCloseFile() const override
Definition: OutputModuleCommunicatorT.cc:52
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
edm::SelectedProductsForBranchType
std::array< SelectedProducts, NumBranchTypes > SelectedProductsForBranchType
Definition: SelectedProducts.h:13
impl
Definition: trackAlgoPriorityOrder.h:18
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::LuminosityBlockPrincipal::id
LuminosityBlockID id() const
Definition: LuminosityBlockPrincipal.h:53
edm::make_sentry
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:30
LuminosityBlockIndex.h
edm::ActivityRegistry::preModuleWriteProcessBlockSignal_
PreModuleWriteProcessBlock preModuleWriteProcessBlockSignal_
Definition: ActivityRegistry.h:941
edm::OutputModuleCommunicatorT::openFile
void openFile(edm::FileBlock const &fb) override
Definition: OutputModuleCommunicatorT.cc:57
OutputModuleBase.h
genParticles_cff.map
map
Definition: genParticles_cff.py:11
edm::OutputModuleDescription
Definition: OutputModuleDescription.h:17
edm::LuminosityBlockPrincipal::index
LuminosityBlockIndex index() const
Definition: LuminosityBlockPrincipal.h:51
edm::LuminosityBlockPrincipal::beginTime
Timestamp const & beginTime() const
Definition: LuminosityBlockPrincipal.h:55
OutputModuleBase.h
edm::RunPrincipal
Definition: RunPrincipal.h:34
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
edm::ServiceRegistry::Operate
Definition: ServiceRegistry.h:40
ModuleContextSentry.h
benchmark_cfg.fb
fb
Definition: benchmark_cfg.py:14
edm::LimitedTaskQueue::push
void push(T &&iAction)
asynchronously pushes functor iAction into queue
Definition: LimitedTaskQueue.h:126
edm::ModuleCallingContext
Definition: ModuleCallingContext.h:29
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:318