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

BfldBenchmark.cc

Go to the documentation of this file.
00001 //
00002 //
00003 // A program to test various methods of interpolating the B field.
00004 //
00005 //
00006 
00007 #include <iostream> //System includes
00008 #include <fstream>
00009 #include <unistd.h>
00010 #include <string.h>
00011 
00012 #include "TROOT.h" //ROOT includes
00013 
00014 #include "MessageService/MsgService.h" //MINOS includes
00015 
00016 // --- Constants ---
00017 const char kDefaultAccTestOutFileName[20] = "accresults.root";
00018 const char kDefaultPerfTestOutFileName[20] = "perfresults.bfb";
00019 const char kDefaultConfigFileName[20] = "config.bfb";
00020 
00021 const char kProgramOptions[] = "pahdf:"; //To be passed to getopt()
00022 
00023 // --- Function Prototypes ---
00024 void BenchmarkPerformance(const char *outFileName,const char *rectMapFileName,
00025                           const char *vorMapFileName,
00026                           const char *vorMeshFileName,
00027                           const char *vorBFldFileName,
00028                           const char *testPtsFileName);
00029 void BenchmarkAccuracy(const char *outFileName,const char *rectMapFileName,
00030                        const char *vorMapFileName,const char *vorMeshFileName,
00031                        const char *vorBFldFileName,
00032                        const char *rectAccTestPtsFileName,
00033                        const char *vorAccTestPtsFileName);
00034 
00035 // --- Global Variables ---
00036 
00037 TROOT root("root1","root1");
00038 
00039 // --- main ---
00040 
00041 int main(int argc, char** argv) {
00042   bool isPerf = true;
00043   bool isAcc = true;
00044 
00045   bool isConfigFileArg = false;
00046   char configFileName[255];
00047 
00048   bool isDebug = false;
00049 
00050   char opt = getopt(argc,argv,kProgramOptions);
00051   if(opt == EOF) {
00052     isDebug = false;
00053     isConfigFileArg = false;
00054     isPerf = true;
00055     isAcc = true;
00056     cout << "Running both performance and accuracy tests..." << endl;
00057   }
00058   else {
00059     isPerf = false;
00060     isAcc = false;
00061 
00062     while(opt != EOF) {
00063       switch(opt) {
00064       case EOF:
00065         break;
00066       case '?':
00067         cout << "Invalid option. Use BfldBenchmark -h for help." << endl;
00068         exit(1);
00069         break;
00070       case 'h':
00071         cout << "usage: BfldBenchmark [-pahd] [-f configfile] [[file1] file2]"
00072              << endl
00073              << "Benchmarks the BField package." << endl;
00074         cout << "By default, does both performance and accuracy tests."
00075              << endl;
00076         cout << "-p: Do performance tests. Output to file1 or to the" << endl
00077              << "    default, " << kDefaultPerfTestOutFileName << endl;
00078         cout << "-a: Do accuracy tests. Can be used together with -p or alone."
00079              << endl
00080              << "    If alone, file1 specifies where to write results; "
00081              << endl << "    otherwise, file2 does. If the appropriate file " 
00082              << endl << "    is not specified, the default, "
00083              << kDefaultAccTestOutFileName << ", is used." << endl;
00084         cout << "-f  configfile: Use the configuration file given instead of"
00085              << endl
00086              << "                the default file " << kDefaultConfigFileName
00087              << endl;
00088         cout << "-d: Print out lots of debugging information." << endl;
00089         cout << "-h: Display this help." << endl << endl;
00090         cout << "Config file format:" << endl
00091              << "perfTestPtsFileName" << endl
00092              << "rectAccTestPtsName" << endl
00093              << "vorAccTestPtsName" << endl
00094              << "rectMapName (currently ignored)" << endl
00095              << "vorMapName (currently ignored)" << endl
00096              << "vorMeshName (currently ignored)" << endl
00097              << "vorBFldName (currently ignored)" << endl;
00098         exit(0);
00099         break;
00100       case 'p':
00101         isPerf = true;
00102         break;
00103       case 'a':
00104         isAcc = true;
00105         break;
00106       case 'f':
00107         isConfigFileArg = true;
00108         if(optarg == 0) {
00109           cout << "You must specify a configuration file name with" << endl
00110                << "the -f option. Use the -h option for help." << endl;
00111           cout << "This run will use the default configuration file." << endl;
00112           isConfigFileArg = false;
00113         }
00114         else
00115           strcpy(configFileName,optarg);
00116         break;
00117       case 'd':
00118         isDebug = true;
00119         break;
00120       default:
00121         cout << "Error processing arguments. Bail." << endl;
00122         exit(1);
00123       }
00124     
00125       opt = getopt(argc,argv,kProgramOptions);
00126     }
00127   }
00128 
00129   if(isDebug) {
00130     MsgService::Instance()->GetStream("Bfldtest")->SetLogLevel(Msg::kDebug);
00131     //We'll also hear from the package itself, but without lots of extra
00132     //information appended by the MessageService.
00133     MsgService::Instance()->GetStream("Bfld")->SetFormat(Msg::kInfo,
00134                                                          Msg::kName);
00135     MsgService::Instance()->GetStream("Bfld")->SetFormat(Msg::kWarning,
00136                                                          Msg::kName
00137                                                          & Msg::kPriority);
00138     MsgService::Instance()->GetStream("BFL")->SetFormat(Msg::kInfo,
00139                                                         Msg::kName);
00140     MsgService::Instance()->GetStream("BFL")->SetFormat(Msg::kWarning,
00141                                                         Msg::kName
00142                                                         & Msg::kPriority);
00143   }
00144   else {
00145     //We leave Bfldtest at kInfo level. In addition, we want to quiet
00146     //chatter from the BField package itself.
00147     MsgService::Instance()->GetStream("BFL")->SetLogLevel(Msg::kFatal);
00148     MsgService::Instance()->GetStream("Bfld")->SetLogLevel(Msg::kFatal);
00149   }
00150   //We don't want all the information Msg normally prints out.
00151   MsgService::Instance()->GetStream("Bfldtest")->SetFormat(Msg::kDebug,0);
00152   MsgService::Instance()->GetStream("Bfldtest")->SetFormat(Msg::kWarning,0);
00153 
00154   if(!isConfigFileArg) { //Use default config file
00155     strcpy(configFileName,kDefaultConfigFileName);
00156   }
00157 
00158   ifstream configFile(configFileName,ios::in);
00159   if(!configFile.good()) {
00160     cout << "Couldn't open configuration file " << configFileName << endl;
00161     exit(1);
00162   }
00163 
00164   char *rectMapName,*vorMapName,*vorMeshName,*vorBFldName,
00165     *perfTestPtsName,*rectAccTestPtsName,*vorAccTestPtsName;
00166 
00167   configFile.gets(&perfTestPtsName);
00168   configFile.gets(&rectAccTestPtsName);
00169   configFile.gets(&vorAccTestPtsName);
00170 
00171   configFile.gets(&rectMapName);
00172   configFile.gets(&vorMapName);
00173   configFile.gets(&vorMeshName);
00174   configFile.gets(&vorBFldName);
00175 
00176   if(isPerf) {
00177     cout << endl << "Running performance tests with test point file "
00178          << perfTestPtsName << endl;
00179 
00180     if(argc - optind == 0)
00181       BenchmarkPerformance(kDefaultPerfTestOutFileName,rectMapName,vorMapName,
00182                            vorMeshName,vorBFldName,perfTestPtsName);
00183     else
00184       BenchmarkPerformance(argv[optind],rectMapName,vorMapName,
00185                            vorMeshName,vorBFldName,perfTestPtsName);
00186 
00187   }
00188 
00189   if(isAcc) {
00190     cout << endl << "Running accuracy tests with test point files:" << endl
00191          << "rect2d:  " << rectAccTestPtsName << endl
00192          << "Voronoi: " << vorAccTestPtsName << endl;
00193 
00194     int reqArgCount = (isPerf) ? 1 : 0;
00195 
00196     if(argc - optind == reqArgCount)
00197       BenchmarkAccuracy(kDefaultAccTestOutFileName,rectMapName,vorMapName,
00198                         vorMeshName,vorBFldName,rectAccTestPtsName,
00199                         vorAccTestPtsName);
00200     else
00201       BenchmarkAccuracy(argv[optind + reqArgCount],rectMapName,vorMapName,
00202                         vorMeshName,vorBFldName,rectAccTestPtsName,
00203                         vorAccTestPtsName);
00204   }
00205 }

Generated on Mon Feb 15 11:06:25 2010 for loon by  doxygen 1.3.9.1