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 } // namespace
47 
48 namespace edm {
49 
50  template <typename T>
52  module().doCloseFile();
53  }
54 
55  template <typename T>
57  return module().shouldWeCloseFile();
58  }
59 
60  template <typename T>
62  module().doOpenFile(fb);
63  }
64 
65  template <typename T>
67  edm::RunPrincipal const& rp,
68  ProcessContext const* processContext,
69  ActivityRegistry* activityRegistry,
70  MergeableRunProductMetadata const* mergeableRunProductMetadata) {
71  auto token = ServiceRegistry::instance().presentToken();
73  LuminosityBlockID(rp.run(), 0),
74  rp.index(),
76  rp.endTime(),
77  processContext);
78  auto t = [& mod = module(),
79  &rp,
80  globalContext,
81  token,
82  desc = &description(),
83  activityRegistry,
84  mergeableRunProductMetadata,
85  iTask]() mutable {
86  std::exception_ptr ex;
87  try {
88  ServiceRegistry::Operate op(token);
89  ParentContext parentContext(&globalContext);
90  ModuleCallingContext mcc(desc);
91  ModuleContextSentry moduleContextSentry(&mcc, parentContext);
92  activityRegistry->preModuleWriteRunSignal_(globalContext, mcc);
93  auto sentry(make_sentry(activityRegistry, [&globalContext, &mcc](ActivityRegistry* activityRegistry) {
94  activityRegistry->postModuleWriteRunSignal_(globalContext, mcc);
95  }));
96  mod.doWriteRun(rp, &mcc, mergeableRunProductMetadata);
97  } catch (...) {
98  ex = std::current_exception();
99  }
100  iTask.doneWaiting(ex);
101  };
102  async(module(), std::move(t));
103  }
104 
105  template <typename T>
108  ProcessContext const* processContext,
109  ActivityRegistry* activityRegistry) {
110  auto token = ServiceRegistry::instance().presentToken();
112  lbp.id(),
113  lbp.runPrincipal().index(),
114  lbp.index(),
115  lbp.beginTime(),
116  processContext);
117  auto t = [& mod = module(), &lbp, activityRegistry, token, globalContext, desc = &description(), iTask]() mutable {
118  std::exception_ptr ex;
119  try {
120  ServiceRegistry::Operate op(token);
121 
122  ParentContext parentContext(&globalContext);
123  ModuleCallingContext mcc(desc);
124  ModuleContextSentry moduleContextSentry(&mcc, parentContext);
125  activityRegistry->preModuleWriteLumiSignal_(globalContext, mcc);
126  auto sentry(make_sentry(activityRegistry, [&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>
140  return module().wantAllEvents();
141  }
142 
143  template <typename T>
145  return module().limitReached();
146  }
147 
148  template <typename T>
150  module().configure(desc);
151  }
152 
153  template <typename T>
155  return module().keptProducts();
156  }
157 
158  template <typename T>
161  module().selectProducts(preg, helper);
162  }
163 
164  template <typename T>
166  std::map<std::string, std::vector<std::pair<std::string, int>>> const& outputModulePathPositions,
167  bool anyProductProduced) {
168  module().setEventSelectionInfo(outputModulePathPositions, anyProductProduced);
169  }
170 
171  template <typename T>
173  return module().description();
174  }
175 
176  namespace impl {
177  std::unique_ptr<edm::OutputModuleCommunicator> createCommunicatorIfNeeded(void*) {
178  return std::unique_ptr<edm::OutputModuleCommunicator>{};
179  }
180  std::unique_ptr<edm::OutputModuleCommunicator> createCommunicatorIfNeeded(::edm::OutputModule* iMod) {
181  return std::make_unique<OutputModuleCommunicatorT<edm::OutputModule>>(iMod);
182  }
183  std::unique_ptr<edm::OutputModuleCommunicator> createCommunicatorIfNeeded(::edm::global::OutputModuleBase* iMod) {
184  return std::make_unique<OutputModuleCommunicatorT<edm::global::OutputModuleBase>>(iMod);
185  }
186  std::unique_ptr<edm::OutputModuleCommunicator> createCommunicatorIfNeeded(::edm::one::OutputModuleBase* iMod) {
187  return std::make_unique<OutputModuleCommunicatorT<edm::one::OutputModuleBase>>(iMod);
188  }
189  std::unique_ptr<edm::OutputModuleCommunicator> createCommunicatorIfNeeded(::edm::limited::OutputModuleBase* iMod) {
190  return std::make_unique<OutputModuleCommunicatorT<edm::limited::OutputModuleBase>>(iMod);
191  }
192  } // namespace impl
193 } // namespace edm
194 
195 namespace edm {
200 } // namespace edm
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:30
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:99
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:60
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:68
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:56
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