Commit e591218e authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Move core to using the LOG mechanism

parent 4341646f
......@@ -4,6 +4,7 @@
// Local include files
#include "Analysis.h"
#include "objects/Timepix3Track.h"
#include "utils/log.h"
using namespace corryvreckan;
......@@ -41,6 +42,10 @@ Analysis::Analysis(std::string config_file_name){
m_parameters->masked[m] = true;
}
// FIXME Read remaining parametes from command line:
// Overwrite steering file values from command line
//parameters->readCommandLineOptions(argc,argv);
// Load alignment parameters
std::string conditionsFile = global_config.get<std::string>("conditionsFile");
m_parameters->conditionsFile = conditionsFile;
......@@ -71,7 +76,7 @@ void Analysis::add(Algorithm* algorithm){
void Analysis::run(){
// Loop over all events, running each algorithm on each "event"
cout << endl << "========================| Event loop |========================" << endl;
LOG(STATUS) << "========================| Event loop |========================";
m_events=1;
while(1){
bool run = true;
......@@ -91,7 +96,7 @@ void Analysis::run(){
// Timepix3Tracks* tracks = (Timepix3Tracks*)m_clipboard->get("Timepix3","tracks");
// if(tracks != NULL) nTracks += tracks->size();
// cout<<"\r[Analysis] Current time is "<<fixed<<setw(10)<<m_parameters->currentTime<<". Produced "<<nTracks<<" tracks"<<flush;
// LOG(DEBUG) << "\r[Analysis] Current time is "<<fixed<<setw(10)<<m_parameters->currentTime<<". Produced "<<nTracks<<" tracks"<<flush;
// Clear objects from this iteration from the clipboard
m_clipboard->clear();
......@@ -115,13 +120,13 @@ void Analysis::initialiseAll(){
int nTracks = 0;
// Loop over all algorithms and initialise them
cout << endl << "=================| Initialising algorithms |==================" << endl;
LOG(STATUS) << "=================| Initialising algorithms |==================";
for(int algorithmNumber = 0; algorithmNumber<m_algorithms.size();algorithmNumber++) {
// Make a new folder in the output file
m_directory->cd();
m_directory->mkdir(m_algorithms[algorithmNumber]->getName().c_str());
m_directory->cd(m_algorithms[algorithmNumber]->getName().c_str());
cout<<"["<<m_algorithms[algorithmNumber]->getName()<<"] Initialising"<<endl;
LOG(INFO) << "Initialising \"" << m_algorithms[algorithmNumber]->getName() << "\"";
// Initialise the algorithm
m_algorithms[algorithmNumber]->initialise(m_parameters);
}
......@@ -151,12 +156,11 @@ void Analysis::finaliseAll(){
// Display timing statistics for each algorithm, over all events and per event
void Analysis::timing()
{
cout << endl << "===============| Wall-clock timing (seconds) |================" << endl;
LOG(INFO) << "===============| Wall-clock timing (seconds) |================";
for (int algorithmNumber = 0; algorithmNumber<m_algorithms.size();algorithmNumber++) {
cout.width(25);
cout<<m_algorithms[algorithmNumber]->getName()<<" -- ";
cout<<m_algorithms[algorithmNumber]->getStopwatch()->RealTime()<<" = ";
cout<<m_algorithms[algorithmNumber]->getStopwatch()->RealTime()/m_events<<" s/evt"<<endl;
LOG(INFO) << m_algorithms[algorithmNumber]->getName() << " -- "
<< m_algorithms[algorithmNumber]->getStopwatch()->RealTime() << " = "
<< m_algorithms[algorithmNumber]->getStopwatch()->RealTime()/m_events << " s/evt";
}
cout << "==============================================================\n" << endl;
LOG(INFO) << "==============================================================";
}
......@@ -8,6 +8,7 @@
#include "objects/TestBeamObject.h"
#include "Parameters.h"
#include "utils/log.h"
//-------------------------------------------------------------------------------
// The Clipboard class is used to transfer information between algorithms during
......@@ -59,7 +60,7 @@ public:
// Quick function to check what is currently held by the clipboard
void checkCollections(){
for(int name=0;name<m_dataID.size();name++) cout<<"Data held: "<<m_dataID[name]<<endl;
for(int name=0;name<m_dataID.size();name++) LOG(DEBUG) << "Data held: " << m_dataID[name];
}
private:
......
......@@ -4,8 +4,10 @@
#include <sstream>
#include <unistd.h>
#include "utils/log.h"
Parameters::Parameters(){
histogramFile = "outputHistograms.root";
conditionsFile = "cond.dat";
dutMaskFile = "defaultMask.dat";
......@@ -19,10 +21,9 @@ Parameters::Parameters(){
void Parameters::help()
{
cout << "********************************************************************" << endl;
cout << "Typical 'tbAnalysis' executions are:" << endl;
cout << " => bin/tbAnalysis -d directory" << endl;
cout << endl;
LOG(INFO) << "********************************************************************";
LOG(INFO) << "Typical 'tbAnalysis' executions are:";
LOG(INFO) << " => bin/tbAnalysis -d directory";
}
// Sort function for detectors from low to high z
......@@ -33,91 +34,90 @@ bool sortByZ(string detector1, string detector2){
// Read command line options and set appropriate variables
void Parameters::readCommandLineOptions(int argc, char *argv[]){
// If there are no input parameters then display the help function
if(argc == 1){
help();
return;
}
cout<<endl;
cout<<"===================| Reading Parameters |===================="<<endl<<endl;
LOG(STATUS) << "===================| Reading Parameters |====================";
int option; char temp[256];
while ( (option = getopt(argc, argv, "gema:d:c:n:h:t:o:f:t:p:s:")) != -1) {
switch (option) {
case 'a':
align = true;
sscanf( optarg, "%d", &alignmentMethod);
cout<<"Alignment flagged to be run. Running method "<<alignmentMethod<<endl;
LOG(INFO) << "Alignment flagged to be run. Running method " << alignmentMethod;
break;
case 'e':
eventDisplay = true;
cout<<"Event display flagged to be run"<<endl;
LOG(INFO) << "Event display flagged to be run";
break;
case 'g':
gui = true;
cout<<"GUI flagged to be run"<<endl;
LOG(INFO) << "GUI flagged to be run";
break;
case 'm':
produceMask = true;
cout<<"Will update masked pixel files"<<endl;
LOG(INFO) << "Will update masked pixel files";
break;
case 'd':
sscanf( optarg, "%s", &temp);
inputDirectory = (string)temp;
cout<<"Taking data from: "<<inputDirectory<<endl;
LOG(INFO) << "Taking data from: "<<inputDirectory;
break;
case 'c':
sscanf( optarg, "%s", &temp);
conditionsFile = (string)temp;
cout<<"Picking up conditions file: "<<conditionsFile<<endl;
LOG(INFO) << "Picking up conditions file: "<<conditionsFile;
break;
case 'h':
sscanf( optarg, "%s", &temp);
histogramFile = (string)temp;
cout<<"Writing histograms to: "<<histogramFile<<endl;
LOG(INFO) << "Writing histograms to: "<<histogramFile;
break;
case 'n':
sscanf( optarg, "%d", &nEvents);
cout<<"Running over "<<nEvents<<" events"<<endl;
LOG(INFO) << "Running over "<<nEvents<<" events";
break;
case 'o':
sscanf( optarg, "%lf", &currentTime);
cout<<"Starting at time: "<<currentTime<<" s"<<endl;
LOG(INFO) << "Starting at time: "<<currentTime<<" s";
break;
case 't':
sscanf( optarg, "%s", &temp);
inputTupleFile = (string)temp;
cout<<"Reading tuples from: "<<inputTupleFile<<endl;
LOG(INFO) << "Reading tuples from: "<<inputTupleFile;
break;
case 'f':
sscanf( optarg, "%s", &temp);
outputTupleFile = (string)temp;
cout<<"Writing output tuples to: "<<outputTupleFile<<endl;
LOG(INFO) << "Writing output tuples to: "<<outputTupleFile;
break;
case 'p':
sscanf( optarg, "%lf", &eventLength);
cout<<"Running with an event length of: "<<eventLength<<" s"<<endl;
LOG(INFO) << "Running with an event length of: "<<eventLength<<" s";
break;
case 's':
sscanf( optarg, "%s", &temp);
dutMaskFile = (string)temp;
cout<<"Taking dut mask from: "<<dutMaskFile<<endl;
LOG(INFO) << "Taking dut mask from: "<<dutMaskFile;
}
}
cout<<endl;
LOG(INFO) << endl;
}
bool Parameters::writeConditions(){
// Open the conditions file to write detector information
ofstream conditions;
conditions.open("alignmentOutput.dat");
// Write the file header
conditions << std::left << setw(12) << "DetectorID" << setw(14) << "DetectorType" << setw(10) << "nPixelsX" << setw(10) << "nPixelsY" << setw(8) << "PitchX" << setw(8) << "PitchY" << setw(11) << "X" << setw(11) << "Y" << setw(11) << "Z" << setw(11) << "Rx" << setw(11) << "Ry" << setw(11) << "Rz" << setw(14) << "tOffset"<<endl;
// Loop over all detectors
for(int det = 0; det<this->nDetectors; det++){
string detectorID = this->detectors[det];
......@@ -126,33 +126,33 @@ bool Parameters::writeConditions(){
conditions << std::left << setw(12) << detectorID << setw(14) << detectorParameters->type() << setw(10) << detectorParameters->nPixelsX() << setw(10) << detectorParameters->nPixelsY() << setw(8) << 1000.*detectorParameters->pitchX() << setw(8) << 1000.*detectorParameters->pitchY() << setw(11) << std::fixed << detectorParameters->displacementX() << setw(11) << detectorParameters->displacementY() << setw(11) << detectorParameters->displacementZ() << setw(11) << detectorParameters->rotationX() << setw(11) << detectorParameters->rotationY() << setw(11) << detectorParameters->rotationZ() << setw(14) << std::setprecision(10) << detectorParameters->timingOffset() << resetiosflags( ios::fixed ) << std::setprecision(6) << endl;
}
// Close the file
conditions.close();
}
bool Parameters::readConditions(){
// Open the conditions file to read detector information
ifstream conditions;
conditions.open(conditionsFile.c_str());
string line;
cout<<"----------------------------------------------------------------------------------------------------------------------------------------------------------------"<<endl;
LOG(INFO) << "----------------------------------------------------------------------------------------------------------------------------------------------------------------";
// Loop over file
while(getline(conditions,line)){
// Ignore header
if( line.find("DetectorID") != string::npos ){
cout<<"Device parameters: "<<line<<endl;
LOG(INFO) << "Device parameters: "<<line;
continue;
}
// Make default values for detector parameters
string detectorID(""), detectorType(""); double nPixelsX(0), nPixelsY(0); double pitchX(0), pitchY(0), x(0), y(0), z(0), Rx(0), Ry(0), Rz(0);
double timingOffset(0.);
// Grab the line and parse the data into the relevant variables
istringstream detectorInfo(line);
detectorInfo >> detectorID >> detectorType >> nPixelsX >> nPixelsY >> pitchX >> pitchY >> x >> y >> z >> Rx >> Ry >> Rz >> timingOffset;
......@@ -161,32 +161,32 @@ bool Parameters::readConditions(){
// Save the detector parameters in memory
DetectorParameters* detectorSummary = new DetectorParameters(detectorType,nPixelsX,nPixelsY,pitchX,pitchY,x,y,z,Rx,Ry,Rz,timingOffset);
detector[detectorID] = detectorSummary;
// Temp: register detector
registerDetector(detectorID);
cout<<"Device parameters: "<<line<<endl;
LOG(INFO) << "Device parameters: "<<line;
}
cout<<"----------------------------------------------------------------------------------------------------------------------------------------------------------------"<<endl;
LOG(INFO) << "----------------------------------------------------------------------------------------------------------------------------------------------------------------";
// Now check that all devices which are registered have parameters as well
bool unregisteredDetector=false;
// Loop over all registered detectors
for(int det=0;det<nDetectors;det++){
if(detector.count(detectors[det]) == 0){
cout<<"Detector "<<detectors[det]<<" has no conditions loaded"<<endl;
LOG(INFO) << "Detector "<<detectors[det]<<" has no conditions loaded";
unregisteredDetector = true;
}
}
if(unregisteredDetector) return false;
// Finally, sort the list of detectors by z position (from lowest to highest)
globalDetector = detector;
std::sort(detectors.begin(),detectors.end(),sortByZ);
return true;
}
void Parameters::readDutMask() {
......@@ -194,7 +194,7 @@ void Parameters::readDutMask() {
if(dutMaskFile == "defaultMask.dat") return;
detector[this->DUT]->setMaskFile(dutMaskFile);
// Open the file with masked pixels
std::cout<<"Reading DUT mask file from "<<dutMaskFile<<std::endl;
LOG(INFO) << "Reading DUT mask file from "<<dutMaskFile;
std::fstream inputMaskFile(dutMaskFile.c_str(), std::ios::in);
int row,col; std::string id;
std::string line;
......@@ -218,13 +218,3 @@ void Parameters::maskDutRow(int row){
int nColumns = detector[this->DUT]->nPixelsX();
for(int column=0;column<nColumns;column++) detector[this->DUT]->maskChannel(column,row);
}
#ifndef TEE_H
#define TEE_H 1
#include "utils/log.h"
//-------------------------------------------------------------------------------
// Simple class to replace cout. It adds the algorithm name to the beginning of
// every new line.
......@@ -9,32 +11,32 @@
class tee{
public:
tee(){m_newLine=true;}
tee(std::string algorithmName){
m_algorithmName = algorithmName;
}
~tee(){}
template<class T>
tee &operator<<(const T &x)
{
if(m_newLine){
std::cout<<"["<<m_algorithmName<<"] "<<x;
LOG(INFO)<<"["<<m_algorithmName<<"] "<<x;
m_newLine = false;
}else std::cout<<x;
}else LOG(INFO)<<x;
return *this;
}
tee& operator<<(std::ostream& (*fun)(std::ostream&)){
std::cout << std::endl;
LOG(INFO) << std::endl;
m_newLine=true;
}
// Member variables - the algorithm name and if it is the beginning of a new line
std::string m_algorithmName;
bool m_newLine;
};
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment