Commit d6635994 authored by legoc's avatar legoc

Improved plot to select data signed or not

parent f7d9e724
......@@ -64,20 +64,32 @@ std::vector<int32_t> split(const std::string& content) {
//energy, q-short, q-long, Pos. X, Pos. Y, A, A+B, 0-cross
enum DataInfo {
ENERGY = 0,
Q_SHORT = 1,
Q_LONG = 2,
Q_RATIO = 3,
POSITION_X = 4,
POSITION_Y = 5,
A = 6,
AplusB = 7,
ZERO_CROSSING = 8
NONE = 0,
ENERGY = 1,
Q_SHORT = 2,
Q_LONG = 3,
Q_RATIO = 4,
POSITION_X = 5,
POSITION_Y = 6,
A = 7,
AplusB = 8,
ZERO_CROSSING = 9,
DATA = 10,
DATA_SIGNED = 11,
DATAPLUS = 12,
DATAPLUS_SIGNED = 13
};
std::string dataInfoString(DataInfo dataInfo) {
int32_t toSigned(uint32_t data) {
return *reinterpret_cast<int32_t *>(&data);
}
std::string dataInfoToString(DataInfo dataInfo) {
switch (dataInfo) {
case NONE:
return "None";
case ENERGY:
return "Energy";
......@@ -104,6 +116,18 @@ std::string dataInfoString(DataInfo dataInfo) {
case ZERO_CROSSING:
return "Zero Crossing";
case DATA:
return "Data";
case DATA_SIGNED:
return "Data signed";
case DATAPLUS:
return "Data plus";
case DATAPLUS_SIGNED:
return "Data plus signed";
}
return 0;
......@@ -138,6 +162,18 @@ double eventData(Event const & event, DataInfo dataInfo) {
case ZERO_CROSSING:
return eventZeroCrossing(event);
case DATA:
return eventData(event);
case DATA_SIGNED:
return toSigned(eventData(event));
case DATAPLUS:
return eventData(event);
case DATAPLUS_SIGNED:
return toSigned(eventDataPlus(event));
}
return 0;
......@@ -171,6 +207,15 @@ DataInfo selectDataInfo(BoardType type) {
dataInfos.push_back(ZERO_CROSSING);
}
dataInfos.push_back(DATA);
dataInfos.push_back(DATA_SIGNED);
dataInfos.push_back(DATAPLUS);
dataInfos.push_back(DATAPLUS_SIGNED);
if (dataInfos.size() == 0) {
return NONE;
}
if (dataInfos.size() == 1) {
return dataInfos.front();
}
......@@ -178,7 +223,7 @@ DataInfo selectDataInfo(BoardType type) {
// Select the data to plot.
cout << "Event data:" << endl;
for (int i = 1; i <= dataInfos.size(); ++i) {
cout << i << ": " << dataInfoString(dataInfos[i - 1]) << endl;
cout << i << ": " << dataInfoToString(dataInfos[i - 1]) << endl;
}
int id = 0;
......@@ -194,7 +239,7 @@ DataInfo selectDataInfo(BoardType type) {
return dataInfos[id - 1];
}
void process(int32_t * buffer, int32_t size, int32_t crate, int32_t board, int32_t channel, int numberOfEvents, DataInfo dataInfo, int32_t& eventId, vector<boost::tuple<double, double> >& rollOverToPlot, vector<boost::tuple<double, double> >& timestampToPlot) {
void process(int32_t * buffer, int32_t size, int32_t crate, int32_t board, int32_t channel, int numberOfEvents, DataInfo dataInfo, int32_t& eventId, vector<boost::tuple<double, double> >& rollOverToPlot, vector<boost::tuple<double, double> >& timestampToPlot, vector<boost::tuple<double, double> >& dataToPlot) {
// reading next block
int32_t index = 0;
......@@ -213,6 +258,11 @@ void process(int32_t * buffer, int32_t size, int32_t crate, int32_t board, int32
if (display && ((numberOfEvents == -1) || (numberOfEvents > 0 && eventId < numberOfEvents))) {
rollOverToPlot.push_back(boost::make_tuple(eventId, event.rollover));
timestampToPlot.push_back(boost::make_tuple(eventId, event.timestamp));
if (dataInfo != NONE) {
dataToPlot.push_back(boost::make_tuple(eventId, eventData(event, dataInfo)));
}
eventId++;
}
......@@ -231,6 +281,7 @@ void process(int32_t * buffer, int32_t size, int32_t crate, int32_t board, int32
void plotRollOver(vector<boost::tuple<double, double> > const & rollOverToPlot) {
Gnuplot gpPlot;
gpPlot << "set multiplot\n";
gpPlot << "set title 'ROLL OVER'\n";
gpPlot << "unset key\n";
gpPlot << "plot '-' w histep\n";
......@@ -246,6 +297,15 @@ void plotTimestamp(vector<boost::tuple<double, double> > const & timestampToPlot
gpPlot.send(timestampToPlot);
}
void plotData(vector<boost::tuple<double, double> > const & dataToPlot) {
Gnuplot gpPlot;
gpPlot << "set title 'DATA'\n";
gpPlot << "unset key\n";
gpPlot << "plot '-' w histep\n";
gpPlot.send(dataToPlot);
}
int main(int argc, char * argv[]) {
if (argc < 2) {
......@@ -327,8 +387,8 @@ int main(int argc, char * argv[]) {
}
// Select the data to plot.
//DataInfo dataInfo = selectDataInfo(boardType);
DataInfo dataInfo = ENERGY;
DataInfo dataInfo = selectDataInfo(boardType);
cout << "Data plotted is " << dataInfoToString(dataInfo) << endl;
// events
int32_t eventId = 0;
......@@ -346,7 +406,7 @@ int main(int argc, char * argv[]) {
}
// processing
process(reader.buffer(), size, crate, board, channel, numberOfEvents, dataInfo, eventId, rollOverToPlot, timestampToPlot);
process(reader.buffer(), size, crate, board, channel, numberOfEvents, dataInfo, eventId, rollOverToPlot, timestampToPlot, dataToPlot);
// Exit the loop.
if (numberOfEvents > 0 && eventId > numberOfEvents) {
......@@ -354,10 +414,13 @@ int main(int argc, char * argv[]) {
}
}
cout << "number of events " << dataToPlot.size() << endl;
plotRollOver(rollOverToPlot);
plotTimestamp(timestampToPlot);
if (dataInfo != NONE) {
cout << "number of events " << dataToPlot.size() << endl;
plotData(dataToPlot);
}
return EXIT_SUCCESS;
}
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