cfCfg Class Reference

List of all members.

Public Member Functions

 cfCfg ()
 ~cfCfg ()
void ParseArgv (int argc, char **argv)
void Usage (std::string msg, int exitval)
void PrintConfig ()

Public Attributes

int32_t Verbose
bool PrintAndQuit
bool CountAndQuit
bool AllowRotoErrors
bool ExitDevUnpackErr
bool WriteEmptyFiles
msTimeStamp_t TimeStampStart
msTimeStamp_t Duration
msTimeStamp_t TimeStampStop
std::string RotoNode
msTimeStamp_t Epsilon
msTimeStamp_t MergeWindow
size_t MinDevices
int32_t DtTolerance
std::string PrintOpts
std::vector< std::string > Paths
std::vector< std::string > FilePatterns
std::set< std::string > FileList
int32_t Reread

Detailed Description

Definition at line 201 of file cf2rr.cc.


Constructor & Destructor Documentation

cfCfg::cfCfg (  ) 

Definition at line 401 of file cf2rr.cc.

00402   : Verbose(0)               // quiet
00403   , PrintAndQuit(false)      // quit after parsing argv and print config
00404   , CountAndQuit(false)      // count # of spills w/o rotorooter connection
00405   , AllowRotoErrors(false)   // continue after rotorooter connection/file errs
00406   , ExitDevUnpackErr(false)  // should one stop on cfDeviceData unpack errors
00407   , WriteEmptyFiles(false)   // files with no records are boring
00408   , TimeStampStart(0)        // user must supply starting time
00409   , Duration(8*60*60*1000)   // default duration is 8 hours
00410   , TimeStampStop(0)         // ... calculated
00411 
00412   , RotoNode("minos-nearline.fnal.gov") // default where rotorooter is running
00413   , Epsilon(200)             // records this close are merged (ms)
00414   , MergeWindow(600*1000)    // default is 10min
00415   , MinDevices(15)            // merge records that have fewer devices than this
00416   , DtTolerance(500)         // allowed time between spill and device times
00417                              // without complaint
00418   , PrintOpts("") // ("trigger,device,file")
00419   , Reread(1)
00420 {
00421   // example timestamp
00422   //   msTimeStamp_t = 1373660869000;  // Fri Jul 12 15:27:49 CDT 2013
00423   //                                   // 2013-07-12 20:27:49 UTC
00424   //                                   // 2013-07-12 15:27:49 local
00425 }

cfCfg::~cfCfg (  )  [inline]

Definition at line 204 of file cf2rr.cc.

00204 { ; }


Member Function Documentation

void cfCfg::ParseArgv ( int  argc,
char **  argv 
)

Definition at line 471 of file cf2rr.cc.

References AllowRotoErrors, CountAndQuit, DtTolerance, Duration, Epsilon, ExitDevUnpackErr, FilePatterns, MergeWindow, MinDevices, option, ParseTimeString(), Paths, PrintAndQuit, PrintOpts, Reread, RotoNode, TimeStampStart, TimeStampStop, TokenizeString(), Usage(), Verbose, and WriteEmptyFiles.

Referenced by main().

00471                                            {
00472 
00473   std::string patternstmp = "";
00474 
00475   /*
00476    * Define the options
00477    *
00478    */
00479 
00480   static struct option long_opts[] = {
00481     { "help",         no_argument,       0, 'h' },
00482     { "timestamp",    required_argument, 0, 't' },
00483     { "timestring",   required_argument, 0, 'T' },
00484     { "duration",     required_argument, 0, 'd' },
00485     { "rotonode",     required_argument, 0, 'r' },
00486     { "url",          required_argument, 0, 'u' },
00487     { "print-config", no_argument,       0, 'C' },
00488     { "count-spills", no_argument,       0, 'c' },
00489     { "verbose",      no_argument,       0, 'v' },
00490     { "bypass-roto",  no_argument,       0, 'A' },
00491     { "exit-unpack",  no_argument,       0, 'E' },
00492     { "write-empty",  no_argument,       0, '0' },
00493 
00494     { "epsilon",      required_argument, 0, 'e' },
00495     { "mergew",       required_argument, 0, 'W' },
00496     { "mindev",       required_argument, 0, 'M' },
00497     { "dt-tolerance", required_argument, 0, 'q' },
00498     { "reread",       required_argument, 0, 'R' },
00499     { "print-opts",   required_argument, 0, 'P' },
00500     { "pattern",      required_argument, 0, 'p' },
00501     { 0, 0, 0, 0 } // signal end of list
00502   };
00503   const char short_opts[] = "ht:T:d:r:u:CcvA0e:W:M:q:R:P:p:";
00504 
00505   /*
00506    * Parse the options
00507    *
00508    */
00509 
00510   // getopt_long stored the option index here
00511 #ifndef MACOSX
00512   optind = 0; // getopt.h: Reset getopt to start of arguments
00513 #else
00514   optind = 1; // skip 0th argument (executable) for MACOSX
00515 #endif
00516   int opt_index = 0;
00517   int c;
00518   while ((c = getopt_long(argc,argv,short_opts,long_opts,&opt_index)) != -1 ) {
00519     if (Verbose>1) {
00520       std::cout << " c from getopt_long " << c << " '" << (char)c << "'"
00521                 << " optarg \"" << (optarg?optarg:"") << "\""
00522                 << std::endl;
00523     }
00524     switch ( c ) {
00525     case 0: {
00526       // if option set a flag, do nothing else
00527       if ( long_opts[opt_index].flag != 0 ) {
00528         if (Verbose>1) {
00529           std::cout << " c==0  opt_index " << opt_index
00530                     << " flag " << long_opts[opt_index].flag << std::endl;
00531         }
00532         break;
00533       }
00534       std::string opt_name = long_opts[opt_index].name;
00535       if (Verbose>1) {
00536         std::cout << "c==0  opt_index " << opt_index
00537                   << " opt_name=\"" << opt_name
00538                   << "\" optarg=\"" << optarg << "\"" << std::endl;
00539       }
00540       break;
00541     }
00542     case 'h': {
00543       Usage("",0);
00544       break;
00545     }
00546     case 'C': {
00547       PrintAndQuit = true;
00548       break;
00549     }
00550     case 'c': {
00551       CountAndQuit = true;
00552       break;
00553     }
00554     case 'v': {
00555       ++Verbose;
00556       break;
00557     }
00558     case 'A': {
00559       AllowRotoErrors = true;
00560       break;
00561     }
00562     case 'E': {
00563       ExitDevUnpackErr = true;
00564       break;
00565     }
00566     case '0': {
00567       WriteEmptyFiles = true;
00568       break;
00569     }
00570     case 't': {
00571       TimeStampStart = atoll(optarg)*1000;  // user supplies sec, value ms
00572       TimeStampStop  = TimeStampStart + Duration;
00573       break;
00574     }
00575     case 'T': {
00576       TimeStampStart = ParseTimeString(optarg);
00577       TimeStampStop  = TimeStampStart + Duration;
00578       break;
00579     }
00580     case 'd': {
00581       float dval;
00582       char units[128] = { 0 };
00583       //int nitems = 
00584         sscanf(optarg,"%f%s",&dval,units);
00585       switch ( units[0] ) {
00586       case 's':
00587         Duration = dval;
00588         break;
00589       case 'm':
00590         Duration = dval*60;
00591         break;
00592       case 'h':
00593         Duration = dval*60*60;
00594         break;
00595       case 'd':
00596         Duration = dval*24*60*60;
00597         break;
00598       case '\0': 
00599         // cout << "RWH no units, " << nitems << " nitems" << endl;
00600         Duration = dval*60*60;
00601         break;
00602       default: 
00603         std::ostringstream oss;
00604         oss << "ERROR, --duration set with unknown units"
00605             << " \"" << units << "\"";
00606         Usage(oss.str(),1);
00607         break;
00608       } // done unit handling
00609       Duration *= 1000;  // above gives sec, scale up to ms
00610       TimeStampStop = TimeStampStart + Duration;
00611       break;
00612     }
00613     case 'r': {
00614       RotoNode = optarg;
00615       break;
00616     }
00617     case 'e': {
00618       Epsilon = atoi(optarg);
00619       break;
00620     }
00621     case 'W': {
00622       MergeWindow = atoi(optarg)*1000; // assume user specifies seconds
00623       break;
00624     }
00625     case 'M': {
00626       MinDevices = atoi(optarg);
00627       break;
00628     }
00629     case 'q': {
00630       DtTolerance = atoi(optarg);
00631       break;
00632     }
00633     case 'R': {
00634       Reread = atoi(optarg);
00635       break;
00636     }
00637     case 'P': {
00638       PrintOpts = optarg;
00639       break;
00640     }
00641     case 'p': {
00642       if ( patternstmp != "" ) patternstmp +=":";
00643       patternstmp += optarg;
00644       break;
00645     }
00646     default: {
00647       std::ostringstream oss;
00648       oss << "ERROR, unhandled/unrecognized option '" << (char)optopt << "' ("
00649           << optopt << ")";
00650       Usage(oss.str(),1);
00651     }
00652 
00653     } // end of switch(c)
00654   } // end of getopt_long
00655 
00656   if ( CountAndQuit ) {
00657     if ( PrintOpts != "" ) PrintOpts += ",";
00658     PrintOpts += "spillcnt";
00659   }
00660 
00661   // handle non-flag (positional) arguments
00662   // these are all assumed to be names of files
00663   if ( optind < argc ) {
00664     if (Verbose>1) {
00665       std::cout << "non-option (positional) ARGV-elements: " << std::endl;
00666     }
00667     int32_t posindx = -1;
00668     while ( optind < argc ) {
00669       ++posindx;
00670       std::string arg = argv[optind++];
00671       Paths.push_back(arg);
00672     } // end of while
00673   } // end of "if ( optind < argc )"
00674 
00675   // a few cases where default set after parsing, or post parsing processing
00676 
00677   if ( MergeWindow < 2*Epsilon ) MergeWindow = 2*Epsilon; 
00678 
00679   // user could have either specified one or more patterns by
00680   // separating items w/ one -p and items separated by ":"
00681   // or by multiple -p flags
00682   // if user didn't specify any file patterns then use a global match
00683   // don't allow empty (blank) tokens
00684   FilePatterns = TokenizeString(patternstmp,":",false,(Verbose>1));
00685   if ( FilePatterns.empty() ) FilePatterns.push_back("*"); 
00686 
00687 }

void cfCfg::PrintConfig (  ) 

Definition at line 426 of file cf2rr.cc.

References AllowRotoErrors, CountAndQuit, DtTolerance, Duration, Epsilon, exename, ExitDevUnpackErr, FilePatterns, LocalTimeString(), MergeWindow, MinDevices, Paths, PrintAndQuit, PrintOpts, Reread, RotoNode, TimeStampStart, TimeStampStop, UTCTimeString(), Verbose, and WriteEmptyFiles.

Referenced by main().

00426                         {
00427 
00428   std::cout << exename << ": current configuration:" << std::endl
00429             << "  Verbose     " << Verbose 
00430             << "   " << ( (PrintAndQuit) ? "PrintAndQuit" : "" )
00431             << "   " << ( (CountAndQuit) ? "CountAndQuit" : "" )
00432             << "   " << ( (AllowRotoErrors) ? "AllowRotoErrors" : "" )
00433             << "   " << ( (ExitDevUnpackErr) ? "ExitDevUnpackErr" : "" )
00434             << "   " << ( (WriteEmptyFiles) ? "WriteEmptyFiles" : "" )
00435             << std::endl
00436             << "  TimeStampStart " << std::setw(14) << TimeStampStart
00437             << " (ms) " << UTCTimeString(TimeStampStart) << std::endl
00438             << std::setw(17+14+6) << " " << LocalTimeString(TimeStampStart)
00439             << std::endl
00440             << "  TimeStampStop  " << std::setw(14) << TimeStampStop
00441             << " (ms) " << UTCTimeString(TimeStampStop) << std::endl
00442             << std::setw(17+14+6) << " " << LocalTimeString(TimeStampStop)
00443             << std::endl
00444             << "  Duration     " << std::setw(14)
00445             << Duration << " (ms)" << std::endl
00446             << "  RotoNode    \"" << RotoNode << "\"" << std::endl
00447             << "  Epsilon " << Epsilon << " ms "
00448             << "  MergeWindow " << MergeWindow << " ms "
00449             << "  MinDevices " << MinDevices
00450             << "  DtTolerance " << DtTolerance << std::endl
00451             << "  PrintOpts \"" << PrintOpts << "\"" << std::endl
00452             << "  Reread " << Reread << std::endl;
00453   std::cout << std::endl;
00454 
00455   size_t indx = 0;
00456   for (indx=0; indx < Paths.size(); ++indx) {
00457     if ( 0 == indx ) std::cout << "  Paths: " << std::endl;
00458     std::cout << "     [" << std::setw(4) << indx << "] " 
00459               << Paths[indx] << std::endl;
00460   }
00461   std::cout << std::endl;
00462 
00463   for (indx=0; indx < FilePatterns.size(); ++indx) {
00464     if ( 0 == indx ) std::cout << "  FilePatterns: " << std::endl;
00465     std::cout << "     [" << std::setw(4) << indx << "] " 
00466               << FilePatterns[indx] << std::endl;
00467   }
00468   std::cout << std::endl;
00469 }

void cfCfg::Usage ( std::string  msg,
int  exitval 
)

Referenced by ParseArgv().


Member Data Documentation

Definition at line 212 of file cf2rr.cc.

Referenced by ParseArgv(), PrintConfig(), and cfProcessor::SendToRotorooter().

Definition at line 211 of file cf2rr.cc.

Referenced by ParseArgv(), and PrintConfig().

Definition at line 225 of file cf2rr.cc.

Referenced by ParseArgv(), and PrintConfig().

Definition at line 217 of file cf2rr.cc.

Referenced by ParseArgv(), and PrintConfig().

Definition at line 222 of file cf2rr.cc.

Referenced by cfProcessor::MergeAdjacent(), ParseArgv(), and PrintConfig().

Definition at line 213 of file cf2rr.cc.

Referenced by ParseArgv(), PrintConfig(), and cfProcessor::ReadOneFile().

std::set<std::string> cfCfg::FileList

Definition at line 230 of file cf2rr.cc.

Referenced by cfProcessor::ExpandFileList(), and cfProcessor::ReadFiles().

std::vector<std::string> cfCfg::FilePatterns

Definition at line 229 of file cf2rr.cc.

Referenced by cfProcessor::ExpandFileList(), ParseArgv(), and PrintConfig().

Definition at line 223 of file cf2rr.cc.

Referenced by ParseArgv(), PrintConfig(), and cfProcessor::ReadOneFile().

Definition at line 224 of file cf2rr.cc.

Referenced by cfProcessor::MergeAdjacent(), ParseArgv(), and PrintConfig().

std::vector<std::string> cfCfg::Paths

Definition at line 228 of file cf2rr.cc.

Referenced by cfProcessor::ExpandFileList(), ParseArgv(), and PrintConfig().

Definition at line 210 of file cf2rr.cc.

Referenced by main(), ParseArgv(), and PrintConfig().

std::string cfCfg::PrintOpts
int32_t cfCfg::Reread

Definition at line 232 of file cf2rr.cc.

Referenced by main(), ParseArgv(), and PrintConfig().

std::string cfCfg::RotoNode

Definition at line 220 of file cf2rr.cc.

Referenced by ParseArgv(), PrintConfig(), and cfProcessor::SendToRotorooter().

int32_t cfCfg::Verbose

Definition at line 214 of file cf2rr.cc.

Referenced by ParseArgv(), PrintConfig(), and cfProcessor::SendToRotorooter().


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

Generated on 3 Oct 2018 for loon by  doxygen 1.6.1