#include <JobCEnv.h>
Public Member Functions | |
| ~JobCEnv () | |
| int | GetArgc () const |
| char *const * | GetArgv () const |
| const char * | GetArgv (int i) const |
| const char * | GetModuleHelpList () const |
| const char * | GetMacroFile (unsigned int i) const |
| const char * | GetFileName (int i) const |
| int | GetNfile () const |
| const char * | GetDefaultOutputFileName () const |
| bool | HaveInaccessibleFile () const |
| bool | ContinueRun (int n) const |
| bool | CheckTimeLimit (int *t) const |
| bool | CheckRecordLimit (int n) const |
| bool | IsBatch () const |
| int | RunRootApp () |
Static Public Member Functions | |
| static JobCEnv & | Instance () |
| static JobCEnv & | Instance (int argc, char **argv) |
Private Member Functions | |
| JobCEnv () | |
| JobCEnv (int argc, char **argv) | |
| void | AddDataFile (const char *filename) |
| void | AddMacroFile (const char *filelist) |
| void | CreateInteractiveMom () |
| void | DeleteInteractiveMom () |
| void | ProcessCommandLine (int argc, char *const *argv) |
| void | SetTimeLimit (const char *timelimit) |
| void | SetSignalHandlers () |
Private Attributes | |
| int | fArgc |
| char *const * | fArgv |
| const char * | fModuleHelpList |
| std::vector< std::string > | fDataFileList |
| std::vector< std::string > | fMacroFileList |
| std::string | fDfltOutFile |
| time_t | fTimeStart |
| double | fTimeLimit |
| int | fRecordLimit |
| bool | fIsBatch |
| JobCRootEnv * | fRootEnv |
Static Private Attributes | |
| static JobCEnv * | fInstance = 0 |
Friends | |
| struct | Cleaner |
Classes | |
| struct | Cleaner |
Definition at line 28 of file JobCEnv.h.
| JobCEnv::~JobCEnv | ( | ) |
Definition at line 111 of file JobCEnv.cxx.
References fRootEnv.
00112 { 00113 //====================================================================== 00114 // Purpose: Clean up after JobCEnv... 00115 //====================================================================== 00116 if (fRootEnv) { 00117 delete fRootEnv; fRootEnv = 0; 00118 } 00119 }
| JobCEnv::JobCEnv | ( | ) | [private] |
Definition at line 66 of file JobCEnv.cxx.
Referenced by Instance().
00066 : 00067 fArgc(0), 00068 fArgv(0), 00069 fModuleHelpList(0), 00070 fDfltOutFile(""), 00071 fTimeStart(time(0)), 00072 fTimeLimit(-1.0), 00073 fRecordLimit(-1), 00074 fIsBatch(false), 00075 fRootEnv(0) 00076 { 00077 //======================================================================== 00078 // Purpose: Create the default job environment 00079 //======================================================================== 00080 }
| JobCEnv::JobCEnv | ( | int | argc, | |
| char ** | argv | |||
| ) | [private] |
Definition at line 84 of file JobCEnv.cxx.
References fRootEnv, ProcessCommandLine(), and SetSignalHandlers().
00084 : 00085 fArgc(argc), 00086 fArgv(argv), 00087 fModuleHelpList(0), 00088 fDfltOutFile(""), 00089 fTimeStart(time(0)), 00090 fTimeLimit(-1.0), 00091 fRecordLimit(-1), 00092 fIsBatch(false), 00093 fRootEnv(0) 00094 { 00095 //======================================================================== 00096 // Purpose: Create the job environment given command line options 00097 //======================================================================== 00098 this->ProcessCommandLine(argc,argv); 00099 00100 // Only set up the root environment after command line has been parsed 00101 // Don't forget delete in d'tor 00102 fRootEnv = new JobCRootEnv(argc,argv); 00103 assert(fRootEnv); 00104 00105 // Set the system signal handlers 00106 this->SetSignalHandlers(); 00107 }
| void JobCEnv::AddDataFile | ( | const char * | filename | ) | [private] |
Definition at line 529 of file JobCEnv.cxx.
References fDataFileList, and Munits::s.
00530 { 00531 //====================================================================== 00532 // Purpose: Add a data file to the list of files on the command line 00533 //====================================================================== 00534 assert(filename); 00535 string s(filename); 00536 fDataFileList.push_back(s); 00537 }
| void JobCEnv::AddMacroFile | ( | const char * | filelist | ) | [private] |
Definition at line 541 of file JobCEnv.cxx.
References fMacroFileList.
Referenced by ProcessCommandLine().
00542 { 00543 //====================================================================== 00544 // Inputs: filelist - list of files in format 'file1 file2 fil3'... 00545 //====================================================================== 00546 const char *p; 00547 for (p=filelist; *p!='\0';) { 00548 for (; *p==' ' && *p!='\0'; ++p); 00549 if (*p!='\0') { 00550 string s; 00551 s = ""; 00552 for (; *p!=' ' && *p!='\0'; ++p) s += *p; 00553 if (s.length()>0) fMacroFileList.push_back(s); 00554 } 00555 } 00556 }
| bool JobCEnv::CheckRecordLimit | ( | int | n | ) | const |
Definition at line 281 of file JobCEnv.cxx.
References fRecordLimit.
00282 { 00283 //====================================================================== 00284 // Check if the number of records n is within the set limit. Return 00285 // true if the limit has been exceeded. False if it has not. 00286 //====================================================================== 00287 if (fRecordLimit<0) return false; // No limit set 00288 if (n>=fRecordLimit) return true; 00289 return false; 00290 }
| bool JobCEnv::CheckTimeLimit | ( | int * | t | ) | const |
Definition at line 292 of file JobCEnv.cxx.
References fTimeLimit, and fTimeStart.
00293 { 00294 //====================================================================== 00295 // Check if the time limit for the job has been exceeded. Return true 00296 // if the limit for the job has been exceeded. False if it has not. 00297 //====================================================================== 00298 if (fTimeLimit<0.0) return false; // No limit set 00299 00300 time_t t = time(0); 00301 *tsec = t; // Return time used in seconds 00302 if (difftime(t,fTimeStart) >= fTimeLimit) return true; 00303 00304 return false; 00305 }
| bool JobCEnv::ContinueRun | ( | int | n | ) | const |
Definition at line 309 of file JobCEnv.cxx.
References MsgService::GetCurrentRunSnarl(), gsSIGHUP, gsSIGTERM, gsSIGUSR1, gSystem(), MsgService::Instance(), Msg::kWarning, MSG, Mphysical::pi, and run().
00310 { 00311 //====================================================================== 00312 // Check if there is any information from the environment that signals 00313 // whether a run should stop. 00314 // 00315 // Inputs: n = number of records processed 00316 // Returns: true=keep running, false=stop run 00317 //====================================================================== 00318 int t; 00319 if (this->CheckRecordLimit(n) == true) { 00320 MSG("JobC",Msg::kWarning) << 00321 "Record limit exceeded at "<<n<<" records." << endl; 00322 return false; 00323 } 00324 if (this->CheckTimeLimit(&t) == true) { 00325 MSG("JobC",Msg::kWarning) << 00326 "Time limit exceeded at "<<t<<" seconds." << endl; 00327 return false; 00328 } 00329 if (gsSIGHUP) { 00330 MSG("JobC",Msg::kWarning) << 00331 "Process received SIGHUP.\n" << endl; 00332 return false; 00333 } 00334 if (gsSIGTERM) { 00335 MSG("JobC",Msg::kWarning) << 00336 "Process received SIGTERM.\n" << endl; 00337 return false; 00338 } 00339 if (gsSIGUSR1) { 00340 int run, snarl; 00341 MsgService::Instance()->GetCurrentRunSnarl(run,snarl); 00342 cout << flush; // just so things don't get intermixed 00343 cerr << "JobCEnv: Process " << gSystem->GetPid() 00344 << " received SIGUSR1 after " 00345 << n << " record sets," 00346 << endl 00347 <<" last processed run " << run << " snarl " << snarl 00348 << flush << endl; 00349 ProcInfo_t pi; 00350 gSystem->GetProcInfo(&pi); 00351 cerr << " CPU: user " << pi.fCpuUser << "s, sys " 00352 << pi.fCpuSys << "s, " 00353 << " Mem: res " << pi.fMemResident 00354 << "k, virtual " << pi.fMemVirtual << "k " 00355 << flush << endl; 00356 00357 gsSIGUSR1 = false; // we've emitted the msg, clear signal 00358 } 00359 return true; // Keep going... 00360 }
| void JobCEnv::CreateInteractiveMom | ( | ) | [private] |
| void JobCEnv::DeleteInteractiveMom | ( | ) | [private] |
| int JobCEnv::GetArgc | ( | ) | const |
| const char * JobCEnv::GetArgv | ( | int | i | ) | const |
Definition at line 138 of file JobCEnv.cxx.
00139 { 00140 //====================================================================== 00141 // Purpose: Return the ith command line argument 00142 //====================================================================== 00143 assert(i>=0 && i<fArgc); 00144 return fArgv[i]; 00145 }
| char *const * JobCEnv::GetArgv | ( | ) | const |
| const char * JobCEnv::GetDefaultOutputFileName | ( | ) | const |
Definition at line 184 of file JobCEnv.cxx.
References fDfltOutFile.
00185 { 00186 //====================================================================== 00187 // Return the name of the default output file. Value set from command 00188 // line. 00189 //====================================================================== 00190 return fDfltOutFile.c_str(); 00191 }
| const char * JobCEnv::GetFileName | ( | int | i | ) | const |
Definition at line 161 of file JobCEnv.cxx.
References fDataFileList, and GetNfile().
Referenced by get_run_number(), GetRunNumber(), IoInputModule::LoadFilesFromCommandLine(), merge_configure(), and Set_TSQL_Override().
00162 { 00163 //====================================================================== 00164 // Purpose: Return the ith data file name listed on the command line 00165 //====================================================================== 00166 // Compute index into argv array 00167 assert(i>=0 && i<this->GetNfile()); 00168 return fDataFileList[i].c_str(); 00169 }
| const char * JobCEnv::GetMacroFile | ( | unsigned int | i | ) | const |
Definition at line 149 of file JobCEnv.cxx.
References fMacroFileList.
Referenced by JobController::Init().
00150 { 00151 //====================================================================== 00152 // Purpose: Return the ith macro file specified on the command line 00153 //====================================================================== 00154 //always true: assert(i>=0); 00155 if (i<this->fMacroFileList.size()) return fMacroFileList[i].c_str(); 00156 else return 0; 00157 }
| const char * JobCEnv::GetModuleHelpList | ( | ) | const |
Definition at line 123 of file JobCEnv.cxx.
References fModuleHelpList.
Referenced by JobController::Init().
00124 { 00125 return fModuleHelpList; 00126 }
| int JobCEnv::GetNfile | ( | ) | const |
Definition at line 173 of file JobCEnv.cxx.
References fDataFileList.
Referenced by GetFileName(), IoInputModule::LoadFilesFromCommandLine(), and merge_configure().
00174 { 00175 //====================================================================== 00176 // Purpose: Return the number of data file names specified on the 00177 // command line 00178 //====================================================================== 00179 return fDataFileList.size(); 00180 }
| bool JobCEnv::HaveInaccessibleFile | ( | ) | const |
Definition at line 195 of file JobCEnv.cxx.
References fRootEnv, and JobCRootEnv::HaveInaccessibleFile().
00196 { 00197 if (!fRootEnv) return false; 00198 return fRootEnv->HaveInaccessibleFile(); 00199 }
| JobCEnv & JobCEnv::Instance | ( | int | argc, | |
| char ** | argv | |||
| ) | [static] |
Definition at line 376 of file JobCEnv.cxx.
References JobCEnv::Cleaner::ClassIsUsed(), fInstance, and JobCEnv().
00377 { 00378 if (fInstance) return *fInstance; 00379 00380 // Helper class to handle delete 00381 static JobCEnv::Cleaner c; 00382 c.ClassIsUsed(); 00383 00384 fInstance = new JobCEnv(argc, argv); 00385 return *fInstance; 00386 }
| JobCEnv & JobCEnv::Instance | ( | ) | [static] |
Definition at line 368 of file JobCEnv.cxx.
References fInstance.
Referenced by IoOutputModule::DefaultConfig(), get_run_number(), JobController::GetJobEnv(), GetRunNumber(), JobController::Init(), JobC::JobC(), JobController::JobController(), IoInputModule::LoadFilesFromCommandLine(), main(), merge_configure(), JobController::operator<<(), JobCPath::Run(), JobController::Run(), Set_TSQL_Override(), and test_filename().
00369 { 00370 if (fInstance) return *fInstance; 00371 return JobCEnv::Instance(0,0); 00372 }
| bool JobCEnv::IsBatch | ( | ) | const |
| void JobCEnv::ProcessCommandLine | ( | int | argc, | |
| char *const * | argv | |||
| ) | [private] |
Definition at line 406 of file JobCEnv.cxx.
References AddMacroFile(), fDfltOutFile, fModuleHelpList, fRecordLimit, GETOPTDONE, MsgService::GetStream(), MsgService::Instance(), IsArgMacroFile(), JobCEnvSetenv(), Msg::kDebug, Msg::kError, Msg::kFatal, Msg::kInfo, Msg::kVerbose, Msg::kWarning, len, MSG, Munits::s, and SetTimeLimit().
Referenced by JobCEnv().
00407 { 00408 //====================================================================== 00409 // Purpose: Parse command line options 00410 // Inputs: Standard "argc" and "argv" from main() 00411 //====================================================================== 00412 int c; 00413 00414 #ifndef MACOSX 00415 optind = 0; // getopt.h: Reset getopt to start of arguments 00416 #else 00417 optind = 1; // skip 0th argument ("loon") for MACOSX 00418 #endif 00419 00420 #ifdef IRIX6 00421 getoptreset(); // needed by IRIX to reset getopt 00422 #endif 00423 while ((c = getopt(argc, argv, "bs:nqlt:r:x:hH:d:u:p:o:v:")) != GETOPTDONE) { 00424 MSG("JobC",Msg::kDebug) << "Processing job command-line option argument: " << c << endl; 00425 switch (c) { 00426 case 'b': break; // ROOT batch option 00427 case 's': break; // ROOT's hidden -splash option... 00428 case 'q': break; // ROOT quit option 00429 case 'n': break; // ROOT logon/logoff macro option 00430 case 'l': break; // ROOT no splash option 00431 case 't': this->SetTimeLimit(optarg); break; // Set time limit 00432 case 'r': fRecordLimit = atoi(optarg); break; // Set record limit 00433 case 'x': // x is to "execute" a JobControl macro 00434 this->AddMacroFile(optarg); // optarg from getopt.h 00435 break; 00436 case 'h': 00437 MSG("JobC",Msg::kInfo) 00438 << " usage: " << argv[0] 00439 << " -bnq -H<modules> -x<file>" 00440 << " -d<url> -u<user> -p<passwd> -t'<time>' -r[n]" 00441 << " -o<filename> <filenames...>\n" 00442 << " -b: Run in batch mode without graphics.\n" 00443 << " -n: Do not execute logon and logoff macros.\n" 00444 << " -q: Exit after processing command line macro files.\n" 00445 << " -h: Print this friendly help message.\n" 00446 << " -H: Print help for modules in list.\n" 00447 << " -x: Specifies a Job Control Macro to load.\n" 00448 << " Multiple instances of '-x' are allowed.\n" 00449 << " -d: Supply database URL (replaces ENV_TSQL_URL)\n" 00450 << " -u: Supply database user (replaces ENV_TSQL_USER)\n" 00451 << " -p: Supply database password (replaces ENV_TSQL_PSWD)\n" 00452 << " -t: Specify job time limit. Eg. -t'10 minutes'\n" 00453 << " -r: Specify limit on number of records to process.\n" 00454 << " -o: Set the name of the default output file.\n" 00455 << " -v: Set JobC message verbosity [V,D,I,W,E,F].\n"; 00456 exit(1); 00457 case 'H': fModuleHelpList = optarg; break; 00458 case 'd': if (optarg) JobCEnvSetenv("ENV_TSQL_URL", optarg); break; 00459 case 'u': if (optarg) JobCEnvSetenv("ENV_TSQL_USER",optarg); break; 00460 case 'p': if (optarg) JobCEnvSetenv("ENV_TSQL_PSWD",optarg); break; 00461 case 'o': fDfltOutFile = optarg; break; 00462 case 'v': // set the MsgService level for JobControl 00463 { 00464 Msg::LogLevel_t lvl = Msg::kInfo; 00465 switch (optarg[0]) { 00466 case 'V': case 'v': lvl = Msg::kVerbose; break; 00467 case 'D': case 'd': lvl = Msg::kDebug; break; 00468 case 'I': case 'i': lvl = Msg::kInfo; break; 00469 case 'W': case 'w': lvl = Msg::kWarning; break; 00470 case 'E': case 'e': lvl = Msg::kError; break; 00471 case 'F': case 'f': lvl = Msg::kFatal; break; 00472 default: 00473 MSG("JobC",Msg::kWarning) 00474 << "Can not interpret -v level '" << optarg << "'." << endl; 00475 } 00476 MsgStream *s = MsgService::Instance()->GetStream("JobC"); 00477 if (s) s->SetLogLevel(lvl); 00478 else 00479 MSG("JobC",Msg::kWarning) 00480 << "Can not find JobC message stream." << endl; 00481 break; 00482 } 00483 default: // Do nothing just pass them along... 00484 MSG("JobC",Msg::kInfo) 00485 << " getopt returned unexpected character code " << c << "." << endl; 00486 break; 00487 } 00488 } 00489 00490 // Check if the remaining stuff on the command line is: 00491 // a data file (.root) 00492 // a macro script (.C,.c,.cc,.cxx) 00493 // a directory name 00494 // If not warn the user in case it's just a simple typo. 00495 for (int i=optind; i<argc; ++i) { 00496 int len = strlen(argv[i]); 00497 if (strcmp(argv[i]+len-5,".root")==0) { 00498 this->AddDataFile(argv[i]); 00499 MSG("JobC",Msg::kDebug) 00500 << "JobCEnv::ProcessCommandLine() added data file: " 00501 << argv[i] << endl; 00502 } 00503 else if ( IsArgMacroFile(argv[i]) != "" ) { 00504 MSG("JobC",Msg::kDebug) 00505 << "JobCEnv::ProcessCommandLine() saw macro script: " 00506 << argv[i] << endl; 00507 } 00508 else { 00509 DIR* d = opendir(argv[i]); 00510 if (d) { 00511 // if ROOT is given a directory it will cd to it before executing 00512 closedir(d); 00513 MSG("JobC",Msg::kDebug) 00514 << "JobCEnv::ProcessCommandLine() saw directory: " 00515 << argv[i] << endl; 00516 } 00517 else { 00518 MSG("JobC",Msg::kInfo) 00519 << "JobCEnv::ProcessCommandLine() unrecognizable arg: " 00520 << argv[i] << endl; 00521 } 00522 } 00523 } // loop over optind 00524 00525 }
| int JobCEnv::RunRootApp | ( | ) |
Definition at line 390 of file JobCEnv.cxx.
References fRootEnv, JobCleaner::Instance(), JobCleaner::Reap(), and JobCRootEnv::RunTheApp().
Referenced by JobController::Run().
00391 { 00392 //====================================================================== 00393 // Purpose: Transfer control to the ROOT application 00394 //====================================================================== 00395 if (fRootEnv) { 00396 int r = fRootEnv->RunTheApp(); 00397 // Ensure that JobC objects get deleted. Root is sloopy about this... 00398 JobCleaner::Instance().Reap(); 00399 return r; 00400 } 00401 return 0; 00402 }
| void JobCEnv::SetSignalHandlers | ( | ) | [private] |
Definition at line 261 of file JobCEnv.cxx.
References gsSIGHUPhandler(), gsSIGTERMhandler(), and gsSIGUSR1handler().
Referenced by JobCEnv().
00262 { 00263 //====================================================================== 00264 // Set signal handlers. 00265 //====================================================================== 00266 signal(SIGHUP,gsSIGHUPhandler); // End job "gracefully" 00267 signal(SIGTERM,gsSIGTERMhandler); // End job "gracefully" 00268 signal(SIGUSR1,gsSIGUSR1handler); // Emit status msg on signal 00269 00270 bool activateFPE = true; 00271 00272 if(gEnv) { 00273 if(strcasecmp(gEnv->GetValue("Loon.fpe","on"),"off")==0) activateFPE=false; 00274 } 00275 static JobCFloatXImp floatX(activateFPE); // Trap floating point exceptions 00276 00277 }
| void JobCEnv::SetTimeLimit | ( | const char * | timelimit | ) | [private] |
Definition at line 203 of file JobCEnv.cxx.
References Munits::day, fTimeLimit, Munits::hour, Msg::kWarning, Munits::minute, MSG, Munits::second, and Munits::year.
Referenced by ProcessCommandLine().
00204 { 00205 //====================================================================== 00206 // Set the time limit for the job. Expected format is <float> <unit> 00207 // for example: 00208 // '10.5 minutes' 00209 // '2.5 hours' 00210 // '90 seconds' 00211 //====================================================================== 00212 int i; // Loop variable 00213 float t; // Numerical value of time limit 00214 char unit[256]; // Units that the time is given in 00215 double fac; // Factor to apply to t to convert to seconds 00216 // My best guess all all the possible units people could use... 00217 const char* second[] = {"s","second","seconds","sec", "secs", 0}; 00218 const char* minute[] = {"m","minute","minutes","min", "mins", 0}; 00219 const char* hour[] = {"h","hour","hours","hr","hrs", 0}; 00220 const char* day[] = {"d","day","days", 0}; 00221 const char* week[] = {"w","week","weeks","wk","wks", 0}; 00222 const char* year[] = {"y","year","years","yr","yrs", 0}; 00223 00224 // Read the value and unit of the time limit string 00225 sscanf(s,"%f %s",&t,unit); 00226 00227 // Sort which units the time limit is given in 00228 fac = 0.0; 00229 for (i=0; second[i]!=0; ++i) { 00230 if (strcasecmp(unit,second[i])==0) fac = 1.0; 00231 } 00232 for (i=0; minute[i]!=0; ++i) { 00233 if (strcasecmp(unit,minute[i])==0) fac = 60.0; 00234 } 00235 for (i=0; hour[i]!=0; ++i) { 00236 if (strcasecmp(unit,hour[i])==0) fac = 60.0*60.0; 00237 } 00238 for (i=0; day[i]!=0; ++i) { 00239 if (strcasecmp(unit,day[i])==0) fac = 60.0*60.0*24.0; 00240 } 00241 for (i=0; week[i]!=0; ++i) { 00242 if (strcasecmp(unit,week[i])==0) fac = 60.0*60.0*24.0*7.0; 00243 } 00244 for (i=0; year[i]!=0; ++i) { 00245 if (strcasecmp(unit,year[i])==0) fac=60.0*60.0*24.0*365.25; 00246 } 00247 if (fac==0.0 && strlen(unit)>0) { 00248 MSG("JobC",Msg::kWarning) << 00249 "Time unit '"<<unit<<"' is not recognized.\n" << 00250 "Try 's', 'm', 'h', 'd', 'w', or 'y'\n" << 00251 "Assuming unit given is seconds.\n"; 00252 fac = 1.0; 00253 } 00254 00255 // Set the time limit 00256 fTimeLimit = t*fac; 00257 }
int JobCEnv::fArgc [private] |
char* const* JobCEnv::fArgv [private] |
std::vector<std::string> JobCEnv::fDataFileList [private] |
Definition at line 86 of file JobCEnv.h.
Referenced by AddDataFile(), GetFileName(), and GetNfile().
std::string JobCEnv::fDfltOutFile [private] |
Definition at line 88 of file JobCEnv.h.
Referenced by GetDefaultOutputFileName(), and ProcessCommandLine().
JobCEnv * JobCEnv::fInstance = 0 [static, private] |
Definition at line 102 of file JobCEnv.h.
Referenced by Instance(), and JobCEnv::Cleaner::~Cleaner().
bool JobCEnv::fIsBatch [private] |
std::vector<std::string> JobCEnv::fMacroFileList [private] |
const char* JobCEnv::fModuleHelpList [private] |
Definition at line 85 of file JobCEnv.h.
Referenced by GetModuleHelpList(), and ProcessCommandLine().
int JobCEnv::fRecordLimit [private] |
Definition at line 93 of file JobCEnv.h.
Referenced by CheckRecordLimit(), and ProcessCommandLine().
JobCRootEnv* JobCEnv::fRootEnv [private] |
Definition at line 99 of file JobCEnv.h.
Referenced by HaveInaccessibleFile(), JobCEnv(), RunRootApp(), and ~JobCEnv().
double JobCEnv::fTimeLimit [private] |
time_t JobCEnv::fTimeStart [private] |
1.4.7