ATLAS Offline Software
Loading...
Searching...
No Matches
EL::PrunDriver Class Referencefinal

a Driver to submit jobs via prun More...

#include <PrunDriver.h>

Inheritance diagram for EL::PrunDriver:
Collaboration diagram for EL::PrunDriver:

Public Member Functions

 PrunDriver ()
void testInvariant () const
SH::MetaObject * options ()
 the list of options to jobs with this driver
const SH::MetaObject * options () const
std::string submit (const Job &job, const std::string &location) const
 submit the given job with the given output location and wait for it to finish
std::string submitOnly (const Job &job, const std::string &location) const
 submit the given job with the given output location and return immediately

Static Public Member Functions

static void status (const std::string &location)
static void setState (const std::string &location, const std::string &task, const std::string &state)
static void resubmit (const std::string &location, const std::string &option)
 resubmit all failed sub-jobs for the job in the given location
static bool retrieve (const std::string &location)
 retrieve all the output for the job in the given location
static bool wait (const std::string &location, unsigned time=60)
 retrieve all the output for the job in the given location and wait until it is finished completely.
static void updateLocation (const std::string &location)
 update the internal location of files, after moving the submission directory
static void mergedOutputSave (Detail::ManagerData &data)
 create and save a sample handler assuming we created all the merged files at the requested locations
static void diskOutputSave (Detail::ManagerData &data)
 make the output sample handler for the given job or stream from the information stored in the histogram files.

Protected Member Functions

virtual::StatusCode doManagerStep (Detail::ManagerData &data) const override

Static Protected Attributes

static bool abortRetrieve
 this flag is set to true when the wait() function is running and a SIGINT is caught, meaning that control should be returned to the user as soon as possible.

Private Member Functions

::StatusCode doRetrieve (Detail::ManagerData &data) const
 ClassDef (EL::PrunDriver, 1)

Private Attributes

SH::MetaObject m_options
 members directly corresponding to accessors

Detailed Description

a Driver to submit jobs via prun

Definition at line 23 of file PrunDriver.h.

Constructor & Destructor Documentation

◆ PrunDriver()

EL::PrunDriver::PrunDriver ( )

Definition at line 501 of file PrunDriver.cxx.

502{
503 RCU_NEW_INVARIANT(this);
504}
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:221

Member Function Documentation

◆ ClassDef()

EL::PrunDriver::ClassDef ( EL::PrunDriver ,
1  )
private

◆ diskOutputSave()

void EL::Driver::diskOutputSave ( Detail::ManagerData & data)
staticinherited

make the output sample handler for the given job or stream from the information stored in the histogram files.

This is optional, but it is convenient for drivers that use (conventional) writers

Guarantee
basic
Failures
out of memory II
i/o errors

◆ doManagerStep()

StatusCode EL::PrunDriver::doManagerStep ( Detail::ManagerData & data) const
overrideprotected

Definition at line 506 of file PrunDriver.cxx.

508{
509 using namespace msgEventLoop;
511 switch (data.step)
512 {
514 {
515 const std::string jobELGDir = data.submitDir + "/elg";
516 const std::string runShFile = jobELGDir + "/runjob.sh";
517 //const std::string runShOrig = "$ROOTCOREBIN/data/EventLoopGrid/runjob.sh";
518 const std::string mergeShFile = jobELGDir + "/elg_merge";
519 //const std::string mergeShOrig =
520 // "$ROOTCOREBIN/user_scripts/EventLoopGrid/elg_merge";
521 const std::string runShOrig = PathResolverFindCalibFile("EventLoopGrid/runjob.sh");
522 const std::string mergeShOrig = PathResolverFindCalibFile("EventLoopGrid/elg_merge");
523
524 const std::string jobDefFile = jobELGDir + "/jobdef.root";
525 gSystem->Exec(Form("mkdir -p %s", jobELGDir.c_str()));
526 gSystem->Exec(Form("cp %s %s", runShOrig.c_str(), runShFile.c_str()));
527 gSystem->Exec(Form("chmod +x %s", runShFile.c_str()));
528 gSystem->Exec(Form("cp %s %s", mergeShOrig.c_str(), mergeShFile.c_str()));
529 gSystem->Exec(Form("chmod +x %s", mergeShFile.c_str()));
530
531 // create symbolic links for additionnal files/directories if any to ship to the grid
532 std::string listToShipToGrid = data.options.castString(EL::Job::optGridPrunShipAdditionalFilesOrDirs, "");
533 // parse the list of comma separated files and/or directories to ship to the grid
534 if (listToShipToGrid.size()){
536 "Creating symbolic links for additional files or directories to be sent to grid.\n"
537 "For root or heavy files you should also add their name (not the full path) to EL::Job::optUserFiles.\n"
538 "Otherwise prun ignores those files."
539 );
540
541 std::vector<std::string> vect_filesOrDirToShip;
542 for (auto&& part : std::views::split(listToShipToGrid, ',')) vect_filesOrDirToShip.emplace_back(part.begin(), part.end());
543 // Create symbolic links of files or directories to the submission directory
544 for (const std::string & fileOrDirToShip: vect_filesOrDirToShip){
545 ANA_MSG_INFO (("Creating symbolic link for: " +fileOrDirToShip).c_str());
546 RCU::Shell::exec("ln -sf " + fileOrDirToShip + " " + jobELGDir);
547 }
548 ANA_MSG_INFO ("Finished creation of symbolic links");
549 }
550
551 const SH::SampleHandler& sh = data.job->sampleHandler();
552
553 for (SH::SampleHandler::iterator s = sh.begin(); s != sh.end(); ++s) {
554 SH::MetaObject& meta = *(*s)->meta();
555 meta.fetchDefaults(data.options);
557 meta.setString("nc_outputs", outputFileNames(*data.job));
558 std::string outputSampleName = meta.castString("nc_outputSampleName");
559 if (outputSampleName.empty()) {
560 outputSampleName = "user.%nickname%.%in:name%";
561 }
562 meta.setString("nc_outDS", formatOutputName(meta, outputSampleName));
563 meta.setString("nc_inDS", meta.castString("nc_grid", (*s)->name()));
564 meta.setString("nc_writeInputToTxt", "IN:input.txt");
565 meta.setString("nc_match", meta.castString("nc_grid_filter"));
566 const std::string execstr = "runjob.sh " + (*s)->name();
567 meta.setString("nc_exec", execstr);
568 meta.setString("nc_framework", "EventLoopGrid");
569 }
570
571 saveJobDef(jobDefFile, *data.job, sh);
572
573 for (EL::Job::outputIter out = data.job->outputBegin();
574 out != data.job->outputEnd(); ++out) {
575 SH::SampleHandler shOut = outputSH(sh, out->label());
576 shOut.save(data.submitDir + "/output-" + out->label());
577 }
578 SH::SampleHandler shHist = outputSH(sh, "hist-output");
579 shHist.save(data.submitDir + "/output-hist");
580
581 TmpCd keepDir(jobELGDir);
582
583 processAllInState(sh, JobState::INIT, 0);
584
585 sh.save(data.submitDir + "/input");
586 data.submitted = true;
587 }
588 break;
589
591 {
592 ANA_CHECK (doRetrieve (data));
593 }
594 break;
595
596 default:
597 (void) true; // safe to do nothing
598 }
599 return ::StatusCode::SUCCESS;
600}
#define ANA_MSG_INFO(xmsg,...)
Macro printing info messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
static SH::MetaObject defaultOpts()
static void processAllInState(const SH::SampleHandler &sh, JobState::Enum state, const size_t nThreads)
std::string outputFileNames(const EL::Job &job)
static std::string formatOutputName(const SH::MetaObject &sampleMeta, const std::string &pattern)
static void saveJobDef(const std::string &fileName, const EL::Job &job, const SH::SampleHandler sh)
static SH::SampleHandler outputSH(const SH::SampleHandler &in, const std::string &outputLabel)
virtual::StatusCode doManagerStep(Detail::ManagerData &data) const
const OutputStream * outputIter
Definition Job.h:139
static const std::string optGridPrunShipAdditionalFilesOrDirs
Enables to ship additional files to the tarbal sent to the grid Should be a list of comma separated p...
Definition Job.h:473
::StatusCode doRetrieve(Detail::ManagerData &data) const
void fetchDefaults(const MetaObject &source)
fetch the meta-data from the given sample not present in this sample.
void setString(const std::string &name, const std::string &value)
set the meta-data string with the given name
std::string castString(const std::string &name, const std::string &def_val="", CastMode mode=CAST_ERROR_THROW) const
the meta-data string with the given name
void save(const std::string &directory) const
save the list of samples to the given directory
boost::transform_iterator< SamplePtrToRawSample, std::vector< std::shared_ptr< Sample > >::const_iterator > iterator
the iterator to use
@ doRetrieve
call the actual doRetrieve method
@ submitJob
do the actual job submission
Definition ManagerStep.h:92
void exec(const std::string &cmd)
effects: execute the given command guarantee: strong failures: out of memory II failures: system fail...
Definition ShellExec.cxx:27

◆ doRetrieve()

StatusCode EL::PrunDriver::doRetrieve ( Detail::ManagerData & data) const
private

Definition at line 602 of file PrunDriver.cxx.

603{
604 RCU_READ_INVARIANT(this);
605 RCU_REQUIRE(not data.submitDir.empty());
606
607 TmpCd tmpDir(data.submitDir);
608
609 SH::SampleHandler sh;
610 sh.load("input");
611 RCU_ASSERT(sh.size());
612
613 const size_t nRunThreads = options()->castDouble("nc_run_threads", 0);
614 const size_t nDlThreads = options()->castDouble("nc_download_threads", 0);
615 processAllInState(sh, JobState::INIT, 0);
616 processAllInState(sh, JobState::RUN, nRunThreads);
617 processAllInState(sh, JobState::DOWNLOAD, nDlThreads);
618 processAllInState(sh, JobState::MERGE, 0);
619
620 sh.save("input");
621
622 std::cout << std::endl;
623
624 bool allDone = true;
625 for (SH::SampleHandler::iterator s = sh.begin(); s != sh.end(); ++s) {
626 JobState::Enum state = sampleState(*s);
627 std::string details = (*s)->meta()->castString("nc_ELG_state_details", "", SH::MetaObject::CAST_NOCAST_DEFAULT);
628 if (not details.empty()) { details = '(' + details + ')'; }
629
630 std::cout << (*s)->name() << "\t";
631 switch (state) {
632 case JobState::INIT:
633 case JobState::RUN:
634 case JobState::DOWNLOAD:
635 case JobState::MERGE:
636 std::cout << JobState::name[state] << "\t";
637 break;
638 case JobState::FINISHED:
639 std::cout << "\033[1;32m" << JobState::name[state] << "\033[0m\t";
640 break;
641 case JobState::FAILED:
642 std::cout << "\033[1;31m" << JobState::name[state] << "\033[0m\t";
643 break;
644 }
645 std::cout << details << std::endl;
646
647 allDone &= (state == JobState::FINISHED || state == JobState::FAILED);
648 }
649
650 std::cout << std::endl;
651
652 data.retrieved = true;
653 data.completed = allDone;
654 return ::StatusCode::SUCCESS;
655}
#define RCU_ASSERT(x)
Definition Assert.h:210
#define RCU_REQUIRE(x)
Definition Assert.h:196
#define RCU_READ_INVARIANT(x)
Definition Assert.h:217
static JobState::Enum sampleState(SH::Sample *sample)
SH::MetaObject * options()
the list of options to jobs with this driver
double castDouble(const std::string &name, double def_val=0, CastMode mode=CAST_ERROR_THROW) const
the meta-data double with the given name
@ CAST_NOCAST_DEFAULT
cast and return the default value if the input has the wrong type
Definition MetaObject.h:70

◆ mergedOutputSave()

void EL::Driver::mergedOutputSave ( Detail::ManagerData & data)
staticinherited

create and save a sample handler assuming we created all the merged files at the requested locations

This is optional, but it is convenient for drivers that want to keep their outputs locally.

Guarantee
basic
Failures
out of memory II
i/o errors

◆ options() [1/2]

SH::MetaObject * EL::Driver::options ( )
inherited

the list of options to jobs with this driver

Guarantee
no-fail
Postcondition
result != 0

◆ options() [2/2]

const SH::MetaObject * EL::Driver::options ( ) const
inherited

◆ resubmit()

void EL::Driver::resubmit ( const std::string & location,
const std::string & option )
staticinherited

resubmit all failed sub-jobs for the job in the given location

\parm option driver-specific option string selecting which jobs to resubmit (and how)

Guarantee
basic, may partially resubmit
Failures
out of memory III
job resubmission errors
job can't be read
job was made with different driver

◆ retrieve()

bool EL::Driver::retrieve ( const std::string & location)
staticinherited

retrieve all the output for the job in the given location

While job failures will cause this method to fail you can typically retry it multiple times if you can use partial results.

Returns
whether the job completed successfully
Guarantee
basic, may partially retrieve
Failures
out of memory III
job failures
job can't be read
job was made with different driver

◆ setState()

void EL::PrunDriver::setState ( const std::string & location,
const std::string & task,
const std::string & state )
static

Definition at line 675 of file PrunDriver.cxx.

678{
679 RCU_REQUIRE(not location.empty());
680 RCU_REQUIRE(not task.empty());
681 RCU_REQUIRE(not state.empty());
682 TmpCd tmpDir(location);
683 SH::SampleHandler sh;
684 sh.load("input");
685 RCU_ASSERT(sh.size());
686 if (not sh.get(task)) {
687 std::cout << "Unknown task: " << task << std::endl;
688 std::cout << "Choose one of: " << std::endl;
689 sh.print();
690 return;
691 }
692 JobState::parse(state);
693 sh.get(task)->meta()->setString("nc_ELG_state", state);
694 sh.save("input");
695}

◆ status()

void EL::PrunDriver::status ( const std::string & location)
static

Definition at line 657 of file PrunDriver.cxx.

658{
659 RCU_REQUIRE(not location.empty());
660 TmpCd tmpDir(location);
661 SH::SampleHandler sh;
662 sh.load("input");
663 RCU_ASSERT(sh.size());
664 processAllInState(sh, JobState::RUN, 0);
665 sh.save("input");
666 for (SH::SampleHandler::iterator s = sh.begin(); s != sh.end(); ++s) {
667 JobState::Enum state = sampleState(*s);
668 std::string details = (*s)->meta()->castString("nc_ELG_state_details", "", SH::MetaObject::CAST_NOCAST_DEFAULT);
669 if (not details.empty()) { details = '(' + details + ')'; }
670 std::cout << (*s)->name() << "\t" << JobState::name[state]
671 << "\t" << details << std::endl;
672 }
673}

◆ submit()

std::string EL::Driver::submit ( const Job & job,
const std::string & location ) const
inherited

submit the given job with the given output location and wait for it to finish

This is mostly for small jobs and backward compatibility. For longer jobs use submitOnly instead.

Returns
The actual location of the submit directory, if the job was configured to generate a unique directory.
Guarantee
basic, may partially submit
Failures
out of memory II
Failures
can't create directory at location
submission errors

◆ submitOnly()

std::string EL::Driver::submitOnly ( const Job & job,
const std::string & location ) const
inherited

submit the given job with the given output location and return immediately

This method allows you to submit jobs to your local batch system, log out and at a later point log back in again.

Returns
The actual location of the submit directory, if the job was configured to generate a unique directory.
Guarantee
basic, may partially submit
Failures
out of memory II
can't create directory at location
submission errors \warn not all drivers support this. some will do all their work in the submit function. \warn you normally need to call wait() or retrieve() before you can use the output.

◆ testInvariant()

void EL::PrunDriver::testInvariant ( ) const

Definition at line 498 of file PrunDriver.cxx.

499{}

◆ updateLocation()

void EL::Driver::updateLocation ( const std::string & location)
staticinherited

update the internal location of files, after moving the submission directory

Guarantee
basic, may update partially
Failures
out of memory II \warn only move the submission directory after all your jobs are finished, or the results will be unpredictable

◆ wait()

bool EL::Driver::wait ( const std::string & location,
unsigned time = 60 )
staticinherited

retrieve all the output for the job in the given location and wait until it is finished completely.

poll the output every time seconds.

While job failures will cause this method to fail you can typically retry it multiple times if you can use partial results.

Typically sleeping for 60 seconds is an appropriate interval, but if it doesn't work for you, you can change it here.

Guarantee
basic, may partially retrieve
Failures
out of memory III
job failures
job can't be read
job was made with different driver

Member Data Documentation

◆ abortRetrieve

bool EL::Driver::abortRetrieve
staticprotectedinherited

this flag is set to true when the wait() function is running and a SIGINT is caught, meaning that control should be returned to the user as soon as possible.

drivers can use it to abort long running operations in doRetrieve before completion

Definition at line 212 of file Driver.h.

◆ m_options

SH::MetaObject EL::Driver::m_options
privateinherited

members directly corresponding to accessors

Definition at line 233 of file Driver.h.


The documentation for this class was generated from the following files: