#include <JobCommand.h>
Public Member Functions | |
| JobCommand () | |
| JobCommand (const char *cmd) | |
| ~JobCommand () | |
| bool | HaveCmd () const |
| bool | HaveOpt () const |
| const char * | PopCmd () |
| const char * | PopOpt () |
| const char * | PushCmd () |
| const char * | PushOpt () |
| int | PopIntOpt () |
| double | PopFloatOpt () |
Static Public Member Functions | |
| void | SplitLine (const char *line, char sep, string &a, string &b) |
| void | StringTok (std::vector< std::string > &ls, const std::string &str, const std::string &tok) |
| bool | IsBool (const char *value) |
| bool | IsInt (const char *s) |
| bool | IsFloat (const char *s) |
| void | StringToRegistry (Registry &r, const char *s) |
| bool | atob (const char *value) |
Private Member Functions | |
| void | Parse (const char *cmd) |
Private Attributes | |
| vector< string > | fCmdList |
| vector< string >::iterator | fItrCmdList |
| vector< string > | fOptList |
| vector< string >::iterator | fItrOptList |
Friends | |
| ostream & | operator<< (ostream &os, const JobCommand &jc) |
|
|
Definition at line 35 of file JobCommand.cxx. References fCmdList, fItrCmdList, fItrOptList, and fOptList. 00036 {
00037 //======================================================================
00038 // Purpose: Create an empty command
00039 //======================================================================
00040 // Flag these as empty
00041 fItrCmdList = fCmdList.end();
00042 fItrOptList = fOptList.end();
00043 }
|
|
|
Definition at line 47 of file JobCommand.cxx. References Parse(). 00048 {
00049 this->Parse(cmd);
00050 }
|
|
|
Definition at line 167 of file JobCommand.cxx. 00167 {}
|
|
|
Definition at line 493 of file JobCommand.cxx. References MSG. Referenced by StringToRegistry(). 00494 {
00495 //======================================================================
00496 // Convert the text string to its bool equivalent No error checking is
00497 // done. Returns "false" if the contents of value are not regognized
00498 //======================================================================
00499 std::string v(value);
00500 if (v == "true") return true; // C++ style
00501 if (v == "false") return false;
00502 if (v == "kTRUE") return true; // ROOT style
00503 if (v == "kFALSE") return false;
00504 if (v == "TRUE") return true; // Some other reasonable variations...
00505 if (v == "FALSE") return false;
00506 if (v == "True") return true;
00507 if (v == "False") return false;
00508 if (v == "on") return true;
00509 if (v == "off") return false;
00510 if (v == "On") return true;
00511 if (v == "Off") return false;
00512 if (v == "ON") return true;
00513 if (v == "OFF") return false;
00514
00515 // Oops, what have we here?
00516 MSG("JobC",Msg::kWarning) <<
00517 "Attmept to convert string '" << value << "' to bool. Result is 'false'\n";
00518 return false;
00519 }
|
|
|
Definition at line 171 of file JobCommand.cxx. References fCmdList, and fItrCmdList. Referenced by UserAnalysis::HandleCommand(), PTSimModule::HandleCommand(), MuCalFitterModule::HandleCommand(), MCInitModule::HandleCommand(), LIRawNt::HandleCommand(), JobCDemoModuleA::HandleCommand(), IoOutputModule::HandleCommand(), FarPlaneCheckout::HandleCommand(), CDTrackerModule::HandleCommand(), CDPreFilterModule::HandleCommand(), AltModuleSliceQualityCheck::HandleCommand(), and PopCmd(). 00172 {
00173 //======================================================================
00174 // Purpose: Are there parts of the command that need processing?
00175 //
00176 // Returns: true - there are more parts of the command to parse
00177 // false - there are no more parts of the command to parse
00178 //======================================================================
00179 if (fItrCmdList == fCmdList.end()) return false;
00180 return true;
00181 }
|
|
|
Definition at line 185 of file JobCommand.cxx. References fItrOptList, and fOptList. Referenced by JobController::ControllerCommand(), UserAnalysis::HandleCommand(), PTSimModule::HandleCommand(), JobCPathModule::HandleCommand(), JobCDemoModuleA::HandleCommand(), IoOutputModule::HandleCommand(), DemoSnarlList::HandleCommand(), DemoEventDump::HandleCommand(), DemoDataReject::HandleCommand(), CDPreFilterModule::HandleCommand(), JobController::Help(), JobCPathHandler::PathFilterCommand(), JobCPathHandler::PathRunCommand(), PopFloatOpt(), PopIntOpt(), and PopOpt(). 00186 {
00187 //======================================================================
00188 // Purpose: Are there options that need processing?
00189 //
00190 // Returns: true - options remain,
00191 // false - no more options left
00192 //======================================================================
00193 if (fItrOptList == fOptList.end()) return false;
00194 return true;
00195 }
|
|
|
Definition at line 468 of file JobCommand.cxx. Referenced by StringToRegistry(). 00469 {
00470 //======================================================================
00471 // Can the string value be interpreted as a bool value?
00472 //======================================================================
00473 std::string v(value);
00474 if (v == "true") return true; // C++ style
00475 if (v == "false") return true;
00476 if (v == "kTRUE") return true; // ROOT style
00477 if (v == "kFALSE") return true;
00478 if (v == "TRUE") return true; // Some other reasonable variations...
00479 if (v == "FALSE") return true;
00480 if (v == "True") return true;
00481 if (v == "False") return true;
00482 if (v == "on") return true;
00483 if (v == "off") return true;
00484 if (v == "On") return true;
00485 if (v == "Off") return true;
00486 if (v == "ON") return true;
00487 if (v == "OFF") return true;
00488 return false;
00489 }
|
|
|
Definition at line 401 of file JobCommand.cxx. References s(). Referenced by StringToRegistry(). 00402 {
00403 //======================================================================
00404 // Does the string s represent an integer?
00405 //======================================================================
00406 char* endptr;
00407 double d = strtod(s, &endptr);
00408 if (endptr==s && d==0.0) return false; // Conversion to double failed...
00409
00410 // All checks for "floatness" passed
00411 return true;
00412 }
|
|
|
Definition at line 380 of file JobCommand.cxx. References s(). Referenced by StringToRegistry(). 00381 {
00382 //======================================================================
00383 // Does the string s represent an integer?
00384 //======================================================================
00385 char* endptr;
00386 double d = strtod(s, &endptr);
00387 if (endptr==s && d==0.0) return false; // Conversion to double failed...
00388
00389 // Check if this number is int or float
00390 if (strchr(s,'.')) return false;
00391 if (strchr(s,'E')) return false;
00392 if (strchr(s,'e')) return false;
00393
00394 // All checks for "intness" passed
00395 return true;
00396 }
|
|
|
Definition at line 54 of file JobCommand.cxx. References fCmdList, fItrCmdList, fItrOptList, fOptList, and len. Referenced by JobCommand(). 00055 {
00056 //======================================================================
00057 // Purpose: Parse a command line
00058 //
00059 // For example the command:
00060 //
00061 // /Path/Module/Set a 10
00062 //
00063 // Has fCmdList = {"Path","Module","Set"} and
00064 // fOptList = {"a", "10"}
00065 //
00066 // Any command starting as "#" is taken to be a comment. Also,
00067 // standard C and C++ commenting styles are supported. However,
00068 // multi-line comments are *not* supported.
00069 //======================================================================
00070 int len; // Number of characters in the command
00071 bool procCmd; // Are we working on the command?
00072 bool procOpt; // Are we handling options?
00073 bool inQuotes; // Are we inside a quoted string?
00074 bool expectSpecial; // Expect a special character?
00075 string word; // The current word in the command line
00076 // MsgStream& msgDebug = MSGSTREAM("JobC",Msg::kDebug); // Debug stream
00077
00078 word = "";
00079 len = strlen(cmd);
00080 procCmd = true;
00081 procOpt = false;
00082 inQuotes = false;
00083 expectSpecial = false;
00084 // msgDebug << "Parse: ";
00085 for (int i=0; i<len; ++i) {
00086 // If we've been told not to treat this character as a token, just
00087 // and it to the word
00088 if (expectSpecial) {
00089 word += cmd[i];
00090 expectSpecial = false;
00091 continue; // next character
00092 }
00093
00094 // See if we have a \ which flags that the next character is not a token
00095 if (cmd[i] == '\\') {
00096 expectSpecial = true;
00097 continue; // next character;
00098 }
00099
00100 // Check if we are entering/leaving a quoted passage
00101 if (cmd[i] == '"' || cmd[i] == '\'') {
00102 inQuotes = !inQuotes;
00103 continue; // next character
00104 }
00105 if (inQuotes) {
00106 // Use every character inside quotes
00107 word += cmd[i];
00108 continue; // next character
00109 }
00110
00111 // Skip extra white space
00112 if (i>0 && cmd[i]==' ' && cmd[i-1]==' ') {
00113 continue; // next character
00114 }
00115
00116 // Check for command separator
00117 if (procCmd && cmd[i] == '/') {
00118 // Place the previous word (if there is one) in the command list
00119 if (word.length()>0) fCmdList.push_back(word);
00120 // msgDebug << '/' << word;
00121 word = "";
00122 continue; // next character
00123 }
00124
00125 // White space is used to separate commands from options and
00126 // options from each other
00127 if (cmd[i] == ' ' || cmd[i] == '=') {
00128 if (procCmd) {
00129 // Place the previous work in the command list
00130 // msgDebug << '/' << word;
00131 if (word.length()>0) fCmdList.push_back(word);
00132 word = "";
00133 // Switch from processing commands to options
00134 procCmd = false;
00135 procOpt = true;
00136 }
00137 else if (procOpt) {
00138 // msgDebug << '|' << word;
00139 if (word.length()>0) fOptList.push_back(word);
00140 word = "";
00141 }
00142 continue; // next character
00143 }
00144
00145 // Character triggered no special action -- add it to word
00146 word += cmd[i];
00147 } // End loop over characters
00148
00149
00150 if (procCmd) {
00151 // msgDebug << '/' << word;
00152 if (word.length()) fCmdList.push_back(word);
00153 }
00154 if (procOpt) {
00155 // msgDebug << '|' << word;
00156 if (word.length()) fOptList.push_back(word);
00157 }
00158 // msgDebug << "\n";
00159
00160 // Point the iterators at the begining of the lists
00161 fItrCmdList = fCmdList.begin();
00162 fItrOptList = fOptList.begin();
00163 }
|
|
|
|
Definition at line 293 of file JobCommand.cxx. References HaveOpt(). Referenced by UserAnalysis::HandleCommand(), RerootToRawDataModule::HandleCommand(), PTSimModule::HandleCommand(), PlotMuonClusterModule::HandleCommand(), MCInitModule::HandleCommand(), DmxDeMuxFilterModule::HandleCommand(), DemoMCFilter::HandleCommand(), CheezyDisplayModule::HandleCommand(), CDTrackerModule::HandleCommand(), and CalDetPIDModule::HandleCommand(). 00294 {
00295 //======================================================================
00296 // Purpose: Return the current option parameter as a floating point
00297 // number and advance the counter.
00298 //
00299 // Returns: The current option interpreted as a floating point number
00300 // If the list of options has been exhausted this returns 0.0
00301 //======================================================================
00302 if (this->HaveOpt()) {
00303 double val = 0.0;
00304 val = atof((*fItrOptList).c_str());
00305 ++fItrOptList;
00306 return val;
00307 }
00308 return 0.0;
00309 }
|
|
|
Definition at line 273 of file JobCommand.cxx. References HaveOpt(). Referenced by UserAnalysis::HandleCommand(), RotoClientModule::HandleCommand(), RerootToRawDataModule::HandleCommand(), PTSimModule::HandleCommand(), PEGainModule::HandleCommand(), MCInitModule::HandleCommand(), JobCRootModule::HandleCommand(), IoOutputModule::HandleCommand(), DmxDeMuxCosmicsModule::HandleCommand(), DemoEventDump::HandleCommand(), DemoDataReject::HandleCommand(), DbuDaqMonitorModule::HandleCommand(), CheezyDisplayModule::HandleCommand(), CDTrackerModule::HandleCommand(), CDPreFilterModule::HandleCommand(), and CalDetPIDModule::HandleCommand(). 00274 {
00275 //======================================================================
00276 // Purpose: Return the current option parameter as an integer number
00277 // and advance the counter.
00278 //
00279 // Returns: The current option interpreted as an integer number
00280 // If the list of options has been exhausted this returns 0
00281 //======================================================================
00282 if (this->HaveOpt()) {
00283 int val;
00284 val = atoi((*fItrOptList).c_str());
00285 ++fItrOptList;
00286 return val;
00287 }
00288 return 0;
00289 }
|
|
|
|
Definition at line 218 of file JobCommand.cxx. References fCmdList, and fItrCmdList. Referenced by JobController::ControllerCommand(), JobController::HandleCommand(), and JobCDisplayModule::HandleCommand(). 00219 {
00220 //======================================================================
00221 // Purpose: Return the current option parameter as a character string
00222 //
00223 // Returns: A pointer to the start of the option character string
00224 // If the list of options has been exhausted this returns ""
00225 //======================================================================
00226 if (fItrCmdList != fCmdList.begin()) {
00227 const char *val = 0;
00228 --fItrCmdList;
00229 val = (*fItrCmdList).c_str();
00230 return val;
00231 }
00232 return 0;
00233 }
|
|
|
Definition at line 235 of file JobCommand.cxx. References fItrOptList, and fOptList. Referenced by JobCRootModule::HandleCommand(). 00236 {
00237 //======================================================================
00238 // Purpose: Return the current option parameter as a character string
00239 //
00240 // Returns: A pointer to the start of the option character string
00241 // If the list of options has been exhausted this returns ""
00242 //======================================================================
00243 if (fItrOptList != fOptList.begin()) {
00244 const char *val = 0;
00245 --fItrOptList;
00246 val = (*fItrOptList).c_str();
00247 return val;
00248 }
00249 return 0;
00250 }
|
|
||||||||||||||||||||
|
Definition at line 313 of file JobCommand.cxx. References MSG. Referenced by JobCPathModule::Add(), JobCPath::AddBetween(), JobCMsgModule::Attach(), JobCPathModule::Create(), JobCMsgModule::Format(), JobCPath::Node(), and JobCPathHandler::PathFilterCommand(). 00314 {
00315 //======================================================================
00316 // Purpose: Split a character string into two pieces given a
00317 // separator. Example peas::carots into peas and carrots
00318 //
00319 // Inputs: line - the text to split
00320 // sep - the separation character (':' in the example above)
00321 // a - text before the separator
00322 // b - text after separator
00323 //======================================================================
00324 // Clear a and b strings
00325 a = "";
00326 b = "";
00327 bool doFront = true;
00328 for (const char* c = line; *c != '\0'; ++c) {
00329 if (*c == ' ') continue;
00330 if (*c == sep) {
00331 doFront = false;
00332 continue;
00333 }
00334 if (doFront) a += (*c);
00335 else b += (*c);
00336 }
00337
00338 MSG("JobC",Msg::kVerbose) <<
00339 "Split " << line << " into " << a << " " << b << ".\n";
00340 }
|
|
||||||||||||||||
|
Definition at line 345 of file JobCommand.cxx. Referenced by JobCPathModule::Add(), JobCPathModule::Create(), JobCMsgModule::Format(), and JobCMsgModule::SetDefaultFormat(). 00348 {
00349 //======================================================================
00350 // Split a long string into a set of shorter strings spliting along
00351 // divisions makers by the characters listed in the token string
00352 //======================================================================
00353 const string::size_type S = str.size();
00354 const string::size_type toksz = tok.size();
00355 string::size_type i = 0;
00356
00357 while (i < S) {
00358 // eat leading whitespace
00359 while ( (i<S) && (tok.find(str[i])<=toksz) ) {
00360 ++i;
00361 }
00362 if (i == S) return; // nothing left but WS
00363
00364 // find end of word
00365 string::size_type j = i+1;
00366 while ( (j<S) && !(tok.find(str[j])<=toksz) ) {
00367 ++j;
00368 }
00369
00370 // add word
00371 ls.push_back(str.substr(i,j-i));
00372
00373 // set up for next loop
00374 i = j+1;
00375 }
00376 }
|
|
||||||||||||
|
Definition at line 416 of file JobCommand.cxx. References atob(), IsBool(), IsFloat(), IsInt(), Registry::LockValues(), MSG, Registry::Set(), and Registry::UnLockValues(). Referenced by JobCModule::Set(). 00417 {
00418 //======================================================================
00419 // Convert a string like "a=1 b=2.0 name=Mark" to a registry
00420 //======================================================================
00421 // JobCommand's expect format Command option1 option2... so cast
00422 // the string into this form by prepending a bogus command string
00423 string cmd("Set "); // Set is as good a command name as any...
00424 cmd += s; // Append the registry string
00425 JobCommand c(cmd.c_str());
00426
00427 // Use the command to build a registry
00428 r.UnLockValues();
00429 while (c.HaveOpt()) {
00430 const char* key;
00431 const char* value;
00432
00433 // Extract key/value pair
00434 key = c.PopOpt();
00435 if (c.HaveOpt() == false) {
00436 MSG("JobC",Msg::kWarning) << "Missing value for key \""
00437 << key << "\"!" << endl;
00438 return;
00439 }
00440 value = c.PopOpt();
00441
00442 // Guess type of value and build registry
00443 if (JobCommand::IsInt(value)) {
00444 // Intergers are floats so check them next
00445 int i = atoi(value);
00446 r.Set(key, i);
00447 }
00448 else if (JobCommand::IsFloat(value)) {
00449 // Check float as it is the smallest set
00450 double d = atof(value);
00451 r.Set(key, d);
00452 }
00453 else if (JobCommand::IsBool(value)) {
00454 bool b = JobCommand::atob(value);
00455 r.Set(key, b); // Which Set is this?? char? int? Dunno...
00456 }
00457 else {
00458 // Everything is a string so check that last
00459 r.Set(key, value);
00460 }
00461 }
00462
00463 r.LockValues();
00464 }
|
|
||||||||||||
|
Definition at line 17 of file JobCommand.cxx. 00018 {
00019 vector<string>::const_iterator itrend(jc.fCmdList.end());
00020 vector<string>::const_iterator itr;
00021 bool ifirst = true;
00022 for (itr = jc.fCmdList.begin(); itr!= itrend; ++itr) {
00023 if (ifirst) { os << (*itr); ifirst = false; }
00024 else os << "/" << (*itr);
00025 }
00026 itrend = jc.fOptList.end();
00027 for (itr = jc.fOptList.begin(); itr!= itrend; ++itr) {
00028 os << " " << (*itr);
00029 }
00030 return os;
00031 }
|
|
|
Definition at line 57 of file JobCommand.h. Referenced by HaveCmd(), JobCommand(), Parse(), and PushCmd(). |
|
|
Definition at line 58 of file JobCommand.h. Referenced by HaveCmd(), JobCommand(), Parse(), and PushCmd(). |
|
|
Definition at line 60 of file JobCommand.h. Referenced by HaveOpt(), JobCommand(), Parse(), and PushOpt(). |
|
|
Definition at line 59 of file JobCommand.h. Referenced by HaveOpt(), JobCommand(), Parse(), and PushOpt(). |
1.3.9.1