BfldBenchmark.cc File Reference

#include <iostream>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include "TROOT.h"
#include "MessageService/MsgService.h"

Go to the source code of this file.

Functions

void BenchmarkPerformance (const char *outFileName, const char *rectMapFileName, const char *vorMapFileName, const char *vorMeshFileName, const char *vorBFldFileName, const char *testPtsFileName)
void BenchmarkAccuracy (const char *outFileName, const char *rectMapFileName, const char *vorMapFileName, const char *vorMeshFileName, const char *vorBFldFileName, const char *rectAccTestPtsFileName, const char *vorAccTestPtsFileName)
TROOT root ("root1","root1")
int main (int argc, char **argv)

Variables

const char kDefaultAccTestOutFileName [20] = "accresults.root"
const char kDefaultPerfTestOutFileName [20] = "perfresults.bfb"
const char kDefaultConfigFileName [20] = "config.bfb"
const char kProgramOptions [] = "pahdf:"

Function Documentation

void BenchmarkAccuracy ( const char *  outFileName,
const char *  rectMapFileName,
const char *  vorMapFileName,
const char *  vorMeshFileName,
const char *  vorBFldFileName,
const char *  rectAccTestPtsFileName,
const char *  vorAccTestPtsFileName 
)

Definition at line 49 of file TestAcc.cc.

References AccTest(), GetAccTestPts(), kAlgRect, kAlgVor, Msg::kDebug, kDefaultNumAccTestPts, Msg::kInfo, kRectDataName, kVorDataName, Msg::kWarning, MSG, NewBFieldRect(), and NewBFieldVor().

Referenced by main().

00053                                                           {
00054 
00055   MSG("Bfldtest",Msg::kDebug) << "Running accuracy test..." << endl;
00056 
00057   TFile outFile(outFileName,"RECREATE"); //Root datafile to store results.
00058 
00059   vector<TVector3> testPts(kDefaultNumAccTestPts);
00060   vector<TVector3> testField(kDefaultNumAccTestPts);
00061   
00062   BField *theRectField, *theVorField;
00063   TNtuple *theData; //Ntuple to store data as we go
00064 
00065 #ifdef WRITE_OUT_BIG_ERR_PTS
00066   gBigErrPtsFile = new ofstream("bigErrPts.bfb",ios::out);
00067 #endif
00068 
00069   MSG("Bfldtest",Msg::kDebug) << "Building rect2d BField using file "
00070                               << rectMapFileName << endl;
00071 
00072   theRectField = NewBFieldRect(rectMapFileName);
00073   
00074   if(!GetAccTestPts(testPts,testField,rectAccTestPtsFileName)) {
00075     MSG("Bfldtest",Msg::kWarning)
00076       << "Problem reading in rect2d test point file. Bailing." << endl;
00077     return;
00078   }
00079 
00080   theData = new TNtuple(kRectDataName,kRectDataName,
00081                         "x:y:z:btx:bty:btz:brcx:brcy:brcz:brbx:brby:brbz:brpx:brpy:brpz:brvx:brvy:brvz");
00082 
00083   //Translation:
00084   //First letter is 'b' for magnetic field.
00085   //Second letter is algorithm, 'r' for rect and 'v' for vor
00086   //Third letter is interpolation method's first letter exc.
00087   //PlanarVec, which is 'v'.
00088   //Fourth letter is component of the vector.
00089 
00090   AccTest(testPts,testField,theRectField,theData,kAlgRect);
00091 
00092   MSG("Bfldtest",Msg::kDebug) << "Saving Ntuple " << kRectDataName << endl;
00093 
00094   //Because TFile::Write will write whatever ntuples are in memory to disk,
00095   //we have to remove the rect2d data ntuple from memory before we build
00096   //and write the Voronoi data ntuple.
00097 
00098   outFile.Write();
00099   delete theData;
00100   delete theRectField;
00101 
00102   MSG("Bfldtest",Msg::kDebug)
00103     << "Building Voronoi BField using the following: " << endl;
00104   MSG("Bfldtest",Msg::kDebug) << "Voronoi diagram: " << vorMapFileName << endl;
00105   MSG("Bfldtest",Msg::kDebug) << "Voronoi mesh: " << vorMeshFileName << endl;
00106   MSG("Bfldtest",Msg::kDebug) << "Generator BField data: "
00107                               << vorBFldFileName << endl;
00108   
00109   theVorField = NewBFieldVor(vorMapFileName,vorMeshFileName,
00110                              vorBFldFileName);
00111   
00112   if(!GetAccTestPts(testPts,testField,vorAccTestPtsFileName)) {
00113     MSG("Bfldtest",Msg::kWarning)
00114       << "Problem reading in Voronoi test point file. Bailing." << endl;
00115     return;
00116   }
00117 
00118   theData = new TNtuple(kVorDataName,kVorDataName,
00119                         "x:y:z:btx:bty:btz:bvcx:bvcy:bvcz:bvpx:bvpy:bvpz");
00120 
00121   AccTest(testPts,testField,theVorField,theData,kAlgVor);
00122   
00123   MSG("Bfldtest",Msg::kDebug) << "Saving Ntuple " << kVorDataName << endl;
00124 
00125   outFile.Write();
00126   delete theData;
00127   delete theVorField;
00128 
00129   MSG("Bfldtest",Msg::kInfo) << "Done with accuracy test." << endl;
00130   MSG("Bfldtest",Msg::kInfo) << "Output written to " << outFileName << endl;
00131 }

void BenchmarkPerformance ( const char *  outFileName,
const char *  rectMapFileName,
const char *  vorMapFileName,
const char *  vorMeshFileName,
const char *  vorBFldFileName,
const char *  testPtsFileName 
)

Definition at line 54 of file TestPerf.cc.

References BfldInterpMethod::AsString(), GetNumPointsRect(), GetNumPointsVor(), GetPerfTestPts(), kAlgRect, kAlgVor, Msg::kDebug, kDefaultNumPerfTestPts, Msg::kInfo, kNumRectInterpMethods, kNumVorInterpMethods, kRectInterpMethods, kVorInterpMethods, MSG, RectPerformanceTest(), PerfTestFile::Store(), and VorPerformanceTest().

Referenced by main().

00058                                                        {
00059   //For each algorithm and interpolation method, compute the time to calculate
00060   //the B field as a function of number of points in the map used. This gives
00061   //a rough picture of the relation between performance and memory usage for
00062   //each interpolation algorithm.
00063 
00064   PerfTestFile outFile(outFileName);
00065 
00066   int numPoints;
00067   double timeTaken;
00068 
00069   //Read the test points into memory so that reading from the disk doesn't
00070   //affect the outcome of the test...is that what we want?
00071   vector<TVector3> testPts(kDefaultNumPerfTestPts);
00072   GetPerfTestPts(testPts,testPtsFileName);
00073   
00074   MSG("Bfldtest",Msg::kDebug) << "Testing rect2d algorithm..." << endl;
00075   MSG("Bfldtest",Msg::kDebug)
00076     << "At the moment, does not use file specified but instead" << endl;
00077   MSG("Bfldtest",Msg::kDebug)
00078     << "reverts to default file $BMAPPATH/bfld_142.dat" << endl;
00079   
00080   numPoints = GetNumPointsRect(rectMapFileName);
00081   
00082   //Iterate through the rectilinear interpolation methods.
00083   int j;  
00084   for(j = 0;j < kNumRectInterpMethods;j++) {
00085     MSG("Bfldtest",Msg::kDebug) << "Testing interpolation method: "
00086          << BfldInterpMethod::AsString(kRectInterpMethods[j]) << endl;
00087     timeTaken = RectPerformanceTest(rectMapFileName,kRectInterpMethods[j],
00088                                     testPts);
00089       
00090     outFile.Store(numPoints,timeTaken,kAlgRect,kRectInterpMethods[j]);
00091   }
00092   
00093   //Voronoi algorithm performance test
00094 
00095   MSG("Bfldtest",Msg::kDebug) << "Testing Voronoi algorithm..." << endl;
00096   MSG("Bfldtest",Msg::kDebug)
00097     << "At the moment does not use files specified but instead" << endl;
00098   MSG("Bfldtest",Msg::kDebug)
00099     << "reverts to default files BField/*.default" << endl;
00100   
00101   MSG("Bfldtest",Msg::kDebug) << "Using the following files:" << endl;
00102   MSG("Bfldtest",Msg::kDebug)
00103     << "Voronoi diagram file: " << vorMapFileName << endl;
00104   MSG("Bfldtest",Msg::kDebug)
00105     << "Voronoi mesh file: " << vorMeshFileName << endl;
00106   MSG("Bfldtest",Msg::kDebug)
00107     << "Generator BField data file: " << vorBFldFileName << endl;
00108   
00109   numPoints = GetNumPointsVor(vorMapFileName);
00110   
00111   for(j = 0;j < kNumVorInterpMethods;j++) {
00112     MSG("Bfldtest",Msg::kDebug) << "Testing interpolation method: "
00113          << BfldInterpMethod::AsString(kVorInterpMethods[j]) << endl;
00114     
00115     timeTaken = VorPerformanceTest(vorMapFileName,vorMeshFileName,
00116                                    vorBFldFileName,kVorInterpMethods[j],
00117                                    testPts);
00118     
00119     outFile.Store(numPoints,timeTaken,kAlgVor,kVorInterpMethods[j]);
00120   }
00121   
00122   MSG("Bfldtest",Msg::kInfo) << "Done with performance test." << endl;
00123   MSG("Bfldtest",Msg::kInfo) << "Output written to " << outFileName << endl;
00124 }

int main ( int  argc,
char **  argv 
)

Definition at line 41 of file BfldBenchmark.cc.

References BenchmarkAccuracy(), BenchmarkPerformance(), exit(), MsgService::GetStream(), MsgService::Instance(), Msg::kDebug, kDefaultAccTestOutFileName, kDefaultConfigFileName, kDefaultPerfTestOutFileName, Msg::kFatal, Msg::kInfo, Msg::kName, Msg::kPriority, kProgramOptions, Msg::kWarning, MsgStream::SetFormat(), and MsgStream::SetLogLevel().

00041                                 {
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 }

TROOT root ( "root1"  ,
"root1"   
)

Variable Documentation

const char kDefaultAccTestOutFileName[20] = "accresults.root"

Definition at line 17 of file BfldBenchmark.cc.

Referenced by main().

const char kDefaultConfigFileName[20] = "config.bfb"

Definition at line 19 of file BfldBenchmark.cc.

Referenced by main().

const char kDefaultPerfTestOutFileName[20] = "perfresults.bfb"

Definition at line 18 of file BfldBenchmark.cc.

Referenced by main().

const char kProgramOptions[] = "pahdf:"

Definition at line 21 of file BfldBenchmark.cc.

Referenced by main().


Generated on 19 Jan 2018 for loon by  doxygen 1.6.1