From 0c7e0aa2e0171d9ef6eeaaaea9e6ae12aa87905f Mon Sep 17 00:00:00 2001
From: Petr Zejdl <petr.zejdl@cern.ch>
Date: Fri, 19 Oct 2018 13:52:01 +0200
Subject: [PATCH] Updating makefile for WZ DMA; Making pipeline processors
 configurable through conf file

---
 src/Makefile   | 29 +++++++++++++++++------------
 src/config.h   | 13 +++++++++++--
 src/scdaq.cc   | 31 ++++++++++++++++++++++---------
 src/scdaq.conf | 14 +++++++++++---
 4 files changed, 61 insertions(+), 26 deletions(-)

diff --git a/src/Makefile b/src/Makefile
index 4537122f..acc05d03 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -12,22 +12,24 @@
 TARGET = scdaq
 
 # source files
-SOURCES = config.cc  dma_input.cc elastico.cc  file_input.cc  input.cc  output.cc  processor.cc  scdaq.cc  session.cc  slice.cc
+SOURCES = config.cc dma_input.cc elastico.cc  file_input.cc  input.cc  output.cc  processor.cc  scdaq.cc  session.cc  slice.cc wzdma_input.cc
+C_SOURCES = wz_dma.c
 
 # work out names of object files from sources
 OBJECTS = $(SOURCES:.cc=.o)
+OBJECTS += $(C_SOURCES:.c=.o)
 
 # compiler flags (do not include -c here as it's dealt with by the
 # appropriate rules; CXXFLAGS gets passed as part of command
 # invocation for both compilation (where -c is needed) and linking
 # (where it's not.)
-#CXXFLAGS = -std=c++11 -Wall -Wextra -O0 -g -rdynamic
-CXXFLAGS = -std=c++11 -Wall -Wextra 
+CXXFLAGS = -std=c++11 -Wall -Wextra -O0 -g -rdynamic
+#CXXFLAGS = -std=c++11 -Wall -Wextra 
 
+CFLAGS = $(CXXFLAGS)
 LDFLAGS = -ltbb -lboost_thread -lcurl
 
-CPPFLAGS = -I.
-
+CPPFLAGS = -I. -Iwzdma
 
 # default target (to build all)
 all: ${TARGET}
@@ -55,13 +57,16 @@ ${TARGET}: ${OBJECTS}
 
 #test2.o : product.h test2.h
 
-scdaq.o:		file_input.h processor.h elastico.h output.h format.h server.h controls.h config.h
-config.o:		config.h
+scdaq.o:	file_input.h processor.h elastico.h output.h format.h server.h controls.h config.h
+config.o:	config.h
 dma_input.o:	dma_input.h slice.h
-elastico.o:		elastico.h format.h slice.h controls.h
+elastico.o:	elastico.h format.h slice.h controls.h
 file_input.o:	file_input.h slice.h utility.h
-input.o:		input.h slice.h
-output.o:		output.h slice.h
+input.o:	input.h slice.h
+output.o:	output.h slice.h
 processor.o:	processor.h slice.h format.h
-session.o:		session.h
-slice.o: 		slice.h
+session.o:	session.h
+slice.o: 	slice.h
+wzdma_input.o:	wzdma_input.h slice.h
+wz_dma.o:	wz_dma.h
+
diff --git a/src/config.h b/src/config.h
index 1030aa60..66c50048 100644
--- a/src/config.h
+++ b/src/config.h
@@ -10,7 +10,7 @@
 class config{
 public:
   
-  enum class InputType { DMA, FILE };
+  enum class InputType { WZDMA, DMA, FILE };
 
   config(std::string filename);
 
@@ -18,6 +18,9 @@ public:
 
   InputType getInput() const {
     const std::string& input = vmap.at("input");
+    if (input == "wzdma") {
+      return InputType::WZDMA;
+    }
     if (input == "dma") {
       return InputType::DMA;
     }
@@ -77,7 +80,13 @@ public:
     std::string v = vmap.at("port");
     return boost::lexical_cast<short>(v.c_str());
   }
-  
+  bool getEnableStreamProcessor() const {
+    return (true ? vmap.at("enable_stream_processor") == "yes" : false);
+  }
+  bool getEnableElasticProcessor() const {
+    return (true ? vmap.at("enable_stream_processor") == "yes" : false);
+  }
+
 private:
   
   std::map<std::string,std::string> vmap;
diff --git a/src/scdaq.cc b/src/scdaq.cc
index b27ba464..296ae56c 100644
--- a/src/scdaq.cc
+++ b/src/scdaq.cc
@@ -15,7 +15,7 @@
 #include <boost/thread.hpp>
 
 
-
+#include "wzdma_input.h"
 #include "dma_input.h"
 #include "file_input.h"
 #include "processor.h"
@@ -64,6 +64,17 @@ int run_pipeline( int nthreads, ctrl *control, config *conf)
 
       // Create DMA reader
       input_filter = std::make_shared<DmaInputFilter>( conf->getDmaDevice(), MAX_BYTES_PER_INPUT_SLICE, TOTAL_SLICES );
+
+  } else if (input == config::InputType::WZDMA ) {
+      // Prepare reading from WZ DMA
+      MAX_BYTES_PER_INPUT_SLICE = conf->getDmaPacketBufferSize();
+      TOTAL_SLICES = conf->getNumberOfDmaPacketBuffers();
+
+      // Create WZ DMA reader
+      input_filter = std::make_shared<WZDmaInputFilter>( MAX_BYTES_PER_INPUT_SLICE, TOTAL_SLICES );
+
+  } else {
+    throw std::invalid_argument("Configuration error: Unknown input type was specified");
   }
 
   // Add input reader to a pipeline
@@ -74,17 +85,19 @@ int run_pipeline( int nthreads, ctrl *control, config *conf)
   std::cout << "  TOTAL_SLICES: " << TOTAL_SLICES << '\n';
 
   // Create reformatter and add it to the pipeline
-  StreamProcessor stream_processor(MAX_BYTES_PER_INPUT_SLICE); 
-  pipeline.add_filter( stream_processor );
+  if ( conf->getEnableStreamProcessor() ) {
+    StreamProcessor stream_processor(MAX_BYTES_PER_INPUT_SLICE); 
+    pipeline.add_filter( stream_processor );
+  }
 
   // Create elastic populator (if requested)
-  std::string url = conf->getElasticUrl();
-  if(url.compare(0,2,"no")!=0){
+  if ( conf->getEnableElasticProcessor() ) {
+    std::string url = conf->getElasticUrl();
     ElasticProcessor elastic_processor(MAX_BYTES_PER_INPUT_SLICE,
-				       control,
-				       url,
-				       conf->getPtCut(),
-				       conf->getQualCut());
+              control,
+              url,
+              conf->getPtCut(),
+              conf->getQualCut());
     pipeline.add_filter(elastic_processor);
   }
 
diff --git a/src/scdaq.conf b/src/scdaq.conf
index 62193ee2..b77f5996 100644
--- a/src/scdaq.conf
+++ b/src/scdaq.conf
@@ -1,5 +1,8 @@
-# Input settings, allowed values are "dma" or "file"
-input:dma
+# Input settings, allowed values are:
+#   "wzdma" for DMA driver from Wojciech M. Zabolotny
+#   "dma"   for XILINX DMA driver
+#   "file"  for reading from file
+input:wzdma
 
 
 ## Settings for DMA input
@@ -25,6 +28,11 @@ max_file_size:1073741824
 
 threads:8
 port:8000
-elastic_url:no 
+#elastic_url:http://something.somewhere
+elastic_url:http://something.somewhere
 pt_cut:7
 quality_cut:12
+
+# Pipeline settings
+enable_stream_processor:yes
+enable_elastic_processor:no
-- 
GitLab