The code.ill.fr has been recreated and upgraded with the latest version this weekend, If you encounter any problem please inform the Helpdesk.

Commit 732e4f2f authored by legoc's avatar legoc
Browse files

Added gnuplot application.

parent 2811a30b
...@@ -44,6 +44,17 @@ AC_ARG_ENABLE(cameo, ...@@ -44,6 +44,17 @@ AC_ARG_ENABLE(cameo,
esac],[cameo=false]) esac],[cameo=false])
AM_CONDITIONAL([CAMEO], [test "$cameo" = true]) AM_CONDITIONAL([CAMEO], [test "$cameo" = true])
AC_ARG_ENABLE(gnuplot,
[ --enable-gnuplot compile Gnuplot applications],
[case "${enableval}" in
yes) gnuplot=true ;;
no) gnuplot=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-gnuplot) ;;
esac],[gnuplot=false])
AM_CONDITIONAL([GNUPLOT], [test "$gnuplot" = true])
AC_SUBST(LIBRARY_VERSION) AC_SUBST(LIBRARY_VERSION)
ROOT_LDFLAGS=`root-config --glibs` ROOT_LDFLAGS=`root-config --glibs`
...@@ -55,22 +66,26 @@ AC_SUBST(ROOT_CFLAGS) ...@@ -55,22 +66,26 @@ AC_SUBST(ROOT_CFLAGS)
AX_BOOST_BASE([1.41],, [AC_MSG_ERROR([Boost 1.41 required])]) AX_BOOST_BASE([1.41],, [AC_MSG_ERROR([Boost 1.41 required])])
AM_COND_IF([CAMEO], [AC_CAMEO]) AM_COND_IF([CAMEO], [AC_CAMEO])
AM_COND_IF([GNUPLOT], [AC_GNUPLOT])
LST_CXXFLAGS="$BOOST_CPPFLAGS \ LST_CXXFLAGS="$BOOST_CPPFLAGS \
$ZMQ_CFLAGS \ $ZMQ_CFLAGS \
$PROTOBUF_CFLAGS \ $PROTOBUF_CFLAGS \
$CAMEO_CFLAGS" $CAMEO_CFLAGS \
$GNUPLOT_CFLAGS"
LST_LDFLAGS="$BOOST_LDFLAGS \ LST_LDFLAGS="$BOOST_LDFLAGS \
$ZMQ_LDFLAGS \ $ZMQ_LDFLAGS \
$PROTOBUF_LDFLAGS \ $PROTOBUF_LDFLAGS \
$CAMEO_LDFLAGS" $CAMEO_LDFLAGS \
$GNUPLOT_LDFLAGS"
LST_LIBS="$BOOST_SYSTEM_LIB \ LST_LIBS="$BOOST_SYSTEM_LIB \
$BOOST_THREAD_LIB \ $BOOST_THREAD_LIB \
$ZMQ_LIB \ $ZMQ_LIB \
$PROTOBUF_LIB \ $PROTOBUF_LIB \
$CAMEO_LIBS" $CAMEO_LIBS \
$GNUPLOT_LIBS"
AC_SUBST(LST_CXXFLAGS) AC_SUBST(LST_CXXFLAGS)
AC_SUBST(LST_LDFLAGS) AC_SUBST(LST_LDFLAGS)
...@@ -90,5 +105,6 @@ AC_CONFIG_FILES([ ...@@ -90,5 +105,6 @@ AC_CONFIG_FILES([
src/lstdpp128/apps/nomad/Makefile src/lstdpp128/apps/nomad/Makefile
src/lstdpp128/apps/root/Makefile src/lstdpp128/apps/root/Makefile
src/lstdpp128/apps/cameo/Makefile src/lstdpp128/apps/cameo/Makefile
src/lstdpp128/apps/gnuplot/Makefile
]) ])
AC_OUTPUT AC_OUTPUT
###############################################################################
# Version 02/12/2016
# defines GNUPLOT_CFLAGS, GNUPLOT_LDFLAGS, GNUPLOT_LIBS
#
AC_DEFUN([AC_GNUPLOT],
[
GNUPLOT_CFLAGS=
GNUPLOT_LDFLAGS=
GNUPLOT_LIBS=-lboost_iostreams
AC_SUBST(GNUPLOT_CFLAGS)
AC_SUBST(GNUPLOT_LDFLAGS)
AC_SUBST(GNUPLOT_LIBS)
])
...@@ -10,4 +10,9 @@ if CAMEO ...@@ -10,4 +10,9 @@ if CAMEO
CAMEODIR = cameo CAMEODIR = cameo
endif endif
SUBDIRS = common $(NOMADDIR) $(ROOTDIR) $(CAMEODIR) if GNUPLOT
\ No newline at end of file GNUPLOT = gnuplot
endif
SUBDIRS = common $(NOMADDIR) $(ROOTDIR) $(CAMEODIR) $(GNUPLOT)
\ No newline at end of file
bin_PROGRAMS = \
lstplot128
libs = ../../liblstdpp128.la
lstplot128_SOURCES = \
Plot.cpp
lstplot128_CPPFLAGS = $(LST_CXXFLAGS)
lstplot128_LDFLAGS = $(LST_LDFLAGS)
lstplot128_LDADD = $(libs) $(LST_LIBS)
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://www.osor.eu/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include <iostream>
#include <stdint.h>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <boost/tuple/tuple.hpp>
#include <boost/lexical_cast.hpp>
#define GNUPLOT_ENABLE_PTY
#include "gnuplot-iostream.h"
#include "../../EventData.h"
#include "../../Reader.h"
using namespace std;
using namespace lstdpp128;
const int BUFFER_SIZE = 1 << 10;
std::vector<int32_t> split(const std::string& content) {
vector<int32_t> result;
int lastIndex = 0;
int index = content.find(',');
while (index != string::npos) {
istringstream is(content.substr(lastIndex, index - lastIndex));
int32_t value;
is >> value;
result.push_back(value);
lastIndex = index + 1;
index = content.find(',', lastIndex);
}
istringstream is(content.substr(lastIndex));
int32_t value;
is >> value;
result.push_back(value);
return result;
}
//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
};
std::string dataInfoString(DataInfo dataInfo) {
switch (dataInfo) {
case ENERGY:
return "Energy";
case Q_SHORT:
return "QShort";
case Q_LONG:
return "QLong";
case Q_RATIO:
return "QRatio";
case POSITION_X:
return "PositionX";
case POSITION_Y:
return "PositionY";
case A:
return "A";
case AplusB:
return "A+B";
case ZERO_CROSSING:
return "Zero Crossing";
}
return 0;
}
double eventData(Event const & event, DataInfo dataInfo) {
switch (dataInfo) {
case ENERGY:
return eventEnergy(event);
case Q_SHORT:
return eventQShort(event);
case Q_LONG:
return eventQLong(event);
case Q_RATIO:
return eventQRatio(event);
case POSITION_X:
return eventPositionX(event);
case POSITION_Y:
return eventPositionY(event);
case A:
return eventA(event);
case AplusB:
return eventAplusB(event);
case ZERO_CROSSING:
return eventZeroCrossing(event);
}
return 0;
}
DataInfo selectDataInfo(BoardType type) {
vector<DataInfo> dataInfos;
if (boardHasEnergy(type)) {
dataInfos.push_back(ENERGY);
}
if (boardHasQ(type)) {
dataInfos.push_back(Q_SHORT);
dataInfos.push_back(Q_LONG);
dataInfos.push_back(Q_RATIO);
}
if (boardHasPositionXY(type)) {
dataInfos.push_back(POSITION_X);
dataInfos.push_back(POSITION_Y);
}
if (boardHasAB(type)) {
dataInfos.push_back(A);
dataInfos.push_back(AplusB);
}
if (boardHasZeroCrossing(type)) {
dataInfos.push_back(ZERO_CROSSING);
}
if (dataInfos.size() == 1) {
return dataInfos.front();
}
// Select the data to plot.
cout << "Event data:" << endl;
for (int i = 1; i <= dataInfos.size(); ++i) {
cout << i << ": " << dataInfoString(dataInfos[i - 1]) << endl;
}
int id = 0;
while (true) {
cout << "Select the data to plot:";
cin >> id;
if (id >= 1 && id <= dataInfos.size()) {
break;
}
}
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) {
// reading next block
int32_t index = 0;
int32_t nbIndex = size;
int32_t * bufferPtr = buffer;
while (index < nbIndex) {
// reading event
Event event;
if (readEvent(event, bufferPtr + index)) {
bool display = ((crate == -1 || (crate == event.crate))
&& (board == -1 || (board == event.board))
&& (channel == -1 || (channel == event.channel)));
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));
eventId++;
}
} else {
cout << "problem with event " << hex << " " << setw(8) << setfill('0') << (uint32_t)(*(bufferPtr + index))
<< " " << setw(8) << setfill('0') << (uint32_t)(*(bufferPtr + index + 1))
<< " " << setw(8) << setfill('0') << (uint32_t)(*(bufferPtr + index + 2))
<< " " << setw(8) << setfill('0') << (uint32_t)(*(bufferPtr + index + 3))
<< setw(0) << setfill(' ') << dec << endl;
}
index += 4;
}
}
void plotRollOver(vector<boost::tuple<double, double> > const & rollOverToPlot) {
Gnuplot gpPlot;
gpPlot << "set title 'ROLL OVER'\n";
gpPlot << "unset key\n";
gpPlot << "plot '-' w histep\n";
gpPlot.send(rollOverToPlot);
}
void plotTimestamp(vector<boost::tuple<double, double> > const & timestampToPlot) {
Gnuplot gpPlot;
gpPlot << "set title 'TIME'\n";
gpPlot << "unset key\n";
gpPlot << "plot '-' w histep\n";
gpPlot.send(timestampToPlot);
}
int main(int argc, char * argv[]) {
if (argc < 2) {
cerr << "usage : lstplot128 <file> <filter> [number of events]" << endl;
cerr << " filter is [crate,board,channel]" << endl;
return EXIT_FAILURE;
}
string fileName = argv[1];
int32_t crate = -1;
int32_t board = -1;
int32_t channel = -1;
int numberOfEvents = -1;
if (argc >= 3) {
string valuesString(argv[2]);
valuesString = valuesString.substr(1, valuesString.length() - 2);
vector<int32_t> values = split(valuesString);
cout << "filter:" << endl;
if (values.size() > 0) {
crate = values[0];
cout << "crate " << crate << endl;
}
if (values.size() > 1) {
board = values[1];
cout << "board " << board << endl;
}
if (values.size() > 2) {
channel = values[2];
cout << "channel " << channel << endl;
}
cout << endl;
}
else {
cerr << "please specify a filter [crate,board,channel]" << endl;
exit(0);
}
if (argc >= 4) {
istringstream is(argv[3]);
is >> numberOfEvents;
cout << "reading " << numberOfEvents << " events" << endl;
}
Reader reader(BUFFER_SIZE);
bool success = reader.open(fileName);
if (!success) {
return EXIT_FAILURE;
}
cout << listModeContext << endl;
// Search for the type of the board.
BoardIterator b;
BoardType boardType;
bool found = false;
while (!b.end()) {
if (b.crate() == crate && b.board() == board) {
boardType = (*b).boardType;
found = true;
break;
}
++b;
}
if (!found) {
cerr << "please select a valid board" << endl;
exit(0);
}
// Select the data to plot.
DataInfo dataInfo = selectDataInfo(boardType);
// events
int32_t eventId = 0;
vector<boost::tuple<double, double> > rollOverToPlot;
vector<boost::tuple<double, double> > timestampToPlot;
vector<boost::tuple<double, double> > dataToPlot;
// reading
while (true) {
// reading next block
int32_t size = reader.read();
if (size == 0) {
break;
}
// processing
process(reader.buffer(), size, crate, board, channel, numberOfEvents, dataInfo, eventId, rollOverToPlot, timestampToPlot);
// Exit the loop.
if (numberOfEvents > 0 && eventId > numberOfEvents) {
break;
}
}
cout << "number of events " << dataToPlot.size() << endl;
plotRollOver(rollOverToPlot);
plotTimestamp(timestampToPlot);
// plot the data.
// Gnuplot gpPlot;
//
// gpPlot << "set title '" << dataInfoString(dataInfo) << "'\n";
// gpPlot << "unset key\n";
// gpPlot << "plot '-' w histep\n";
// gpPlot.send(dataToPlot);
return EXIT_SUCCESS;
}
This diff is collapsed.
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