TestPerf.cc File Reference

#include <iostream>
#include <fstream>
#include <vector>
#include "TVector3.h"
#include "TStopwatch.h"
#include "BField/BfldValidate.h"
#include "BField/BfldLoanPool.h"
#include "MessageService/MsgService.h"
#include "TestConstants.h"

Go to the source code of this file.

Classes

class  PerfTestFile

Functions

 CVSID ("$Id: TestPerf.cc,v 1.3 2001/08/21 19:42:54 agoldst Exp $")
void BenchmarkPerformance (const char *outFileName, const char *rectMapFileName, const char *vorMapFileName, const char *vorMeshFileName, const char *vorBFldFileName, const char *testPtsFileName)
double RectPerformanceTest (const char *mapFileName, BfldInterpMethod::InterpMethod_t interpMethod, vector< TVector3 > &testPts)
double VorPerformanceTest (const char *vorMapFileName, const char *meshFileName, const char *vorBFieldFileName, BfldInterpMethod::InterpMethod_t interpMethod, vector< TVector3 > &testPts)
int GetNumPointsRect (const char *fileName)
int GetNumPointsVor (const char *fileName)
BFieldNewBFieldRect (const char *mapFileName)
BFieldNewBFieldVor (const char *vorMapFileName, const char *meshFileName, const char *vorBFieldFileName)
void GetPerfTestPts (vector< TVector3 > &pts, const char *fileName)

Variables

const int kDefaultNumPerfTestPts = 1224

Function Documentation

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 }

CVSID ( "$Id: TestPerf.  cc,
v 1.3 2001/08/21 19:42:54 agoldst Exp $"   
)
int GetNumPointsRect ( const char *  fileName  ) 

Definition at line 20 of file Utils.cc.

00021 {
00022   //Provide an estimate of the space used by the rect2d interpolator.
00023 
00024   //Currently not implemented. But see my documentation for estimates
00025   //of this.
00026   return 0;
00027 }

int GetNumPointsVor ( const char *  fileName  ) 

Definition at line 29 of file Utils.cc.

00030 {
00031   //Provide an estimate of the size used by the Voronoi interpolator.
00032 
00033   //Currently not implemented. But see my documentation for estimates
00034   //of this.
00035   return 0;
00036 }

void GetPerfTestPts ( vector< TVector3 > &  pts,
const char *  fileName 
)

Definition at line 196 of file TestPerf.cc.

References Msg::kDebug, Msg::kWarning, MSG, and n.

Referenced by BenchmarkPerformance().

00196                                                                 {
00197   //Read fileName into pts
00198   //For now, assume the file has the format of NuMuEventHits.dat
00199   //To wit, each line is int id, float x, float y, float z.
00200   //And the units are cm.
00201   //What does Swimmer output look like? This should really be isolated out.
00202 
00203   MSG("Bfldtest",Msg::kDebug) << "Reading in performance test points file "
00204                               << fileName << endl;
00205 
00206   ifstream inFile(fileName,ios::in);
00207   if(!inFile.good()) {
00208     MSG("Bfldtest",Msg::kWarning)
00209       << "Error opening file " << fileName << endl;
00210     return;
00211   }
00212 
00213   int n = pts.size();
00214   int i = 0;
00215 
00216   int id_ignored;
00217   float x,y,z;
00218 
00219   while(!inFile.eof()) {
00220     inFile >> id_ignored >> x >> y >> z;
00221     if(i >= n) {
00222       n *= 2;
00223       pts.resize(n);
00224     }
00225 
00226     pts[i].SetXYZ(x / 100.0,y / 100.0,z / 100.0);
00227     i++;
00228   }
00229   
00230   pts.resize(i);
00231 }

BField* NewBFieldRect ( const char *  mapFileName  ) 

Definition at line 44 of file Utils.cc.

References BfldInterpMethod::kDefault, kFakeMapNum, Detector::kNear, SimFlag::kReroot, and BField::SetInterpMethod().

00044                                                {
00045   BField *theField;
00046 
00047   //***Finish this function!
00048   //At the moment, just uses the standard $BMAPPATH/bfld_142.dat,
00049   //which should be all right. The only way to get rect2d
00050   //to use an arbitrary file is to rewrite the class a bit.
00051 
00052   VldContext theContext(Detector::kNear,SimFlag::kReroot,VldTimeStamp());
00053   theField = new BField(theContext,-1,kFakeMapNum);
00054   theField->SetInterpMethod(BfldInterpMethod::kDefault);
00055 
00056   return theField;
00057 }

BField* NewBFieldVor ( const char *  vorMapFileName,
const char *  meshFileName,
const char *  vorBFieldFileName 
)

Definition at line 65 of file Utils.cc.

References BfldInterpMethod::kDefault, Detector::kNear, SimFlag::kReroot, kVorCoarseness, and BField::SetInterpMethod().

00066                                                     {
00067   //***How do I convince the BField wrapper to use arbitrary data files?
00068   //Again, it would seem that a rewrite of BField is in order.
00069   //In any case, eventually BField will have to get its data from the
00070   //database...
00071   //***Finish this function!
00072 
00073   VldContext theContext(Detector::kNear,SimFlag::kReroot,VldTimeStamp());
00074 
00075   BField *theField = new BField(theContext,kVorCoarseness,true);
00076   theField->SetInterpMethod(BfldInterpMethod::kDefault);
00077 
00078   return theField;
00079 }

double RectPerformanceTest ( const char *  mapFileName,
BfldInterpMethod::InterpMethod_t  interpMethod,
vector< TVector3 > &  testPts 
)

Definition at line 126 of file TestPerf.cc.

References BField::GetBField(), Msg::kDebug, MSG, NewBFieldRect(), BField::SetInterpMethod(), and timer().

Referenced by BenchmarkPerformance().

00128                                                       {
00129   //For the given mapFile, time how long it takes to compute the B field
00130   //by rectilinear interpolation at the points given in the performance test
00131   //point file--typically consisting of a number of plausible paths of muons
00132   //through the detectors.
00133 
00134   //Here should set up the rect interpolator (BField theField) using mapFile.
00135   //Will have to rewrite Bfld package to accept an arbitrary file in this form.
00136   //This should not take too much work. Otherwise, can be kludged.
00137 
00138   MSG("Bfldtest",Msg::kDebug) << "Beginning performance test..." << endl;
00139 
00140   BField *theField = NewBFieldRect(mapFileName);
00141   theField->SetInterpMethod(interpMethod);
00142 
00143   TVector3 b;
00144   int i;
00145   TStopwatch timer;
00146 
00147   theField->GetBField(testPts[0]);
00148   //We make a dummy call because the first call on GetBField has
00149   //lots of overhead (allocating maps, etc.)
00150 
00151   timer.Start();
00152   for(i = 0;i < testPts.size();++i)
00153     b = theField->GetBField(testPts[i]);
00154   timer.Stop();
00155 
00156   delete theField; //NewBFieldRect allocates memory!
00157 
00158   MSG("Bfldtest",Msg::kDebug) << "Test done." << endl;
00159 
00160   return timer.CpuTime();
00161 }

double VorPerformanceTest ( const char *  vorMapFileName,
const char *  meshFileName,
const char *  vorBFieldFileName,
BfldInterpMethod::InterpMethod_t  interpMethod,
vector< TVector3 > &  testPts 
)

Definition at line 163 of file TestPerf.cc.

References BField::GetBField(), Msg::kDebug, MSG, NewBFieldVor(), BField::SetInterpMethod(), and timer().

Referenced by BenchmarkPerformance().

00166                                                      {
00167   //For the given mapFile, compute the time needed to calculate the B field
00168   //at the points given in the performance test point file using the method
00169   //of the team from Athens, with the given interpolation method.
00170 
00171   BField *theField =  NewBFieldVor(vorMapFileName,meshFileName,
00172                                    vorBFieldFileName);
00173   theField->SetInterpMethod(interpMethod);
00174   TVector3 v,b;
00175   int i;
00176 
00177   theField->GetBField(testPts[0]);
00178   //We make a dummy call because the first call on GetBField has
00179   //lots of overhead (allocating maps, etc.)
00180 
00181   MSG("Bfldtest",Msg::kDebug) << "Beginning performance test..." << endl;
00182 
00183   TStopwatch timer;
00184   timer.Start();
00185   for(i = 0;i < testPts.size();++i)
00186     b = theField->GetBField(testPts[i]);
00187   timer.Stop();
00188 
00189   delete theField;
00190 
00191   MSG("Bfldtest",Msg::kDebug) << "Test done." << endl;
00192 
00193   return timer.CpuTime();
00194 }


Variable Documentation

const int kDefaultNumPerfTestPts = 1224

Definition at line 16 of file TestPerf.cc.

Referenced by BenchmarkPerformance().


Generated on 8 Jul 2019 for loon by  doxygen 1.6.1