Commit 77947274 authored by Daniel Hynds's avatar Daniel Hynds
Browse files

new algorithm to dump raw data from DUT in hex form


Former-commit-id: a90fd9fbee98b42a5ca427be79a8d3d80dff14cc
parent 413e8420
#include "DataDump.h"
DataDump::DataDump(bool debugging)
: Algorithm("DataDump"){
debug = debugging;
m_detector = "DeviceToDumpData";
}
void DataDump::initialise(Parameters* par){
parameters = par;
// Initialise member variables
m_eventNumber = 0;
}
StatusCode DataDump::run(Clipboard* clipboard){
// Take input directory from global parameters
string inputDirectory = parameters->inputDirectory + "/" + m_detector;
// File structure is RunX/ChipID/files.dat
// Open the root directory
DIR* directory = opendir(inputDirectory.c_str());
if (directory == NULL){tcout<<"Directory "<<inputDirectory<<" does not exist"<<endl; return Failure;}
// Get a list of files and store them
dirent* file;
vector<string> datafiles;
int nFiles(0);
FILE* currentFile = NULL;
long long int syncTime = 0;
bool clearedHeader = false;
// Get all of the files for this chip
while (file = readdir(directory)){
string filename = inputDirectory+"/"+file->d_name;
// Check if file has extension .dat
if (string(file->d_name).find("-1.dat") != string::npos){
datafiles.push_back(filename.c_str());
nFiles++;
}
}
// Now loop over the files, and for each file make a dump of the hex values (except for the header)
for(int fileNumber=0;fileNumber<1;fileNumber++){
// Open a new file
currentFile = fopen(datafiles[fileNumber].c_str(),"rb");
tcout<<"Loading file "<<datafiles[fileNumber]<<endl;
// Open a new output file to dump the data to
ofstream dataDumpFile;
string dataDumpFilename = "outputHexDump.dat";
dataDumpFile.open(dataDumpFilename.c_str());
// Skip the header - first read how big it is
uint32_t headerID;
if (fread(&headerID, sizeof(headerID), 1, currentFile) == 0) {
tcout << "Cannot read header ID" << endl;
return Failure;
}
// Skip the rest of the file header
uint32_t headerSize;
if (fread(&headerSize, sizeof(headerSize), 1, currentFile) == 0) {
tcout << "Cannot read header size" << endl;
return Failure;
}
// Finally skip the header
rewind(currentFile);
fseek(currentFile, headerSize, SEEK_SET);
// Read till the end of file
while (!feof(currentFile)) {
// Read one 64-bit chunk of data
ULong64_t pixdata = 0;
const int retval = fread(&pixdata, sizeof(ULong64_t), 1, currentFile);
dataDumpFile << hex << pixdata << dec << endl;
}
}
// Return value telling analysis to stop
return Failure;
}
void DataDump::finalise(){
if(debug) tcout<<"Analysed "<<m_eventNumber<<" events"<<endl;
}
#ifndef DataDump_H
#define DataDump_H 1
#include "Algorithm.h"
#include <iostream>
#include "TH1F.h"
#include "TH2F.h"
#include "TCanvas.h"
#include "Pixel.h"
#include "Cluster.h"
#include "Track.h"
#include <dirent.h>
#include <sstream>
#include <fstream>
class DataDump : public Algorithm {
public:
// Constructors and destructors
DataDump(bool);
~DataDump(){}
// Functions
void initialise(Parameters*);
StatusCode run(Clipboard*);
void finalise();
// Member variables
int m_eventNumber;
string m_detector;
};
#endif // DataDump_H
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