Commit c83e49de authored by rohe's avatar rohe
Browse files

cleaned up code a little

parent 01a629b8
......@@ -2,7 +2,7 @@
UNAME := $(shell uname)
#cmd_analyzer.o
OBJS = cmd.o command.o cmd_dtb.o cmd_analyzer.o error.o file.o pixel_dtb.o profiler.o protocol.o r4stest.o rpc_calls.o rpc.o rpc_error.o rpc_io.o scanner.o settings.o usb.o linux/rs232.o
OBJS = cmd.o command.o cmd_dtb.o cmd_analyzer.o error.o file.o pixel_dtb.o profiler.o protocol.o r4stest.o rpc_calls.o rpc.o rpc_error.o rpc_io.o scanner.o settings.o usb.o linux/rs232.o R4sImg.o R4sLine.o
ROOTCFLAGS = $(shell $(ROOTSYS)/bin/root-config --cflags)
# root C flags = -pthread -m64 -I/home/pitzl/ROOT/armin/root-cern/include
......
/* -------------------------------------------------------------
*
* file: R4sImg.cpp
*
* description: Converts rawdata from dtb into a "readable" Image
*
* author: Beat Meier
* modified: 31.8.2007
*
* rev: Tilman Rohe
* dat: 28.08.2017
*
* -------------------------------------------------------------
*/
#include "cmd.h"
#include "datalink.h"
#include "R4sImg.h"
//#include "pixelAlive.h"
#include "TROOT.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TH2F.h"
#include "TCanvas.h"
#include "TFile.h"
#include "TString.h"
#include "TTree.h"
#include "TBranch.h"
#include "TLeaf.h"
#include "TGraph.h"
#include "TMultiGraph.h"
#include "TLegend.h"
#include "TCanvas.h"
int R4sImg::Get(int x, int y) {
if ( y>IMG_HEIGHT || x>IMG_WIDTH )
{printf("ERROR: Out of range");return -9999;}
return data[y*IMG_WIDTH + x];
}
bool R4sImg::CreateRaw(const vector<uint16_t> &rawdata)
{
Clear();
if (rawdata.size() < IMG_WIDTH*IMG_HEIGHT) return false;
data = new int[IMG_WIDTH*IMG_HEIGHT];
for (int pos=0; pos<IMG_WIDTH*IMG_HEIGHT; pos++)
{
int value = rawdata[pos];
if (value & 0x1000) // ADC overrange
value = R4S_VALUE_OR;
else if (value & 0x0800) // negative
value -= 0x1000;
data[pos] = value;
dataNEW.push_back(value);
}
return true;
};
void R4sImg::Print(unsigned int count)
{
if (!data)
{
printf("<<empty>>\n");
return;
}
if (count > IMG_WIDTH*IMG_HEIGHT) count = IMG_WIDTH*IMG_HEIGHT;
for (unsigned int i=0; i<count; i++)
{
int v = data[i];
if (v == R4S_VALUE_OR) printf(" or"); else printf(" %4i", v);
}
printf("\n");
tb.Daq_Close();
}
void R4sImg::Save(const string &filename)
{
if (!data)
{
printf("<<empty>>\n");
return;
}
FILE *f = fopen(filename.c_str(), "wt");
if (!f) return;
int i = 0, x, y;
for (y=IMG_HEIGHT-1; y>=0; y--)
{
for (x=0; x<IMG_WIDTH; x++)
{
int v = Get(x,y);
if (v == R4S_VALUE_OR) fprintf(f, " or"); else fprintf(f, " %4i", v);
}
fputs("\n", f);
}
fclose(f);
}
#define IMG_WIDTH 157
#define IMG_HEIGHT 163
#define R4S_VALUE_OR 4096
class R4sImg
{
int *data;
std::vector<int> dataNEW;
public:
R4sImg() : data(0) {}
bool CreateRaw(const vector<uint16_t> &rawdata);
void Clear() { if (data) delete[] data; data = 0; dataNEW.clear();}
void Save(const string &filename);
void Print(unsigned int count);
int Get(int x, int y);
std::vector<int> getData() {return dataNEW;}
};
\ No newline at end of file
/* -------------------------------------------------------------
*
* file: R4sLine.cpp
*
* description: converts rawdata of 1 pixel line from dtb to Integers
*
* author: Tilman Rohe
* modified: 29.9.2017
*
* rev:
* dat:
*
* -------------------------------------------------------------
*/
#include "cmd.h"
#include "datalink.h"
#include "R4sLine.h"
//#include "pixelAlive.h"
#include "TROOT.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TH2F.h"
#include "TCanvas.h"
#include "TFile.h"
#include "TString.h"
#include "TTree.h"
#include "TBranch.h"
#include "TLeaf.h"
#include "TGraph.h"
#include "TMultiGraph.h"
#include "TLegend.h"
#include "TCanvas.h"
int R4sLine::Get(int x) {
if (x>IMG_WIDTH )
{printf("ERROR: Out of range");return -9999;}
return data[x];
}
bool R4sLine::CreateRaw(const vector<uint16_t> &rawdata)
{
Clear();
if (rawdata.size() < IMG_WIDTH) return false;
data = new int[IMG_WIDTH];
for (int pos=0; pos<IMG_WIDTH; pos++)
{
int value = rawdata[pos];
if (value & 0x1000) // ADC overrange
value = R4S_VALUE_OR;
else if (value & 0x0800) // negative
value -= 0x1000;
data[pos] = value;
dataNEW.push_back(value);
}
return true;
};
void R4sLine::Print(unsigned int count)
{
if (!data)
{
printf("<<empty>>\n");
return;
}
if (count > IMG_WIDTH) count = IMG_WIDTH;
for (unsigned int i=0; i<count; i++)
{
int v = data[i];
if (v == R4S_VALUE_OR) printf(" or"); else printf(" %4i", v);
}
printf("\n");
//tb.Daq_Close();
}
void R4sLine::Save(const string &filename)
{
if (!data)
{
printf("<<empty>>\n");
return;
}
FILE *f = fopen(filename.c_str(), "wt");
if (!f) return;
int i = 0, x;
for (x=0; x<IMG_WIDTH; x++)
{
int v = Get(x);
if (v == R4S_VALUE_OR) fprintf(f, " or"); else fprintf(f, " %4i", v);
}
fputs("\n", f);
fclose(f);
}
#define IMG_WIDTH 157
#define IMG_HEIGHT 163
#define R4S_VALUE_OR 4096
class R4sLine
{
int *data;
std::vector<int> dataNEW;
public:
R4sLine() : data(0) {}
bool CreateRaw(const vector<uint16_t> &rawdata);
void Clear() { if (data) delete[] data; data = 0; dataNEW.clear();}
void Save(const string &filename);
void Print(unsigned int count);
int Get(int x);
std::vector<int> getData() {return dataNEW;}
};
......@@ -16,6 +16,8 @@
#include "cmd.h"
#include "datalink.h"
#include "R4sImg.h"
#include "R4sLine.h"
//#include "pixelAlive.h"
#include "TROOT.h"
......@@ -34,105 +36,10 @@
#include "TCanvas.h"
#define IMG_WIDTH 157
#define IMG_HEIGHT 163
#define R4S_VALUE_OR 4096
//================================================================================
class R4sImg
{
int *data;
std::vector<int> dataNEW;
public:
R4sImg() : data(0) {}
bool CreateRaw(const vector<uint16_t> &rawdata);
void Clear() { if (data) delete[] data; data = 0; dataNEW.clear();}
void Save(const string &filename);
void Print(unsigned int count);
int Get(int x, int y);
std::vector<int> getData() {return dataNEW;}
};
int R4sImg::Get(int x, int y) {
if ( y>IMG_HEIGHT || x>IMG_WIDTH )
{printf("ERROR: Out of range");return -9999;}
return data[y*IMG_WIDTH + x];
}
bool R4sImg::CreateRaw(const vector<uint16_t> &rawdata)
{
Clear();
if (rawdata.size() < IMG_WIDTH*IMG_HEIGHT) return false;
data = new int[IMG_WIDTH*IMG_HEIGHT];
for (int pos=0; pos<IMG_WIDTH*IMG_HEIGHT; pos++)
{
int value = rawdata[pos];
if (value & 0x1000) // ADC overrange
value = R4S_VALUE_OR;
else if (value & 0x0800) // negative
value -= 0x1000;
data[pos] = value;
dataNEW.push_back(value);
}
return true;
};
void R4sImg::Print(unsigned int count)
{
if (!data)
{
printf("<<empty>>\n");
return;
}
if (count > IMG_WIDTH*IMG_HEIGHT) count = IMG_WIDTH*IMG_HEIGHT;
for (unsigned int i=0; i<count; i++)
{
int v = data[i];
if (v == R4S_VALUE_OR) printf(" or"); else printf(" %4i", v);
}
printf("\n");
tb.Daq_Close();
}
void R4sImg::Save(const string &filename)
{
if (!data)
{
printf("<<empty>>\n");
return;
}
FILE *f = fopen(filename.c_str(), "wt");
if (!f) return;
int i = 0, x, y;
for (y=IMG_HEIGHT-1; y>=0; y--)
{
for (x=0; x<IMG_WIDTH; x++)
{
int v = Get(x,y);
if (v == R4S_VALUE_OR) fprintf(f, " or"); else fprintf(f, " %4i", v);
}
fputs("\n", f);
}
fclose(f);
}
bool ReadImage(R4sImg &map, bool verbose=true)
{
......@@ -165,99 +72,6 @@ bool ReadImage(R4sImg &map, bool verbose=true)
return map.CreateRaw(data);
}
//================================================================================
//
class R4sLine
{
int *data;
std::vector<int> dataNEW;
public:
R4sLine() : data(0) {}
bool CreateRaw(const vector<uint16_t> &rawdata);
void Clear() { if (data) delete[] data; data = 0; dataNEW.clear();}
void Save(const string &filename);
void Print(unsigned int count);
int Get(int x);
std::vector<int> getData() {return dataNEW;}
};
int R4sLine::Get(int x) {
if (x>IMG_WIDTH )
{printf("ERROR: Out of range");return -9999;}
return data[x];
}
bool R4sLine::CreateRaw(const vector<uint16_t> &rawdata)
{
Clear();
if (rawdata.size() < IMG_WIDTH) return false;
data = new int[IMG_WIDTH];
for (int pos=0; pos<IMG_WIDTH; pos++)
{
int value = rawdata[pos];
if (value & 0x1000) // ADC overrange
value = R4S_VALUE_OR;
else if (value & 0x0800) // negative
value -= 0x1000;
data[pos] = value;
dataNEW.push_back(value);
}
return true;
};
void R4sLine::Print(unsigned int count)
{
if (!data)
{
printf("<<empty>>\n");
return;
}
if (count > IMG_WIDTH) count = IMG_WIDTH;
for (unsigned int i=0; i<count; i++)
{
int v = data[i];
if (v == R4S_VALUE_OR) printf(" or"); else printf(" %4i", v);
}
printf("\n");
//tb.Daq_Close();
}
void R4sLine::Save(const string &filename)
{
if (!data)
{
printf("<<empty>>\n");
return;
}
FILE *f = fopen(filename.c_str(), "wt");
if (!f) return;
int i = 0, x;
for (x=0; x<IMG_WIDTH; x++)
{
int v = Get(x);
if (v == R4S_VALUE_OR) fprintf(f, " or"); else fprintf(f, " %4i", v);
}
fputs("\n", f);
fclose(f);
}
bool ReadLine(R4sLine &pixLine, bool verbose=true)
{
......@@ -316,7 +130,7 @@ TGraph* CreatePulseShapeGraph(int calX,int calY, int Rgpr, int Rgsh, int Va, int
// set readoutsequence to read a line only
tb.r4s_SetSeqReadLine();
// measure pedestal
// measure pedestals
printf("Measureing pedestals...\n");fflush(stdout);
......
......@@ -15,6 +15,7 @@
#include <string>
#include <vector>
#include "r4stest.h"
#include "R4sImg.h"
#include "profiler.h"
......
......@@ -20,6 +20,7 @@
#include "settings.h"
#include "protocol.h"
#define VERSIONINFO TITLE " " VERSION " (" TIMESTAMP ")"
......
Markdown is supported
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