Commit cfcaeff5 authored by Georg Auzinger's avatar Georg Auzinger
Browse files

added easylogging to Utils classes

parent ae6f7722
......@@ -27,18 +27,18 @@ struct CbcRegWriter : public HwDescriptionVisitor
std::string fRegName;
uint8_t fRegValue;
CbcRegWriter( CbcInterface* pInterface, std::string pRegName, uint8_t pRegValue ): fInterface( pInterface ), fRegName( pRegName ), fRegValue( pRegValue ) {}
CbcRegWriter( const CbcRegWriter& writer ) : fInterface( writer.fInterface ), fRegName( writer.fRegName ), fRegValue( writer.fRegValue ) {}
CbcRegWriter ( CbcInterface* pInterface, std::string pRegName, uint8_t pRegValue ) : fInterface ( pInterface ), fRegName ( pRegName ), fRegValue ( pRegValue ) {}
CbcRegWriter ( const CbcRegWriter& writer ) : fInterface ( writer.fInterface ), fRegName ( writer.fRegName ), fRegValue ( writer.fRegValue ) {}
void setRegister( std::string pRegName, uint8_t pRegValue )
void setRegister ( std::string pRegName, uint8_t pRegValue )
{
fRegName = pRegName;
fRegValue = pRegValue;
}
void visit( Ph2_HwDescription::Cbc& pCbc )
void visit ( Ph2_HwDescription::Cbc& pCbc )
{
fInterface->WriteCbcReg( &pCbc, fRegName, fRegValue );
fInterface->WriteCbcReg ( &pCbc, fRegName, fRegValue );
}
};
......@@ -48,19 +48,19 @@ struct BeBoardRegWriter : public HwDescriptionVisitor
std::string fRegName;
uint32_t fRegValue;
BeBoardRegWriter( BeBoardInterface* pInterface, std::string pRegName, uint32_t pRegValue ) : fInterface( pInterface ), fRegName( pRegName ), fRegValue( pRegValue ) {}
BeBoardRegWriter ( BeBoardInterface* pInterface, std::string pRegName, uint32_t pRegValue ) : fInterface ( pInterface ), fRegName ( pRegName ), fRegValue ( pRegValue ) {}
BeBoardRegWriter( const BeBoardRegWriter& writer ) : fInterface( writer.fInterface ), fRegName( writer.fRegName ), fRegValue( writer.fRegValue ) {}
BeBoardRegWriter ( const BeBoardRegWriter& writer ) : fInterface ( writer.fInterface ), fRegName ( writer.fRegName ), fRegValue ( writer.fRegValue ) {}
void setRegister( std::string pRegName, uint8_t pRegValue )
void setRegister ( std::string pRegName, uint8_t pRegValue )
{
fRegName = pRegName;
fRegValue = pRegValue;
}
void visit( Ph2_HwDescription::BeBoard& pBoard )
void visit ( Ph2_HwDescription::BeBoard& pBoard )
{
fInterface->WriteBoardReg( &pBoard, fRegName, fRegValue );
fInterface->WriteBoardReg ( &pBoard, fRegName, fRegValue );
}
};
......@@ -70,35 +70,35 @@ struct CbcMultiRegWriter : public HwDescriptionVisitor
CbcInterface* fInterface;
std::vector<std::pair<std::string, uint8_t>> fRegVec;
CbcMultiRegWriter( CbcInterface* pInterface, std::vector<std::pair<std::string, uint8_t>> pRegVec ): fInterface( pInterface ), fRegVec( pRegVec ) {}
CbcMultiRegWriter ( CbcInterface* pInterface, std::vector<std::pair<std::string, uint8_t>> pRegVec ) : fInterface ( pInterface ), fRegVec ( pRegVec ) {}
void visit( Ph2_HwDescription::Cbc& pCbc )
void visit ( Ph2_HwDescription::Cbc& pCbc )
{
fInterface->WriteCbcMultReg( &pCbc, fRegVec );
fInterface->WriteCbcMultReg ( &pCbc, fRegVec );
}
};
// HwDescription Objects Counter
class Counter : public HwDescriptionVisitor
{
private:
private:
uint32_t fNCbc;
uint32_t fNFe;
uint32_t fNBe;
uint32_t fCbcMask;
public:
Counter() : fNCbc( 0 ), fNFe( 0 ), fNBe( 0 ), fCbcMask( 0 ) {}
void visit( Ph2_HwDescription::Cbc& pCbc )
public:
Counter() : fNCbc ( 0 ), fNFe ( 0 ), fNBe ( 0 ), fCbcMask ( 0 ) {}
void visit ( Ph2_HwDescription::Cbc& pCbc )
{
fNCbc++;
fCbcMask |= (1 << pCbc.getCbcId());
fCbcMask |= (1 << pCbc.getCbcId() );
}
void visit( Ph2_HwDescription::Module& pModule )
void visit ( Ph2_HwDescription::Module& pModule )
{
fNFe++;
}
void visit( Ph2_HwDescription::BeBoard& pBoard )
void visit ( Ph2_HwDescription::BeBoard& pBoard )
{
fNBe++;
}
......@@ -123,20 +123,20 @@ public:
// Configurator
class Configurator: public HwDescriptionVisitor
{
private:
private:
BeBoardInterface* fBeBoardInterface;
CbcInterface* fCbcInterface;
public:
Configurator( BeBoardInterface* pBeBoardInterface, CbcInterface* pCbcInterface ): fBeBoardInterface( pBeBoardInterface ), fCbcInterface( pCbcInterface ) {}
void visit( BeBoard& pBoard )
public:
Configurator ( BeBoardInterface* pBeBoardInterface, CbcInterface* pCbcInterface ) : fBeBoardInterface ( pBeBoardInterface ), fCbcInterface ( pCbcInterface ) {}
void visit ( BeBoard& pBoard )
{
fBeBoardInterface->ConfigureBoard( &pBoard );
std::cout << "Successfully configured Board " << +pBoard.getBeId() << std::endl;
fBeBoardInterface->ConfigureBoard ( &pBoard );
LOG (INFO) << "Successfully configured Board " << +pBoard.getBeId();
}
void visit( Cbc& pCbc )
void visit ( Cbc& pCbc )
{
fCbcInterface->ConfigureCbc( &pCbc );
std::cout << "Successfully configured Cbc " << +pCbc.getCbcId() << std::endl;
fCbcInterface->ConfigureCbc ( &pCbc );
LOG (INFO) << "Successfully configured Cbc " << +pCbc.getCbcId();
}
};
......@@ -149,45 +149,47 @@ struct CbcRegReader : public HwDescriptionVisitor
uint8_t fReadRegValue;
CbcInterface* fInterface;
CbcRegReader( CbcInterface* pInterface, std::string pRegName ): fInterface( pInterface ), fRegName( pRegName ) {}
CbcRegReader( const CbcRegReader& reader ): fInterface( reader.fInterface ), fRegName( reader.fRegName ) {}
CbcRegReader ( CbcInterface* pInterface, std::string pRegName ) : fInterface ( pInterface ), fRegName ( pRegName ) {}
CbcRegReader ( const CbcRegReader& reader ) : fInterface ( reader.fInterface ), fRegName ( reader.fRegName ) {}
void setRegister( std::string pRegName )
void setRegister ( std::string pRegName )
{
fRegName = pRegName;
}
void visit( Cbc& pCbc )
void visit ( Cbc& pCbc )
{
fRegValue = pCbc.getReg( fRegName );
fInterface->ReadCbcReg( &pCbc, fRegName );
fReadRegValue = pCbc.getReg( fRegName );
fRegValue = pCbc.getReg ( fRegName );
fInterface->ReadCbcReg ( &pCbc, fRegName );
fReadRegValue = pCbc.getReg ( fRegName );
std::cout << "Reading Reg " << RED << fRegName << RESET << " on CBC " << +pCbc.getCbcId() << " memory value: " << +fRegValue << " read value: " << +fReadRegValue << std::endl;
LOG (INFO) << "Reading Reg " << RED << fRegName << RESET << " on CBC " << +pCbc.getCbcId() << " memory value: " << +fRegValue << " read value: " << +fReadRegValue ;
}
};
struct CbcRegIncrementer : public HwDescriptionVisitor
{
struct CbcRegIncrementer : public HwDescriptionVisitor
{
CbcInterface* fInterface;
std::string fRegName;
int fRegIncrement;
CbcRegIncrementer( CbcInterface* pInterface, std::string pRegName, int pRegIncrement ): fInterface( pInterface ), fRegName( pRegName ), fRegIncrement( pRegIncrement ) {}
CbcRegIncrementer( const CbcRegIncrementer& incrementer ) : fInterface( incrementer.fInterface ), fRegName( incrementer.fRegName ), fRegIncrement( incrementer.fRegIncrement ) {}
CbcRegIncrementer ( CbcInterface* pInterface, std::string pRegName, int pRegIncrement ) : fInterface ( pInterface ), fRegName ( pRegName ), fRegIncrement ( pRegIncrement ) {}
CbcRegIncrementer ( const CbcRegIncrementer& incrementer ) : fInterface ( incrementer.fInterface ), fRegName ( incrementer.fRegName ), fRegIncrement ( incrementer.fRegIncrement ) {}
void setRegister( std::string pRegName, int pRegIncrement )
void setRegister ( std::string pRegName, int pRegIncrement )
{
fRegName = pRegName;
fRegIncrement = pRegIncrement;
}
void visit( Ph2_HwDescription::Cbc& pCbc )
void visit ( Ph2_HwDescription::Cbc& pCbc )
{
uint8_t currentValue = pCbc.getReg(fRegName);
int targetValue = int(currentValue)+fRegIncrement;
if (targetValue > 255) std::cerr << "Error: cannot increment register above 255" << std::endl , targetValue = 255;
else if (targetValue < 0) std::cerr << "Error: cannot increment register below 0 " << std::endl , targetValue = 0;
fInterface->WriteCbcReg( &pCbc, fRegName, uint8_t(targetValue) );
uint8_t currentValue = pCbc.getReg (fRegName);
int targetValue = int (currentValue) + fRegIncrement;
if (targetValue > 255) LOG (ERROR) << "Error: cannot increment register above 255" << std::endl , targetValue = 255;
else if (targetValue < 0) LOG (ERROR) << "Error: cannot increment register below 0 " << std::endl , targetValue = 0;
fInterface->WriteCbcReg ( &pCbc, fRegName, uint8_t (targetValue) );
}
};
......
......@@ -84,10 +84,10 @@ namespace Ph2_HwInterface {
word = swap_bytes (word);
#ifdef __CBCDAQ_DEV__
std::cout << std::setw (3) << "Original " << cWordIndex << " ### " << std::bitset<32> (pData.at (cWordIndex) ) << std::endl;
std::cout << std::setw (3) << "Treated " << cWordIndex << " ### " << std::bitset<32> (word) << std::endl;
LOG (DEBUG) << std::setw (3) << "Original " << cWordIndex << " ### " << std::bitset<32> (pData.at (cWordIndex) );
LOG (DEBUG) << std::setw (3) << "Treated " << cWordIndex << " ### " << std::bitset<32> (word);
if ( (cWordIndex + 1) % fEventSize == 0 && cWordIndex > 0 ) std::cout << std::endl << std::endl;
if ( (cWordIndex + 1) % fEventSize == 0 && cWordIndex > 0 ) LOG (DEBUG) << std::endl << std::endl;
#endif
......
......@@ -17,6 +17,7 @@
#include <ios>
#include <istream>
#include "../Utils/Event.h"
#include "../Utils/easylogging++.h"
#include "../HWDescription/BeBoard.h"
#include "../HWDescription/Definition.h"
......
......@@ -101,7 +101,7 @@ namespace Ph2_HwInterface {
cbcData.assign (cData->second.begin(), cData->second.end() );
}
else
std::cout << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." << std::endl;
LOG (INFO) << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." ;
}
void Event::GetCbcEvent ( const uint8_t& pFeId, const uint8_t& pCbcId, std::vector< uint8_t >& cbcData ) const
......@@ -122,7 +122,7 @@ namespace Ph2_HwInterface {
}
}
else
std::cout << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." << std::endl;
LOG (INFO) << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found.";
}
std::string Event::HexString() const
......@@ -157,7 +157,7 @@ namespace Ph2_HwInterface {
}
else
{
std::cout << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." << std::endl;
LOG (INFO) << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." ;
return false;
}
}
......@@ -177,7 +177,7 @@ namespace Ph2_HwInterface {
return ( (cData->second.at (0) >> 30) & 0x00000003);
else
{
std::cout << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." << std::endl;
LOG (INFO) << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." ;
return 0;
}
}
......@@ -191,7 +191,7 @@ namespace Ph2_HwInterface {
return ( (cData->second.at (0) >> 22) & 0x000000FF);
else
{
std::cout << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." << std::endl;
LOG (INFO) << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." ;
return 0;
}
}
......@@ -231,7 +231,7 @@ namespace Ph2_HwInterface {
}
else
{
std::cout << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." << std::endl;
LOG (INFO) << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." ;
return "";
}
}
......@@ -258,7 +258,7 @@ namespace Ph2_HwInterface {
}
}
else
std::cout << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." << std::endl;
LOG (INFO) << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." ;
return blist;
}
......@@ -295,7 +295,7 @@ namespace Ph2_HwInterface {
}
}
else
std::cout << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." << std::endl;
LOG (INFO) << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." ;
return blist;
}
......@@ -407,7 +407,7 @@ namespace Ph2_HwInterface {
cNHits += __builtin_popcount (cData->second.back() & 0xFF000000);
}
else
std::cout << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." << std::endl;
LOG (INFO) << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." ;
return cNHits;
}
......@@ -437,7 +437,7 @@ namespace Ph2_HwInterface {
}
}
else
std::cout << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." << std::endl;
LOG (INFO) << "Event: FE " << +pFeId << " CBC " << +pCbcId << " is not found." ;
}
std::ostream& operator<< ( std::ostream& os, const Event& ev )
......
......@@ -18,6 +18,7 @@
#include <cstring>
#include <iomanip>
#include "ConsoleColor.h"
#include "../Utils/easylogging++.h"
#include "../HWDescription/Definition.h"
#include "../HWDescription/BeBoard.h"
......
......@@ -65,7 +65,7 @@ bool FileHandler::openFile( )
// if the header is null or not valid, continue without and delete the header
if ( fHeader.fValid == false )
std::cout << "FileHandler: Warning - No valid file Header provided, writing file without ... " << std::endl;
LOG (INFO) << "FileHandler: Warning - No valid file Header provided, writing file without ... " ;
//if the header object is valid i serialize it in the file
else if ( fHeader.fValid)
{
......@@ -91,12 +91,12 @@ bool FileHandler::openFile( )
// and treat it as normal data
if (!fHeader.fValid)
{
std::cout << "FileHandler: No valid header found in file " << fBinaryFileName << " - resetting to 0 and treating as normal data!" << std::endl;
LOG (INFO) << "FileHandler: No valid header found in file " << fBinaryFileName << " - resetting to 0 and treating as normal data!" ;
fBinaryFile.clear( );
fBinaryFile.seekg ( 0, std::ios::beg );
// if the file Header is nullptr I do not get info from it!
}
else std::cout << "FileHandler: Found a valid header in file " << fBinaryFileName << std::endl;
else LOG (INFO) << "FileHandler: Found a valid header in file " << fBinaryFileName ;
}
fMutex.unlock();
......@@ -158,7 +158,7 @@ std::vector<uint32_t> FileHandler::readFileChunks ( uint32_t pNWords32 )
if (fBinaryFile.eof() )
closeFile();
if (cWordCounter < pNWords32) std::cout << "FileHandler: Attention, input file " << fBinaryFileName << " ended before reading " << pNWords32 << " 32-bit words!" << std::endl;
if (cWordCounter < pNWords32) LOG (INFO) << "FileHandler: Attention, input file " << fBinaryFileName << " ended before reading " << pNWords32 << " 32-bit words!" ;
return cVector;
}
......
......@@ -9,6 +9,7 @@
#include <mutex>
#include <thread>
#include "FileHeader.h"
#include "../Utils/easylogging++.h"
/*!
* \class FileHandler
......@@ -106,7 +107,7 @@ class FileHandler
else
fBinaryFile.seekg ( 0, std::ios::beg );
}
else std::cout << "FileHandler: Error, should not try to rewind a file opened in write mode (or file not open!)" << std::endl;
else LOG (INFO) << "FileHandler: Error, should not try to rewind a file opened in write mode (or file not open!)";
}
/*!
......
......@@ -13,6 +13,7 @@
#include <iostream>
#include <vector>
#include "easylogging++.h"
/*!
* \class FileHandler
......@@ -74,7 +75,7 @@ class FileHeader
if (fType.size() < 9)
strcpy (cType, fType.c_str() );
else
std::cout << "FileHeader: Error, type string can only be up to 8 characters long!" << std::endl;
LOG (INFO) << "FileHeader: Error, type string can only be up to 8 characters long!" ;
cVec.push_back (cType[0] << 24 | cType[1] << 16 | cType[2] << 8 | cType[3]);
cVec.push_back (cType[4] << 24 | cType[5] << 16 | cType[6] << 8 | cType[7]);
......@@ -95,7 +96,7 @@ class FileHeader
cVec.push_back (fEventSize32);
cVec.push_back (0xAAAAAAAA);
std::cout << "Board Type: " << fType << " FWMajor " << fVersionMajor << " FWMinor " << fVersionMinor << " BeId " << fBeId << " fNCbc " << fNCbc << " EventSize32 " << fEventSize32 << " valid: " << fValid << std::endl;
LOG (INFO) << "Board Type: " << fType << " FWMajor " << fVersionMajor << " FWMinor " << fVersionMinor << " BeId " << fBeId << " fNCbc " << fNCbc << " EventSize32 " << fEventSize32 << " valid: " << fValid ;
return cVec;
}
......@@ -127,12 +128,12 @@ class FileHeader
fEventSize32 = pVec.at (10);
fValid = true;
std::cout << "Sucess, this is a valid header!" << std::endl;
std::cout << "Board Type: " << fType << " FWMajor " << fVersionMajor << " FWMinor " << fVersionMinor << " BeId " << fBeId << " fNCbc " << fNCbc << " EventSize32 " << fEventSize32 << " valid: " << fValid << std::endl;
LOG (INFO) << "Sucess, this is a valid header!" ;
LOG (INFO) << "Board Type: " << fType << " FWMajor " << fVersionMajor << " FWMinor " << fVersionMinor << " BeId " << fBeId << " fNCbc " << fNCbc << " EventSize32 " << fEventSize32 << " valid: " << fValid ;
}
else
{
std::cout << "Error, this is not a valid header!" << std::endl;
LOG (INFO) << "Error, this is not a valid header!" ;
fValid = false;
}
}
......
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