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

making File Handler into an object and add it to Utils.so library;

cleaning up;
adding miniDAQ binary
parent b6b5bb26
*.o
._*
*~
Data/*
latex/*
html/*
html/
latex/
*.bin
*.raw
Results/*
settings/connections_slc6.xml
# just for G. Auzingers sanity
CalibrationResults
.run_number.txt
......@@ -13,7 +13,7 @@
#include "../Utils/ConsoleColor.h"
#define DEV_FLAG 0
#define COUNT_FLAG 0
// #define COUNT_FLAG 0
namespace Ph2_HwInterface
{
......
......@@ -78,13 +78,19 @@ On this Repo, you can find different version of the software :
- Data class now holds a vector of Events and the events are directly decoded after acquisition - the char* databuffer does not exist any longer
- added methods: std::vector<Event*> GetEvents(); Event* GetEvent()
- updated all scripts
- 17/07/2015: including a new executable flashfpga to upload .mcs files to the EPROM, updated tool base-class, included DQM code from the Beamtest
- 17/07/2015: including a new executable fpgaconfig to upload .mcs files to the EPROM, updated tool base-class, included DQM code from the Beamtest
- fpgaconfig binary allows to upload FW images to EPROM (2 separate images)
- tool base class now contains containers for histograms along with bookHisto(), getHisto(), saveHisto() methods
- modified all other tools accordingly
- merged the DQM code from the June '15 beamtest into miniDQM binary
- updated Makefiles to build RootWeb & miniDQM
- 04/08/2015: adding a faster & more precise algorithm to extract the parameters from SCurves via differentiating it
- 04/08/2015: adding a faster & more precise algorithm to extract the parameters from SCurves via differentiating it - implemented in FastCalibration
- 11/08/2015: adding threaded File IO features (v1-21)
- added FileHandler class for threaded saving of binary data as it comes from the GLIB to file (without speed penalty)
- FileHandler can also read binary files for playback (see miniDAQ/datatestFromfile.cc)
- adding miniDAQ executable that saves to file and handles runnumber in a hidden Data/.run_number.txt file
- miniDQM code based on BT DQM still available for playing back the binary data
- datatest now has a -s option to specify a filename where binary data should be saved (optionally)
......@@ -202,7 +208,11 @@ Follow these instructions to install and compile the libraries:
1. Clone the GitHub repo.
2. Do a make in the root of the repo (make sure you have all µHal, root, boost... libraries on your computer).
2.
$> source setup.sh
3. Do a make in the root of the repo (make sure you have all µHal, root, boost... libraries on your computer).
3. Launch
......@@ -230,8 +240,31 @@ Follow these instructions to install and compile the libraries:
to run the CM noise study
7. Launch
$> commission --help
to do latency & threshold scans
8. Launch
$> fpgaconfig --help
to upload a new FW image to the GLIB
9. Launch
$> miniDAQ --help
to save binary data from the GLIB to file
10. Launch
$> miniDQM --help
to run the DQM code from the June '15 beamtest
7. an example of how to use visitors can be found in src/interfacetest.cc or in the HybridTester class
an example of how to use visitors can be found in src/interfacetest.cc or in the HybridTester class
##### What can you do with the software ?
......@@ -246,6 +279,10 @@ At the moment the package provides the following features:
- Validate Hybrids
- Perform CM noise tests
- user external trigger and clock signals for your tests
- upload .mcs files to the GLIB
- perform simple commissioning procedures
- save binary data to file
- create simple DQM histograms from binary data
- any other routine you want to implement yourself ...
......
#include "FileHandler.h"
//Constructor
FileHandler::FileHandler( std::string pBinaryFileName, char pOption ):
fBinaryFileName( pBinaryFileName ),
fOption( pOption ),
fFileIsOpened( false ) ,
is_set( false )
{
openFile();
if ( fOption == 'w' )
fThread = std::thread( &FileHandler::writeFile, this );
}
//destructor
FileHandler::~FileHandler()
{
fThread.join();
closeFile();
}
void FileHandler::set( std::vector<uint32_t> pVector )
{
fMutex.lock();
fData.clear();
fData = pVector;
is_set = true;
if ( is_set )
fMutex.unlock();
}
bool FileHandler::openFile( )
{
if ( !file_open() )
{
fMutex.lock();
if ( fOption == 'w' ) fBinaryFile.open( ( getFilename() ).c_str(), std::fstream::trunc | std::fstream::out | std::fstream::binary );
else if ( fOption == 'r' ) fBinaryFile.open( getFilename().c_str(), std::fstream::in | std::fstream::binary );
fMutex.unlock();
fFileIsOpened = true;
}
return file_open();
}
void FileHandler::closeFile()
{
fMutex.lock();
fBinaryFile.close();
fMutex.unlock();
}
//read from raw file to vector
std::vector<uint32_t> FileHandler::readFile( )
{
std::vector<uint32_t> cVector;
//open file for reading
while ( !fBinaryFile.eof() )
{
char buffer[4];
fBinaryFile.read( buffer, 4 );
uint32_t word;
std::memcpy( &word, buffer, 4 );
cVector.push_back( word );
}
fBinaryFile.close();
return cVector;
}
void FileHandler::writeFile()
{
while ( true )
{
if ( is_set )
{
fMutex.lock();
uint32_t cBuffer[fData.size()];
std::copy( fData.begin(), fData.end(), cBuffer );
fBinaryFile.write( ( char* )&cBuffer, sizeof( cBuffer ) );
fData.clear();
is_set = false;
fMutex.unlock();
continue;
}
else
{
fMutex.lock();
fMutex.unlock();
continue;
}
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@
#define __FILEHANDLER_H__
#include <istream>
#include <cstring>
#include <iostream>
#include <fstream>
#include <vector>
......@@ -28,89 +29,29 @@ class FileHandler
std::vector<uint32_t> fData;
//Constructor
FileHandler( std::string pBinaryFileName, char pOption ):
fBinaryFileName( pBinaryFileName ),
fOption( pOption ),
fFileIsOpened( false ) ,
is_set( false ) {
openFile();
if ( fOption == 'w' )
fThread = std::thread( &FileHandler::writeFile, this );
}
FileHandler( std::string pBinaryFileName, char pOption );
//destructor
~FileHandler() {
fThread.join();
closeFile();
}
void set( std::vector<uint32_t> pVector ) {
fMutex.lock();
fData.clear();
fData = pVector;
is_set = true;
if ( is_set )
fMutex.unlock();
}
~FileHandler();
void set( std::vector<uint32_t> pVector );
std::string getFilename() {
return fBinaryFileName;
}
bool openFile( ) {
if ( !file_open() ) {
fMutex.lock();
if ( fOption == 'w' ) fBinaryFile.open( ( getFilename() ).c_str(), std::fstream::trunc | std::fstream::out | std::fstream::binary );
else if ( fOption == 'r' ) fBinaryFile.open( getFilename().c_str(), std::fstream::in | std::fstream::binary );
fMutex.unlock();
fFileIsOpened = true;
}
return file_open();
}
bool openFile( );
void closeFile() {
fMutex.lock();
fBinaryFile.close();
fMutex.unlock();
}
void closeFile();
bool file_open() {
return fFileIsOpened;
}
//read from raw file to vector
std::vector<uint32_t> readFile( ) {
std::vector<uint32_t> cVector;
//open file for reading
while ( !fBinaryFile.eof() ) {
char buffer[4];
fBinaryFile.read( buffer, 4 );
uint32_t word;
memcpy( &word, buffer, 4 );
cVector.push_back( word );
}
fBinaryFile.close();
return cVector;
}
std::vector<uint32_t> readFile( );
private:
void writeFile() {
while ( true ) {
if ( is_set ) {
fMutex.lock();
fMutex.unlock();
fMutex.lock();
uint32_t cBuffer[fData.size()];
std::copy( fData.begin(), fData.end(), cBuffer );
fBinaryFile.write( ( char* )&cBuffer, sizeof( cBuffer ) );
fData.clear();
is_set = false;
fMutex.unlock();
continue;
}
else continue;
}
}
void writeFile() ;
};
#endif
......
Objs = Exception.o Utilities.o Event.o Data.o argvparser.o
Objs = Exception.o Utilities.o Event.o Data.o argvparser.o FileHandler.o
CC = gcc
CXX = g++
CCFlags = -g -O1 -w -Wall -pedantic -fPIC -Wcpp
......
#include <cstring>
#include "../Utils/Utilities.h"
#include "../HWDescription/Cbc.h"
#include "../HWDescription/Module.h"
#include "../HWDescription/BeBoard.h"
#include "../HWInterface/CbcInterface.h"
#include "../HWInterface/BeBoardInterface.h"
#include "../HWDescription/Definition.h"
#include "../Utils/Timer.h"
#include <fstream>
#include <inttypes.h>
#include <boost/filesystem.hpp>
#include "../Utils/argvparser.h"
#include "../Utils/ConsoleColor.h"
#include "../System/SystemController.h"
#include "TString.h"
using namespace Ph2_HwDescription;
using namespace Ph2_HwInterface;
using namespace Ph2_System;
using namespace CommandLineProcessing;
//Class used to process events acquired by a parallel acquisition
class AcqVisitor: public HwInterfaceVisitor
{
int cN;
public:
AcqVisitor() {
cN = 0;
}
//void init(std::ofstream* pfSave, bool bText);
virtual void visit( const Ph2_HwInterface::Event& pEvent ) {
cN++;
std::cout << ">>> Event #" << cN << std::endl;
std::cout << pEvent << std::endl;
}
};
void syntax( int argc )
{
if ( argc > 4 ) std::cerr << RED << "ERROR: Syntax: calibrationtest VCth NEvents (HWDescriptionFile)" << std::endl;
else if ( argc < 3 ) std::cerr << RED << "ERROR: Syntax: calibrationtest VCth NEvents (HWDescriptionFile)" << std::endl;
else return;
}
std::string getFileName()
{
std::string line;
std::fstream cFile;
int cRunNumber;
if ( boost::filesystem::exists( ".run_number.txt" ) )
{
cFile.open( ".run_number.txt", std::fstream::out | std::fstream::in );
if ( cFile.is_open() )
{
cFile >> cRunNumber ;
cRunNumber ++;
cFile.clear();
cFile.seekp( 0 );
cFile << cRunNumber;
cFile.close();
}
else
std::cout << "File not opened!" << std::endl;
}
else
{
cRunNumber = 1;
cFile.open( ".run_number.txt", std::fstream::out );
cFile << cRunNumber;
cFile.close();
}
TString cRunString = Form( "run_%03d.raw", cRunNumber );
return cRunString.Data();
}
int main( int argc, char* argv[] )
{
int pEventsperVcth;
int cVcth;
SystemController cSystemController;
ArgvParser cmd;
// init
cmd.setIntroductoryDescription( "CMS Ph2_ACF Data acquisition test and Data dump" );
// error codes
cmd.addErrorCode( 0, "Success" );
cmd.addErrorCode( 1, "Error" );
// options
cmd.setHelpOption( "h", "help", "Print this help page" );
cmd.defineOption( "file", "Hw Description File . Default value: settings/HWDescription_2CBC.xml", ArgvParser::OptionRequiresValue /*| ArgvParser::OptionRequired*/ );
cmd.defineOptionAlternative( "file", "f" );
cmd.defineOption( "events", "Number of Events . Default value: 10", ArgvParser::OptionRequiresValue /*| ArgvParser::OptionRequired*/ );
cmd.defineOptionAlternative( "events", "e" );
cmd.defineOption( "parallel", "Acquisition running in parallel in a separate thread" );
cmd.defineOptionAlternative( "parallel", "p" );
cmd.defineOption( "dqm", "Print every i-th event. ", ArgvParser::OptionRequiresValue );
cmd.defineOptionAlternative( "dqm", "d" );
int result = cmd.parse( argc, argv );
if ( result != ArgvParser::NoParserError )
{
std::cout << cmd.parseErrorDescription( result );
exit( 1 );
}
//bool cSaveToFile = false;
std::string cOutputFile;
// now query the parsing results
std::string cHWFile = ( cmd.foundOption( "file" ) ) ? cmd.optionValue( "file" ) : "settings/HWDescription_2CBC.xml";
const char* cDirectory = "Data";
mkdir( cDirectory , 777 );
cOutputFile = "Data/" + getFileName() ;
pEventsperVcth = ( cmd.foundOption( "events" ) ) ? convertAnyInt( cmd.optionValue( "events" ).c_str() ) : 10;
cSystemController.addFileHandler( cOutputFile, 'w' );
cSystemController.InitializeHw( cHWFile );
cSystemController.ConfigureHw( std::cout );
BeBoard* pBoard = cSystemController.fShelveVector.at( 0 )->fBoardVector.at( 0 );
if ( cmd.foundOption( "parallel" ) )
{
uint32_t nbPacket = pBoard->getReg( CBC_PACKET_NB ), nbAcq = pEventsperVcth / ( nbPacket + 1 ) + ( pEventsperVcth % ( nbPacket + 1 ) != 0 ? 1 : 0 );
std::cout << "Packet number=" << nbPacket << ", Nb events=" << pEventsperVcth << " -> Nb acquisition iterations=" << nbAcq << std::endl;
AcqVisitor visitor;
std::cout << "Press Enter to start the acquisition, press Enter again to stop i" << std::endl;
std::cin.ignore();
cSystemController.fBeBoardInterface->StartThread( pBoard, nbAcq, &visitor );
std::cin.ignore();
cSystemController.fBeBoardInterface->StopThread( pBoard );
}
else
{
// make event counter start at 1 as does the L1A counter
uint32_t cN = 1;
uint32_t cNthAcq = 0;
uint32_t count = 0;
cSystemController.fBeBoardInterface->Start( pBoard );
while ( cN <= pEventsperVcth )
{
uint32_t cPacketSize = cSystemController.fBeBoardInterface->ReadData( pBoard, cNthAcq, false );
if ( cN + cPacketSize >= pEventsperVcth )
cSystemController.fBeBoardInterface->Stop( pBoard, cNthAcq );
const std::vector<Event*>& events = cSystemController.GetEvents( pBoard );
for ( auto& ev : events )
{
count++;
cN++;
if ( cmd.foundOption( "dqm" ) )
{
if ( count % atoi( cmd.optionValue( "dqm" ).c_str() ) == 0 )
{
std::cout << ">>> Event #" << count << std::endl;
std::cout << *ev << std::endl;
}
}
if ( count % 100 == 0 )
std::cout << ">>> Recorded Event #" << count << std::endl;
}
cNthAcq++;
}
}
}
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