Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feminos support #4

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
110 changes: 67 additions & 43 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,93 @@
#Setup the project

project(restDAQ)

set(CMAKE_CXX_STANDARD 17)

if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
# this will only be entered when build restDAQ as a standalone package, not when building the framework
message(STATUS "${PROJECT_NAME} standalone build")
CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
find_package(REST REQUIRED)
string(FIND ${REST_LIBRARIES} "RestRaw" REST_RAW_FOUND)
if (${REST_RAW_FOUND} EQUAL -1)
message(SEND_ERROR "REST found but 'RestRaw' library is not present. Please install REST with RawLib")
endif ()
endif ()

message("-- Found REST version: ${REST_VERSION} with libraries: ${REST_LIBRARIES}")

message("=============== ${PROJECT_NAME} ==============")

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake ${CMAKE_MODULE_PATH})

# Find ROOT
find_package(ROOT REQUIRED COMPONENTS Gui)
find_package(ROOT REQUIRED COMPONENTS Gui CONFIG)
execute_process(COMMAND root-config --cflags OUTPUT_VARIABLE ROOT_CFLAGS)
string(STRIP ${ROOT_CFLAGS} ROOT_CFLAGS)
message("-- Found ROOT version: ${ROOT_VERSION} with compilation flags: ${ROOT_CFLAGS} and libraries: ${ROOT_LIBRARIES}")

#Find REST
IF(NOT DEFINED REST_PATH)
IF(DEFINED ENV{REST_PATH})
set(REST_PATH $ENV{REST_PATH})
ELSE()
message(FATAL_ERROR "ERROR ::: REST_PATH must be defined as an environment variable and point to REST install directory")
return()
ENDIF()
ENDIF()
set(CMAKE_INSTALL_PREFIX ${REST_PATH})
message(STATUS "Using REST PATH: " ${REST_PATH})
# Find REST
if (NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX ${REST_PATH})
endif ()

message(STATUS "Package ${PROJECT_NAME} will be installed in ${CMAKE_INSTALL_PREFIX}")

message("-- Found REST version: ${REST_VERSION} with libraries: ${REST_LIBRARIES}")
# TODO: Implement a check for '-lRestRaw' in ${REST_LIBRARIES} (and exit if not found)
# Still if we use -DREST_DAQ=ON at the framework compilation it will enable RawLib by default

if (NOT CMAKE_CXX_FLAGS)
SET(CMAKE_CXX_FLAGS "-std=c++1y") # We should use the c++ flags from ${ROOT_CFLAGS}
endif ()

#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
#Set include and lib
if(DEFINED rest_include_dirs)
set(incdir ${PROJECT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIRS} ${rest_include_dirs})
else()
set(incdir ${PROJECT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIRS} ${REST_PATH}/include)
endif()
set(INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${REST_INCLUDE_DIRS})

if (NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${rest_include_dirs})
endif ()

set(lnklib ${ROOT_LIBRARIES} RestRaw)
string(STRIP "${lnklib}" lnklib)
set(LINK_LIBRARIES ${ROOT_LIBRARIES} RestRaw)
string(STRIP "${LINK_LIBRARIES}" LINK_LIBRARIES)

add_subdirectory(daq)
add_subdirectory(gui)

#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
#Add execuatable and link to restDAQ libraries
add_executable(restDAQManager restDAQManager.cxx)
target_link_libraries(restDAQManager LINK_PUBLIC RESTDAQ ${lnklib})

#----------------------------------------------------------------------------
# Copy restDAQManager to the install directory
install(TARGETS restDAQManager DESTINATION bin)

#----------------------------------------------------------------------------
# Copy macros to the install directory
file(GLOB_RECURSE MAC "${CMAKE_CURRENT_SOURCE_DIR}/macros/*")
INSTALL(FILES ${MAC} DESTINATION ./macros/daq)

#----------------------------------------------------------------------------
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
#
#install(TARGETS ${PROJECT_NAME} DESTINATION bin)
set(package_added "${PROJECT_NAME}")
set(package_added ${package_added} PARENT_SCOPE)
#Add executable and link to restDAQ libraries

include(FetchContent)

# External dependencies
# cli11 (CLI parser)
FetchContent_Declare(
cli11
GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git
GIT_TAG v2.2.0
)
FetchContent_MakeAvailable(cli11)

set(EXECUTABLE_NAME restDAQ)

add_executable(${EXECUTABLE_NAME} main.cxx)

target_link_libraries(${EXECUTABLE_NAME} PUBLIC RESTDAQ RestDAQGUI ${LINK_LIBRARIES} ${ROOT_LIBRARIES} RestRaw PRIVATE CLI11::CLI11)
target_include_directories(${EXECUTABLE_NAME} SYSTEM PUBLIC ${INCLUDE_DIRS})

install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin)

if (NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
set(package_added "${PROJECT_NAME}")
set(package_added ${package_added} PARENT_SCOPE)
endif ()

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/examples
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/examples/
DESTINATION examples
COMPONENT install
)

if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
include(cmake/source.cmake)
endif ()
17 changes: 17 additions & 0 deletions cmake/source.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set(FILENAME ${CMAKE_BINARY_DIR}/source.sh)

file(WRITE ${FILENAME})
file(APPEND ${FILENAME} "#!/bin/bash\n\n")

execute_process(COMMAND rest-config --prefix OUTPUT_VARIABLE REST_PREFIX)
string(REGEX REPLACE "\n$" "" REST_PREFIX ${REST_PREFIX})
file(APPEND ${FILENAME} "source ${REST_PREFIX}/thisREST.sh\n")

file(APPEND ${FILENAME} "\n")

file(APPEND ${FILENAME} "export PATH=${CMAKE_INSTALL_PREFIX}/bin:$PATH\n")
file(APPEND ${FILENAME} "export LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:$LD_LIBRARY_PATH\n")

file(APPEND ${FILENAME} "\n")

install(FILES ${FILENAME} DESTINATION ${CMAKE_INSTALL_PREFIX})
5 changes: 2 additions & 3 deletions daq/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

add_library(RESTDAQ SHARED TRESTDAQ.cxx TRESTDAQSocket.cxx DCCPacket.cxx TRESTDAQDCC.cxx FEMINOSPacket.cxx TRESTDAQFEMINOS.cxx TRESTDAQDummy.cxx TRESTDAQManager.cxx)

target_include_directories(RESTDAQ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${rest_include_dirs})
target_include_directories(RESTDAQ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIRS})

target_link_libraries(RESTDAQ ${lnklib} RestRaw)
target_link_libraries(RESTDAQ PUBLIC ${LINK_LIBRARIES} RestFramework RestRaw)

install(TARGETS RESTDAQ DESTINATION lib)

44 changes: 18 additions & 26 deletions daq/DCCPacket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,28 @@

#include <cstdio>

void DCCPacket::DataPacket_Print( DataPacket *pck){


void DCCPacket::DataPacket_Print(DataPacket* pck) {
// DCC data packet has a different structure
if (GET_FRAME_TY_V2(ntohs(pck->dcchdr)) & FRAME_TYPE_DCC_DATA) {
DCC_Data_Print((EndOfEventPacket*)pck);
return;
} // FEM data - Pedestal Histogram Mathematics
} // FEM data - Pedestal Histogram Mathematics
else if (GET_TYPE(ntohs(pck->hdr)) == RESP_TYPE_HISTOSTAT) {
Pedestal_PrintHistoMathPacket((PedestalHistoMathPacket*)pck);
return;
} // FEM data - Pedestal Histogram Bins
} // FEM data - Pedestal Histogram Bins
else if (GET_TYPE(ntohs(pck->hdr)) == RESP_TYPE_HISTOGRAM) {
Pedestal_PrintHistoBinPacket((PedestalHistoBinPacket*)pck);
return;
} // FEM data - Pedestal Histogram Summary
} // FEM data - Pedestal Histogram Summary
else if (GET_TYPE(ntohs(pck->hdr)) == RESP_TYPE_HISTOSUMMARY) {
Pedestal_PrintHistoSummaryPacket((PedestalHistoSummaryPacket*)pck);
return;
} // FEM data - ADC samples in zero-suppressed or non zero-suppressed mode
} // FEM data - ADC samples in zero-suppressed or non zero-suppressed mode
else if (GET_TYPE(ntohs(pck->hdr)) == RESP_TYPE_ADC_DATA) {
FemAdcDataPrint(pck);
return;
}

}

void DCCPacket::DCC_Data_Print(EndOfEventPacket* pck) {
Expand All @@ -43,7 +40,7 @@ void DCCPacket::DCC_Data_Print(EndOfEventPacket* pck) {
}

else {
printf("DCC_Data_Print: unknown frame type 0x%x\n", GET_FRAME_TY_V2(ntohs(pck->dcchdr) ) );
printf("DCC_Data_Print: unknown frame type 0x%x\n", GET_FRAME_TY_V2(ntohs(pck->dcchdr)));
}
}

Expand Down Expand Up @@ -82,20 +79,18 @@ void DCCPacket::DCC_Histogram_Print(HistogramPacket* pck) {
printf("------------------------------------\n");
}


void DCCPacket::EndOfEvent_PrintPacket(EndOfEventPacket* eop) {
int i;

printf("------------------------------------\r\n");
printf("Message size : %d bytes\r\n", ntohs(eop->size));
printf("DCC Header: Type:0x%x DCC_index:0x%x FEM_index:0x%x\r\n", GET_FRAME_TY_V2(ntohs(eop->dcchdr)), GET_DCC_INDEX(ntohs(eop->dcchdr)),
GET_FEM_INDEX(ntohs(eop->dcchdr)));
GET_FEM_INDEX(ntohs(eop->dcchdr)));
printf("FEM Header: 0x%x\r\n", ntohs(eop->hdr));
for (i = 0; i < MAX_NB_OF_FEM_PER_DCC; i++) {
printf("Fem(%2d) : recv: %d bytes sent: %d bytes\r\n", i, ntohl(eop->byte_rcv[i]), ntohl(eop->byte_snd[i]));
}
printf("Total : recv: %d bytes sent: %d bytes\r\n", ntohl(eop->tot_byte_rcv), ntohl(eop->tot_byte_snd));

}

/*******************************************************************************
Expand All @@ -105,10 +100,10 @@ void DCCPacket::Pedestal_PrintHistoMathPacket(PedestalHistoMathPacket* phm) {
printf("------------------------------------\n");
printf("Message size : %d bytes\n", ntohs(phm->size));
printf("DCC Header: Type:0x%x DCC_index:0x%x FEM_index:0x%x\n", GET_FRAME_TY_V2(ntohs(phm->dcchdr)), GET_DCC_INDEX(ntohs(phm->dcchdr)),
GET_FEM_INDEX(ntohs(phm->dcchdr)));
GET_FEM_INDEX(ntohs(phm->dcchdr)));
printf("FEM Header: 0x%x\n", ntohs(phm->hdr)),
printf("Read-back : Mode:%d Compress:%d Arg1:0x%x Arg2:0x%x\n", GET_RB_MODE(ntohs(phm->args)), GET_RB_COMPRESS(ntohs(phm->args)),
GET_RB_ARG1(ntohs(phm->args)), GET_RB_ARG2(ntohs(phm->args)));
GET_RB_ARG1(ntohs(phm->args)), GET_RB_ARG2(ntohs(phm->args)));

printf("Bin min : %d\n", ntohs(phm->min_bin));
printf("Bin max : %d\n", ntohs(phm->max_bin));
Expand All @@ -135,7 +130,7 @@ void DCCPacket::Pedestal_PrintHistoBinPacket(PedestalHistoBinPacket* pck) {
printf("------------------------------------\n");
printf("Message size : %d bytes\n", ntohs(pck->size));
printf("DCC Header : Type:0x%x DCC_index:0x%x FEM_index:0x%x\n", GET_FRAME_TY_V2(ntohs(pck->dcchdr)), GET_DCC_INDEX(ntohs(pck->dcchdr)),
GET_FEM_INDEX(ntohs(pck->dcchdr)));
GET_FEM_INDEX(ntohs(pck->dcchdr)));

printf("FEM Header : Msg_type:0x%x Index:0x%x\n", GET_RESP_TYPE(ntohs(pck->hdr)));
printf("Read-back : Arg1:0x%x Arg2:0x%x\n", GET_RB_ARG1(ntohs(pck->args)), GET_RB_ARG2(ntohs(pck->args)));
Expand Down Expand Up @@ -165,7 +160,7 @@ void DCCPacket::Pedestal_PrintHistoSummaryPacket(PedestalHistoSummaryPacket* pck
printf("------------------------------------\n");
printf("Message size : %d bytes\n", ntohs(pck->size));
printf("DCC Header : Type:0x%x DCC_index:0x%x FEM_index:0x%x\n", GET_FRAME_TY_V2(ntohs(pck->dcchdr)), GET_DCC_INDEX(ntohs(pck->dcchdr)),
GET_FEM_INDEX(ntohs(pck->dcchdr)));
GET_FEM_INDEX(ntohs(pck->dcchdr)));

printf("FEM Header : Msg_type:0x%x Index:0x%x\n", GET_RESP_TYPE(ntohs(pck->hdr)));
printf("Read-back : Arg1:0x%x Arg2:0x%x\n", GET_RB_ARG1(ntohs(pck->args)), GET_RB_ARG2(ntohs(pck->args)));
Expand All @@ -180,7 +175,7 @@ void DCCPacket::Pedestal_PrintHistoSummaryPacket(PedestalHistoSummaryPacket* pck

for (i = 0; i < (nbsw / 2); i++) {
printf("Stat (%3d) : mean = %.2f stdev = %.2f\n", i, ((double)(ntohs(pck->stat[i].mean))) / 100.0,
((double)(ntohs(pck->stat[i].stdev))) / 100.0);
((double)(ntohs(pck->stat[i].stdev))) / 100.0);
}
printf("------------------------------------\n");
}
Expand All @@ -200,21 +195,21 @@ void DCCPacket::FemAdcDataPrint(DataPacket* pck) {
printf("------------------------------------\n");
printf("Packet sz : %d bytes\n", (ntohs(pck->size)));
printf("DCC Header: Type:0x%x DCC_index:0x%x FEM_index:0x%x\n", GET_FRAME_TY_V2(ntohs(pck->dcchdr)), GET_DCC_INDEX(ntohs(pck->dcchdr)),
GET_FEM_INDEX(ntohs(pck->dcchdr)));
GET_FEM_INDEX(ntohs(pck->dcchdr)));

printf("FEM Header: Msg_type:0x%x Index:0x%x\n", GET_RESP_TYPE(ntohs(pck->hdr)), GET_RESP_INDEX(ntohs(pck->hdr)));
printf("Errors : FEC:0x%x Unable to SYNCH:%d Framing LOS:%d\n", GET_FEC_ERROR(ntohs(pck->hdr)), GET_SYNCH_FAIL(ntohs(pck->hdr)),
GET_LOS_FLAG(ntohs(pck->hdr)));
GET_LOS_FLAG(ntohs(pck->hdr)));
printf("Read-back : Mode:%d Compress:%d Arg1:0x%x Arg2:0x%x\n", GET_RB_MODE(ntohs(pck->args)), GET_RB_COMPRESS(ntohs(pck->args)),
GET_RB_ARG1(ntohs(pck->args)), GET_RB_ARG2(ntohs(pck->args)));
GET_RB_ARG1(ntohs(pck->args)), GET_RB_ARG2(ntohs(pck->args)));

Arg12ToFecAsicChannel((unsigned short)GET_RB_ARG1(ntohs(pck->args)), (unsigned short)GET_RB_ARG2(ntohs(pck->args)), fec, asic,channel);
Arg12ToFecAsicChannel((unsigned short)GET_RB_ARG1(ntohs(pck->args)), (unsigned short)GET_RB_ARG2(ntohs(pck->args)), fec, asic, channel);

printf(" Fec:%d Asic:%d Channel:%d\n", fec, asic, channel);

ts = (((int)ntohs((pck->ts_h))) << 16) | (int)ntohs((pck->ts_l));
printf("Event : Type:%d Count:%d Time:0x%x NbOfWords:%d\n", GET_EVENT_TYPE(ntohs(pck->ecnt)), GET_EVENT_COUNT(ntohs(pck->ecnt)), ts,
ntohs(pck->scnt));
ntohs(pck->scnt));
scnt = ntohs(pck->scnt) & 0x7FF;

// Compute the number of short words in the packet
Expand Down Expand Up @@ -247,8 +242,7 @@ void DCCPacket::FemAdcDataPrint(DataPacket* pck) {
/*******************************************************************************
Arg12ToFecAsicChannel
*******************************************************************************/
int DCCPacket::Arg12ToFecAsicChannel(unsigned short arg1, unsigned short arg2, unsigned short &fec, unsigned short &asic, unsigned short &channel) {

int DCCPacket::Arg12ToFecAsicChannel(unsigned short arg1, unsigned short arg2, unsigned short& fec, unsigned short& asic, unsigned short& channel) {
fec = (10 * (arg1 % 6) / 2 + arg2) / 4;
asic = (10 * (arg1 % 6) / 2 + arg2) % 4;
channel = arg1 / 6;
Expand Down Expand Up @@ -279,5 +273,3 @@ int DCCPacket::Arg12ToFecAsicChannel(unsigned short arg1, unsigned short arg2, u

return physChannel;
}


Loading