CMS 3D CMS Logo

PythonEventProcessor.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Subsystem/Package
4 // Class : PythonEventProcessor
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: root
10 // Created: Fri, 20 Jan 2017 16:36:41 GMT
11 //
12 
13 // system include files
14 #include <mutex>
15 #include "tbb/task_arena.h"
16 
17 // user include files
20 
24 
27 
29 
34 
35 namespace {
36  std::once_flag pluginFlag;
37  int setupPluginSystem() {
38  std::call_once(pluginFlag, []() { edmplugin::PluginManager::configure(edmplugin::standard::config()); });
39  return 0;
40  }
41 
42  std::shared_ptr<edm::ProcessDesc> addDefaultServicesToProcessDesc(std::shared_ptr<edm::ProcessDesc> iDesc) {
43  iDesc->addServices(edm::defaultCmsRunServices());
44  return iDesc;
45  }
46 
47  //Only one ThreadsController can be active at a time
48  CMS_THREAD_SAFE std::unique_ptr<edm::ThreadsController> tsiPtr;
50 
51  std::shared_ptr<edm::ProcessDesc> setupThreading(std::shared_ptr<edm::ProcessDesc> iDesc) {
52  // check the "options" ParameterSet
53  std::shared_ptr<edm::ParameterSet> pset = iDesc->getProcessPSet();
54  auto threadsInfo = threadOptions(*pset);
55 
56  threadsInfo.nThreads_ = edm::setNThreads(threadsInfo.nThreads_, threadsInfo.stackSize_, tsiPtr);
57  nThreads = threadsInfo.nThreads_;
58 
59  // update the numberOfThreads and sizeOfStackForThreadsInKB in the "options" ParameterSet
60  setThreadOptions(threadsInfo, *pset);
61 
62  return iDesc;
63  }
64 
65  edm::ServiceToken createJobReport() {
68  std::make_unique<edm::JobReport>(nullptr)));
69  }
70 } // namespace
71 
72 //
73 // constants, enums and typedefs
74 //
75 
76 //
77 // static data member definitions
78 //
79 
80 //
81 // constructors and destructor
82 //
84  : forcePluginSetupFirst_(setupPluginSystem()),
85  processor_(addDefaultServicesToProcessDesc(setupThreading(iDesc.processDesc())),
86  createJobReport(),
87  edm::serviceregistry::kOverlapIsError) {}
88 
89 namespace {
90  class TaskCleanupSentry {
91  public:
92  TaskCleanupSentry(edm::EventProcessor* ep) : ep_(ep) {}
93  ~TaskCleanupSentry() { ep_->taskCleanup(); }
94 
95  private:
97  };
98 } // namespace
99 
101  auto gil = PyEval_SaveThread();
102  // Protects the destructor from throwing exceptions.
103  CMS_SA_ALLOW try {
104  tbb::task_arena{nThreads}.execute([this]() {
105  TaskCleanupSentry s(&processor_);
106  processor_.endJob();
107  });
108  } catch (...) {
109  }
110  PyEval_RestoreThread(gil);
111 }
112 
114  auto gil = PyEval_SaveThread();
115  try {
116  tbb::task_arena{nThreads}.execute([this]() { (void)processor_.runToCompletion(); });
117  } catch (...) {
118  }
119  PyEval_RestoreThread(gil);
120 }
edm::defaultCmsRunServices
std::vector< std::string > defaultCmsRunServices()
Definition: defaultCmsRunServices.cc:19
ServiceRegistry.h
PythonEventProcessor::processor_
edm::EventProcessor processor_
Definition: PythonEventProcessor.h:58
PyBind11ProcessDesc.h
edm::setThreadOptions
void setThreadOptions(ThreadsInfo const &threadsInfo, edm::ParameterSet &pset)
Definition: ThreadsInfo.cc:27
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::EventProcessor::endJob
void endJob()
Definition: EventProcessor.cc:693
setNThreads.h
edm::EventProcessor::runToCompletion
StatusCode runToCompletion()
Definition: EventProcessor.cc:789
ServiceToken.h
CMS_SA_ALLOW
#define CMS_SA_ALLOW
Definition: thread_safety_macros.h:5
edm::threadOptions
ThreadsInfo threadOptions(edm::ParameterSet const &pset)
Definition: ThreadsInfo.cc:11
edm::ServiceToken
Definition: ServiceToken.h:42
alignCSCRings.s
s
Definition: alignCSCRings.py:92
ProcessDesc.h
CMS_THREAD_SAFE
#define CMS_THREAD_SAFE
Definition: thread_safety_macros.h:4
runTheMatrix.nThreads
nThreads
Definition: runTheMatrix.py:371
PythonEventProcessor.h
PyBind11ProcessDesc
Definition: PyBind11ProcessDesc.h:16
standard.h
PythonEventProcessor::run
void run()
Definition: PythonEventProcessor.cc:113
PythonEventProcessor::PythonEventProcessor
PythonEventProcessor(PyBind11ProcessDesc const &)
Definition: PythonEventProcessor.cc:83
edmplugin::PluginManager::configure
static PluginManager & configure(const Config &)
Definition: PluginManager.cc:315
thread_safety_macros.h
edm::serviceregistry::kOverlapIsError
Definition: ServiceLegacy.h:29
edmplugin::standard::config
PluginManager::Config config()
Definition: standard.cc:21
PluginManager.h
edm::setNThreads
unsigned int setNThreads(unsigned int iNThreads, unsigned int iStackSize, std::unique_ptr< ThreadsController > &oPtr)
Definition: setNThreads.cc:11
edm::ServiceRegistry::createContaining
static ServiceToken createContaining(std::unique_ptr< T > iService)
create a service token that holds the service defined by iService
Definition: ServiceRegistry.h:99
funct::void
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
PythonEventProcessor::~PythonEventProcessor
~PythonEventProcessor()
Definition: PythonEventProcessor.cc:100
defaultCmsRunServices.h
JobReport.h
edm::EventProcessor
Definition: EventProcessor.h:66
SiStripBadComponentsDQMServiceTemplate_cfg.ep
ep
Definition: SiStripBadComponentsDQMServiceTemplate_cfg.py:86
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
edm::serviceregistry::ServiceWrapper
Definition: ServiceRegistry.h:35
ThreadsInfo.h