Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

jobc::CmdLine Class Reference

Encapsulate the list of options set from the command line. More...

#include <CmdLine.h>

List of all members.

Public Member Functions

const std::list< std::string > & InFileList () const
const std::list< std::string > & XMLFileList () const
const std::list< std::string > & XMLDirList () const
const std::list< std::string > & EvtListFiles () const
const char * OutFileName () const
const char * XMLPath () const
const char * HistoFileName () const
int FirstRun () const
int FirstEvent () const
int Nevt () const
int NSkip () const
int NmemReport () const
int SizeLimit () const
int DumpOnException () const
void Usage () const
void Print () const
void SetupIoModule (io::ReadWriteModule &iomod, int *nevent) const
void Parse (int argc, char **argv)
void SetSIGHUP ()
bool HaveSIGHUP ()

Static Public Member Functions

CmdLineInstance ()

Private Member Functions

 CmdLine ()

Private Attributes

std::list< std::string > fInFileList
 Input data files.

std::list< std::string > fXMLFileList
 Input XML files.

std::list< std::string > fXMLDir
 XML directory to scan.

std::list< std::string > fEvtList
 Files containing event lists.

std::string fXMLPath
 XML path to search.

std::string fOutFileName
 Output data file name.

std::string fHistoFileName
 Histogram output file name.

int fFirstRun
 First run to process.

int fFirstEvent
 First event to process.

int fNevt
 Number of events to process.

int fNskip
 Number of events to skip.

int fNmemReport
 Frequency of memory reporting.

bool fSIGHUP
 Has SIGHUP signal been sent?

int fDumpOnException
 Dump core on JobCExceptions?

int fSizeLimit
 Max output file size.


Static Private Attributes

CmdLinefInstance = 0


Detailed Description

Encapsulate the list of options set from the command line.

Definition at line 16 of file CmdLine.h.


Constructor & Destructor Documentation

CmdLine::CmdLine  )  [private]
 

Definition at line 44 of file CmdLine.cxx.

Referenced by Instance().

00044                  :
00045   fOutFileName(""),
00046   fFirstRun   ( -1 ),
00047   fFirstEvent ( -1 ),
00048   fNevt       ( INT_MAX ),
00049   fNskip      ( 0  ),
00050   fNmemReport (-1  ),
00051   fSIGHUP     (false),
00052   fDumpOnException(0),
00053   fSizeLimit  ( 0 )
00054 { }


Member Function Documentation

int jobc::CmdLine::DumpOnException  )  const [inline]
 

Definition at line 35 of file CmdLine.h.

References fDumpOnException.

Referenced by jobc::Job::Run().

00035 { return fDumpOnException; }

const std::list<std::string>& jobc::CmdLine::EvtListFiles  )  const [inline]
 

Definition at line 23 of file CmdLine.h.

References fEvtList.

Referenced by SetupIoModule().

00023 {return fEvtList;    }

int jobc::CmdLine::FirstEvent  )  const [inline]
 

Definition at line 30 of file CmdLine.h.

References fFirstEvent.

Referenced by SetupIoModule().

00030 { return fFirstEvent; }

int jobc::CmdLine::FirstRun  )  const [inline]
 

Definition at line 29 of file CmdLine.h.

References fFirstRun.

Referenced by SetupIoModule().

00029 { return fFirstRun;   }

bool jobc::CmdLine::HaveSIGHUP  )  [inline]
 

Definition at line 46 of file CmdLine.h.

References fSIGHUP.

Referenced by jobc::Job::Run().

00046 { return fSIGHUP; }

const char* jobc::CmdLine::HistoFileName  )  const [inline]
 

Definition at line 27 of file CmdLine.h.

References fHistoFileName.

00027 { return fHistoFileName.c_str(); }

const std::list<std::string>& jobc::CmdLine::InFileList  )  const [inline]
 

Definition at line 20 of file CmdLine.h.

References fInFileList.

Referenced by SetupIoModule().

00020 {return fInFileList; }

CmdLine & CmdLine::Instance  )  [static]
 

Definition at line 58 of file CmdLine.cxx.

References CmdLine(), and fInstance.

Referenced by gsSIGHUPhandler(), and main().

00059 {
00060   if (fInstance==0) fInstance = new CmdLine();
00061   return *fInstance;
00062 }

int jobc::CmdLine::Nevt  )  const [inline]
 

Definition at line 31 of file CmdLine.h.

References fNevt.

Referenced by SetupIoModule().

00031 { return fNevt;       }

int jobc::CmdLine::NmemReport  )  const [inline]
 

Definition at line 33 of file CmdLine.h.

References fNmemReport.

Referenced by jobc::Job::Run().

00033 { return fNmemReport; }

int jobc::CmdLine::NSkip  )  const [inline]
 

Definition at line 32 of file CmdLine.h.

References fNskip.

Referenced by SetupIoModule().

00032 { return fNskip;      }

const char* jobc::CmdLine::OutFileName  )  const [inline]
 

Definition at line 25 of file CmdLine.h.

References fOutFileName.

Referenced by jobc::Job::Run(), and SetupIoModule().

00025 { return fOutFileName.c_str();}

void CmdLine::Parse int  argc,
char **  argv
 

Definition at line 66 of file CmdLine.cxx.

References fDumpOnException, fEvtList, fFirstEvent, fFirstRun, fHistoFileName, fInFileList, fNevt, fNmemReport, fNskip, fOutFileName, fSizeLimit, fXMLDir, fXMLFileList, fXMLPath, and Usage().

00067 {
00068   static const int kXMLDirOpt    = 'd';
00069   static const int kEvtOpt       = 'e';
00070   static const int kHFileOpt     = 'g';
00071   static const int kHelpOpt      = 'h';
00072   static const int kInputOpt     = 'i';
00073   static const int kNevtOpt      = 'n';
00074   static const int kOutputOpt    = 'o';
00075   static const int kXMLPathOpt   = 'p';
00076   static const int kRunOpt       = 'r';
00077   static const int kNskipOpt     = 's';
00078   static const int kXMLOpt       = 'x';
00079   static const int kMemReportOpt = 'm';
00080   static const int kEvtListOpt   = 'l';
00081   static const int kSizeLimitOpt = 'L';
00082   static const int kCoreDumpOpt  = 'D';
00083   static struct option long_options[] = {
00084     {"input",        1, 0, kInputOpt},
00085     {"output",       1, 0, kOutputOpt},
00086     {"help",         0, 0, kHelpOpt},
00087     {"histo",        1, 0, kHFileOpt},
00088     {"nevt",         1, 0, kNevtOpt},
00089     {"nskip",        1, 0, kNskipOpt},
00090     {"run",          1, 0, kRunOpt},
00091     {"evt",          1, 0, kEvtOpt},
00092     {"xml",          1, 0, kXMLOpt},
00093     {"xmlpath",      1, 0, kXMLPathOpt},
00094     {"xmldir",       1, 0, kXMLDirOpt},
00095     {"memory-report",1, 0, kMemReportOpt},
00096     {"event-list",   1, 0, kEvtListOpt},
00097     {"size-limit",   1, 0, kSizeLimitOpt},
00098     {"dump",         1, 0, kCoreDumpOpt},
00099     {0,0,0,0}
00100   };
00101   while (1) {
00102     int c;
00103     int optindx;
00104     c = getopt_long(argc, argv, "hg:i:o:n:s:r:e:x:p:d:m:l:L:D:", 
00105                     long_options, &optindx);
00106     if (c==-1) break;
00107     switch (c) {
00108     case kInputOpt:     fInFileList.push_back(std::string(optarg));  break;
00109     case kOutputOpt:    fOutFileName     = optarg;                   break;
00110     case kHelpOpt:      this->Usage(); exit(0);                      break;
00111     case kHFileOpt:     fHistoFileName   = optarg;                   break;
00112     case kNevtOpt:      fNevt            = atoi(optarg);             break;
00113     case kNskipOpt:     fNskip           = atoi(optarg);             break;
00114     case kRunOpt:       fFirstRun        = atoi(optarg);             break;
00115     case kEvtOpt:       fFirstEvent      = atoi(optarg);             break;
00116     case kXMLOpt:       fXMLFileList.push_back(std::string(optarg)); break;
00117     case kXMLPathOpt:   fXMLPath         = std::string(optarg);      break;
00118     case kXMLDirOpt:    fXMLDir.push_back(std::string(optarg));      break;
00119     case kMemReportOpt: fNmemReport      = atoi(optarg);             break;
00120     case kEvtListOpt:   fEvtList.push_back(std::string(optarg));     break;
00121     case kSizeLimitOpt: fSizeLimit       = atoi(optarg);             break;
00122     case kCoreDumpOpt:  fDumpOnException = atoi(optarg) + 1;         break;
00123     default: 
00124       std::cerr << "Unknown option: " << optind << argv[optind] << std::endl;
00125       this->Usage();
00126       exit(1);
00127     }
00128   }
00129   for (; optind<argc; ++optind) {
00130     fInFileList.push_back(std::string(argv[optind]));
00131   }
00132 };

void CmdLine::Print  )  const
 

Definition at line 136 of file CmdLine.cxx.

References fFirstEvent, fFirstRun, fInFileList, fNevt, fNmemReport, fNskip, fOutFileName, fXMLDir, fXMLFileList, and fXMLPath.

00137 {
00138   std::cerr <<
00139     "Command line options:" << std::endl   <<
00140     "  fFirstRun   = "      << fFirstRun   << std::endl <<
00141     "  fFirstEvent = "      << fFirstEvent << std::endl <<
00142     "  fNevt       = "      << fNevt       << std::endl <<
00143     "  fNskip      = "      << fNskip      << std::endl <<
00144     "  fNmemReport = "      << fNmemReport << std::endl;
00145 
00146   std::list<std::string>::const_iterator itr;
00147   std::list<std::string>::const_iterator itrEnd;
00148   
00149   std::cerr << "  Input files = " << std::endl;
00150   itr    = fInFileList.begin();
00151   itrEnd = fInFileList.end();
00152   for (; itr!=itrEnd; ++itr) std::cerr << "    " << (*itr) << std::endl;
00153 
00154   std::cerr << "  Output file = " << fOutFileName << std::endl;
00155   std::cerr << "  XML path  = " << fXMLPath << std::endl;
00156 
00157   std::cerr << "  XML files = " << std::endl;
00158   itr    = fXMLFileList.begin();
00159   itrEnd = fXMLFileList.end();
00160   for (; itr!=itrEnd; ++itr) std::cerr << "    " << (*itr) << std::endl;
00161 
00162   std::cerr << "  XML dirs  = " << std::endl;
00163   itr    = fXMLDir.begin();
00164   itrEnd = fXMLDir.end();
00165   for (; itr!=itrEnd; ++itr) std::cerr << "    " << (*itr) << std::endl;
00166 }

void CmdLine::SetSIGHUP  ) 
 

Sets variable which terminates the executable "nicely". If we happen to receive the signal second time around, then we abort.

Definition at line 224 of file CmdLine.cxx.

References fSIGHUP.

00225 {
00226   if (fSIGHUP) {
00227     std::cout << "jobc::CmdLine: aborting anamipp!" << std::endl;
00228     abort();
00229   }
00230   std::cout << "Stopping job..."
00231             << "This may take a minute..." << std::endl;
00232   fSIGHUP = true; 
00233 }

void CmdLine::SetupIoModule io::ReadWriteModule iomod,
int *  nevent
const
 

Definition at line 170 of file CmdLine.cxx.

References io::ReadWriteModule::AddFile(), io::ReadWriteModule::AdoptInputFilter(), io::ReadWriteModule::Advance(), EvtListFiles(), FirstEvent(), FirstRun(), fSizeLimit, io::ReadWriteModule::GoTo(), InFileList(), Nevt(), NSkip(), OutFileName(), io::ReadWriteModule::RunNumber(), io::ReadWriteModule::SetOutputFileName(), and io::ReadWriteModule::SetOutSizeLimit().

Referenced by jobc::Job::Run().

00171 {
00172 //======================================================================
00173 // Setup and I/O module give parameters specified on the command line
00174 //======================================================================
00175   const std::list<std::string>& fileList = this->InFileList();
00176   std::list<std::string>::const_iterator itr(fileList.begin());
00177   std::list<std::string>::const_iterator itrEnd(fileList.end());
00178   for (; itr!=itrEnd; ++itr) iomod.AddFile(itr->c_str());
00179 
00180   // Set output file limit
00181   iomod.SetOutSizeLimit(fSizeLimit);
00182 
00183   // Add input file filters
00184   const std::list<std::string>& evtList = this->EvtListFiles();
00185   itr    = evtList.begin();
00186   itrEnd = evtList.end();
00187   for (; itr!=itrEnd; ++itr) {
00188     io::EventFilter* iof = new io::EventFilter();
00189     iof->ReadEventFile(itr->c_str());
00190     iomod.AdoptInputFilter(iof);
00191   }
00192 
00193   // Setup the output streams
00194   std::string outfile = this->OutFileName();
00195   if (outfile!="") iomod.SetOutputFileName(outfile.c_str());
00196 
00197   int firstRun   = this->FirstRun();
00198   int firstEvent = this->FirstEvent();
00199   int nevt       = (*nevent);
00200   if (nevt==-1) nevt = this->Nevt(); // Fall back on command line
00201   if (nevt==-1) nevt = INT_MAX;    // Then fall back on all events
00202   int nskip      = this->NSkip();
00203   if (firstRun>=0) {
00204     if (firstEvent>=0) {
00205       iomod.GoTo(firstRun,firstEvent);
00206     }
00207     else {
00208       iomod.GoTo(firstRun,0);
00209     }
00210   }
00211   else {
00212     if (firstEvent>=0) {
00213       iomod.GoTo(iomod.RunNumber(),firstEvent);
00214     }
00215   }
00216   if (nskip>0) iomod.Advance(nskip);
00217   *nevent = nevt;
00218 }

int jobc::CmdLine::SizeLimit  )  const [inline]
 

Definition at line 34 of file CmdLine.h.

References fSizeLimit.

00034 { return fSizeLimit; }

void CmdLine::Usage  )  const
 

Definition at line 20 of file CmdLine.cxx.

Referenced by Parse().

00021 {
00022   std::cerr <<
00023     "usage: anamipp [options] file1.root file2.root ...\n" <<
00024     "options are:\n" <<
00025     "  -i file.root,--input=file.root  : Add input data file\n"
00026     "  -o file.root,--output=file.root : Set output data file\n"
00027     "  -g file.root,--histo=file.root  : Set output histogram file\n"
00028     "  -n #, --nevt=#                  : Set number of events to process\n"
00029     "  -s #, --nskip=#                 : Skip number of events at start\n"
00030     "  -r #, --run=#                   : Skip to run number at start\n"
00031     "  -e #, --event=#                 : Skip to event number at start\n"
00032     "  -x #, --xml=file.xml            : Parse XML file\n"
00033     "  -p #, --xmlpath=dir             : Add directory to XML serach path\n"
00034     "  -d #, --xmldir=dir              : Read all XML files in directory\n"
00035     "  -m #, --memory-report=#         : Summarize resources used energy n events\n"
00036     "  -l file.txt,--evtent-list=file  : Read event list from text file\n"
00037     "  -L #, --size-limit=#            : Largest acceptable file size (in MB)\n"
00038     "  -D #, --dumpcore                : If 0 stop cleanly, if 1 dump core on assert_jobc's\n";
00039 }

const std::list<std::string>& jobc::CmdLine::XMLDirList  )  const [inline]
 

Definition at line 22 of file CmdLine.h.

References fXMLDir.

00022 {return fXMLDir;     }

const std::list<std::string>& jobc::CmdLine::XMLFileList  )  const [inline]
 

Definition at line 21 of file CmdLine.h.

References fXMLFileList.

00021 {return fXMLFileList;}

const char* jobc::CmdLine::XMLPath  )  const [inline]
 

Definition at line 26 of file CmdLine.h.

References fXMLPath.

00026 { return fXMLPath.c_str();}


Member Data Documentation

int jobc::CmdLine::fDumpOnException [private]
 

Dump core on JobCExceptions?

Definition at line 67 of file CmdLine.h.

Referenced by DumpOnException(), and Parse().

std::list<std::string> jobc::CmdLine::fEvtList [private]
 

Files containing event lists.

Definition at line 57 of file CmdLine.h.

Referenced by EvtListFiles(), and Parse().

int jobc::CmdLine::fFirstEvent [private]
 

First event to process.

Definition at line 62 of file CmdLine.h.

Referenced by FirstEvent(), Parse(), and Print().

int jobc::CmdLine::fFirstRun [private]
 

First run to process.

Definition at line 61 of file CmdLine.h.

Referenced by FirstRun(), Parse(), and Print().

std::string jobc::CmdLine::fHistoFileName [private]
 

Histogram output file name.

Definition at line 60 of file CmdLine.h.

Referenced by HistoFileName(), and Parse().

std::list<std::string> jobc::CmdLine::fInFileList [private]
 

Input data files.

Definition at line 54 of file CmdLine.h.

Referenced by InFileList(), Parse(), and Print().

CmdLine * CmdLine::fInstance = 0 [static, private]
 

Definition at line 18 of file CmdLine.cxx.

Referenced by Instance().

int jobc::CmdLine::fNevt [private]
 

Number of events to process.

Definition at line 63 of file CmdLine.h.

Referenced by Nevt(), Parse(), and Print().

int jobc::CmdLine::fNmemReport [private]
 

Frequency of memory reporting.

Definition at line 65 of file CmdLine.h.

Referenced by NmemReport(), Parse(), and Print().

int jobc::CmdLine::fNskip [private]
 

Number of events to skip.

Definition at line 64 of file CmdLine.h.

Referenced by NSkip(), Parse(), and Print().

std::string jobc::CmdLine::fOutFileName [private]
 

Output data file name.

Definition at line 59 of file CmdLine.h.

Referenced by OutFileName(), Parse(), and Print().

bool jobc::CmdLine::fSIGHUP [private]
 

Has SIGHUP signal been sent?

Definition at line 66 of file CmdLine.h.

Referenced by HaveSIGHUP(), and SetSIGHUP().

int jobc::CmdLine::fSizeLimit [private]
 

Max output file size.

Definition at line 68 of file CmdLine.h.

Referenced by Parse(), SetupIoModule(), and SizeLimit().

std::list<std::string> jobc::CmdLine::fXMLDir [private]
 

XML directory to scan.

Definition at line 56 of file CmdLine.h.

Referenced by Parse(), Print(), and XMLDirList().

std::list<std::string> jobc::CmdLine::fXMLFileList [private]
 

Input XML files.

Definition at line 55 of file CmdLine.h.

Referenced by Parse(), Print(), and XMLFileList().

std::string jobc::CmdLine::fXMLPath [private]
 

XML path to search.

Definition at line 58 of file CmdLine.h.

Referenced by Parse(), Print(), and XMLPath().


The documentation for this class was generated from the following files:
Generated on Fri Jul 25 02:05:54 2008 for NOvA Offline by doxygen 1.3.5