Minor Changes
This commit is contained in:
@@ -7,3 +7,112 @@
|
||||
//
|
||||
|
||||
#include "logger.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
Logger::Logger() {
|
||||
if (numberZBins == 0) {
|
||||
cout<<"Logging turned off."<<endl;
|
||||
logging = false;
|
||||
return;
|
||||
}
|
||||
set_zLogValues();
|
||||
set_outStream();
|
||||
}
|
||||
|
||||
void Logger::logElectron(Electron *logElectron, blitz::TinyVector<double,3> oldLoc_m) {
|
||||
if (!logging) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Assumption: no change of sign in v_z
|
||||
if (numberZBins == -1) {
|
||||
outStream[0]<<*logElectron<<endl;
|
||||
} else {
|
||||
double zold = oldLoc_m[2];
|
||||
double znew = logElectron->getLoc_m()[2];
|
||||
double zmin = min(zold,znew);
|
||||
double zmax = max(zold,znew);
|
||||
|
||||
for (int i=0;i<numberZBins;i++) {
|
||||
if (zLogValues[i]>=zmin && zLogValues[i]<=zmax) {
|
||||
outStream[i]<<*logElectron<<endl; // Location wrong, because it s the new Location.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::set_zLogValues() {
|
||||
zLogValues.clear();
|
||||
logging = true;
|
||||
if (numberZBins == -1) {
|
||||
cout<<"Logging everything to one file."<<endl;
|
||||
} else if (numberZBins == 1) {
|
||||
cout<<"Logging 1 z-Value: "<<wgtsLength_m<<endl;
|
||||
zLogValues.push_back(wgtsLength_m);
|
||||
} else {
|
||||
for (int i = 0;i<numberZBins;i++) {
|
||||
zLogValues.push_back( i*wgtsLength_m/(numberZBins-1) );
|
||||
}
|
||||
cout<<"Logging "<<numberZBins<<" z-Values."<<endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void Logger::set_outStream() {
|
||||
string dirname = getDirName();
|
||||
|
||||
if (numberZBins == -1) {
|
||||
outStream = new ofstream [1];
|
||||
stringstream ss;
|
||||
ss <<dirname << "/all" << ".dat";
|
||||
outStream[0].open(ss.str().c_str());
|
||||
} else {
|
||||
outStream = new ofstream [numberZBins];
|
||||
for (int i = 0; i < numberZBins; i++)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << dirname << "/z=" << zLogValues[i] << ".dat";
|
||||
outStream[i].open(ss.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string Logger::getDirName() {
|
||||
string poub = getenv("parpath");
|
||||
string pname = getenv("parfile");
|
||||
int i = 1;
|
||||
stringstream dirname;
|
||||
struct stat statbuf;
|
||||
int isDir;
|
||||
do {
|
||||
dirname.str(std::string());
|
||||
dirname << poub << "/" << pname << "_" << getTimeString() << "_" << i++;
|
||||
isDir = 0;
|
||||
if (stat(dirname.str().c_str(), &statbuf) != -1) {
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
isDir = 1;
|
||||
}
|
||||
}
|
||||
} while ( isDir == 1 );
|
||||
if (mkdir(dirname.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
|
||||
stringstream ss;
|
||||
ss<<"Simulation::initLogger: Could not create folder "<<dirname.str()<<" for Logging.";
|
||||
throw (ss.str());
|
||||
}
|
||||
return(dirname.str());
|
||||
}
|
||||
|
||||
string Logger::getTimeString() {
|
||||
time_t rawtime;
|
||||
struct tm * timeinfo;
|
||||
char buffer[80];
|
||||
time (&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
strftime(buffer,sizeof(buffer),"%Y%m%d",timeinfo);
|
||||
string str(buffer);
|
||||
return(str);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user