CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes
OscarMTProducer Class Reference
Inheritance diagram for OscarMTProducer:
edm::stream::EDProducer< edm::GlobalCache< OscarMTMasterThread >, edm::RunCache< int > >

Public Types

typedef std::vector< std::shared_ptr< SimProducer > > Producers
 
- Public Types inherited from edm::stream::EDProducer< edm::GlobalCache< OscarMTMasterThread >, edm::RunCache< int > >
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Public Member Functions

void beginRun (const edm::Run &r, const edm::EventSetup &c) override
 
void endRun (const edm::Run &r, const edm::EventSetup &c) override
 
 OscarMTProducer (edm::ParameterSet const &p, const OscarMTMasterThread *)
 
void produce (edm::Event &e, const edm::EventSetup &c) override
 
 ~OscarMTProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer< edm::GlobalCache< OscarMTMasterThread >, edm::RunCache< int > >
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static std::shared_ptr< int > globalBeginRun (const edm::Run &iRun, const edm::EventSetup &iSetup, const OscarMTMasterThread *masterThread)
 
static void globalEndJob (OscarMTMasterThread *masterThread)
 
static void globalEndRun (const edm::Run &iRun, const edm::EventSetup &iSetup, const RunContext *iContext)
 
static std::unique_ptr< OscarMTMasterThreadinitializeGlobalCache (const edm::ParameterSet &iConfig)
 

Private Attributes

omt::ThreadHandoff m_handoff
 
const OscarMTMasterThreadm_masterThread
 
const edm::ParameterSetID m_psetID
 
std::unique_ptr< RunManagerMTWorkerm_runManagerWorker
 
int m_verbose
 

Static Private Attributes

static const OscarMTMasterThreads_masterThread = nullptr
 
static edm::ParameterSetID s_psetID {}
 

Detailed Description

Definition at line 42 of file OscarMTProducer.cc.

Member Typedef Documentation

◆ Producers

typedef std::vector<std::shared_ptr<SimProducer> > OscarMTProducer::Producers

Definition at line 44 of file OscarMTProducer.cc.

Constructor & Destructor Documentation

◆ OscarMTProducer()

OscarMTProducer::OscarMTProducer ( edm::ParameterSet const &  p,
const OscarMTMasterThread ms 
)
explicit

Definition at line 108 of file OscarMTProducer.cc.

References AlCaHLTBitMon_ParallelJobs::p.

109  : m_handoff{p.getUntrackedParameter<int>("workerThreadStackSize", 10 * 1024 * 1024)}, m_psetID{p.id()} {
110  m_verbose = p.getParameter<int>("EventVerbose");
111  // Random number generation not allowed here
112  StaticRandomEngineSetUnset random(nullptr);
113 
115  m_handoff.runAndWait([this, &p, token]() {
117  StaticRandomEngineSetUnset random(nullptr);
118  m_runManagerWorker = std::make_unique<RunManagerMTWorker>(p, consumesCollector());
119  });
120  m_masterThread = (nullptr != ms) ? ms : s_masterThread;
122  m_masterThread->callConsumes(consumesCollector());
123 
124  // declair hit collections
125  produces<edm::SimTrackContainer>().setBranchAlias("SimTracks");
126  produces<edm::SimVertexContainer>().setBranchAlias("SimVertices");
127 
128  auto trackHits = p.getParameter<std::vector<std::string>>("TrackHits");
129  for (auto const& ss : trackHits) {
130  produces<edm::PSimHitContainer>(ss);
131  }
132 
133  auto caloHits = p.getParameter<std::vector<std::string>>("CaloHits");
134  for (auto const& ss : caloHits) {
135  produces<edm::PCaloHitContainer>(ss);
136  }
137 
138  //register any products
139  auto& producers = m_runManagerWorker->producers();
140  for (auto& ptr : producers) {
141  ptr->registerProducts(producesCollector());
142  }
143  edm::LogVerbatim("SimG4CoreApplication")
144  << "OscarMTProducer is constructed with hit collections:" << trackHits.size() << " tracking type; "
145  << caloHits.size() << " calo type; " << producers.size() << " watcher type.";
146 }
Log< level::Info, true > LogVerbatim
std::unique_ptr< RunManagerMTWorker > m_runManagerWorker
void runAndWait(F &&iF)
Definition: ThreadHandoff.h:42
assert(be >=bs)
static const OscarMTMasterThread * s_masterThread
const OscarMTMasterThread * m_masterThread
const edm::ParameterSetID m_psetID
static ServiceRegistry & instance()
void callConsumes(edm::ConsumesCollector &&iC) const
omt::ThreadHandoff m_handoff
ServiceToken presentToken() const

◆ ~OscarMTProducer()

OscarMTProducer::~OscarMTProducer ( )
override

Member Function Documentation

◆ beginRun()

void OscarMTProducer::beginRun ( const edm::Run r,
const edm::EventSetup c 
)
override

Definition at line 196 of file OscarMTProducer.cc.

References Exception, l1ctLayer2EG_cff::id, edm::ServiceRegistry::instance(), m_handoff, m_masterThread, m_psetID, m_runManagerWorker, edm::ServiceRegistry::presentToken(), omt::ThreadHandoff::runAndWait(), OscarMTMasterThread::runManagerMasterPtr(), s_psetID, and unpackBuffers-CaloStage2::token.

196  {
197  if (s_psetID != m_psetID) {
198  throw cms::Exception("DiffOscarMTProducers")
199  << "At least two different OscarMTProducer instances have been"
200  "loaded into the job and they have different configurations.\n"
201  " All OscarMTProducers in a job must have exactly the same configuration.";
202  }
203  int id = m_runManagerWorker->getThreadIndex();
204  edm::LogVerbatim("SimG4CoreApplication") << "OscarMTProducer::beginRun threadID=" << id;
206  m_handoff.runAndWait([this, &es, token]() {
208  m_runManagerWorker->beginRun(es);
210  });
211  edm::LogVerbatim("SimG4CoreApplication") << "OscarMTProducer::beginRun done threadID=" << id;
212 }
Log< level::Info, true > LogVerbatim
RunManagerMT * runManagerMasterPtr() const
std::unique_ptr< RunManagerMTWorker > m_runManagerWorker
static edm::ParameterSetID s_psetID
void runAndWait(F &&iF)
Definition: ThreadHandoff.h:42
const OscarMTMasterThread * m_masterThread
const edm::ParameterSetID m_psetID
static ServiceRegistry & instance()
omt::ThreadHandoff m_handoff
ServiceToken presentToken() const

◆ endRun()

void OscarMTProducer::endRun ( const edm::Run r,
const edm::EventSetup c 
)
override

Definition at line 214 of file OscarMTProducer.cc.

References l1ctLayer2EG_cff::id, edm::ServiceRegistry::instance(), m_handoff, m_runManagerWorker, edm::ServiceRegistry::presentToken(), omt::ThreadHandoff::runAndWait(), and unpackBuffers-CaloStage2::token.

214  {
215  StaticRandomEngineSetUnset random(nullptr);
216  int id = m_runManagerWorker->getThreadIndex();
217  edm::LogVerbatim("SimG4CoreApplication") << "OscarMTProducer::endRun threadID=" << id;
219  m_handoff.runAndWait([this, token]() {
221  m_runManagerWorker->endRun();
222  });
223  edm::LogVerbatim("SimG4CoreApplication") << "OscarMTProducer::endRun done threadID=" << id;
224 }
Log< level::Info, true > LogVerbatim
std::unique_ptr< RunManagerMTWorker > m_runManagerWorker
void runAndWait(F &&iF)
Definition: ThreadHandoff.h:42
static ServiceRegistry & instance()
omt::ThreadHandoff m_handoff
ServiceToken presentToken() const

◆ globalBeginRun()

std::shared_ptr< int > OscarMTProducer::globalBeginRun ( const edm::Run iRun,
const edm::EventSetup iSetup,
const OscarMTMasterThread masterThread 
)
static

Definition at line 169 of file OscarMTProducer.cc.

References OscarMTMasterThread::beginRun().

171  {
172  // Random number generation not allowed here
173  StaticRandomEngineSetUnset random(nullptr);
174  edm::LogVerbatim("SimG4CoreApplication") << "OscarMTProducer::globalBeginRun";
175  if (masterThread) {
176  masterThread->beginRun(iSetup);
177  }
178  edm::LogVerbatim("SimG4CoreApplication") << "OscarMTProducer::globalBeginRun done";
179  return std::shared_ptr<int>();
180 }
Log< level::Info, true > LogVerbatim
void beginRun(const edm::EventSetup &iSetup) const

◆ globalEndJob()

void OscarMTProducer::globalEndJob ( OscarMTMasterThread masterThread)
static

Definition at line 189 of file OscarMTProducer.cc.

References OscarMTMasterThread::stopThread().

189  {
190  edm::LogVerbatim("SimG4CoreApplication") << "OscarMTProducer::globalEndJob";
191  if (masterThread) {
192  masterThread->stopThread();
193  }
194 }
Log< level::Info, true > LogVerbatim

◆ globalEndRun()

void OscarMTProducer::globalEndRun ( const edm::Run iRun,
const edm::EventSetup iSetup,
const RunContext iContext 
)
static

Definition at line 182 of file OscarMTProducer.cc.

References edm::stream::RunContextT< R, G >::global().

182  {
183  edm::LogVerbatim("SimG4CoreApplication") << "OscarMTProducer::globalEndRun";
184  if (nullptr != iContext->global()) {
185  iContext->global()->endRun();
186  }
187 }
Log< level::Info, true > LogVerbatim

◆ initializeGlobalCache()

std::unique_ptr< OscarMTMasterThread > OscarMTProducer::initializeGlobalCache ( const edm::ParameterSet iConfig)
static

Definition at line 156 of file OscarMTProducer.cc.

References edm::ParameterSet::id(), runTheMatrix::ret, s_masterThread, and s_psetID.

156  {
157  // Random number generation not allowed here
158  StaticRandomEngineSetUnset random(nullptr);
159  edm::LogVerbatim("SimG4CoreApplication") << "OscarMTProducer::initializeGlobalCache";
160  if (nullptr == s_masterThread) {
161  auto ret = std::make_unique<OscarMTMasterThread>(iConfig);
162  s_masterThread = ret.get();
163  s_psetID = iConfig.id();
164  return ret;
165  }
166  return {};
167 }
Log< level::Info, true > LogVerbatim
ret
prodAgent to be discontinued
static edm::ParameterSetID s_psetID
static const OscarMTMasterThread * s_masterThread
ParameterSetID id() const

◆ produce()

void OscarMTProducer::produce ( edm::Event e,
const edm::EventSetup c 
)
override

Definition at line 226 of file OscarMTProducer.cc.

References MillePedeFileConverter_cfg::e, mps_fire::i, l1ctLayer2EG_cff::id, edm::ServiceRegistry::instance(), TmpSimEvent::load(), m_handoff, m_masterThread, m_runManagerWorker, m_verbose, eostools::move(), Skims_PA_cff::name, groupFilesInBlocks::nn, LaserDQM_cfg::p1, SiStripOfflineCRack_cfg::p2, edm::ServiceRegistry::presentToken(), dumpMFGeometry_cfg::prod, HLT_2024v12_cff::producers, omt::ThreadHandoff::runAndWait(), OscarMTMasterThread::runManagerMaster(), unpackBuffers-CaloStage2::token, PbPb_ZMuSkimMuonDPG_cff::tracker, and findQualityFiles::v.

226  {
227  StaticRandomEngineSetUnset random(e.streamID());
228  auto engine = random.currentEngine();
229  int id = m_runManagerWorker->getThreadIndex();
230  if (0 < m_verbose) {
231  edm::LogVerbatim("SimG4CoreApplication")
232  << "Produce event " << e.id() << " stream " << e.streamID() << " threadID=" << id;
233  //edm::LogVerbatim("SimG4CoreApplication") << " rand= " << G4UniformRand();
234  }
235 
236  auto& sTk = m_runManagerWorker->sensTkDetectors();
237  auto& sCalo = m_runManagerWorker->sensCaloDetectors();
238 
239  TmpSimEvent* evt = nullptr;
241  m_handoff.runAndWait([this, &e, &es, &evt, token, engine]() {
243  StaticRandomEngineSetUnset random(engine);
244  evt = m_runManagerWorker->produce(e, es, m_masterThread->runManagerMaster());
245  });
246 
247  std::unique_ptr<edm::SimTrackContainer> p1(new edm::SimTrackContainer);
248  std::unique_ptr<edm::SimVertexContainer> p2(new edm::SimVertexContainer);
249  evt->load(*p1);
250  evt->load(*p2);
251 
252  if (0 < m_verbose) {
253  edm::LogVerbatim("SimG4CoreApplication") << "Produced " << p2->size() << " SimVertex objects";
254  if (1 < m_verbose) {
255  int nn = p2->size();
256  for (int i = 0; i < nn; ++i) {
257  edm::LogVerbatim("Vertex") << " " << (*p2)[i] << " " << (*p2)[i].processType();
258  }
259  }
260  edm::LogVerbatim("SimG4CoreApplication") << "Produced " << p1->size() << " SimTrack objects";
261  if (1 < m_verbose) {
262  int nn = p1->size();
263  for (int i = 0; i < nn; ++i) {
264  edm::LogVerbatim("Track") << " " << i << ". " << (*p1)[i] << " " << (*p1)[i].crossedBoundary() << " "
265  << (*p1)[i].getIDAtBoundary();
266  }
267  }
268  }
269  e.put(std::move(p1));
270  e.put(std::move(p2));
271 
272  for (auto const& tracker : sTk) {
273  const std::vector<std::string>& v = tracker->getNames();
274  for (auto const& name : v) {
275  std::unique_ptr<edm::PSimHitContainer> product(new edm::PSimHitContainer);
276  tracker->fillHits(*product, name);
277  if (0 < m_verbose && product != nullptr && !product->empty())
278  edm::LogVerbatim("SimG4CoreApplication") << "Produced " << product->size() << " tracker hits <" << name << ">";
279  e.put(std::move(product), name);
280  }
281  }
282  for (auto const& calo : sCalo) {
283  const std::vector<std::string>& v = calo->getNames();
284  for (auto const& name : v) {
285  std::unique_ptr<edm::PCaloHitContainer> product(new edm::PCaloHitContainer);
286  calo->fillHits(*product, name);
287  if (0 < m_verbose && product != nullptr && !product->empty())
288  edm::LogVerbatim("SimG4CoreApplication") << "Produced " << product->size() << " calo hits <" << name << ">";
289  e.put(std::move(product), name);
290  }
291  }
292 
293  auto& producers = m_runManagerWorker->producers();
294  for (auto& prod : producers) {
295  prod.get()->produce(e, es);
296  }
297  if (0 < m_verbose) {
298  edm::LogVerbatim("SimG4CoreApplication")
299  << "Event is produced event " << e.id() << " streamID=" << e.streamID() << " threadID=" << id;
300  //edm::LogWarning("SimG4CoreApplication") << "EventID=" << e.id() << " rand=" << G4UniformRand();
301  }
302 }
Log< level::Info, true > LogVerbatim
std::vector< PCaloHit > PCaloHitContainer
std::unique_ptr< RunManagerMTWorker > m_runManagerWorker
void runAndWait(F &&iF)
Definition: ThreadHandoff.h:42
RunManagerMT & runManagerMaster() const
const OscarMTMasterThread * m_masterThread
static ServiceRegistry & instance()
void load(edm::SimTrackContainer &c) const
Definition: TmpSimEvent.cc:29
std::vector< SimVertex > SimVertexContainer
std::vector< PSimHit > PSimHitContainer
omt::ThreadHandoff m_handoff
std::vector< SimTrack > SimTrackContainer
ServiceToken presentToken() const
def move(src, dest)
Definition: eostools.py:511
Definition: Common.h:9

Member Data Documentation

◆ m_handoff

omt::ThreadHandoff OscarMTProducer::m_handoff
private

Definition at line 61 of file OscarMTProducer.cc.

Referenced by beginRun(), endRun(), produce(), and ~OscarMTProducer().

◆ m_masterThread

const OscarMTMasterThread* OscarMTProducer::m_masterThread
private

Definition at line 63 of file OscarMTProducer.cc.

Referenced by beginRun(), and produce().

◆ m_psetID

const edm::ParameterSetID OscarMTProducer::m_psetID
private

Definition at line 64 of file OscarMTProducer.cc.

Referenced by beginRun().

◆ m_runManagerWorker

std::unique_ptr<RunManagerMTWorker> OscarMTProducer::m_runManagerWorker
private

Definition at line 62 of file OscarMTProducer.cc.

Referenced by beginRun(), endRun(), produce(), and ~OscarMTProducer().

◆ m_verbose

int OscarMTProducer::m_verbose
private

Definition at line 65 of file OscarMTProducer.cc.

Referenced by produce().

◆ s_masterThread

const OscarMTMasterThread * OscarMTProducer::s_masterThread = nullptr
staticprivate

Definition at line 66 of file OscarMTProducer.cc.

Referenced by initializeGlobalCache().

◆ s_psetID

edm::ParameterSetID OscarMTProducer::s_psetID {}
staticprivate

Definition at line 67 of file OscarMTProducer.cc.

Referenced by beginRun(), and initializeGlobalCache().