diff --git a/MQ/CMakeLists.txt b/MQ/CMakeLists.txt index 3bc8ce8b40b9ccb5ec2c4ee1a135b7628d4869c3..0062e61c1bc1492d0b18143426a3d9b0e1486ff1 100644 --- a/MQ/CMakeLists.txt +++ b/MQ/CMakeLists.txt @@ -5,7 +5,7 @@ EndIf() add_subdirectory(base) add_subdirectory(source) add_subdirectory(sink) -#add_subdirectory(unpacker) +add_subdirectory(unpacker) add_subdirectory(monitor) add_subdirectory(histoServer) @@ -20,4 +20,4 @@ add_subdirectory(mcbm) # Don't compile it for the time being # TODO: Fix the compilation problems add_subdirectory(parmq) -# add_subdirectory(hitbuilder) + add_subdirectory(hitbuilder) diff --git a/MQ/hitbuilder/CMakeLists.txt b/MQ/hitbuilder/CMakeLists.txt index 819fb4e4d087ea231eec06e4ceea4b7c8c2bd2fc..e20c7ecf367a96d418d98dd2f6d31f0559359bd1 100644 --- a/MQ/hitbuilder/CMakeLists.txt +++ b/MQ/hitbuilder/CMakeLists.txt @@ -4,14 +4,11 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/startMQ_Mcbm.sh.in ${CMAKE_BINARY_DIR set(INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} - ${CBMROOT_SOURCE_DIR}/fles/cern2016/param - ${CBMROOT_SOURCE_DIR}/fles/cern2016/unpacker - ${CBMROOT_SOURCE_DIR}/beamtime/base ${CBMDATA_DIR} + ${CBMDATA_DIR}/base ${CBMDATA_DIR}/tof ${CBMBASE_DIR} - ${CBMROOT_SOURCE_DIR}/tof/TofParam - ${CBMROOT_SOURCE_DIR}/tof/TofTools + ${CBMDETECTORBASE_DIR}/tof ) Set(SYSTEM_INCLUDE_DIRECTORIES @@ -23,8 +20,8 @@ Set(SYSTEM_INCLUDE_DIRECTORIES ${FAIRMQ_INCLUDE_DIR}/options ${IPC_INCLUDE_DIRECTORY} - ${CBMROOT_SOURCE_DIR}/external/cppzmq - ${CBMROOT_SOURCE_DIR}/tof/TofReco + ${CBMROOT_SOURCE_DIR}/external/cppzmq + ${CBMROOT_SOURCE_DIR}/reco/detectors/tof ) include_directories(${INCLUDE_DIRECTORIES}) @@ -72,10 +69,9 @@ set(DEPENDENCIES ${FAIR_LIBS} ${BOOST_LIBS} # fles_ipc - CbmFlibCern2016 CbmBase CbmData - CbmTof + CbmTofBase Geom Core MathCore diff --git a/MQ/unpacker/CMakeLists.txt b/MQ/unpacker/CMakeLists.txt index abceb285b823da83cf574443617c65cbc3606102..a7ededc4ca46400cf78897b6ad2cde8a5c163bb5 100644 --- a/MQ/unpacker/CMakeLists.txt +++ b/MQ/unpacker/CMakeLists.txt @@ -3,14 +3,12 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/startMQSamplerUnpackerParserver.sh.in set(INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} ${CBMROOT_SOURCE_DIR}/MQ/base - ${CBMROOT_SOURCE_DIR}/fles/cern2016/param - ${CBMROOT_SOURCE_DIR}/fles/cern2016/unpacker ${CBMROOT_SOURCE_DIR}/fles/mcbm2018/parameter ${CBMROOT_SOURCE_DIR}/fles/mcbm2018/dataformat ${CBMROOT_SOURCE_DIR}/fles/mcbm2018/unpacker ${CBMROOT_SOURCE_DIR}/fles/mcbm2018/commonMQ - ${CBMROOT_SOURCE_DIR}/beamtime/base ${CBMDATA_DIR} + ${CBMDATA_DIR}/raw ${CBMDATA_DIR}/tof ${CBMBASE_DIR} ) @@ -64,16 +62,16 @@ If(FAIRLOGGER_FOUND) EndIf() set(EXE_NAME UnpackTofMcbm2018) -set(SRCS CbmDeviceUnpackTofMcbm2018.cxx runUnpackTofMcbm2018.cxx) +set(SRCS CbmTbDaqBuffer.cxx CbmDeviceUnpackTofMcbm2018.cxx runUnpackTofMcbm2018.cxx) set(DEPENDENCIES ${DEPENDENCIES} ${FAIR_LIBS} ${BOOST_LIBS} fles_ipc - CbmFlibCern2016 CbmFlibMcbm2018 CbmBase +# CbmBeamtimeBase CbmData Core RIO diff --git a/MQ/unpacker/CbmTbDaqBuffer.cxx b/MQ/unpacker/CbmTbDaqBuffer.cxx new file mode 100644 index 0000000000000000000000000000000000000000..56327c7f9bd384e5816f3037835a6fb034f363fd --- /dev/null +++ b/MQ/unpacker/CbmTbDaqBuffer.cxx @@ -0,0 +1,87 @@ +/** @file CbmTbDaqBuffer.cxx + ** @author Volker Friese <v.friese@gsi.de> + ** @date 13 December 2013 + **/ + +#include "CbmTbDaqBuffer.h" + +#include <FairLogger.h> // for Logger, LOG +#include <stddef.h> // for NULL +#include <iomanip> // for setprecision, __iom_t5 +#include <sstream> // for basic_stringstream<>::string_type +#include <boost/any.hpp> + +// ----- Initialisation of static variables ------------------------------ +CbmTbDaqBuffer* CbmTbDaqBuffer::fgInstance = nullptr; +// --------------------------------------------------------------------------- + + + +// ----- Constructor ----------------------------------------------------- +CbmTbDaqBuffer::CbmTbDaqBuffer() : fData() { +} +// --------------------------------------------------------------------------- + + +// ----- Destructor ------------------------------------------------------ +CbmTbDaqBuffer::~CbmTbDaqBuffer() { +} +// --------------------------------------------------------------------------- + +Double_t CbmTbDaqBuffer::GetTimeFirst() const +{ + if ( ! GetSize() ) return -1.; + // Return the key from the first element in the map + // The key of the map is the time of digi + return fData.begin()->first; +} + +Double_t CbmTbDaqBuffer::GetTimeLast() const +{ + if ( ! GetSize() ) return -1.; + // Return the key from the last element in the map + // The key of the map is the time of digi + return (--fData.end())->first; +} + +// ----- Access to next data --------------------------------------------- +CbmTbDaqBuffer::Data CbmTbDaqBuffer::GetNextData(Double_t time) { + + // --- Check for empty buffer + if ( ! fData.size() ) return std::make_pair(boost::any(), ECbmModuleId::kNotExist); + + // --- Get data from buffer + std::multimap<Double_t, std::pair<boost::any, ECbmModuleId>>::iterator it = fData.begin(); + Double_t digi_time = it->first; + + if ( digi_time < time ) { + boost::any digi = it->second.first; + ECbmModuleId sysID = it->second.second; + fData.erase(it); + return std::make_pair(digi, sysID); + } + return std::make_pair(boost::any(), ECbmModuleId::kNotExist); +} +// --------------------------------------------------------------------------- + +// ----- Instance -------------------------------------------------------- +CbmTbDaqBuffer* CbmTbDaqBuffer::Instance() { + if ( ! fgInstance ) fgInstance = new CbmTbDaqBuffer(); + return fgInstance; +} +// --------------------------------------------------------------------------- + +// ----- Print status ---------------------------------------------------- +void CbmTbDaqBuffer::PrintStatus() const { + Int_t size = GetSize(); + std::stringstream ss; + ss << "CbmTbDaqBuffer: Status "; + if ( ! size ) { + LOG(info) << ss.str() << "empty"; + return; + } + LOG(info) << ss.str() << GetSize() << " digis from " + << std::fixed << std::setprecision(9) << GetTimeFirst() * 1.e-9 << " s to " + << GetTimeLast() *1.e-9 << " s"; +} +// --------------------------------------------------------------------------- diff --git a/MQ/unpacker/CbmTbDaqBuffer.h b/MQ/unpacker/CbmTbDaqBuffer.h new file mode 100644 index 0000000000000000000000000000000000000000..a66952b285df441e8dae1229d8ae2c4340f72bf8 --- /dev/null +++ b/MQ/unpacker/CbmTbDaqBuffer.h @@ -0,0 +1,118 @@ +/** @file CbmDaqBuffer.h + ** @author Volker Friese <v.friese@gsi.de> + ** @date 17 July 2012 + **/ + +#ifndef CBMTBDAQBUFFER_H +#define CBMTBDAQBUFFER_H 1 + +#include <RtypesCore.h> // for Double_t, Int_t +#include <map> // for multimap, __map_const_iterator, multimap<>::... +#include <utility> // for pair +#include <boost/any.hpp> +#include "CbmDefs.h" + +/** @class CbmTbDaqBuffer + ** @author Volker Friese <v.friese@gsi.de> + ** @date 13 December 2012 + ** @brief Singleton buffer class for CBM raw data + ** + ** The CbmTbDaqBuffer stores and sorts (w.r.t. time) CBM raw data + ** (currently: boost::any) transiently. + ** Data can be send to the buffer by the method InsertData. + ** They can be retrieved by GetNextData, which delivers a + ** time-ordered sequence of raw data objects. + ** + ** There is only one buffer stream, irrespective of the detector system. + ** + ** The buffer handles objects only by pointer, i.e. the data have + ** to be instantiated by the sending task (digitiser) and + ** deleted by the receiving class (CbmDaq). + **/ +class CbmTbDaqBuffer +{ + public: + + typedef std::pair<boost::any, ECbmModuleId> Data; + + /** Destructor **/ + ~CbmTbDaqBuffer(); + + /** Pointer to next raw data object + ** up to given time + ** @param time maximal time [ns] + ** @return pointer to raw data object + ** + ** A NULL pointer will be returned if no further data can be released. + ** This does not mean that the buffer is empty. + **/ + // boost::any GetNextData(Double_t time); + Data GetNextData(Double_t time); + + + /** Current buffer size + ** @return number of objects in buffer + */ + Int_t GetSize() const { return fData.size(); } + + + /** Get first digi time **/ + Double_t GetTimeFirst() const; + + /** Get last digi time **/ + Double_t GetTimeLast() const; + + /** Access to singleton instance + ** @return pointer to instance + **/ + static CbmTbDaqBuffer* Instance(); + + /** Print buffer status **/ + void PrintStatus() const; + + /** Insert digi of any type into the buffer */ + template <class Digi> + void InsertData(Digi* digi) + { + Double_t digi_time = digi->GetTime(); + ECbmModuleId systemID = Digi::GetSystem(); + InsertData(digi, digi_time, systemID); + } + + private: + + + /** Buffer management **/ + std::multimap<Double_t, Data> fData; + + + /** Pointer to singleton instance **/ + static CbmTbDaqBuffer* fgInstance; + + + /** Default constructor + ** Declared private to prevent instantiation. + **/ + CbmTbDaqBuffer(); + + + /** Copy constructor. Defined private to prevent usage. **/ + CbmTbDaqBuffer(const CbmTbDaqBuffer&); + + + /** Assignment operator. Defined private to prevent usage. **/ + CbmTbDaqBuffer& operator=(const CbmTbDaqBuffer&); + + /** Insert data into the buffer + ** @param digi pointer to data object to be inserted + **/ + // void InsertData(boost::any digi); + void InsertData(boost::any digi, Double_t time, ECbmModuleId systemID) + { + fData.insert(std::make_pair(time, std::make_pair(std::move(digi), systemID))); + } + +}; + + +#endif /* CBMTBDAQBUFFER_H */