Commit 4c71c356 authored by dino's avatar dino
Browse files

This is the first/main commit of the "new" version of narvel_tests with removal of the local

adf version (myADF0.2, used during the LNL campaign) and unification to the official adf in
svn+ssh://anonsvn@anonsvn.in2p3.fr/agata/gammaware/trunk/src/adf

git-svn-id: svn://gal-serv.lnl.infn.it/agata/trunk/narval_emulator@1064 170316e4-aea8-4b27-aad4-0380ec0519c9
parent 5452fe1d
#
# This is a begin of the ADF configuration record
# Option is Init. It means the Agent is reset before being initialised
#
#////ADF::ConfAgent_beg//// Agata 1 Init
#
#
Endian: kLittle
#
# List of factories required
#
# Factories for Keys
#
KeyFactory: Default
KeyFactory: Agata
#
# Factories for Frames
#
FrameFactory: Agata
#
#
# Version of the primary key that structures the data flow
# and the frame expected to reconfigure it
#
PrimaryKey: Default FS 0 1
#
AutoConf: Agata conf:global 2 0 Agata conf:global 0 0
#
#
# Current Frames going through the data flow
#
Frame: Agata data:crystal 4 0 Agata data:crystal 65000 0
Frame: Agata data:ccrystal 4 0 Agata data:ccrystal 65000 0
Frame: Agata data:ranc0 4 0 Agata data:ranc0 65000 0
Frame: Agata data:ranc1 4 0 Agata data:ranc1 65000 0
Frame: Agata data:psa 4 0 Agata data:psa 65000 1
Frame: Agata data:tracked 4 0 Agata data:tracked 65000 0
Frame: Agata event:data 4 0 Agata event:data 4 0
Frame: Agata event:data:psa 4 0 Agata event:data:psa 4 0
#
# end of Data Flow Defaults
#
#////ADF::ConfAgent_end////
#
#////ADF::AgataKeyFactory_beg//// Init
#
# Definition of the message part for Agata like Keys
#
# Format: KeyNAME message mask
#
# KeyNAME is the string to be passed to the AgataKeyFactory. It should be unique !
# message is the message part as coded in the key
# mask is to be used to extract part of the message when comparing keys
#
# with 0xFAXXYYZZ
#
# XX = Sub-detector number (associated to a given factories)
# 01 for Agata (Agata factory), others are for Ancillaries
# YY = 01 (Frame type)
# 01 data
# 02 service (configuration,info,interface)
# ZZ = Level inside the data flow
#
agata 0xFA000000 0xFF000000
conf 0xFA000200 0xFF00FF00
conf:global 0xFA000200 0xFFFFFFFF
conf:crystal 0xFA010201 0xFFFFFFFF
conf:psa 0xFA010202 0xFFFFFFFF
data 0xFA000100 0xFF00FF00
data:crystal 0xFA010101 0xFFFFFFFF
data:ccrystal 0xFA010111 0xFFFFFFFF
data:psa 0xFA010102 0xFFFFFFFF
event:data:psa 0xFA010103 0xFFFFFFFF
event:data 0xFA010104 0xFFFFFFFF
data:tracked 0xFA010105 0xFFFFFFFF
data:ranc0 0xFA0201A0 0xFFFFFFFF
data:ranc1 0xFA0201A1 0xFFFFFFFF
data:ranc2 0xFA0201A2 0xFFFFFFFF
meta:vertex 0xFA010300 0xFFFFFFFF
#
#////ADF::AgataKeyFactory_end////
#
#
# This is a begin of the ADF configuration record
# Option is Init. It means the Agent is reset before being initialised
#
#////ADF::ConfAgent_beg//// Agata 1 Init
#
#
Endian: kLittle
#
# List of factories required
#
# Factories for Keys
#
KeyFactory: Default
KeyFactory: Agata
#
# Factories for Frames
#
FrameFactory: Agata
#
#
# Version of the primary key that structures the data flow
# and the frame expected to reconfigure it
#
PrimaryKey: Default FS 0 1
#
# comment/uncomment to switch off/on auto-reconf
AutoConf: Agata conf:global 2 0 Agata conf:global 0 0
#
#
# Current Frames going through the data flow
#
Frame: Agata data:crystal 4 0 Agata data:crystal 65000 0
Frame: Agata data:ccrystal 4 0 Agata data:ccrystal 65000 0
Frame: Agata data:ranc0 4 0 Agata data:ranc0 65000 0
Frame: Agata data:ranc1 4 0 Agata data:ranc1 65000 0
Frame: Agata data:psa 4 0 Agata data:psa 65000 1
Frame: Agata data:tracked 4 0 Agata data:tracked 0 0
Frame: Agata event:data 4 0 Agata event:data 4 0
Frame: Agata event:data:psa 4 0 Agata event:data:psa 4 0
Frame: Agata event:data:tracked 4 0 Agata event:data:tracked 4 0
Frame: Agata meta:vertex 4 0 Agata meta:vertex 0 0
#
# end of Data Flow Defaults
#
#////ADF::ConfAgent_end////
/*
C program to emulate how narval loads shared libraries.
J. Ljungvall 2008
D. Bazzacco 2008
D. Mengoni 2008
*/
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#define MXACTORS 10 // maximum number of actors
#define PRSTEP 1 // frequency of prompt
// the pointers to the processes
void (*process_config) (char *configpath, unsigned int *error_code);
void *(*process_register) ( unsigned int *error_code);
void (*process_initialise) (void *algo, unsigned int *error_code);
void (*process_stop) (void *algo, unsigned int *error_code);
void (*process_block_producer) (void *algo,
void *output_buffer, unsigned int size_of_output_buffer,
unsigned int *used_size_of_output_buffer,
unsigned int *error_code);
void (*process_block_filter[MXACTORS-2])(void *algo,
void *input_buffer, unsigned int size_of_input_buffer,
void *output_buffer, unsigned int size_of_output_buffer,
unsigned int *used_size_of_output_buffer,
unsigned int *error_code);
void (*process_block_consumer) (void *algo,
void *input_buffer, unsigned int size_of_input_buffer,
unsigned int *error_code);
int getlibraries (int argc, char **argv);
int getrequiredsymbols ();
int parsenarvalscript (char *scriptfile);
int configureactors (char *configpath);
int getprocesspointers ();
int stopactors ();
char requiredsymbol[256][256];
int numberofrequiredsymbols = 0;
int size_of_input_buffer = 15000000;
int size_of_output_buffer = 15000000;
int used_size_of_output_buffer = 0;
int numberofactors = 0;
char *buffers[MXACTORS];
void *actors [MXACTORS];
void *algos [MXACTORS];
// handler of the SIGINT (CTRL_C) interrupt
unsigned short keep_on_going = 1;
void catch_int(int sig_num)
{
printf("Stopping test\n");
fflush(stdout);
keep_on_going = 0;
}
int main(int argc, char **argv)
{
int ii;
int turn = 0;
int error_code;
printf("\n");
printf("C Code to test c/c++ Narval PSA actors without narval,\n");
printf("using a c main program and dlopen, dlsym etc\n");
printf("Why? Unlike ada, c++ is difficult to get right.\n");
printf(" <-> Narval and debugger does not go together!\n");
printf(" <-> Narval and valgrind does not go together!\n");
printf(" <-> Narval and me (Joa) does not go together!\n");
printf("\n");
if(argc<3) {
printf("usage: %s narvalscript configpath [-Lpathtolib -llib1 -llib2...]\n", argv[0]);
return 0;
}
ii = getlibraries(argc, argv);
if(!ii) return 0;
printf("--------------> ok getlibraries\n\n");
ii = getrequiredsymbols("requiredsymbols");
if(!ii) return 0;
numberofrequiredsymbols = ii;
printf("Number of required symbols %d\n", numberofrequiredsymbols);
printf("--------------> ok getrequiredsimbols\n\n");
ii = parsenarvalscript(argv[1]);
if(!ii) return 0;
printf("--------------> ok parsenarvalscript\n\n");
ii = configureactors(argv[2]);
if(!ii) return 0;
printf("--------------> ok configureactors\n\n");
ii = getprocesspointers();
if(!ii) return 0;
printf("--------------> ok getprocesspointers\n\n");
// CNTRL_C used to stop execution
signal(SIGINT, catch_int);
//////////////////////////////////////////////////////////
/////////////// the execution loop ///////////////////////
printf("****************** START ********************\n");
for(turn = 1; keep_on_going; turn++) {
if(turn%PRSTEP == 0) {
printf("turn %5d\n", turn);
fflush(stdout);
}
// the producer
process_block_producer( algos[0],
buffers[0],
size_of_output_buffer,
&used_size_of_output_buffer,
&error_code);
if(error_code) {
printf("process_block actor %d returned error %d\n", 0, error_code);
break;
}
// the intermediate filters
for (ii=1; ii<numberofactors-1; ii++) {
size_of_input_buffer = used_size_of_output_buffer;
process_block_filter[ii-1]( algos[ii],
buffers[ii-1],
size_of_input_buffer,
buffers[ii],
size_of_output_buffer,
&used_size_of_output_buffer,
&error_code);
if(error_code) {
printf("process_block actor %d returned error %d\n", ii, error_code);
break;
}
}
// the consumer
size_of_input_buffer=used_size_of_output_buffer;
process_block_consumer( algos[numberofactors-1],
buffers[numberofactors-2],
size_of_input_buffer,
&error_code);
if(error_code) {
printf("process_block actor %d returned error %d\n", numberofactors-1, error_code);
break;
}
}
printf("\n****************** STOP ********************\n");
//////////// end of execution loop ///////////////////////
//////////////////////////////////////////////////////////
printf("\n");
stopactors();
printf("\n");
for (ii=0; ii<numberofactors-1; ii++) {
free(buffers[ii]);
}
return 0;
}
int getlibraries(int argc, char **argv)
{
int atlib;
void *libname;
char libbase[256];
char totalpath[512];
char *errormsg = NULL;
libbase[0] = totalpath[0] = 0;
for (atlib=3; atlib<argc; atlib++) {
if(argv[atlib][0]=='-' && argv[atlib][1]=='L') { // change lib directory
strcpy(libbase, argv[atlib]+2);
printf("Changed lib directory to %s\n", libbase);
}
else if(argv[atlib][0]=='-' && argv[atlib][1]=='l') { // load lib
strcpy(totalpath, libbase);
strcat(totalpath, "/lib");
strcat(totalpath, argv[atlib]+2);
strcat(totalpath, ".so");
printf("Loading lib %s.\n", totalpath);
libname = dlopen(totalpath, RTLD_NOW | RTLD_GLOBAL);
errormsg = dlerror();
if(errormsg) {
printf("%s\n", errormsg);
return 0;
}
}
else {
strcpy(totalpath, argv[atlib]);
printf("Loading lib %s\n", totalpath);
libname = dlopen(totalpath, RTLD_NOW | RTLD_GLOBAL);
errormsg = dlerror();
if(errormsg) {
printf("%s\n", errormsg);
return 0;
}
}
}
return 1;
}
int getrequiredsymbols(char * filename)
{
FILE *symbolsfp;
int nlines = 0;
int sizeofline = 1024;
char oneline[1024];
symbolsfp = fopen(filename, "r");
if(!symbolsfp) {
printf("could not open file %s\n", filename);
printf("You have to provide a list of required symbols!\n");
return 0;
}
while(!feof(symbolsfp)) {
if(fgets(oneline, sizeofline, symbolsfp)) {
sscanf(oneline, "%s", requiredsymbol[nlines]);
nlines++;
}
}
fclose(symbolsfp);
return nlines;
}
int parsenarvalscript(char *scriptfile)
{
char keyword1[64], keyword2[64], librarypath[256];
char oneline[1024];
int sizeofline = 1024;
int atsymbol;
char *errormsg = NULL;
FILE *scriptfp;
scriptfp = fopen(scriptfile, "r");
if(scriptfp==0) {
printf("Could not open narval script %s\n", scriptfile);
return 0;
}
numberofactors = 0;
while(!feof(scriptfp) && numberofactors<MXACTORS-1) {
if(fgets(oneline, sizeofline, scriptfp)) {
//printf("%s", oneline);
sscanf(oneline, "%s %s %s", keyword1, keyword2, librarypath);
if(!strcmp(keyword1, "set") && !strcmp(keyword2, "library")) {
/* Get the library*/
actors[numberofactors] = dlopen(librarypath, RTLD_LAZY);
if(!actors[numberofactors]) {
printf("%s\n", dlerror());
return 0;
}
else {
printf("Loaded %s\n", librarypath);
// Make sure it contains the symbols narval needs.
// Define in ./requiredsymbols
printf("Checking for symbols:\n");
for(atsymbol=0;atsymbol<numberofrequiredsymbols; atsymbol++) {
printf("%s...", requiredsymbol[atsymbol]);
dlsym(actors[numberofactors], requiredsymbol[atsymbol]);
errormsg = dlerror();
if(errormsg) {
printf("could not find it.\n");
return 0;
}
printf("ok ");
}
}
buffers[numberofactors] = calloc(15000000, sizeof(char));
numberofactors++;
printf("\n");
}
}
}
// we don't need the last buffer
free(buffers[numberofactors-1]);
buffers[numberofactors-1] = NULL;
fclose(scriptfp);
return 1;
}
int configureactors(char *configpath)
{
int ii;
int error_code = 0;
char *errormsg = NULL;
for (ii=0; ii<numberofactors; ii++) {
/* We need to config the actors*/
printf("Configuring actor %d ", ii);
process_config = dlsym(actors[ii], "process_config");
errormsg = dlerror();
if(errormsg) {
printf("Could not configure actor %d. dlerror() said:%s", ii, errormsg);
}
process_config(configpath, &error_code);
if(error_code) {
printf("Could not configure actor %d. Returned error %d\n", ii, error_code);
return 0;
}
/* We need to register the actor, c++ object is created here*/
printf("done.\nRegistering actor %d ", ii);
process_register = dlsym(actors[ii], "process_register");
errormsg = dlerror();
if(errormsg) {
printf("Could not register actor %d. dlerror() said:%s", ii, errormsg);
}
/*Here create an instance of our c++ class doing the work*/
algos[ii] = process_register(&error_code);
if(error_code) {
printf("Could not register actor %d: Returned error %d\n", ii, error_code);
return 0;
}
printf("done.\nInitializing actor %d ", ii);
process_initialise = dlsym(actors[ii], "process_initialise");
errormsg = dlerror();
if(errormsg) {
printf("Could not initialize actor %d. dlerror() said:%s", ii, errormsg);
}
process_initialise(algos[ii], &error_code);
if(error_code) {
printf("Could not initialize actor %d: Returned error %d\n", ii, error_code);
return 0;
}
printf("done.\n");
}
return 1;
}
int getprocesspointers()
{
int ii;
process_block_producer = dlsym(actors[0], "process_block");
if(!process_block_producer) {
printf("%s\n", dlerror());
return 0;
}
for (ii=1; ii<numberofactors-1; ii++) {
process_block_filter[ii-1] = dlsym(actors[ii], "process_block");
if(!process_block_filter[ii-1]) {
printf("%s\n", dlerror());
return 0;
}
}
process_block_consumer = dlsym(actors[numberofactors-1], "process_block");
if(!process_block_consumer) {
printf("%s\n", dlerror());
return 0;
}
return 1;
}
int stopactors()
{
int ii;
int error_code = 0;
char *errormsg = NULL;
for (ii=0; ii<numberofactors; ii++) {
printf("Stopping actor %d\n", ii);
process_stop = dlsym(actors[ii], "process_stop");
errormsg = dlerror();
if(errormsg) {
printf("Could not find process_stop symbol. dlerror() said:%s", errormsg);
return 0;
}
process_stop(algos[ii], &error_code);
if(error_code) {
printf("Could not stop actor %d: Returned error %d\n", ii, error_code);
}
printf("\n");
}
return 1;
}
WD = $(shell pwd)
DEBUG = -ggdb
ADFINCLUDE = -I$(WD)/../myADF0.2
COMM = $(WD)/../common
PROD = $(WD)/../producers
FILT = $(WD)/../filters
BUIL = $(WD)/../builders
CONS = $(WD)/../consumers
#EHLIBCPP=$(shell g++ -print-file-name=libgcc_eh.a)
#STDLIBCPP=$(shell g++ -print-file-name=libstdc++.so)
##this is for spectrum server GRU implementation
#USEGRU =0
#rootdict=
#ifeq ($(USEGRU),1)
#GRUSYS=/home/daq/narval/_Joa_narvalactors/GRU
## GRUSYS=/home/daq/narval/_Joa_narvalactors/GRU-v_08_07/GRU
#GRUINCLUDES=-I$(GRUSYS)/include
##the folowing lines to avoid root include in the source file
#ROOTEXTRAS = $(shell root-config --cflags)
#ROOTLIB0=/usr/local/lib/root
#ROOTLIB=$(ROOTLIB0)/libCint.so $(ROOTLIB0)/libCore.so $(ROOTLIB0)/libRIO.so $(ROOTLIB0)/libXMLIO.so $(ROOTLIB0)/libThread.so $(ROOTLIB0)/libMatrix.so \
# $(ROOTLIB0)/libHist.so $(ROOTLIB0)/libNet.so $(ROOTLIB0)/libGraf.so $(ROOTLIB0)/libGpad.so $(ROOTLIB0)/libTree.so $(ROOTLIB0)/libGui.so /home/daq/narval/_Joa_narvalactors/GRU/hurddeb/libGRU.so \
# $(ROOTLIB0)/libGX11.so $(ROOTLIB0)/libGX11TTF.so $(ROOTLIB0)/libASImage.so $(ROOTLIB0)/libGraf3d.so $(ROOTLIB0)/libHistPainter.so
#GRUMACRO = -D_FromGRU_
#endif
#MAKEFRAMEFILE= 0
#USEROOT = 0
#ifeq ($(USEROOT),1)
##le librerie ROOT vengono precaricate in narval (script) ma qui devono essere linkate a run time
#ROOTLIB0=/usr/local/lib/root
#ROOTLIB=$(ROOTLIB0)/libCint.so $(ROOTLIB0)/libCore.so $(ROOTLIB0)/libRIO.so $(ROOTLIB0)/libXMLIO.so $(ROOTLIB0)/libThread.so $(ROOTLIB0)/libMatrix.so \$(ROOTLIB0)/libHistPainter.so \
# $(ROOTLIB0)/libHist.so $(ROOTLIB0)/libNet.so $(ROOTLIB0)/libGraf.so $(ROOTLIB0)/libGpad.so \
# $(ROOTLIB0)/libTree.so $(ROOTLIB0)/libGui.so \
# $(ROOTLIB0)/libGX11.so $(ROOTLIB0)/libGX11TTF.so $(ROOTLIB0)/libASImage.so $(ROOTLIB0)/libGraf3d.so
#ROOT = -D_FromROOT_
#ifeq ($(MAKEFRAMEFILE),1)
#ROOT += -D_MakeBINEventFile_
#endif
#ROOTEXTRAS = $(shell root-config --cflags)
#rootdict=tmp.o
#endif
#producer variables
# PCI_EXPRESS=-DPCI_EXPRESS
USETHREADS=-DUSETHREADS # must be defined
BASIC_IO=-DBASIC_IO
CFLAGS = -fPIC -Wall -Wno-reorder $(DEBUG)
CFLAGS += $(ADFINCLUDE)
CFLAGS += $(GRUMACRO) $(USETHREADS) $(PCI_EXPRESS) $(BASIC_IO)
CFLAGS += $(ADFINCLUDE)
CFLAGS += -I$(COMM)
CFLAGS += -I$(PROD)/Crystal -I$(PROD)/Crystal/includeATCA
CFLAGS += -I$(FILT)/Preprocessing -I$(FILT)/Preprocessing/includePrePSA
CFLAGS += -I$(FILT)/PSA -I$(FILT)/PSA/includePSA
CFLAGS += -I$(FILT)/Tracking -I$(FILT)/Tracking/includeOFT
CFLAGS += -I$(BUIL)
CFLAGS += -I$(CONS)
all: library test
test: C_Test
library: libCrystalProducer\
libPreprocessingFilter\
libPSAFilter\
libEventBuilder\
libTrackingFilter\
libBasicAFC
########################## Producer ###################################
libCrystalProducer: libCrystalProducer.o\
CrystalProducer.o\
CrystalProducerATCA.o\
fileATCA.o\
mezzanine.o\
nbReader.o\
misc.o
@echo " Linking " $@
g++ -shared -fPIC $(CFLAGS) $(ROOTLIB) $^ -o $@.so