1 #include "boost/program_options.hpp" 49 constexpr
char timeFormat[] =
"dd-Mon-yyyy hh:mm:ss TZN ";
50 constexpr
size_t kTimeSize =
sizeof(timeFormat);
51 std::array<char, kTimeSize> formattedTime() {
52 auto t =
time(
nullptr);
53 std::array<char, kTimeSize> ts;
56 std::strftime(ts.data(), ts.size(),
"%d-%b-%Y %H:%M:%S %Z", localtime_r(&
t, &timebuf));
68 auto lumi = tester_.testBeginLuminosityBlock(iLumi);
76 auto event = tester_.test();
84 auto lumi = tester_.testEndLuminosityBlock();
89 auto run = tester_.testEndRun();
102 CMS_THREAD_SAFE boost::interprocess::scoped_lock<boost::interprocess::named_mutex>* s_sharedLock =
nullptr;
104 void atexit_handler() {
106 std::cerr <<
s_uniqueID <<
" process: early exit called: unlock " << formattedTime().data() <<
"\n";
107 s_sharedLock->unlock();
114 descString +=
" [--";
116 descString +=
"] memory_name";
117 boost::program_options::options_description
desc(descString);
124 boost::program_options::positional_options_description
p;
128 boost::program_options::options_description all_options(
"All Options");
129 all_options.add(
desc);
131 boost::program_options::variables_map vm;
133 store(boost::program_options::command_line_parser(
argc,
argv).
options(all_options).positional(
p).
run(), vm);
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'.";
152 std::cout <<
" no argument given" << std::endl;
157 std::cout <<
" no second argument given" << std::endl;
162 using namespace std::filesystem;
165 create_directory(newDir);
166 current_path(newDir);
172 std::string presentState =
"setting up communicationChannel";
182 presentState =
"setting up read/write buffers";
187 presentState =
"setting up monitor thread";
189 auto lockPtr = communicationChannel.
accessLock();
193 std::cerr <<
s_uniqueID <<
" process: SIGNAL CAUGHT: unlock " << formattedTime().data() <<
"\n";
198 presentState =
"setting up termination handler";
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 = []() {
206 std::cerr <<
s_uniqueID <<
" process: terminate called: unlock " << formattedTime().data() <<
"\n";
207 s_sharedLock->unlock();
208 s_sharedLock =
nullptr;
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);
219 std::set_terminate(releaseLock);
221 presentState =
"setting up serializers";
229 presentState =
"reading configuration";
230 std::cerr << uniqueID <<
" process: initializing " << formattedTime().data() << std::endl;
235 for (
int i = 0;
i < nlines; ++
i) {
237 std::getline(std::cin,
c);
244 presentState =
"setting up random number generator";
252 std::set_terminate(releaseLock);
255 std::cerr << uniqueID <<
" process: done initializing " << formattedTime().data() << std::endl;
257 presentState =
"finished initialization";
260 presentState =
"waiting for transition";
262 std::cerr << uniqueID <<
" process: waiting " <<
counter <<
" " << formattedTime().data() << std::endl;
265 switch (iTransition) {
267 presentState =
"beginRun transition";
269 std::cerr << uniqueID <<
" process: start beginRun " << formattedTime().
data() << std::endl;
271 std::cerr << uniqueID <<
" process: end beginRun " << formattedTime().
data() << std::endl;
276 presentState =
"begin lumi";
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";
282 std::cerr << uniqueID <<
" random " << randState.state_.size() <<
" " << randState.seed_ << std::endl;
283 randomService->
setState(randState.state_, randState.seed_);
284 presentState =
"processing begin lumi";
287 value.randomState_.seed_ = randomService->
mySeed();
289 presentState =
"serialize lumi";
292 std::cerr << uniqueID <<
" process: end beginLumi " << formattedTime().data() << std::endl;
294 std::cerr << uniqueID <<
" rand " <<
value.randomState_.state_.size() <<
" " <<
value.randomState_.seed_
299 presentState =
"begin event";
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";
308 value.randomState_.seed_ = randomService->
mySeed();
311 std::cerr << uniqueID <<
" process: event " <<
counter <<
" " << formattedTime().data() << std::endl;
313 presentState =
"serialize event";
317 <<
" " <<
counter << std::endl;
322 presentState =
"begin end lumi";
324 std::cerr << uniqueID <<
" process: start endLumi " << formattedTime().data() << std::endl;
325 presentState =
"processing end lumi";
328 presentState =
"serialize end lumi";
331 std::cerr << uniqueID <<
" process: end endLumi " << formattedTime().data() << std::endl;
336 presentState =
"begin end run";
338 std::cerr << uniqueID <<
" process: start endRun " << formattedTime().data() << std::endl;
339 presentState =
"process end run";
342 presentState =
"serialize end run";
345 std::cerr << uniqueID <<
" process: end endRun " << formattedTime().data() << std::endl;
353 presentState =
"notifying and waiting after " + presentState;
355 std::cerr << uniqueID <<
" process: notifying and waiting " <<
counter <<
" " << std::endl;
359 std::cerr <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" 360 <<
s_uniqueID <<
" process: caught exception \n" 361 << iExcept.what() <<
" " << formattedTime().data() <<
"\n" 362 <<
" while " << presentState <<
"\n" 363 <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
366 std::cerr <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" 367 <<
s_uniqueID <<
" process: caught unknown exception " << formattedTime().data() <<
"\n while " 368 << presentState <<
"\n" 369 <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
edmtest::ThingCollection getEndLumiValue()
std::vector< unsigned long > getState() const
edmtest::ThingCollection getEventValue()
boost::interprocess::scoped_lock< boost::interprocess::named_mutex > * accessLock()
the lock is made accessible so that the WorkerMonitorThread can be used to unlock it in the event of ...
ExternalGeneratorEventInfo getEventValue()
static char const *const kHelpOpt
static char const *const kMemoryNameCommandOpt
edmtest::ThingCollection getBeginLumiValue(unsigned int iLumi)
void setState(std::vector< unsigned long > const &, long seed)
void serialize(T &iValue)
void handleTransitions(F &&iF)
GenRunInfoProduct getEndRunValue()
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)
static char const *const kHelpCommandOpt
GenLumiInfoProduct getEndLumiValue()
GenEventInfoProduct eventInfo_
BufferInfo * toWorkerBufferInfo()
This can be used with ReadBuffer to keep Controller and Worker in sync.
void workerSetupDone()
Matches the ControllerChannel::setupWorker call.
static ServiceToken createContaining(std::unique_ptr< T > iService)
create a service token that holds the service defined by iService
static char const *const kVerboseOpt
ExternalGeneratorLumiInfo getBeginLumiValue(unsigned int iLumi)
std::uint32_t mySeed() const final
static char const *const kVerboseCommandOpt
BufferInfo * fromWorkerBufferInfo()
This can be used with WriteBuffer to keep Controller and Worker in sync.
GenLumiInfoHeader header_
static char const *const kUniqueIDCommandOpt
Harness(std::string const &iConfig, edm::ServiceToken iToken)
edmtest::ThingCollection getEndRunValue()
static char const *const kUniqueIDOpt
char data[epos_bytes_allocation]
static std::atomic< unsigned int > counter
int main(int argc, char *argv[])