CMS 3D CMS Logo

Classes | Typedefs | Functions | Variables
interprocess_random.cc File Reference
#include "boost/program_options.hpp"
#include <atomic>
#include <csignal>
#include <iostream>
#include <string>
#include <thread>
#include "FWCore/TestProcessor/interface/TestProcessor.h"
#include "DataFormats/TestObjects/interface/ToyProducts.h"
#include "DataFormats/Common/interface/RandomNumberGeneratorState.h"
#include "FWCore/Services/interface/ExternalRandomNumberGeneratorService.h"
#include "FWCore/SharedMemory/interface/WriteBuffer.h"
#include "FWCore/SharedMemory/interface/WorkerChannel.h"
#include "FWCore/SharedMemory/interface/ROOTSerializer.h"
#include "FWCore/SharedMemory/interface/ReadBuffer.h"
#include "FWCore/SharedMemory/interface/ROOTDeserializer.h"
#include "FWCore/SharedMemory/interface/WorkerMonitorThread.h"

Go to the source code of this file.

Classes

class  Harness
 

Typedefs

using SentType = std::pair< edmtest::IntProduct, edm::RandomNumberGeneratorState >
 

Functions

int main (int argc, char *argv[])
 

Variables

static char const *const kHelpCommandOpt = "help,h"
 
static char const *const kHelpOpt = "help"
 
static char const *const kMemoryNameCommandOpt = "memory-name,m"
 
static char const *const kMemoryNameOpt = "memory-name"
 
static char const *const kUniqueIDCommandOpt = "unique-id,i"
 
static char const *const kUniqueIDOpt = "unique-id"
 

Typedef Documentation

◆ SentType

using SentType = std::pair<edmtest::IntProduct, edm::RandomNumberGeneratorState>

Definition at line 31 of file interprocess_random.cc.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

===============================================================================================================================================================================================


variant2: for each run define phi-averaged A for normalization channel (Dref,16) and then, divide Rijk on it, i.e. get RRijk

eta=27

eta=25

eta=23

eta=22

eta=21

eta=26

eta=24

eta=19

eta=17

eta=25

eta=23

eta=22

eta=21

eta=26

eta=24

eta=20

eta=19

eta=18

eta=27 L1=1

eta=25 L1=1

eta=23 L1=1

eta=22 L1=1

eta=21 L1=1

eta=29 L1=1

eta=26 L1=1

eta=24 L1=1

eta=20 L1=1

eta=19 L1=1

eta=18 L1=1

eta=17 L1=1

eta=28 L7=1

eta=27 L7=1

eta=25 L7=1

eta=23 L7=1

eta=22 L7=1

eta=21 L7=1

eta=26 L7=1

eta=24 L7=1

eta=20 L7=1

eta=19 L7=1

eta=18 L7=1

eta=17 L7=1

eta=27

eta=25

eta=23

eta=22

eta=21

eta=26

eta=24

eta=19

eta=17

eta=25

eta=23

eta=22

eta=21

eta=26

eta=24

eta=20

eta=19

eta=18

eta=27 L1=1

eta=25 L1=1

eta=23 L1=1

eta=22 L1=1

eta=21 L1=1

eta=26 L1=1

eta=24 L1=1

eta=20 L1=1

eta=19 L1=1

eta=18 L1=1

eta=17 L1=1

eta=28 L7=1

eta=27 L7=1

eta=25 L7=1

eta=23 L7=1

eta=22 L7=1

eta=21 L7=1

eta=26 L7=1

eta=24 L7=1

eta=20 L7=1

eta=19 L7=1

eta=18 L7=1

eta=17 L7=1

eta=27

eta=28

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

RBX:

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

RBX:

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

RBX:

Prepare maps of good/bad channels:

Prepare maps of good/bad channels:

Definition at line 53 of file interprocess_random.cc.

53  {
54  std::string descString(argv[0]);
55  descString += " [--";
56  descString += kMemoryNameOpt;
57  descString += "] memory_name";
58  boost::program_options::options_description desc(descString);
59 
60  desc.add_options()(kHelpCommandOpt, "produce help message")(
61  kMemoryNameCommandOpt, boost::program_options::value<std::string>(), "memory name")(
62  kUniqueIDCommandOpt, boost::program_options::value<std::string>(), "unique id");
63 
64  boost::program_options::positional_options_description p;
65  p.add(kMemoryNameOpt, 1);
66  p.add(kUniqueIDOpt, 2);
67 
68  boost::program_options::options_description all_options("All Options");
69  all_options.add(desc);
70 
71  boost::program_options::variables_map vm;
72  try {
73  store(boost::program_options::command_line_parser(argc, argv).options(all_options).positional(p).run(), vm);
74  notify(vm);
75  } catch (boost::program_options::error const& iException) {
76  std::cout << argv[0] << ": Error while trying to process command line arguments:\n"
77  << iException.what() << "\nFor usage and an options list, please do 'cmsRun --help'.";
78  return 1;
79  }
80 
81  if (vm.count(kHelpOpt)) {
82  std::cout << desc << std::endl;
83  return 0;
84  }
85 
86  if (!vm.count(kMemoryNameOpt)) {
87  std::cout << " no argument given" << std::endl;
88  return 1;
89  }
90 
91  if (!vm.count(kUniqueIDOpt)) {
92  std::cout << " no second argument given" << std::endl;
93  return 1;
94  }
95 
96  WorkerMonitorThread monitorThread;
97 
98  monitorThread.startThread();
99 
100  CMS_SA_ALLOW try {
101  std::string const memoryName(vm[kMemoryNameOpt].as<std::string>());
102  std::string const uniqueID(vm[kUniqueIDOpt].as<std::string>());
103  {
104  //This class is holding the lock
105  WorkerChannel communicationChannel(memoryName, uniqueID);
106 
107  WriteBuffer sm_buffer{memoryName, communicationChannel.fromWorkerBufferInfo()};
108  ReadBuffer sm_readbuffer{std::string("Rand") + memoryName, communicationChannel.toWorkerBufferInfo()};
109  int counter = 0;
110 
111  //The lock must be released if there is a catastrophic signal
112  auto lockPtr = communicationChannel.accessLock();
113  monitorThread.setAction([lockPtr]() {
114  if (lockPtr) {
115  std::cerr << "SIGNAL CAUGHT: unlock\n";
116  lockPtr->unlock();
117  }
118  });
119 
120  using TCSerializer = ROOTSerializer<SentType, WriteBuffer>;
121  TCSerializer serializer(sm_buffer);
122  TCSerializer bl_serializer(sm_buffer);
123 
125  TCDeserializer random_deserializer(sm_readbuffer);
126 
127  std::cerr << uniqueID << " process: initializing " << std::endl;
128  int nlines;
129  std::cin >> nlines;
130 
132  for (int i = 0; i < nlines; ++i) {
133  std::string c;
134  std::getline(std::cin, c);
135  std::cerr << c << "\n";
136  configuration += c + "\n";
137  }
138 
140  auto serviceToken =
141  edm::ServiceRegistry::createContaining(std::unique_ptr<edm::RandomNumberGenerator>(randomService));
142 
143  Harness harness(configuration, serviceToken);
144 
145  //Either ROOT or the Framework are overriding the signal handlers
146  monitorThread.setupSignalHandling();
147 
148  std::cerr << uniqueID << " process: done initializing" << std::endl;
149  communicationChannel.workerSetupDone();
150 
151  std::cerr << uniqueID << " process: waiting " << counter << std::endl;
152  communicationChannel.handleTransitions([&](edm::Transition iTransition, unsigned long long iTransitionID) {
153  ++counter;
154  switch (iTransition) {
156  std::cerr << uniqueID << " process: start beginLumi " << std::endl;
157  auto randState = random_deserializer.deserialize();
158  std::cerr << " state " << randState.seed_ << std::endl;
159  randomService->setState(randState.state_, randState.seed_);
160  SentType toSend;
161  toSend.first = harness.getBeginLumiValue(iTransitionID);
162  toSend.second.state_ = randomService->getState();
163  toSend.second.seed_ = randomService->mySeed();
164  bl_serializer.serialize(toSend);
165  std::cerr << uniqueID << " process: end beginLumi " << toSend.first.value << std::endl;
166 
167  break;
168  }
169  case edm::Transition::Event: {
170  std::cerr << uniqueID << " process: begin event " << counter << std::endl;
171  auto randState = random_deserializer.deserialize();
172  randomService->setState(randState.state_, randState.seed_);
173  SentType toSend;
174  toSend.first = harness.getEventValue();
175  toSend.second.state_ = randomService->getState();
176  toSend.second.seed_ = randomService->mySeed();
177  std::cerr << uniqueID << " process: end event " << counter << std::endl;
178 
179  serializer.serialize(toSend);
180  std::cerr << uniqueID << " process: " << toSend.first.value << " " << counter << std::endl;
181  //usleep(10000000);
182  break;
183  }
184  default: {
185  assert(false);
186  }
187  }
188  std::cerr << uniqueID << " process: notifying and waiting" << counter << std::endl;
189  });
190  }
191  } catch (std::exception const& iExcept) {
192  std::cerr << "caught exception \n" << iExcept.what() << "\n";
193  return 1;
194  } catch (...) {
195  std::cerr << "caught unknown exception";
196  return 1;
197  }
198  return 0;
199 }

References edm::shared_memory::WorkerChannel::accessLock(), dir2webdir::argc, cmsBatch::argv, cms::cuda::assert(), edm::BeginLuminosityBlock, c, EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, CMS_SA_ALLOW, ctppsRawToDigi_cff::configuration, counter, gather_cfg::cout, edm::ServiceRegistry::createContaining(), submitPVResolutionJobs::desc, relativeConstraints::error, edm::Event, cppFunctionSkipper::exception, edm::shared_memory::WorkerChannel::fromWorkerBufferInfo(), Harness::getBeginLumiValue(), Harness::getEventValue(), edm::ExternalRandomNumberGeneratorService::getState(), edm::shared_memory::WorkerChannel::handleTransitions(), mps_fire::i, kHelpCommandOpt, kHelpOpt, kMemoryNameCommandOpt, kMemoryNameOpt, kUniqueIDCommandOpt, kUniqueIDOpt, edm::ExternalRandomNumberGeneratorService::mySeed(), AlcaSiPixelAliHarvester0T_cff::options, AlCaHLTBitMon_ParallelJobs::p, writedatasetfile::run, edm::shared_memory::WorkerMonitorThread::setAction(), edm::ExternalRandomNumberGeneratorService::setState(), edm::shared_memory::WorkerMonitorThread::setupSignalHandling(), edm::shared_memory::WorkerMonitorThread::startThread(), AlCaHLTBitMon_QueryRunRegistry::string, edm::shared_memory::WorkerChannel::toWorkerBufferInfo(), and edm::shared_memory::WorkerChannel::workerSetupDone().

Variable Documentation

◆ kHelpCommandOpt

char const* const kHelpCommandOpt = "help,h"
static

Definition at line 27 of file interprocess_random.cc.

Referenced by main().

◆ kHelpOpt

char const* const kHelpOpt = "help"
static

Definition at line 26 of file interprocess_random.cc.

Referenced by main().

◆ kMemoryNameCommandOpt

char const* const kMemoryNameCommandOpt = "memory-name,m"
static

Definition at line 23 of file interprocess_random.cc.

Referenced by main().

◆ kMemoryNameOpt

char const* const kMemoryNameOpt = "memory-name"
static

Definition at line 22 of file interprocess_random.cc.

Referenced by main().

◆ kUniqueIDCommandOpt

char const* const kUniqueIDCommandOpt = "unique-id,i"
static

Definition at line 25 of file interprocess_random.cc.

Referenced by main().

◆ kUniqueIDOpt

char const* const kUniqueIDOpt = "unique-id"
static

Definition at line 24 of file interprocess_random.cc.

Referenced by main().

counter
Definition: counter.py:1
cmsBatch.argv
argv
Definition: cmsBatch.py:279
mps_fire.i
i
Definition: mps_fire.py:428
dir2webdir.argc
argc
Definition: dir2webdir.py:39
edm::Transition::Event
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
cms::cuda::assert
assert(be >=bs)
edm::shared_memory::WorkerMonitorThread
Definition: WorkerMonitorThread.h:32
kHelpOpt
static char const *const kHelpOpt
Definition: interprocess_random.cc:26
edm::ExternalRandomNumberGeneratorService::mySeed
std::uint32_t mySeed() const final
Definition: ExternalRandomNumberGeneratorService.cc:69
edm::shared_memory::ROOTSerializer
Definition: ROOTSerializer.h:31
Harness
Definition: interprocess.cc:28
relativeConstraints.error
error
Definition: relativeConstraints.py:53
CMS_SA_ALLOW
#define CMS_SA_ALLOW
Definition: thread_safety_macros.h:5
edm::shared_memory::ROOTDeserializer
Definition: ROOTDeserializer.h:31
edm::shared_memory::WriteBuffer
Definition: WriteBuffer.h:37
edm::shared_memory::WorkerMonitorThread::setupSignalHandling
void setupSignalHandling()
Sets the unix signal handler which communicates with the thread.
Definition: WorkerMonitorThread.cc:102
kUniqueIDCommandOpt
static char const *const kUniqueIDCommandOpt
Definition: interprocess_random.cc:25
edm::ExternalRandomNumberGeneratorService::setState
void setState(std::vector< unsigned long > const &, long seed)
Definition: ExternalRandomNumberGeneratorService.cc:24
edm::shared_memory::WorkerMonitorThread::startThread
void startThread()
Definition: WorkerMonitorThread.cc:78
edm::shared_memory::WorkerMonitorThread::setAction
void setAction(std::function< void()> iFunc)
Definition: WorkerMonitorThread.h:48
edm::Transition::BeginLuminosityBlock
kMemoryNameCommandOpt
static char const *const kMemoryNameCommandOpt
Definition: interprocess_random.cc:23
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
edm::Transition
Transition
Definition: Transition.h:12
ctppsRawToDigi_cff.configuration
configuration
Definition: ctppsRawToDigi_cff.py:11
counter
static std::atomic< unsigned int > counter
Definition: SharedResourceNames.cc:18
edm::shared_memory::WorkerChannel
Definition: WorkerChannel.h:35
kMemoryNameOpt
static char const *const kMemoryNameOpt
Definition: interprocess_random.cc:22
edm::ExternalRandomNumberGeneratorService::getState
std::vector< unsigned long > getState() const
Definition: ExternalRandomNumberGeneratorService.cc:32
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
writedatasetfile.run
run
Definition: writedatasetfile.py:27
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
AlcaSiPixelAliHarvester0T_cff.options
options
Definition: AlcaSiPixelAliHarvester0T_cff.py:42
kUniqueIDOpt
static char const *const kUniqueIDOpt
Definition: interprocess_random.cc:24
edm::shared_memory::ReadBuffer
Definition: ReadBuffer.h:34
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
edm::ExternalRandomNumberGeneratorService
Definition: ExternalRandomNumberGeneratorService.h:20
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
SentType
std::pair< edmtest::IntProduct, edm::RandomNumberGeneratorState > SentType
Definition: interprocess_random.cc:31
kHelpCommandOpt
static char const *const kHelpCommandOpt
Definition: interprocess_random.cc:27