Commit f39f3cd8 authored by Andrei Muresan's avatar Andrei Muresan
Browse files

Merge branch 'ci/lint' into 'master'

Add code linting

See merge request !2
parents 17eac8de aa52e4a9
Pipeline #27812 passed with stage
in 9 seconds
stages:
- lint
lint:
stage: lint
tags:
- docker-runner
image: "alpine:latest"
script:
- apk add make clang
- ./scripts/ci-lint.sh
\ No newline at end of file
......@@ -29,5 +29,11 @@ obj/RootDict.o : code/Waveform.h code/LecroyFile.h code/V1730File.h code/Wavefor
obj/%.o: code/%.cxx
g++ -c -o $@ $< $(CFLAGS)
format:
find code -name '*.cxx' -or -name '*.h*' | xargs clang-format -i -Werror
lint:
find code -name '*.cxx' -or -name '*.h*' | xargs clang-format --dry-run -Werror -ferror-limit=1
clean:
rm -f obj/* bin/* lib/*
#include "DataFile.h"
// going around macro limitations
int DataFile::timeDifferenceBetweenFiles(){//const char* aFirstFileName,
//const char* aFileName){
//struct stat buf;
//stat(aFirstFileName,&buf);
//time_t firstTime = buf.st_mtime;
//stat(aFileName,&buf);
//return difftime(buf.st_mtime,firstTime);
int DataFile::timeDifferenceBetweenFiles() { // const char* aFirstFileName,
// const char* aFileName){
// struct stat buf;
// stat(aFirstFileName,&buf);
// time_t firstTime = buf.st_mtime;
// stat(aFileName,&buf);
// return difftime(buf.st_mtime,firstTime);
return 1;
}
/*******************************************************
* File reader interface
*
* History:
* v1 2011/11/25 Initial version (Kyle Boone)
*********************************************************/
* File reader interface
*
* History:
* v1 2011/11/25 Initial version (Kyle Boone)
*********************************************************/
#ifndef DATA_FILE_H
#define DATA_FILE_H
#include <time.h>
#include <sys/stat.h>
#include <time.h>
class Waveform;
class DataFile {
protected:
int mWaveformCount;
bool mGood;
int mRun;
double mTriggerTime;
int mWFYNBins;
double mWFYMax;
double mWFYMin;
time_t mFileCreationTime;
public:
// General functions
DataFile(int run) : mGood(true), mWaveformCount(0), mRun(run), mTriggerTime(0), mWFYNBins(-1) {}
virtual int getWaveformCount() { return mWaveformCount; }
int getRun() { return mRun; }
double getTriggerTime(){return mTriggerTime;}
// If the file is not opened properly, or if there are errors reading it
// this will return false.
bool isGood() { return mGood; }
virtual ~DataFile() {};
// Interface to be implemented by subclasses
// Retrieve the waveform at a given index
virtual Waveform* getWaveform(int index){return 0;}
virtual Waveform* getWaveform(const char* aName){return 0;}
virtual Waveform* getNextWaveform()=0;
// Set the format for the names of waveforms that will be retrieved.
virtual void setWaveformNameFormat(const char* format) {};
// when the information about the Y scale of the waveform is stored in the data
int getWFYLimitsKnown(){return mWFYNBins>0;}
double getWFYMax(){return mWFYMax;}
double getWFYMin(){return mWFYMin;}
int getWFYNBins(){return mWFYNBins;}
time_t getFileCreationTime(){return mFileCreationTime;}
static int timeDifferenceBetweenFiles();//(const char* aFirstFileName,
//const char* aFileName);
};
protected:
int mWaveformCount;
bool mGood;
int mRun;
double mTriggerTime;
int mWFYNBins;
double mWFYMax;
double mWFYMin;
time_t mFileCreationTime;
public:
// General functions
DataFile(int run)
: mGood(true), mWaveformCount(0), mRun(run), mTriggerTime(0),
mWFYNBins(-1) {}
virtual int getWaveformCount() { return mWaveformCount; }
int getRun() { return mRun; }
double getTriggerTime() { return mTriggerTime; }
// If the file is not opened properly, or if there are errors reading it
// this will return false.
bool isGood() { return mGood; }
virtual ~DataFile(){};
// Interface to be implemented by subclasses
// Retrieve the waveform at a given index
virtual Waveform *getWaveform(int index) { return 0; }
virtual Waveform *getWaveform(const char *aName) { return 0; }
virtual Waveform *getNextWaveform() = 0;
// Set the format for the names of waveforms that will be retrieved.
virtual void setWaveformNameFormat(const char *format){};
// when the information about the Y scale of the waveform is stored in the
// data
int getWFYLimitsKnown() { return mWFYNBins > 0; }
double getWFYMax() { return mWFYMax; }
double getWFYMin() { return mWFYMin; }
int getWFYNBins() { return mWFYNBins; }
time_t getFileCreationTime() { return mFileCreationTime; }
static int timeDifferenceBetweenFiles(); //(const char* aFirstFileName,
// const char* aFileName);
};
#endif // include guard
/*******************************************************
* Tektronix WFM File reader
*
* History:
* v1 2011/08/17 Initial support for WFM003 mFiles (Kyle Boone)
* v2 2011/11/25 Integration with DataFile class (Kyle Boone)
*
* TODO:
* add support for WFM001 and WFM002 mFiles
* handle endianness
*********************************************************/
* Tektronix WFM File reader
*
* History:
* v1 2011/08/17 Initial support for WFM003 mFiles (Kyle Boone)
* v2 2011/11/25 Integration with DataFile class (Kyle Boone)
*
* TODO:
* add support for WFM001 and WFM002 mFiles
* handle endianness
*********************************************************/
#include "LecroyFile.h"
#include "Waveform.h"
#include "TFile.h"
#include "TKey.h"
#include "TROOT.h"
#include "TList.h"
#include "TROOT.h"
#include "Waveform.h"
//#include <cstring>
//#include <inttypes.h>
#include <iostream>
// --- class functions
LecroyFile::LecroyFile(const char* aFileName):DataFile(0){
// used with macros. Irrelevant with compiled code
mFile = (TFile*) gROOT->GetListOfFiles()->FindObject(aFileName);
if(!mFile){
std::cout << "opening file " << aFileName << std::endl;
mFile = new TFile(aFileName);
}
mKeyIter = new TIter(mFile->GetListOfKeys());
//mKeyLink = mFile->GetListOfKeys()->FirstLink();
mCurIndex=0;
mWaveformCount=mFile->GetNkeys();
LecroyFile::LecroyFile(const char *aFileName) : DataFile(0) {
// used with macros. Irrelevant with compiled code
mFile = (TFile *)gROOT->GetListOfFiles()->FindObject(aFileName);
if (!mFile) {
std::cout << "opening file " << aFileName << std::endl;
mFile = new TFile(aFileName);
}
mKeyIter = new TIter(mFile->GetListOfKeys());
// mKeyLink = mFile->GetListOfKeys()->FirstLink();
mCurIndex = 0;
mWaveformCount = mFile->GetNkeys();
}
LecroyFile::~LecroyFile() {}
LecroyFile::~LecroyFile() {
Waveform *LecroyFile::getNextWaveform() {
Waveform *tWF = (Waveform *)((TKey *)mKeyIter->Next())->ReadObj();
mCurIndex++;
// std::cout << tWF->GetName() << " " << mCurIndex << std::endl;
return tWF;
}
Waveform* LecroyFile::getNextWaveform(){
Waveform* tWF = (Waveform*) ((TKey*) mKeyIter->Next())->ReadObj();
mCurIndex++;
//std::cout << tWF->GetName() << " " << mCurIndex << std::endl;
return tWF;
}
//Waveform* LecroyFile::getWaveform(const char* aHName){
//return (Waveform*) mFile->Get(aHName);
// Waveform* LecroyFile::getWaveform(const char* aHName){
// return (Waveform*) mFile->Get(aHName);
//}
Waveform *LecroyFile::getWaveform(int index) {
Waveform* LecroyFile::getWaveform(int index) {
return 0;//(Waveform*) mFile->Get(wfName);
return 0; //(Waveform*) mFile->Get(wfName);
}
/*******************************************************
* Tektronix WFM File reader
*
* History:
* v1 2011/08/17 Initial support for WFM003 mFiles (Kyle Boone)
* v2 2011/11/25 Integration with DataFile class (Kyle Boone)
*
* TODO:
* add support for LECROY001 and LECROY002 mFiles
* handle endianness
*********************************************************/
#ifndef LECROY_FILE_H
* Tektronix WFM File reader
*
* History:
* v1 2011/08/17 Initial support for WFM003 mFiles (Kyle Boone)
* v2 2011/11/25 Integration with DataFile class (Kyle Boone)
*
* TODO:
* add support for LECROY001 and LECROY002 mFiles
* handle endianness
*********************************************************/
#ifndef LECROY_FILE_H
#define LECROY_FILE_H
#include <fstream>
......@@ -19,32 +19,28 @@
class Waveform;
class TFile;
//class TObjLink;
// class TObjLink;
class TIter;
class LecroyFile : public DataFile {
private:
TFile* mFile;
//TObjLink* mKeyLink;
TIter* mKeyIter;
int mCurIndex;
TFile *mFile;
// TObjLink* mKeyLink;
TIter *mKeyIter;
int mCurIndex;
// waveform data
//Waveform* mWaveform;
// Waveform* mWaveform;
public:
LecroyFile(const char* aFileName);
Waveform* getNextWaveform();
//Waveform* getWaveform(const char* aHName);
Waveform* getWaveform(int index);
LecroyFile(const char *aFileName);
Waveform *getNextWaveform();
// Waveform* getWaveform(const char* aHName);
Waveform *getWaveform(int index);
virtual ~LecroyFile();
private:
// internal helper functions
//bool openFile(const char* filename, int index);
};
// bool openFile(const char* filename, int index);
};
#endif
#include <iostream>
#include <cstdlib>
#include "sys/stat.h"
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <time.h>
#include "sys/stat.h"
#include "LecroyHdfFile.h"
#include "Waveform.h"
#ifdef __CINT__
#include "H5Cpp.h"
#endif
LecroyHdfFile::LecroyHdfFile(const char* aFileName, int aChannel):DataFile(0){
LecroyHdfFile::LecroyHdfFile(const char *aFileName, int aChannel)
: DataFile(0) {
struct stat buf;
stat(aFileName,&buf);
stat(aFileName, &buf);
mFileCreationTime = buf.st_mtime;
mFile = new H5File(aFileName,H5F_ACC_RDONLY );
mFile = new H5File(aFileName, H5F_ACC_RDONLY);
char channelName[100];
sprintf(channelName,"channel%i",aChannel);
sprintf(channelName, "channel%i", aChannel);
mWFDataSet = mFile->openDataSet(channelName);
// --- Read attribute from header. All attribute shown in lecroy manual are available
// --- Read attribute from header. All attribute shown in lecroy manual are
// available
// >>> Attribute were written in the channelx "bank"
Attribute tAttr;
tAttr = mWFDataSet.openAttribute("horiz_interval");
float tDeltaTime;
tAttr.read(PredType::NATIVE_FLOAT,&tDeltaTime);
tAttr.read(PredType::NATIVE_FLOAT, &tDeltaTime);
tAttr = mWFDataSet.openAttribute("horiz_offset");
float tStartTime;
tAttr.read(PredType::NATIVE_FLOAT,&tStartTime);
tAttr.read(PredType::NATIVE_FLOAT, &tStartTime);
tAttr = mWFDataSet.openAttribute("vertical_gain");
tAttr.read(PredType::NATIVE_FLOAT,&mDeltaV);
tAttr.read(PredType::NATIVE_FLOAT, &mDeltaV);
tAttr = mWFDataSet.openAttribute("vertical_offset");
tAttr.read(PredType::NATIVE_FLOAT,&mOffsetV);
tAttr.read(PredType::NATIVE_FLOAT, &mOffsetV);
// --- Read the waveform data from the bank
// >>> Check the bank size
mWFDataSpace = mWFDataSet.getSpace();
......@@ -45,98 +45,101 @@ LecroyHdfFile::LecroyHdfFile(const char* aFileName, int aChannel):DataFile(0){
mWaveformCount = dataDim[0];
mNBins = dataDim[1];
std::cout << "Opening " << aFileName << std::endl;
std::cout << "channel " << aChannel << " bank. nEvents= " << mWaveformCount
<< " | mNBins= " << mNBins
<< " | vertical interval = " << mDeltaV
<< " | vertical offset = " << mOffsetV
<< std::endl;
mWFYMin = mOffsetV-mDeltaV*pow(2,7);
mWFYMax = mOffsetV+mDeltaV*pow(2,7);
mWFYNBins = (int) pow(2,8);
std::cout << "channel " << aChannel << " bank. nEvents= " << mWaveformCount
<< " | mNBins= " << mNBins << " | vertical interval = " << mDeltaV
<< " | vertical offset = " << mOffsetV << std::endl;
mWFYMin = mOffsetV - mDeltaV * pow(2, 7);
mWFYMax = mOffsetV + mDeltaV * pow(2, 7);
mWFYNBins = (int)pow(2, 8);
// >>> select memory for 1 event.
mWFDataOffset[0] = 0; // set to event zero for first event
mWFDataOffset[1] = 0;
mWFDataCount[0] = 1; // read events one by one
mWFDataCount[1] = mNBins;
mWFDataCount[1] = mNBins;
// >>> create memory space for event
hsize_t nDim=1;
hsize_t nDim = 1;
hsize_t dimOut[1];
dimOut[0] = mNBins;
mWFMemSpace = new DataSpace( nDim, dimOut); // not sure what is the difference between this
mWFDataBuffer = new int[mNBins]; // and this. Why twice
mWFMemSpace = new DataSpace(
nDim, dimOut); // not sure what is the difference between this
mWFDataBuffer = new int[mNBins]; // and this. Why twice
// --- create waveform
mWF = new Waveform(mNBins,tStartTime,tStartTime+mNBins*tDeltaTime);
mWF = new Waveform(mNBins, tStartTime, tStartTime + mNBins * tDeltaTime);
// --- Read time data set if present
mTrigTimeDataSetAvailable=1;
try{
mTrigTimeDataSetAvailable = 1;
try {
mTimeDataSet = mFile->openDataSet("trigtime");
}
// catch failure caused by the H5File operations
catch( FileIException error ){
std::cout << std::endl << std::endl << std::endl
<< "No time data set. Must be an older file. You can ignore the earlier error messages but the trigger timing information will not be available" << std::endl;
mTrigTimeDataSetAvailable=0;
catch (FileIException error) {
std::cout << std::endl
<< std::endl
<< std::endl
<< "No time data set. Must be an older file. You can ignore the "
"earlier error messages but the trigger timing information "
"will not be available"
<< std::endl;
mTrigTimeDataSetAvailable = 0;
}
if(mTrigTimeDataSetAvailable){
if (mTrigTimeDataSetAvailable) {
mTimeDataSpace = mTimeDataSet.getSpace(); // space in file
nDataDim = mTimeDataSpace.getSimpleExtentDims(dataDim, NULL);
std::cout << "time bank. n Dim=2? " << nDataDim << " nEvents = " << dataDim[0] << " dim check =2? " << dataDim[1] << std::endl;
std::cout << "time bank. n Dim=2? " << nDataDim
<< " nEvents = " << dataDim[0] << " dim check =2? " << dataDim[1]
<< std::endl;
//
mTimeDataCount[0]=1; // read events one by one
mTimeDataCount[1]=2;
// >>> space in memory
nDim=1;
mTimeDataCount[0] = 1; // read events one by one
mTimeDataCount[1] = 2;
// >>> space in memory
nDim = 1;
dimOut[0] = 2;
mTimeMemSpace = new DataSpace(nDim, dimOut); // only want one value
mTimeMemSpace = new DataSpace(nDim, dimOut); // only want one value
}
}
Waveform* LecroyHdfFile::getNextWaveform(){
Waveform *LecroyHdfFile::getNextWaveform() {
getWaveform(mWFDataOffset[0]);
mWFDataOffset[0]++;
return mWF;
}
Waveform* LecroyHdfFile::getWaveform(int index){
//Attribute tAttr;
//tAttr = mWFDataSet.openAttribute("trigtime_array");
//char tTime[8];
//std::cout << "Attribute "
// << tAttr.getInMemDataSize() << std::endl;
//tAttr.read(PredType::NATIVE_ULONG,&tTime);
//std::cout << atof(tTime) << std::endl;
mWFDataOffset[0]=index;
mWFDataSpace.selectHyperslab( H5S_SELECT_SET, mWFDataCount, mWFDataOffset );
mWFDataSet.read(mWFDataBuffer,
PredType::NATIVE_INT,
*mWFMemSpace,
mWFDataSpace );
for(int iBin=0; iBin<mNBins; iBin++){
mWF->SetBinContent(iBin+1,mOffsetV+mWFDataBuffer[iBin]*mDeltaV);
Waveform *LecroyHdfFile::getWaveform(int index) {
// Attribute tAttr;
// tAttr = mWFDataSet.openAttribute("trigtime_array");
// char tTime[8];
// std::cout << "Attribute "
// << tAttr.getInMemDataSize() << std::endl;
// tAttr.read(PredType::NATIVE_ULONG,&tTime);
// std::cout << atof(tTime) << std::endl;
mWFDataOffset[0] = index;
mWFDataSpace.selectHyperslab(H5S_SELECT_SET, mWFDataCount, mWFDataOffset);
mWFDataSet.read(mWFDataBuffer, PredType::NATIVE_INT, *mWFMemSpace,
mWFDataSpace);
for (int iBin = 0; iBin < mNBins; iBin++) {
mWF->SetBinContent(iBin + 1, mOffsetV + mWFDataBuffer[iBin] * mDeltaV);
}
if(mTrigTimeDataSetAvailable){
mTimeDataSpace.selectHyperslab( H5S_SELECT_SET, mTimeDataCount, mWFDataOffset);
mTimeDataSet.read(mTimeDataBuffer,
PredType::NATIVE_DOUBLE,
*mTimeMemSpace,
mTimeDataSpace);
mTriggerTime = mTimeDataBuffer[0];//+mTimeDataBuffer[1];
//std::cout << mTimeDataBuffer[0] << " " << mTimeDataBuffer[1] << std::endl;
if (mTrigTimeDataSetAvailable) {
mTimeDataSpace.selectHyperslab(H5S_SELECT_SET, mTimeDataCount,
mWFDataOffset);
mTimeDataSet.read(mTimeDataBuffer, PredType::NATIVE_DOUBLE, *mTimeMemSpace,
mTimeDataSpace);
mTriggerTime = mTimeDataBuffer[0]; //+mTimeDataBuffer[1];
// std::cout << mTimeDataBuffer[0] << " " << mTimeDataBuffer[1] <<
// std::endl;
}
return mWF;
}
LecroyHdfFile::~LecroyHdfFile(){
delete mFile;
delete mWFMemSpace;
delete[] mWFDataBuffer;
if(mTrigTimeDataSetAvailable) delete mTimeMemSpace;
delete mWF;
LecroyHdfFile::~LecroyHdfFile() {
delete mFile;
delete mWFMemSpace;
delete[] mWFDataBuffer;
if (mTrigTimeDataSetAvailable)
delete mTimeMemSpace;
delete mWF;
}
/*******************************************************
* Tektronix WFM File reader
*
* History:
* v1 2011/08/17 Initial support for WFM003 mFiles (Kyle Boone)
* v2 2011/11/25 Integration with DataFile class (Kyle Boone)
*
* TODO:
* add support for LECROY001 and LECROY002 mFiles
* handle endianness
*********************************************************/
#ifndef LECROYHDF_FILE_H
* Tektronix WFM File reader
*
* History:
* v1 2011/08/17 Initial support for WFM003 mFiles (Kyle Boone)
* v2 2011/11/25 Integration with DataFile class (Kyle Boone)
*
* TODO:
* add support for LECROY001 and LECROY002 mFiles
* handle endianness
*********************************************************/
#ifndef LECROYHDF_FILE_H
#define LECROYHDF_FILE_H
#include "DataFile.h"
......@@ -28,37 +28,33 @@ class hsize_t;
class Waveform;
class LecroyHdfFile : public DataFile {
public:
LecroyHdfFile(const char* aFileName, int aChannel=1);
Waveform* getNextWaveform();
Waveform* getWaveform(int index);
public:
LecroyHdfFile(const char *aFileName, int aChannel = 1);
Waveform *getNextWaveform();
Waveform *getWaveform(int index);
virtual ~LecroyHdfFile();
private:
H5File* mFile;
H5File *mFile;
DataSet mWFDataSet;