CMS 3D CMS Logo

Classes | Functions | Variables
interprocess.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/TestObjects/interface/ThingCollection.h"
#include "FWCore/SharedMemory/interface/WriteBuffer.h"
#include "FWCore/SharedMemory/interface/WorkerChannel.h"
#include "FWCore/SharedMemory/interface/ROOTSerializer.h"
#include "FWCore/SharedMemory/interface/WorkerMonitorThread.h"

Go to the source code of this file.

Classes

class  Harness
 

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"
 

Function Documentation

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

Definition at line 61 of file interprocess.cc.

References edm::shared_memory::WorkerChannel::accessLock(), edm::BeginLuminosityBlock, edm::BeginRun, EnergyCorrector::c, MessageLogger_cfi::cerr, cmsCodeRulesChecker::configuration, counter, gather_cfg::cout, edm::EndLuminosityBlock, edm::EndRun, relativeConstraints::error, edm::Event, cppFunctionSkipper::exception, edm::shared_memory::WorkerChannel::fromWorkerBufferInfo(), Harness::getBeginLumiValue(), Harness::getBeginRunValue(), Harness::getEndLumiValue(), Harness::getEndRunValue(), Harness::getEventValue(), edm::shared_memory::WorkerChannel::handleTransitions(), mps_fire::i, kHelpCommandOpt, kHelpOpt, kMemoryNameCommandOpt, kMemoryNameOpt, kUniqueIDCommandOpt, kUniqueIDOpt, AlcaSiPixelAliHarvester0T_cff::options, AlCaHLTBitMon_ParallelJobs::p, writedatasetfile::run, edm::shared_memory::WorkerMonitorThread::setAction(), edm::shared_memory::WorkerMonitorThread::setupSignalHandling(), edm::shared_memory::WorkerMonitorThread::startThread(), AlCaHLTBitMon_QueryRunRegistry::string, and edm::shared_memory::WorkerChannel::workerSetupDone().

61  {
62  std::string descString(argv[0]);
63  descString += " [--";
64  descString += kMemoryNameOpt;
65  descString += "] memory_name";
66  boost::program_options::options_description desc(descString);
67 
68  desc.add_options()(kHelpCommandOpt, "produce help message")(
69  kMemoryNameCommandOpt, boost::program_options::value<std::string>(), "memory name")(
70  kUniqueIDCommandOpt, boost::program_options::value<std::string>(), "unique id");
71 
72  boost::program_options::positional_options_description p;
73  p.add(kMemoryNameOpt, 1);
74  p.add(kUniqueIDOpt, 2);
75 
76  boost::program_options::options_description all_options("All Options");
77  all_options.add(desc);
78 
79  boost::program_options::variables_map vm;
80  try {
81  store(boost::program_options::command_line_parser(argc, argv).options(all_options).positional(p).run(), vm);
82  notify(vm);
83  } catch (boost::program_options::error const& iException) {
84  std::cout << argv[0] << ": Error while trying to process command line arguments:\n"
85  << iException.what() << "\nFor usage and an options list, please do 'cmsRun --help'.";
86  return 1;
87  }
88 
89  if (vm.count(kHelpOpt)) {
90  std::cout << desc << std::endl;
91  return 0;
92  }
93 
94  if (!vm.count(kMemoryNameOpt)) {
95  std::cout << " no argument given" << std::endl;
96  return 1;
97  }
98 
99  if (!vm.count(kUniqueIDOpt)) {
100  std::cout << " no second argument given" << std::endl;
101  return 1;
102  }
103 
104  WorkerMonitorThread monitorThread;
105 
106  monitorThread.startThread();
107 
108  try {
109  std::string const memoryName(vm[kMemoryNameOpt].as<std::string>());
110  std::string const uniqueID(vm[kUniqueIDOpt].as<std::string>());
111  {
112  //using namespace boost::interprocess;
113  //auto controlNameUnique = unique_name(memoryName, uniqueID);
114 
115  //This class is holding the lock
116  WorkerChannel communicationChannel(memoryName, uniqueID);
117 
118  WriteBuffer sm_buffer{memoryName, communicationChannel.fromWorkerBufferInfo()};
119  int counter = 0;
120 
121  //The lock must be released if there is a catastrophic signal
122  auto lockPtr = communicationChannel.accessLock();
123  monitorThread.setAction([lockPtr]() {
124  if (lockPtr) {
125  std::cerr << "SIGNAL CAUGHT: unlock\n";
126  lockPtr->unlock();
127  }
128  });
129 
131  TCSerializer serializer(sm_buffer);
132  TCSerializer br_serializer(sm_buffer);
133  TCSerializer bl_serializer(sm_buffer);
134  TCSerializer el_serializer(sm_buffer);
135  TCSerializer er_serializer(sm_buffer);
136 
137  std::cerr << uniqueID << " process: initializing " << std::endl;
138  int nlines;
139  std::cin >> nlines;
140 
142  for (int i = 0; i < nlines; ++i) {
143  std::string c;
144  std::getline(std::cin, c);
145  std::cerr << c << "\n";
146  configuration += c + "\n";
147  }
148 
149  Harness harness(configuration);
150 
151  //Either ROOT or the Framework are overriding the signal handlers
152  monitorThread.setupSignalHandling();
153 
154  std::cerr << uniqueID << " process: done initializing" << std::endl;
155  communicationChannel.workerSetupDone();
156 
157  std::cerr << uniqueID << " process: waiting " << counter << std::endl;
158  communicationChannel.handleTransitions([&](edm::Transition iTransition, unsigned long long iTransitionID) {
159  ++counter;
160  switch (iTransition) {
162  std::cerr << uniqueID << " process: start beginRun " << std::endl;
163  auto value = harness.getBeginRunValue(iTransitionID);
164 
165  br_serializer.serialize(value);
166  std::cerr << uniqueID << " process: end beginRun " << value.size() << std::endl;
167 
168  break;
169  }
171  std::cerr << uniqueID << " process: start beginLumi " << std::endl;
172  auto value = harness.getBeginLumiValue(iTransitionID);
173 
174  bl_serializer.serialize(value);
175  std::cerr << uniqueID << " process: end beginLumi " << value.size() << std::endl;
176 
177  break;
178  }
179  case edm::Transition::Event: {
180  std::cerr << uniqueID << " process: integrating " << counter << std::endl;
181  auto value = harness.getEventValue();
182 
183  std::cerr << uniqueID << " process: integrated " << counter << std::endl;
184 
185  serializer.serialize(value);
186  std::cerr << uniqueID << " process: " << value.size() << " " << counter << std::endl;
187  //usleep(10000000);
188  break;
189  }
191  std::cerr << uniqueID << " process: start endLumi " << std::endl;
192  auto value = harness.getEndLumiValue();
193 
194  el_serializer.serialize(value);
195  std::cerr << uniqueID << " process: end endLumi " << value.size() << std::endl;
196 
197  break;
198  }
200  std::cerr << uniqueID << " process: start endRun " << std::endl;
201  auto value = harness.getEndRunValue();
202 
203  er_serializer.serialize(value);
204  std::cerr << uniqueID << " process: end endRun " << value.size() << std::endl;
205 
206  break;
207  }
208  default: {
209  assert(false);
210  }
211  }
212  std::cerr << uniqueID << " process: notifying and waiting" << counter << std::endl;
213  });
214  }
215  } catch (std::exception const& iExcept) {
216  std::cerr << "caught exception \n" << iExcept.what() << "\n";
217  return 1;
218  } catch (...) {
219  std::cerr << "caught unknown exception";
220  return 1;
221  }
222  return 0;
223 }
void setupSignalHandling()
Sets the unix signal handler which communicates with the thread.
void setAction(std::function< void()> iFunc)
static char const *const kUniqueIDCommandOpt
Definition: interprocess.cc:21
static char const *const kUniqueIDOpt
Definition: interprocess.cc:20
Transition
Definition: Transition.h:12
Definition: value.py:1
static char const *const kMemoryNameOpt
Definition: interprocess.cc:18
static std::atomic< unsigned int > counter
static char const *const kMemoryNameCommandOpt
Definition: interprocess.cc:19
static char const *const kHelpOpt
Definition: interprocess.cc:22
static char const *const kHelpCommandOpt
Definition: interprocess.cc:23

Variable Documentation

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

Definition at line 23 of file interprocess.cc.

Referenced by main().

char const* const kHelpOpt = "help"
static

Definition at line 22 of file interprocess.cc.

Referenced by main().

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

Definition at line 19 of file interprocess.cc.

Referenced by main().

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

Definition at line 18 of file interprocess.cc.

Referenced by main().

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

Definition at line 21 of file interprocess.cc.

Referenced by main().

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

Definition at line 20 of file interprocess.cc.

Referenced by main().