CMS 3D CMS Logo

Classes | Typedefs | Functions | Variables
externalGenerator.cc File Reference
#include "boost/program_options.hpp"
#include <atomic>
#include <csignal>
#include <iostream>
#include <string>
#include <thread>
#include <memory>
#include <filesystem>
#include <ctime>
#include "FWCore/TestProcessor/interface/TestProcessor.h"
#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/GenLumiInfoHeader.h"
#include "SimDataFormats/GeneratorProducts/interface/GenLumiInfoProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/ExternalGeneratorEventInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/ExternalGeneratorLumiInfo.h"
#include "FWCore/Services/interface/ExternalRandomNumberGeneratorService.h"
#include "FWCore/SharedMemory/interface/WriteBuffer.h"
#include "FWCore/SharedMemory/interface/ReadBuffer.h"
#include "FWCore/SharedMemory/interface/WorkerChannel.h"
#include "FWCore/SharedMemory/interface/ROOTSerializer.h"
#include "FWCore/SharedMemory/interface/ROOTDeserializer.h"
#include "FWCore/SharedMemory/interface/WorkerMonitorThread.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

Go to the source code of this file.

Classes

class  Harness
 

Typedefs

template<typename T >
using Serializer = ROOTSerializer< T, WriteBuffer >
 

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"
 
static char const *const kVerboseCommandOpt = "verbose,v"
 
static char const *const kVerboseOpt = "verbose"
 
static std::string s_uniqueID
 

Typedef Documentation

◆ Serializer

template<typename T >
using Serializer = ROOTSerializer<T, WriteBuffer>

Definition at line 98 of file externalGenerator.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:

Sticking ADC counts in neughbouring TS for HB:

Sticking ADC counts in neughbouring TS for HE:

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:

Prepare maps of good/bad channels:

Prepare maps of good/bad channels:

Definition at line 112 of file externalGenerator.cc.

References edm::shared_memory::WorkerChannel::accessLock(), dir2webdir::argc, GCPpyPlots::argv, cms::cuda::assert(), edm::BeginLuminosityBlock, edm::BeginRun, DummyCfis::c, DMR_cfg::cerr, CMS_SA_ALLOW, JetHT_cfg::configuration, counter, gather_cfg::cout, edm::ServiceRegistry::createContaining(), data, submitPVResolutionJobs::desc, edm::shared_memory::ROOTDeserializer< T, READBUFFER >::deserialize(), edm::EndLuminosityBlock, edm::EndRun, relativeConstraints::error, edm::Event, cppFunctionSkipper::exception, edm::shared_memory::WorkerChannel::fromWorkerBufferInfo(), Harness::getBeginLumiValue(), Harness::getEndLumiValue(), Harness::getEndRunValue(), Harness::getEventValue(), edm::ExternalRandomNumberGeneratorService::getState(), edm::shared_memory::WorkerChannel::handleTransitions(), mps_fire::i, kHelpCommandOpt, kHelpOpt, kMemoryNameCommandOpt, kMemoryNameOpt, kUniqueIDCommandOpt, kUniqueIDOpt, kVerboseCommandOpt, kVerboseOpt, edm::ExternalRandomNumberGeneratorService::mySeed(), AlcaSiPixelAliHarvester0T_cff::options, AlCaHLTBitMon_ParallelJobs::p, castor_dqm_sourceclient_file_cfg::path, writedatasetfile::run, alignCSCRings::s, s_uniqueID, edm::shared_memory::ROOTSerializer< T, WRITEBUFFER >::serialize(), 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(), verbose, and edm::shared_memory::WorkerChannel::workerSetupDone().

112  {
113  std::string descString(argv[0]);
114  descString += " [--";
115  descString += kMemoryNameOpt;
116  descString += "] memory_name";
117  boost::program_options::options_description desc(descString);
118 
119  desc.add_options()(kHelpCommandOpt, "produce help message")(
120  kMemoryNameCommandOpt, boost::program_options::value<std::string>(), "memory name")(
121  kUniqueIDCommandOpt, boost::program_options::value<std::string>(), "unique id")(kVerboseCommandOpt,
122  "verbose output");
123 
124  boost::program_options::positional_options_description p;
125  p.add(kMemoryNameOpt, 1);
126  p.add(kUniqueIDOpt, 2);
127 
128  boost::program_options::options_description all_options("All Options");
129  all_options.add(desc);
130 
131  boost::program_options::variables_map vm;
132  try {
133  store(boost::program_options::command_line_parser(argc, argv).options(all_options).positional(p).run(), vm);
134  notify(vm);
135  } catch (boost::program_options::error const& iException) {
136  std::cout << argv[0] << ": Error while trying to process command line arguments:\n"
137  << iException.what() << "\nFor usage and an options list, please do 'cmsRun --help'.";
138  return 1;
139  }
140 
141  if (vm.count(kHelpOpt)) {
142  std::cout << desc << std::endl;
143  return 0;
144  }
145 
146  bool verbose = false;
147  if (vm.count(kVerboseOpt)) {
148  verbose = true;
149  }
150 
151  if (!vm.count(kMemoryNameOpt)) {
152  std::cout << " no argument given" << std::endl;
153  return 1;
154  }
155 
156  if (!vm.count(kUniqueIDOpt)) {
157  std::cout << " no second argument given" << std::endl;
158  return 1;
159  }
160 
161  using namespace std::string_literals;
162  using namespace std::filesystem;
163 
164  auto newDir = path("thread"s + vm[kUniqueIDOpt].as<std::string>());
165  create_directory(newDir);
166  current_path(newDir);
167 
168  WorkerMonitorThread monitorThread;
169 
170  monitorThread.startThread();
171 
172  std::string presentState = "setting up communicationChannel";
173 
174  CMS_SA_ALLOW try {
175  std::string const memoryName(vm[kMemoryNameOpt].as<std::string>());
176  std::string const uniqueID(vm[kUniqueIDOpt].as<std::string>());
177  s_uniqueID = uniqueID;
178  {
179  //This class is holding the lock
180  WorkerChannel communicationChannel(memoryName, uniqueID);
181 
182  presentState = "setting up read/write buffers";
183  WriteBuffer sm_buffer{memoryName, communicationChannel.fromWorkerBufferInfo()};
184  ReadBuffer sm_readbuffer{std::string("Rand") + memoryName, communicationChannel.toWorkerBufferInfo()};
185  int counter = 0;
186 
187  presentState = "setting up monitor thread";
188  //The lock must be released if there is a catastrophic signal
189  auto lockPtr = communicationChannel.accessLock();
190 
191  monitorThread.setAction([lockPtr]() {
192  if (lockPtr) {
193  std::cerr << s_uniqueID << " process: SIGNAL CAUGHT: unlock " << formattedTime().data() << "\n";
194  lockPtr->unlock();
195  }
196  });
197 
198  presentState = "setting up termination handler";
199  //be sure to unset the address of the shared lock before the lock goes away
200  s_sharedLock = lockPtr;
201  auto unsetLockPtr = [](void*) { s_sharedLock = nullptr; };
202  std::unique_ptr<decltype(s_sharedLock), decltype(unsetLockPtr)> sharedLockGuard{&s_sharedLock, unsetLockPtr};
203  std::atexit(atexit_handler);
204  auto releaseLock = []() {
205  if (s_sharedLock) {
206  std::cerr << s_uniqueID << " process: terminate called: unlock " << formattedTime().data() << "\n";
207  s_sharedLock->unlock();
208  s_sharedLock = nullptr;
209  //deactivate the abort signal
210 
211  struct sigaction act;
212  act.sa_sigaction = nullptr;
213  act.sa_flags = SA_SIGINFO;
214  sigemptyset(&act.sa_mask);
215  sigaction(SIGABRT, &act, nullptr);
216  std::abort();
217  }
218  };
219  std::set_terminate(releaseLock);
220 
221  presentState = "setting up serializers";
222  Serializer<ExternalGeneratorEventInfo> serializer(sm_buffer);
223  Serializer<ExternalGeneratorLumiInfo> bl_serializer(sm_buffer);
224  Serializer<GenLumiInfoProduct> el_serializer(sm_buffer);
225  Serializer<GenRunInfoProduct> er_serializer(sm_buffer);
226 
227  ROOTDeserializer<edm::RandomNumberGeneratorState, ReadBuffer> random_deserializer(sm_readbuffer);
228 
229  presentState = "reading configuration";
230  std::cerr << uniqueID << " process: initializing " << formattedTime().data() << std::endl;
231  int nlines;
232  std::cin >> nlines;
233 
235  for (int i = 0; i < nlines; ++i) {
236  std::string c;
237  std::getline(std::cin, c);
238  if (verbose) {
239  std::cerr << c << "\n";
240  }
241  configuration += c + "\n";
242  }
243 
244  presentState = "setting up random number generator";
246  auto serviceToken =
247  edm::ServiceRegistry::createContaining(std::unique_ptr<edm::RandomNumberGenerator>(randomService));
248  Harness harness(configuration, serviceToken);
249 
250  //Some generator libraries override the signal handlers
251  monitorThread.setupSignalHandling();
252  std::set_terminate(releaseLock);
253 
254  if (verbose) {
255  std::cerr << uniqueID << " process: done initializing " << formattedTime().data() << std::endl;
256  }
257  presentState = "finished initialization";
258  communicationChannel.workerSetupDone();
259 
260  presentState = "waiting for transition";
261  if (verbose)
262  std::cerr << uniqueID << " process: waiting " << counter << " " << formattedTime().data() << std::endl;
263  communicationChannel.handleTransitions([&](edm::Transition iTransition, unsigned long long iTransitionID) {
264  ++counter;
265  switch (iTransition) {
267  presentState = "beginRun transition";
268  if (verbose)
269  std::cerr << uniqueID << " process: start beginRun " << formattedTime().data() << std::endl;
270  if (verbose)
271  std::cerr << uniqueID << " process: end beginRun " << formattedTime().data() << std::endl;
272 
273  break;
274  }
276  presentState = "begin lumi";
277  if (verbose)
278  std::cerr << uniqueID << " process: start beginLumi " << formattedTime().data() << std::endl;
279  auto randState = random_deserializer.deserialize();
280  presentState = "deserialized random state in begin lumi";
281  if (verbose)
282  std::cerr << uniqueID << " random " << randState.state_.size() << " " << randState.seed_ << std::endl;
283  randomService->setState(randState.state_, randState.seed_);
284  presentState = "processing begin lumi";
285  auto value = harness.getBeginLumiValue(iTransitionID);
286  value.randomState_.state_ = randomService->getState();
287  value.randomState_.seed_ = randomService->mySeed();
288 
289  presentState = "serialize lumi";
290  bl_serializer.serialize(value);
291  if (verbose)
292  std::cerr << uniqueID << " process: end beginLumi " << formattedTime().data() << std::endl;
293  if (verbose)
294  std::cerr << uniqueID << " rand " << value.randomState_.state_.size() << " " << value.randomState_.seed_
295  << std::endl;
296  break;
297  }
298  case edm::Transition::Event: {
299  presentState = "begin event";
300  if (verbose)
301  std::cerr << uniqueID << " process: event " << counter << " " << formattedTime().data() << std::endl;
302  presentState = "deserialized random state in event";
303  auto randState = random_deserializer.deserialize();
304  randomService->setState(randState.state_, randState.seed_);
305  presentState = "processing event";
306  auto value = harness.getEventValue();
307  value.randomState_.state_ = randomService->getState();
308  value.randomState_.seed_ = randomService->mySeed();
309 
310  if (verbose)
311  std::cerr << uniqueID << " process: event " << counter << " " << formattedTime().data() << std::endl;
312 
313  presentState = "serialize event";
314  serializer.serialize(value);
315  if (verbose)
316  std::cerr << uniqueID << " process: "
317  << " " << counter << std::endl;
318  //usleep(10000000);
319  break;
320  }
322  presentState = "begin end lumi";
323  if (verbose)
324  std::cerr << uniqueID << " process: start endLumi " << formattedTime().data() << std::endl;
325  presentState = "processing end lumi";
326  auto value = harness.getEndLumiValue();
327 
328  presentState = "serialize end lumi";
329  el_serializer.serialize(value);
330  if (verbose)
331  std::cerr << uniqueID << " process: end endLumi " << formattedTime().data() << std::endl;
332 
333  break;
334  }
336  presentState = "begin end run";
337  if (verbose)
338  std::cerr << uniqueID << " process: start endRun " << formattedTime().data() << std::endl;
339  presentState = "process end run";
340  auto value = harness.getEndRunValue();
341 
342  presentState = "serialize end run";
343  er_serializer.serialize(value);
344  if (verbose)
345  std::cerr << uniqueID << " process: end endRun " << formattedTime().data() << std::endl;
346 
347  break;
348  }
349  default: {
350  assert(false);
351  }
352  }
353  presentState = "notifying and waiting after " + presentState;
354  if (verbose)
355  std::cerr << uniqueID << " process: notifying and waiting " << counter << " " << std::endl;
356  });
357  }
358  } catch (std::exception const& iExcept) {
359  std::cerr << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
360  << s_uniqueID << " process: caught exception \n"
361  << iExcept.what() << " " << formattedTime().data() << "\n"
362  << " while " << presentState << "\n"
363  << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
364  return 1;
365  } catch (...) {
366  std::cerr << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
367  << s_uniqueID << " process: caught unknown exception " << formattedTime().data() << "\n while "
368  << presentState << "\n"
369  << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
370  return 1;
371  }
372  return 0;
373 }
#define CMS_SA_ALLOW
bool verbose
static char const *const kHelpOpt
static char const *const kMemoryNameCommandOpt
void setState(std::vector< unsigned long > const &, long seed)
void setupSignalHandling()
Sets the unix signal handler which communicates with the thread.
static char const *const kMemoryNameOpt
static std::string s_uniqueID
void setAction(std::function< void()> iFunc)
assert(be >=bs)
static char const *const kHelpCommandOpt
dictionary configuration
Definition: JetHT_cfg.py:38
Transition
Definition: Transition.h:12
static ServiceToken createContaining(std::unique_ptr< T > iService)
create a service token that holds the service defined by iService
static char const *const kVerboseOpt
Definition: value.py:1
static char const *const kVerboseCommandOpt
static char const *const kUniqueIDCommandOpt
static char const *const kUniqueIDOpt
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
static std::atomic< unsigned int > counter

Variable Documentation

◆ kHelpCommandOpt

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

Definition at line 38 of file externalGenerator.cc.

Referenced by main().

◆ kHelpOpt

char const* const kHelpOpt = "help"
static

Definition at line 37 of file externalGenerator.cc.

Referenced by main().

◆ kMemoryNameCommandOpt

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

Definition at line 34 of file externalGenerator.cc.

Referenced by main().

◆ kMemoryNameOpt

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

Definition at line 33 of file externalGenerator.cc.

Referenced by main().

◆ kUniqueIDCommandOpt

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

Definition at line 36 of file externalGenerator.cc.

Referenced by main().

◆ kUniqueIDOpt

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

Definition at line 35 of file externalGenerator.cc.

Referenced by main().

◆ kVerboseCommandOpt

char const* const kVerboseCommandOpt = "verbose,v"
static

Definition at line 40 of file externalGenerator.cc.

Referenced by main().

◆ kVerboseOpt

char const* const kVerboseOpt = "verbose"
static

Definition at line 39 of file externalGenerator.cc.

Referenced by main().

◆ s_uniqueID

std::string s_uniqueID
static

Definition at line 43 of file externalGenerator.cc.

Referenced by main().