Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • le.koch/cbmroot
  • patrick.pfistner_AT_kit.edu/cbmroot
  • lena.rossel_AT_stud.uni-frankfurt.de/cbmroot
  • i.deppner/cbmroot
  • fweig/cbmroot
  • karpushkin_AT_inr.ru/cbmroot
  • v.akishina/cbmroot
  • rishat.sultanov_AT_cern.ch/cbmroot
  • l_fabe01_AT_uni-muenster.de/cbmroot
  • pwg-c2f/cbmroot
  • j.decuveland/cbmroot
  • a.toia/cbmroot
  • i.vassiliev/cbmroot
  • n.herrmann/cbmroot
  • o.lubynets/cbmroot
  • se.gorbunov/cbmroot
  • cornelius.riesen_AT_physik.uni-giessen.de/cbmroot
  • zhangqn17_AT_mails.tsinghua.edu.cn/cbmroot
  • bartosz.sobol/cbmroot
  • ajit.kumar/cbmroot
  • computing/cbmroot
  • a.agarwal_AT_vecc.gov.in/cbmroot
  • osingh/cbmroot
  • wielanek_AT_if.pw.edu.pl/cbmroot
  • malgorzata.karabowicz.stud_AT_pw.edu.pl/cbmroot
  • m.shiroya/cbmroot
  • s.roy/cbmroot
  • p.-a.loizeau/cbmroot
  • a.weber/cbmroot
  • ma.beyer/cbmroot
  • d.klein/cbmroot
  • d.smith/cbmroot
  • mvdsoft/cbmroot
  • d.spicker/cbmroot
  • y.h.leung/cbmroot
  • aksharma/cbmroot
  • m.deveaux/cbmroot
  • mkunold/cbmroot
  • h.darwish/cbmroot
  • pk.sharma_AT_vecc.gov.in/cbmroot
  • f_fido01_AT_uni-muenster.de/cbmroot
  • g.kozlov/cbmroot
  • d.emschermann/cbmroot
  • evgeny.lavrik/cbmroot
  • v.friese/cbmroot
  • f.uhlig/cbmroot
  • ebechtel_AT_ikf.uni-frankfurt.de/cbmroot
  • a.senger/cbmroot
  • praisig/cbmroot
  • s.lebedev/cbmroot
  • redelbach_AT_compeng.uni-frankfurt.de/cbmroot
  • p.subramani/cbmroot
  • a_meye37_AT_uni-muenster.de/cbmroot
  • om/cbmroot
  • o.golosov/cbmroot
  • l.chlad/cbmroot
  • a.bercuci/cbmroot
  • d.ramirez/cbmroot
  • v.singhal/cbmroot
  • h.schiller/cbmroot
  • apuntke/cbmroot
  • f.zorn/cbmroot
  • rubio_AT_physi.uni-heidelberg.de/cbmroot
  • p.chudoba/cbmroot
  • apuntke/mcbmroot
  • r.karabowicz/cbmroot
66 results
Show changes
Showing
with 597 additions and 634 deletions
/* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Florian Uhlig [committer] */
#include "CbmMQChannels.h"
#include "FairMQDevice.h"
CbmMQChannels::CbmMQChannels(std::vector<std::string> allowedChannels)
: fAllowedChannels {allowedChannels} {
CbmMQChannels::CbmMQChannels(std::vector<std::string> allowedChannels) : fAllowedChannels {allowedChannels}
{
fChannelsToSend.resize(fAllowedChannels.size());
for (auto& entry : fChannelsToSend) {
entry.push_back("");
......@@ -10,32 +15,29 @@ CbmMQChannels::CbmMQChannels(std::vector<std::string> allowedChannels)
fComponentsToSend.resize(fAllowedChannels.size());
}
bool CbmMQChannels::IsChannelNameAllowed(std::string channelName) {
bool CbmMQChannels::IsChannelNameAllowed(std::string channelName)
{
for (auto const& entry : fAllowedChannels) {
std::size_t pos1 = channelName.find(entry);
if (pos1 != std::string::npos) {
const std::vector<std::string>::const_iterator pos =
std::find(fAllowedChannels.begin(), fAllowedChannels.end(), entry);
const std::vector<std::string>::size_type idx =
pos - fAllowedChannels.begin();
const std::vector<std::string>::size_type idx = pos - fAllowedChannels.begin();
LOG(info) << "Found " << entry << " in " << channelName;
LOG(info) << "Channel name " << channelName
<< " found in list of allowed channel names at position "
<< idx;
LOG(info) << "Channel name " << channelName << " found in list of allowed channel names at position " << idx;
fComponentsToSend[idx]++;
// The array is initialized with one empty string. If the string has still teh value from initialization
// exchnge the value by the new channel name. In any other case add one more entry to the vector
if (fChannelsToSend[idx].size() == 1
&& fChannelsToSend[idx].at(0).empty()) {
if (fChannelsToSend[idx].size() == 1 && fChannelsToSend[idx].at(0).empty()) {
fChannelsToSend[idx].at(0) = channelName;
} else {
}
else {
fChannelsToSend[idx].push_back(channelName);
}
return true;
}
}
LOG(info) << "Channel name " << channelName
<< " not found in list of allowed channel names.";
LOG(info) << "Channel name " << channelName << " not found in list of allowed channel names.";
LOG(info) << "The allowed channels are: ";
for (auto const& entry : fAllowedChannels) {
LOG(info) << entry;
......@@ -44,7 +46,8 @@ bool CbmMQChannels::IsChannelNameAllowed(std::string channelName) {
return false;
}
bool CbmMQChannels::CheckChannels(FairMQDevice* device) {
bool CbmMQChannels::CheckChannels(FairMQDevice* device)
{
// Get the information about created channels from the device
// Check if the defined channels from the topology (by name)
// are in the list of channels which are possible/allowed
......
/* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Florian Uhlig [committer] */
#ifndef CBMMQCHANNELS_H_
#define CBMMQCHANNELS_H_
#include "FairMQDevice.h"
#include <string>
#include <vector>
class FairMQDevice;
class CbmMQChannels {
public:
......@@ -14,9 +19,7 @@ public:
bool CheckChannels(FairMQDevice* device);
std::vector<int> GetComponentsToSend() { return fComponentsToSend; }
std::vector<std::vector<std::string>> GetChannelsToSend() {
return fChannelsToSend;
}
std::vector<std::vector<std::string>> GetChannelsToSend() { return fChannelsToSend; }
private:
std::vector<std::string> fAllowedChannels {};
......
//#ifdef HAVE_FAIRMQSTATEMACHINE
//#include "FairMQStateMachine.h"
//#endif
/* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Florian Uhlig [committer] */
#include "FairMQDevice.h"
namespace cbm {
namespace mq {
enum class Transition : int {
namespace cbm
{
namespace mq
{
enum class Transition : int
{
Idle,
DeviceReady,
Ready,
......@@ -14,69 +18,45 @@ namespace cbm {
ErrorFound
};
enum class State : int { Running };
enum class State : int
{
Running
};
void ChangeState(FairMQDevice* device, cbm::mq::Transition transition) {
#ifdef HAVE_FAIRMQSTATEMACHINE
if (transition == cbm::mq::Transition::ErrorFound) {
device->ChangeState(FairMQStateMachine::Event::ERROR_FOUND);
} else if (transition == cbm::mq::Transition::End) {
device->ChangeState(FairMQStateMachine::Event::END);
} else if (transition == cbm::mq::Transition::Ready) {
device->ChangeState(FairMQStateMachine::Event::internal_READY);
} else if (transition == cbm::mq::Transition::DeviceReady) {
device->ChangeState(FairMQStateMachine::Event::internal_DEVICE_READY);
} else if (transition == cbm::mq::Transition::Idle) {
device->ChangeState(FairMQStateMachine::Event::internal_IDLE);
} else {
LOG(fatal) << "State Change not yet implemented";
device->ChangeState(FairMQStateMachine::Event::ERROR_FOUND);
}
#else
if (transition == cbm::mq::Transition::ErrorFound) {
device->ChangeState(fair::mq::Transition::ErrorFound);
} else if (transition == cbm::mq::Transition::End) {
void ChangeState(FairMQDevice* device, cbm::mq::Transition transition)
{
if (transition == cbm::mq::Transition::ErrorFound) { device->ChangeState(fair::mq::Transition::ErrorFound); }
else if (transition == cbm::mq::Transition::End) {
device->ChangeState(fair::mq::Transition::End);
} else if (transition == cbm::mq::Transition::Ready) {
}
else if (transition == cbm::mq::Transition::Ready) {
device->ChangeState(fair::mq::Transition::ResetTask);
} else if (transition == cbm::mq::Transition::DeviceReady) {
}
else if (transition == cbm::mq::Transition::DeviceReady) {
device->ChangeState(fair::mq::Transition::ResetDevice);
} else if (transition == cbm::mq::Transition::Idle) {
}
else if (transition == cbm::mq::Transition::Idle) {
device->ChangeState(fair::mq::Transition::Stop);
} else {
}
else {
LOG(fatal) << "State Change not yet implemented";
device->ChangeState(fair::mq::Transition::ErrorFound);
}
#endif
}
void LogState(FairMQDevice* device) {
#ifdef HAVE_FAIRMQSTATEMACHINE
// LOG(info) << "Current State: " << FairMQStateMachine::GetCurrentStateName();
LOG(info) << "Current State: " << device->GetCurrentStateName();
#else
void LogState(FairMQDevice* device)
{
LOG(info) << "Current State: " << device->GetCurrentStateName();
#endif
}
bool CheckCurrentState(FairMQDevice* device, cbm::mq::State state) {
#ifdef HAVE_FAIRMQSTATEMACHINE
if (state == cbm::mq::State::Running) {
return device->CheckCurrentState(FairMQStateMachine::State::RUNNING);
} else {
LOG(fatal) << "State not yet implemented";
device->ChangeState(FairMQStateMachine::Event::ERROR_FOUND);
return 0;
}
#else
if (state == cbm::mq::State::Running) {
return !(device->NewStatePending());
} else {
bool CheckCurrentState(FairMQDevice* device, cbm::mq::State state)
{
if (state == cbm::mq::State::Running) { return !(device->NewStatePending()); }
else {
LOG(fatal) << "State not yet implemented";
device->ChangeState(fair::mq::Transition::ErrorFound);
return 0;
}
#endif
}
} // namespace mq
} // namespace cbm
/* Copyright (C) 2021 Facility for Antiproton and Ion Research in Europe, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Pierre-Alain Loizeau [committer] */
#ifndef CBMMQTMESSAGE_H_
#define CBMMQTMESSAGE_H_
#include "TMessage.h"
// special class to expose protected TMessage constructor
class CbmMqTMessage : public TMessage {
public:
CbmMqTMessage(void* buf, Int_t len) : TMessage(buf, len) { ResetBit(kIsOwner); }
};
#endif /* CBMMQTMESSAGE_H_ */
......@@ -26,7 +26,7 @@ Set(SYSTEM_INCLUDE_DIRECTORIES
${FAIRMQ_INCLUDE_DIR}
${FAIRMQ_INCLUDE_DIR}/options
${IPC_INCLUDE_DIRECTORY}
${FLES_IPC_INCLUDE_DIRECTORY}
${CBMROOT_SOURCE_DIR}/external/cppzmq
)
......@@ -66,13 +66,18 @@ If(FAIRLOGGER_FOUND)
)
EndIf()
set(EXE_NAME EventBuilderEtofStar2019)
set(SRCS CbmDeviceEventBuilderEtofStar2019.cxx runEventBuilderEtofStar2019.cxx)
set(DEPENDENCIES
# Dependencies common to all executables
set(DEPENDENCIES_ALL
${DEPENDENCIES}
${FAIR_LIBS}
${BOOST_LIBS}
fles_ipc
)
set(EXE_NAME EventBuilderEtofStar2019)
set(SRCS CbmDeviceEventBuilderEtofStar2019.cxx runEventBuilderEtofStar2019.cxx)
set(DEPENDENCIES
${DEPENDENCIES_ALL}
external::fles_ipc
CbmFlibStar2019
CbmFlibMcbm2018
CbmBase
......@@ -94,10 +99,8 @@ Set(NO_DICT_SRCS
# Mask warning from file provided by STAR
SET_SOURCE_FILES_PROPERTIES(${CBMROOT_SOURCE_DIR}/fles/star2017/unpacker/star_rhicf.c PROPERTIES COMPILE_FLAGS -Wno-pointer-sign)
set(DEPENDENCIES
${DEPENDENCIES}
${FAIR_LIBS}
${BOOST_LIBS}
fles_ipc
${DEPENDENCIES_ALL}
external::fles_ipc
CbmFlibStar2019
CbmFlibMcbm2018
CbmBase
......
/* Copyright (C) 2019-2021 PI-UHd, GSI
SPDX-License-Identifier: GPL-3.0-only
Authors: Norbert Herrmann [committer] */
/**
* CbmDeviceEventBuilderEtofStar2019.cxx
*/
#include "CbmDeviceEventBuilderEtofStar2019.h"
#include "CbmMQDefs.h"
#include "CbmMQDefs.h"
#include "CbmStar2019EventBuilderEtofAlgo.h"
#include "CbmStar2019TofPar.h"
......@@ -30,9 +34,8 @@
#include <array>
#include <iomanip>
#include <string>
#include <stdexcept>
#include <string>
struct InitTaskError : std::runtime_error {
using std::runtime_error::runtime_error;
};
......@@ -56,15 +59,15 @@ CbmDeviceEventBuilderEtofStar2019::CbmDeviceEventBuilderEtofStar2019()
, fEventBuilderAlgo(nullptr)
, fTimer()
, fUnpackPar(nullptr)
, fpBinDumpFile(nullptr) {
, fpBinDumpFile(nullptr)
{
fEventBuilderAlgo = new CbmStar2019EventBuilderEtofAlgo();
}
CbmDeviceEventBuilderEtofStar2019::~CbmDeviceEventBuilderEtofStar2019() {
delete fEventBuilderAlgo;
}
CbmDeviceEventBuilderEtofStar2019::~CbmDeviceEventBuilderEtofStar2019() { delete fEventBuilderAlgo; }
void CbmDeviceEventBuilderEtofStar2019::InitTask() try {
void CbmDeviceEventBuilderEtofStar2019::InitTask()
try {
// Get the information about created channels from the device
// Check if the defined channels from the topology (by name)
// are in the list of channels which are possible/allowed
......@@ -79,29 +82,28 @@ void CbmDeviceEventBuilderEtofStar2019::InitTask() try {
LOG(info) << "Number of defined channels: " << noChannel;
for (auto const& entry : fChannels) {
LOG(info) << "Channel name: " << entry.first;
if (!IsChannelNameAllowed(entry.first))
throw InitTaskError("Channel name does not match.");
if (!IsChannelNameAllowed(entry.first)) throw InitTaskError("Channel name does not match.");
if (entry.first == "syscmd") {
OnData(entry.first, &CbmDeviceEventBuilderEtofStar2019::HandleMessage);
continue;
}
//if(entry.first != "etofevts") OnData(entry.first, &CbmDeviceEventBuilderEtofStar2019::HandleData);
if (entry.first != "etofevts")
OnData(entry.first, &CbmDeviceEventBuilderEtofStar2019::HandleParts);
if (entry.first != "etofevts") OnData(entry.first, &CbmDeviceEventBuilderEtofStar2019::HandleParts);
else {
fChannelsToSend[0].push_back(entry.first);
LOG(info) << "Init to send data to channel " << fChannelsToSend[0][0];
}
}
InitContainers();
} catch (InitTaskError& e) {
}
catch (InitTaskError& e) {
LOG(error) << e.what();
// Wrapper defined in CbmMQDefs.h to support different FairMQ versions
cbm::mq::ChangeState(this, cbm::mq::Transition::ErrorFound);
}
bool CbmDeviceEventBuilderEtofStar2019::IsChannelNameAllowed(
std::string channelName) {
bool CbmDeviceEventBuilderEtofStar2019::IsChannelNameAllowed(std::string channelName)
{
for (auto const& entry : fAllowedChannels) {
LOG(info) << "Inspect " << entry;
std::size_t pos1 = channelName.find(entry);
......@@ -110,29 +112,24 @@ bool CbmDeviceEventBuilderEtofStar2019::IsChannelNameAllowed(
std::find(fAllowedChannels.begin(), fAllowedChannels.end(), entry);
const vector<std::string>::size_type idx = pos - fAllowedChannels.begin();
LOG(info) << "Found " << entry << " in " << channelName;
LOG(info) << "Channel name " << channelName
<< " found in list of allowed channel names at position "
<< idx;
LOG(info) << "Channel name " << channelName << " found in list of allowed channel names at position " << idx;
return true;
}
}
LOG(info) << "Channel name " << channelName
<< " not found in list of allowed channel names.";
LOG(info) << "Channel name " << channelName << " not found in list of allowed channel names.";
LOG(error) << "Stop device.";
return false;
}
Bool_t CbmDeviceEventBuilderEtofStar2019::InitContainers() {
LOG(info)
<< "Init parameter containers for CbmDeviceEventBuilderEtofStar2019.";
Bool_t CbmDeviceEventBuilderEtofStar2019::InitContainers()
{
LOG(info) << "Init parameter containers for CbmDeviceEventBuilderEtofStar2019.";
// FairRuntimeDb* fRtdb = FairRuntimeDb::instance();
// NewSimpleMessage creates a copy of the data and takes care of its destruction (after the transfer takes place).
// Should only be used for small data because of the cost of an additional copy
std::string message {"CbmStar2019TofPar,111"};
LOG(info)
<< "Requesting parameter container CbmStar2019TofPar, sending message: "
<< message;
LOG(info) << "Requesting parameter container CbmStar2019TofPar, sending message: " << message;
FairMQMessagePtr req(NewSimpleMessage("CbmStar2019TofPar,111"));
FairMQMessagePtr rep(NewMessage());
......@@ -140,13 +137,12 @@ Bool_t CbmDeviceEventBuilderEtofStar2019::InitContainers() {
if (Send(req, "parameters") > 0) {
if (Receive(rep, "parameters") >= 0) {
if (rep->GetSize() != 0) {
CbmMQTMessage tmsg(rep->GetData(), rep->GetSize());
fUnpackPar =
dynamic_cast<CbmStar2019TofPar*>(tmsg.ReadObject(tmsg.GetClass()));
LOG(info) << "Received unpack parameter from parmq server: "
<< fUnpackPar;
CbmMqTMessage tmsg(rep->GetData(), rep->GetSize());
fUnpackPar = dynamic_cast<CbmStar2019TofPar*>(tmsg.ReadObject(tmsg.GetClass()));
LOG(info) << "Received unpack parameter from parmq server: " << fUnpackPar;
fUnpackPar->Print();
} else {
}
else {
LOG(error) << "Received empty reply. Parameter not available";
}
}
......@@ -164,8 +160,7 @@ Bool_t CbmDeviceEventBuilderEtofStar2019::InitContainers() {
initOK &= fEventBuilderAlgo->CreateHistograms();
/// Obtain vector of pointers on each histo from the algo (+ optionally desired folder)
std::vector<std::pair<TNamed*, std::string>> vHistos =
fEventBuilderAlgo->GetHistoVector();
std::vector<std::pair<TNamed*, std::string>> vHistos = fEventBuilderAlgo->GetHistoVector();
/* FIXME
/// Register the histos in the HTTP server
THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
......@@ -182,13 +177,13 @@ Bool_t CbmDeviceEventBuilderEtofStar2019::InitContainers() {
return initOK;
}
void CbmDeviceEventBuilderEtofStar2019::SetParContainers() {
void CbmDeviceEventBuilderEtofStar2019::SetParContainers()
{
FairRuntimeDb* fRtdb = FairRuntimeDb::instance();
fParCList = fEventBuilderAlgo->GetParList();
LOG(info) << "Setting parameter containers for " << fParCList->GetEntries()
<< " entries ";
LOG(info) << "Setting parameter containers for " << fParCList->GetEntries() << " entries ";
for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
......@@ -196,13 +191,11 @@ void CbmDeviceEventBuilderEtofStar2019::SetParContainers() {
std::string sParamName {tempObj->GetName()};
FairParGenericSet* newObj =
dynamic_cast<FairParGenericSet*>(fRtdb->getContainer(sParamName.data()));
FairParGenericSet* newObj = dynamic_cast<FairParGenericSet*>(fRtdb->getContainer(sParamName.data()));
LOG(info) << " - Get " << sParamName.data() << " at " << newObj;
if (nullptr == newObj) {
LOG(error) << "Failed to obtain parameter container " << sParamName
<< ", for parameter index " << iparC;
LOG(error) << "Failed to obtain parameter container " << sParamName << ", for parameter index " << iparC;
return;
} // if( nullptr == newObj )
if (iparC == 0) {
......@@ -214,14 +207,13 @@ void CbmDeviceEventBuilderEtofStar2019::SetParContainers() {
} // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
}
void CbmDeviceEventBuilderEtofStar2019::AddMsComponentToList(
size_t component,
UShort_t usDetectorId) {
void CbmDeviceEventBuilderEtofStar2019::AddMsComponentToList(size_t component, UShort_t usDetectorId)
{
fEventBuilderAlgo->AddMsComponentToList(component, usDetectorId);
}
Bool_t CbmDeviceEventBuilderEtofStar2019::DoUnpack(const fles::Timeslice& ts,
size_t /*component*/) {
Bool_t CbmDeviceEventBuilderEtofStar2019::DoUnpack(const fles::Timeslice& ts, size_t /*component*/)
{
if (0 == fulTsCounter) {
LOG(info) << "FIXME ===> Jumping 1st TS as corrupted with current FW + "
"FLESNET combination";
......@@ -229,13 +221,11 @@ Bool_t CbmDeviceEventBuilderEtofStar2019::DoUnpack(const fles::Timeslice& ts,
return kTRUE;
} // if( 0 == fulTsCounter )
if (kFALSE == fEventBuilderAlgo->ProcessTs(ts)) {
LOG(error) << "Failed processing TS " << ts.index()
<< " in event builder algorithm class";
LOG(error) << "Failed processing TS " << ts.index() << " in event builder algorithm class";
return kTRUE;
} // if( kFALSE == fEventBuilderAlgo->ProcessTs( ts ) )
std::vector<CbmTofStarSubevent2019>& eventBuffer =
fEventBuilderAlgo->GetEventBuffer();
std::vector<CbmTofStarSubevent2019>& eventBuffer = fEventBuilderAlgo->GetEventBuffer();
for (UInt_t uEvent = 0; uEvent < eventBuffer.size(); ++uEvent) {
/// Send the sub-event to the STAR systems
......@@ -256,16 +246,12 @@ Bool_t CbmDeviceEventBuilderEtofStar2019::DoUnpack(const fles::Timeslice& ts,
pDataBuff, iBuffSzByte );
*/
SendSubevent(eventBuffer[uEvent].GetTrigger().GetStarTrigerWord(),
(char*) pDataBuff,
iBuffSzByte,
0);
SendSubevent(eventBuffer[uEvent].GetTrigger().GetStarTrigerWord(), (char*) pDataBuff, iBuffSzByte, 0);
} // if( kFALSE == fbSandboxMode )
LOG(debug) << "Sent STAR event with size " << iBuffSzByte << " Bytes"
<< " and token "
<< eventBuffer[uEvent].GetTrigger().GetStarToken();
<< " and token " << eventBuffer[uEvent].GetTrigger().GetStarToken();
} // if( NULL != pDataBuff )
else
LOG(error) << "Invalid STAR SubEvent Output, can only happen if trigger "
......@@ -276,22 +262,21 @@ Bool_t CbmDeviceEventBuilderEtofStar2019::DoUnpack(const fles::Timeslice& ts,
}
Bool_t CbmDeviceEventBuilderEtofStar2019::ReInitContainers() {
LOG(info)
<< "ReInit parameter containers for CbmDeviceEventBuilderEtofStar2019";
Bool_t CbmDeviceEventBuilderEtofStar2019::ReInitContainers()
{
LOG(info) << "ReInit parameter containers for CbmDeviceEventBuilderEtofStar2019";
Bool_t initOK = fEventBuilderAlgo->ReInitContainers();
return initOK;
}
// handler is called whenever a message arrives on "data", with a reference to the message and a sub-channel index (here 0)
bool CbmDeviceEventBuilderEtofStar2019::HandleData(FairMQMessagePtr& msg,
int /*index*/) {
bool CbmDeviceEventBuilderEtofStar2019::HandleData(FairMQMessagePtr& msg, int /*index*/)
{
// Don't do anything with the data
// Maybe add an message counter which counts the incomming messages and add
// an output
fNumMessages++;
LOG(debug) << "Received message number " << fNumMessages << " with size "
<< msg->GetSize();
LOG(debug) << "Received message number " << fNumMessages << " with size " << msg->GetSize();
std::string msgStr(static_cast<char*>(msg->GetData()), msg->GetSize());
std::istringstream iss(msgStr);
......@@ -311,21 +296,19 @@ bool CbmDeviceEventBuilderEtofStar2019::HandleData(FairMQMessagePtr& msg,
static Double_t dctime = 0.;
bool CbmDeviceEventBuilderEtofStar2019::HandleParts(FairMQParts& parts,
int /*index*/) {
bool CbmDeviceEventBuilderEtofStar2019::HandleParts(FairMQParts& parts, int /*index*/)
{
// Don't do anything with the data
// Maybe add an message counter which counts the incomming messages and add
// an output
fNumMessages++;
LOG(debug) << "Received message number " << fNumMessages << " with "
<< parts.Size() << " parts";
LOG(debug) << "Received message number " << fNumMessages << " with " << parts.Size() << " parts";
fles::StorableTimeslice ts {0}; // rename ??? FIXME
switch (fiSelectComponents) {
case 0: {
std::string msgStr(static_cast<char*>(parts.At(0)->GetData()),
(parts.At(0))->GetSize());
std::string msgStr(static_cast<char*>(parts.At(0)->GetData()), (parts.At(0))->GetSize());
std::istringstream iss(msgStr);
boost::archive::binary_iarchive inputArchive(iss);
inputArchive >> ts;
......@@ -344,8 +327,7 @@ bool CbmDeviceEventBuilderEtofStar2019::HandleParts(FairMQParts& parts,
uint ncomp = parts.Size();
for (uint i = 0; i < ncomp; i++) {
std::string msgStr(static_cast<char*>(parts.At(i)->GetData()),
(parts.At(i))->GetSize());
std::string msgStr(static_cast<char*>(parts.At(i)->GetData()), (parts.At(i))->GetSize());
std::istringstream iss(msgStr);
boost::archive::binary_iarchive inputArchive(iss);
//fles::StorableTimeslice component{i};
......@@ -353,23 +335,19 @@ bool CbmDeviceEventBuilderEtofStar2019::HandleParts(FairMQParts& parts,
CheckTimeslice(component);
fEventBuilderAlgo->AddMsComponentToList(i, 0x60); // TOF data
LOG(debug) << "HandleParts message " << fNumMessages << " with indx "
<< component.index();
LOG(debug) << "HandleParts message " << fNumMessages << " with indx " << component.index();
}
} break;
default:;
}
if (kFALSE == fEventBuilderAlgo->ProcessTs(ts)) {
LOG(error) << "Failed processing TS " << ts.index()
<< " in event builder algorithm class";
LOG(error) << "Failed processing TS " << ts.index() << " in event builder algorithm class";
return kTRUE;
} // if( kFALSE == fEventBuilderAlgo->ProcessTs( ts ) )
std::vector<CbmTofStarSubevent2019>& eventBuffer =
fEventBuilderAlgo->GetEventBuffer();
LOG(debug) << "Process time slice " << fNumMessages << " with "
<< eventBuffer.size() << " events";
std::vector<CbmTofStarSubevent2019>& eventBuffer = fEventBuilderAlgo->GetEventBuffer();
LOG(debug) << "Process time slice " << fNumMessages << " with " << eventBuffer.size() << " events";
//if(fNumMessages%10000 == 0) LOG(info)<<"Processed "<<fNumMessages<<" time slices";
......@@ -392,31 +370,24 @@ bool CbmDeviceEventBuilderEtofStar2019::HandleParts(FairMQParts& parts,
pDataBuff, iBuffSzByte );
*/
} // if( kFALSE == fbSandboxMode )
SendSubevent(eventBuffer[uEvent].GetTrigger().GetStarTrigerWord(),
(char*) pDataBuff,
iBuffSzByte,
0);
LOG(debug) << "Sent STAR event " << uEvent << " with size " << iBuffSzByte
<< " Bytes"
<< ", token "
<< eventBuffer[uEvent].GetTrigger().GetStarToken()
<< ", TrigWord "
SendSubevent(eventBuffer[uEvent].GetTrigger().GetStarTrigerWord(), (char*) pDataBuff, iBuffSzByte, 0);
LOG(debug) << "Sent STAR event " << uEvent << " with size " << iBuffSzByte << " Bytes"
<< ", token " << eventBuffer[uEvent].GetTrigger().GetStarToken() << ", TrigWord "
<< eventBuffer[uEvent].GetTrigger().GetStarTrigerWord();
}
}
if (0 == fulTsCounter % 10000) {
LOG(info) << "Processed " << fulTsCounter
<< " TS, CPUtime: " << dctime / 10. << " ms/TS";
LOG(info) << "Processed " << fulTsCounter << " TS, CPUtime: " << dctime / 10. << " ms/TS";
dctime = 0.;
}
fulTsCounter++;
return true;
}
bool CbmDeviceEventBuilderEtofStar2019::HandleMessage(FairMQMessagePtr& msg,
int /*index*/) {
bool CbmDeviceEventBuilderEtofStar2019::HandleMessage(FairMQMessagePtr& msg, int /*index*/)
{
const char* cmd = (char*) (msg->GetData());
const char cmda[4] = {*cmd};
LOG(info) << "Handle message " << cmd << ", " << cmd[0];
......@@ -439,16 +410,15 @@ bool CbmDeviceEventBuilderEtofStar2019::HandleMessage(FairMQMessagePtr& msg,
}
bool CbmDeviceEventBuilderEtofStar2019::CheckTimeslice(
const fles::Timeslice& ts) {
bool CbmDeviceEventBuilderEtofStar2019::CheckTimeslice(const fles::Timeslice& ts)
{
if (0 == ts.num_components()) {
LOG(error) << "No Component in TS " << ts.index();
return 1;
}
auto tsIndex = ts.index();
LOG(debug) << "Found " << ts.num_components()
<< " different components in timeslice " << tsIndex;
LOG(debug) << "Found " << ts.num_components() << " different components in timeslice " << tsIndex;
/*
for (size_t c = 0; c < ts.num_components(); ++c) {
......@@ -467,10 +437,9 @@ bool CbmDeviceEventBuilderEtofStar2019::CheckTimeslice(
return true;
}
bool CbmDeviceEventBuilderEtofStar2019::SendEvent(std::vector<Int_t> vdigi,
int idx) {
LOG(debug) << "Send Data for event " << fNumEvt << " with size "
<< vdigi.size() << Form(" at %p ", &vdigi);
bool CbmDeviceEventBuilderEtofStar2019::SendEvent(std::vector<Int_t> vdigi, int idx)
{
LOG(debug) << "Send Data for event " << fNumEvt << " with size " << vdigi.size() << Form(" at %p ", &vdigi);
// LOG(debug) << "EventHeader: "<< fEventHeader[0] << " " << fEventHeader[1] << " " << fEventHeader[2] << " " << fEventHeader[3];
std::stringstream oss;
......@@ -485,8 +454,7 @@ bool CbmDeviceEventBuilderEtofStar2019::SendEvent(std::vector<Int_t> vdigi,
[](void*, void* object) { delete static_cast<std::string*>(object); },
strMsg)); // object that manages the data
LOG(debug) << "Send data to channel " << idx << " "
<< fChannelsToSend[idx][0];
LOG(debug) << "Send data to channel " << idx << " " << fChannelsToSend[idx][0];
// if (Send(msg, fChannelsToSend[idx][0]) < 0) {
......@@ -499,13 +467,10 @@ bool CbmDeviceEventBuilderEtofStar2019::SendEvent(std::vector<Int_t> vdigi,
return true;
}
bool CbmDeviceEventBuilderEtofStar2019::SendSubevent(uint trig,
char* pData,
int nData,
int idx) {
bool CbmDeviceEventBuilderEtofStar2019::SendSubevent(uint trig, char* pData, int nData, int idx)
{
LOG(debug) << "SendSubevent " << fNumEvt << ", TrigWord " << trig
<< " with size " << nData << Form(" at %p ", pData);
LOG(debug) << "SendSubevent " << fNumEvt << ", TrigWord " << trig << " with size " << nData << Form(" at %p ", pData);
std::stringstream ossE;
boost::archive::binary_oarchive oaE(ossE);
......@@ -534,8 +499,7 @@ bool CbmDeviceEventBuilderEtofStar2019::SendSubevent(uint trig,
[](void*, void* object) { delete static_cast<std::string*>(object); },
strMsg)); // object that manages the data
LOG(debug) << "Send data to channel " << idx << " "
<< fChannelsToSend[idx][0];
LOG(debug) << "Send data to channel " << idx << " " << fChannelsToSend[idx][0];
// if (Send(msg, fChannelsToSend[idx][0]) < 0) {
......@@ -550,7 +514,8 @@ bool CbmDeviceEventBuilderEtofStar2019::SendSubevent(uint trig,
void CbmDeviceEventBuilderEtofStar2019::Reset() {}
void CbmDeviceEventBuilderEtofStar2019::Finish() {
void CbmDeviceEventBuilderEtofStar2019::Finish()
{
if (NULL != fpBinDumpFile) {
LOG(info) << "Closing binary file used for event dump.";
fpBinDumpFile->close();
......@@ -559,14 +524,15 @@ void CbmDeviceEventBuilderEtofStar2019::Finish() {
/// If monitor mode enabled, trigger histos creation, obtain pointer on them and add them to the HTTP server
if (kTRUE == fbMonitorMode) {
/// Obtain vector of pointers on each histo from the algo (+ optionally desired folder)
std::vector<std::pair<TNamed*, std::string>> vHistos =
fEventBuilderAlgo->GetHistoVector();
std::vector<std::pair<TNamed*, std::string>> vHistos = fEventBuilderAlgo->GetHistoVector();
/// Save old global file and folder pointer to avoid messing with FairRoot
TFile* oldFile = gFile;
TDirectory* oldDir = gDirectory;
/// (Re-)Create ROOT file to store the histos
TDirectory* oldDir = NULL;
TFile* histoFile = NULL;
// Store current directory position to allow restore later
oldDir = gDirectory;
TFile* histoFile = nullptr;
// open separate histo file in recreate mode
histoFile = new TFile("data/eventBuilderMonHist.root", "RECREATE");
histoFile->cd();
......@@ -583,8 +549,10 @@ void CbmDeviceEventBuilderEtofStar2019::Finish() {
histoFile->cd();
} // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
// Restore original directory position
oldDir->cd();
/// Restore old global file and folder pointer to avoid messing with FairRoot
gFile = oldFile;
gDirectory = oldDir;
histoFile->Close();
} // if( kTRUE == fbMonitorMode )
}
/* Copyright (C) 2019 PI-UHd, GSI
SPDX-License-Identifier: GPL-3.0-only
Authors: Norbert Herrmann [committer] */
/**
* CbmDeviceEventBuilderEtofStar2019.h
*
......@@ -6,11 +10,13 @@
#ifndef CBMDEVICEEVENTBUILDERETOFSTAR2019_H_
#define CBMDEVICEEVENTBUILDERETOFSTAR2019_H_
#include "FairMQDevice.h"
#include "CbmMqTMessage.h"
#include "TMessage.h"
#include "Timeslice.hpp"
#include "FairMQDevice.h"
#include "TMessage.h"
#include "TStopwatch.h"
class CbmStar2019EventBuilderEtofAlgo;
......@@ -31,19 +37,15 @@ public:
Bool_t ReInitContainers();
void SetSandboxMode(Bool_t bSandboxMode = kTRUE) {
fbSandboxMode = bSandboxMode;
}
void SetSandboxMode(Bool_t bSandboxMode = kTRUE) { fbSandboxMode = bSandboxMode; }
void SetEventDumpEnable(Bool_t bDumpEna = kTRUE);
/// Temp until we change from CbmMcbmUnpack to something else
void AddMsComponentToList(size_t component, UShort_t usDetectorId);
void SetNbMsInTs(size_t /*uCoreMsNb*/, size_t /*uOverlapMsNb*/) {};
CbmDeviceEventBuilderEtofStar2019(const CbmDeviceEventBuilderEtofStar2019&) =
delete;
CbmDeviceEventBuilderEtofStar2019
operator=(const CbmDeviceEventBuilderEtofStar2019&) = delete;
CbmDeviceEventBuilderEtofStar2019(const CbmDeviceEventBuilderEtofStar2019&) = delete;
CbmDeviceEventBuilderEtofStar2019 operator=(const CbmDeviceEventBuilderEtofStar2019&) = delete;
protected:
virtual void InitTask();
......@@ -56,13 +58,10 @@ protected:
private:
uint64_t fNumMessages;
/// Control flags
Bool_t
fbMonitorMode; //! Switch ON the filling of a minimal set of histograms
Bool_t
fbDebugMonitorMode; //! Switch ON the filling of a additional set of histograms
Bool_t fbSandboxMode; //! Switch OFF the emission of data toward the STAR DAQ
Bool_t
fbEventDumpEna; //! Switch ON the dumping of the events to a binary file
Bool_t fbMonitorMode; //! Switch ON the filling of a minimal set of histograms
Bool_t fbDebugMonitorMode; //! Switch ON the filling of a additional set of histograms
Bool_t fbSandboxMode; //! Switch OFF the emission of data toward the STAR DAQ
Bool_t fbEventDumpEna; //! Switch ON the dumping of the events to a binary file
/// Parameters management
TList* fParCList;
......@@ -74,10 +73,7 @@ private:
bool CheckTimeslice(const fles::Timeslice& ts);
bool IsChannelNameAllowed(std::string channelName);
std::vector<std::string> fAllowedChannels = {"tofcomponent",
"parameters",
"etofevts",
"syscmd"};
std::vector<std::string> fAllowedChannels = {"tofcomponent", "parameters", "etofevts", "syscmd"};
std::vector<std::vector<std::string>> fChannelsToSend = {{}, {}, {}};
/// Processing algo
......@@ -92,12 +88,4 @@ private:
const UInt_t kuBinDumpEndWord = 0xFAEBDEEF;
};
// special class to expose protected TMessage constructor
class CbmMQTMessage : public TMessage {
public:
CbmMQTMessage(void* buf, Int_t len) : TMessage(buf, len) {
ResetBit(kIsOwner);
}
};
#endif /* CBMDEVICEEVENTBUILDERETOFSTAR2019_H_ */
/* Copyright (C) 2019 PI-UHd, GSI
SPDX-License-Identifier: GPL-3.0-only
Authors: Norbert Herrmann [committer] */
/**
* CbmDeviceTriggerHandlerEtof.cxx
*
......@@ -6,6 +10,7 @@
*/
#include "CbmDeviceTriggerHandlerEtof.h"
#include "CbmMQDefs.h"
#include "FairEventHeader.h"
......@@ -18,23 +23,22 @@
#include "FairRunOnline.h"
#include "FairRuntimeDb.h"
#include <thread> // this_thread::sleep_for
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <chrono>
#include <iomanip>
#include <string>
#include <thread> // this_thread::sleep_for
#include <stdexcept>
#include <string>
struct InitTaskError : std::runtime_error {
using std::runtime_error::runtime_error;
};
static std::chrono::steady_clock::time_point dctime =
std::chrono::steady_clock::now();
static double dSize = 0.;
static std::chrono::steady_clock::time_point dctime = std::chrono::steady_clock::now();
static double dSize = 0.;
using namespace std;
......@@ -45,11 +49,14 @@ CbmDeviceTriggerHandlerEtof::CbmDeviceTriggerHandlerEtof()
, fbDebugMonitorMode(kFALSE)
, fbSandboxMode(kFALSE)
, fbEventDumpEna(kFALSE)
, fdEvent(0.) {}
, fdEvent(0.)
{
}
CbmDeviceTriggerHandlerEtof::~CbmDeviceTriggerHandlerEtof() {}
void CbmDeviceTriggerHandlerEtof::InitTask() try {
void CbmDeviceTriggerHandlerEtof::InitTask()
try {
// Get the information about created channels from the device
// Check if the defined channels from the topology (by name)
// are in the list of channels which are possible/allowed
......@@ -62,21 +69,20 @@ void CbmDeviceTriggerHandlerEtof::InitTask() try {
LOG(info) << "Number of defined input channels: " << noChannel;
for (auto const& entry : fChannels) {
LOG(info) << "Channel name: " << entry.first;
if (!IsChannelNameAllowed(entry.first))
throw InitTaskError("Channel name does not match.");
if (entry.first != "syscmd")
OnData(entry.first, &CbmDeviceTriggerHandlerEtof::HandleData);
if (!IsChannelNameAllowed(entry.first)) throw InitTaskError("Channel name does not match.");
if (entry.first != "syscmd") OnData(entry.first, &CbmDeviceTriggerHandlerEtof::HandleData);
else
OnData(entry.first, &CbmDeviceTriggerHandlerEtof::HandleMessage);
}
InitWorkspace();
} catch (InitTaskError& e) {
}
catch (InitTaskError& e) {
LOG(error) << e.what();
cbm::mq::ChangeState(this, cbm::mq::Transition::ErrorFound);
}
bool CbmDeviceTriggerHandlerEtof::IsChannelNameAllowed(
std::string channelName) {
bool CbmDeviceTriggerHandlerEtof::IsChannelNameAllowed(std::string channelName)
{
for (auto const& entry : fAllowedChannels) {
std::size_t pos1 = channelName.find(entry);
if (pos1 != std::string::npos) {
......@@ -84,19 +90,17 @@ bool CbmDeviceTriggerHandlerEtof::IsChannelNameAllowed(
std::find(fAllowedChannels.begin(), fAllowedChannels.end(), entry);
const vector<std::string>::size_type idx = pos - fAllowedChannels.begin();
LOG(info) << "Found " << entry << " in " << channelName;
LOG(info) << "Channel name " << channelName
<< " found in list of allowed channel names at position "
<< idx;
LOG(info) << "Channel name " << channelName << " found in list of allowed channel names at position " << idx;
return true;
}
}
LOG(info) << "Channel name " << channelName
<< " not found in list of allowed channel names.";
LOG(info) << "Channel name " << channelName << " not found in list of allowed channel names.";
LOG(error) << "Stop device.";
return false;
}
Bool_t CbmDeviceTriggerHandlerEtof::InitWorkspace() {
Bool_t CbmDeviceTriggerHandlerEtof::InitWorkspace()
{
LOG(info) << "Init work space for CbmDeviceTriggerHandlerEtof.";
// steering variables
......@@ -107,19 +111,17 @@ Bool_t CbmDeviceTriggerHandlerEtof::InitWorkspace() {
// handler is called whenever a message arrives on "data", with a reference to the message and a sub-channel index (here 0)
//bool CbmDeviceTriggerHandlerEtof::HandleData(FairMQMessagePtr& msg, int /*index*/)
bool CbmDeviceTriggerHandlerEtof::HandleData(FairMQParts& parts,
int /*index*/) {
bool CbmDeviceTriggerHandlerEtof::HandleData(FairMQParts& parts, int /*index*/)
{
// Don't do anything with the data
// Maybe add an message counter which counts the incomming messages and add
// an output
fNumMessages++;
LOG(debug) << "Received message " << fNumMessages << " with " << parts.Size()
<< " parts"
LOG(debug) << "Received message " << fNumMessages << " with " << parts.Size() << " parts"
<< ", size0: " << parts.At(0)->GetSize();
uint TrigWord {0};
std::string msgStrE(static_cast<char*>(parts.At(0)->GetData()),
(parts.At(0))->GetSize());
std::string msgStrE(static_cast<char*>(parts.At(0)->GetData()), (parts.At(0))->GetSize());
std::istringstream issE(msgStrE);
boost::archive::binary_iarchive inputArchiveE(issE);
inputArchiveE >> TrigWord;
......@@ -128,17 +130,13 @@ bool CbmDeviceTriggerHandlerEtof::HandleData(FairMQParts& parts,
int iBuffSzByte = parts.At(1)->GetSize();
// Send Subevent to STAR
LOG(debug) << "Send Data for event " << fdEvent << ", TrigWord " << TrigWord
<< " with size " << iBuffSzByte << Form(" at %p ", pDataBuff);
if (kFALSE == fbSandboxMode) {
star_rhicf_write(TrigWord, pDataBuff, iBuffSzByte);
}
LOG(debug) << "Send Data for event " << fdEvent << ", TrigWord " << TrigWord << " with size " << iBuffSzByte
<< Form(" at %p ", pDataBuff);
if (kFALSE == fbSandboxMode) { star_rhicf_write(TrigWord, pDataBuff, iBuffSzByte); }
dSize += iBuffSzByte;
if (0 == (int) fdEvent % 10000) {
std::chrono::duration<double> deltatime =
std::chrono::steady_clock::now() - dctime;
LOG(info) << "Processed " << fdEvent
<< " events, delta-time: " << deltatime.count()
std::chrono::duration<double> deltatime = std::chrono::steady_clock::now() - dctime;
LOG(info) << "Processed " << fdEvent << " events, delta-time: " << deltatime.count()
<< ", rate: " << dSize * 1.E-6 / deltatime.count() << "MB/s";
dctime = std::chrono::steady_clock::now();
dSize = 0.;
......@@ -150,8 +148,8 @@ bool CbmDeviceTriggerHandlerEtof::HandleData(FairMQParts& parts,
/************************************************************************************/
bool CbmDeviceTriggerHandlerEtof::HandleMessage(FairMQMessagePtr& msg,
int /*index*/) {
bool CbmDeviceTriggerHandlerEtof::HandleMessage(FairMQMessagePtr& msg, int /*index*/)
{
const char* cmd = (char*) (msg->GetData());
const char cmda[4] = {*cmd};
LOG(info) << "Handle message " << cmd << ", " << cmd[0];
......
/* Copyright (C) 2019 PI-UHd, GSI
SPDX-License-Identifier: GPL-3.0-only
Authors: Norbert Herrmann [committer] */
/**
* CbmDeviceTriggerHandlerStar2019.h
*
......@@ -8,20 +12,19 @@
#ifndef CBMDEVICETRIGGERHANDLERETOF_H_
#define CBMDEVICETRIGGERHANDLERETOF_H_
#include "FairMQDevice.h"
#include "CbmMqTMessage.h"
#include "CbmTofStarData2019.h"
#include "MicrosliceDescriptor.hpp"
#include "Timeslice.hpp"
#include "CbmTofStarData2019.h"
#include "FairMQDevice.h"
#include "Rtypes.h"
#include "TMessage.h"
#include <map>
#include <vector>
class CbmMQTMessage;
// Relevant TOF classes
extern "C" int star_rhicf_write(unsigned int trg_word, void* dta, int bytes);
......@@ -55,11 +58,7 @@ private:
Bool_t ReInitContainers();
uint64_t fNumMessages;
std::vector<std::string> fAllowedChannels = {"tofcomponent",
"parameters",
"etofevts",
"tofhits",
"syscmd"};
std::vector<std::string> fAllowedChannels = {"tofcomponent", "parameters", "etofevts", "tofhits", "syscmd"};
// Input variables
......@@ -68,25 +67,14 @@ private:
// Constants or setting parameters
Int_t fiMsgCnt;
/// Control flags
Bool_t
fbMonitorMode; //! Switch ON the filling of a minimal set of histograms
Bool_t
fbDebugMonitorMode; //! Switch ON the filling of a additional set of histograms
Bool_t fbSandboxMode; //! Switch OFF the emission of data toward the STAR DAQ
Bool_t
fbEventDumpEna; //! Switch ON the dumping of the events to a binary file
Bool_t fbMonitorMode; //! Switch ON the filling of a minimal set of histograms
Bool_t fbDebugMonitorMode; //! Switch ON the filling of a additional set of histograms
Bool_t fbSandboxMode; //! Switch OFF the emission of data toward the STAR DAQ
Bool_t fbEventDumpEna; //! Switch ON the dumping of the events to a binary file
Double_t fdEvent;
// histograms
};
// special class to expose protected TMessage constructor
class CbmMQTMessage : public TMessage {
public:
CbmMQTMessage(void* buf, Int_t len) : TMessage(buf, len) {
ResetBit(kIsOwner);
}
};
#endif /* CBMDEVICETRIGGERHANDLERETOF_H_ */
/* Copyright (C) 2019 PI-UHd, GSI
SPDX-License-Identifier: GPL-3.0-only
Authors: Norbert Herrmann [committer] */
#include "CbmDeviceEventBuilderEtofStar2019.h"
#include "runFairMQDevice.h"
#include <iomanip>
#include <string>
#include "runFairMQDevice.h"
namespace bpo = boost::program_options;
using namespace std;
void addCustomOptions(bpo::options_description& options) { ; }
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) {
return new CbmDeviceEventBuilderEtofStar2019();
}
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) { return new CbmDeviceEventBuilderEtofStar2019(); }
/* Copyright (C) 2019 PI-UHd, GSI
SPDX-License-Identifier: GPL-3.0-only
Authors: Norbert Herrmann [committer] */
#include "CbmDeviceTriggerHandlerEtof.h"
#include "runFairMQDevice.h"
#include <iomanip>
#include <string>
#include "runFairMQDevice.h"
namespace bpo = boost::program_options;
using namespace std;
void addCustomOptions(bpo::options_description& options) {
options.add_options()(
"SandboxMode", bpo::value<bool>()->default_value(1), "Test mode switch");
void addCustomOptions(bpo::options_description& options)
{
options.add_options()("SandboxMode", bpo::value<bool>()->default_value(1), "Test mode switch");
;
}
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) {
return new CbmDeviceTriggerHandlerEtof();
}
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) { return new CbmDeviceTriggerHandlerEtof(); }
#!/bin/bash
# Copyright (C) 2019 PI-UHd,GSI
# SPDX-License-Identifier: GPL-3.0-only
# First commited by Norbert Herrmann
# script to write cosmic data to file
$FAIRROOTPATH/bin/shmmonitor --cleanup
......
......@@ -6,88 +6,49 @@
# copied verbatim in the file "LICENSE" #
################################################################################
Set(INCLUDE_DIRECTORIES
set(INCLUDE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}
${CBMROOT_SOURCE_DIR}/fles/flestools
)
Set(SYSTEM_INCLUDE_DIRECTORIES
${SYSTEM_INCLUDE_DIRECTORIES}
${Boost_INCLUDE_DIR}
${FAIRROOT_INCLUDE_DIR}
${FAIRMQ_INCLUDE_DIR}
${FAIRMQ_INCLUDE_DIR}/options
)
Include_Directories(${INCLUDE_DIRECTORIES})
Include_Directories(SYSTEM ${SYSTEM_INCLUDE_DIRECTORIES})
Set(LINK_DIRECTORIES
${Boost_LIBRARY_DIRS}
${FAIRROOT_LIBRARY_DIR}
${ROOT_LIBRARY_DIR}
)
Link_Directories(${LINK_DIRECTORIES})
set(FAIR_LIBS
FairMQ
)
If(FAIRLOGGER_FOUND)
set(FAIR_LIBS
${FAIR_LIBS}
FairLogger
)
EndIf()
Set(BOOST_LIBS
${Boost_SYSTEM_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
)
If(UNIX AND NOT APPLE)
List(APPEND BOOST_LIBS pthread)
EndIf()
If(FairRoot_VERSION VERSION_LESS 18.2.0)
Add_Definitions(-DHAVE_RootDeserializer)
EndIf()
# Set the install path within the build directory
set(EXECUTABLE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/MQ/histogramServer")
# Set the install path within the installation directory
set(BIN_DESTINATION bin/MQ/histogramServer)
set(DEPENDENCIES_ALL
${DEPENDENCIES}
${FAIR_LIBS}
${BOOST_LIBS}
)
set(PUBLIC_DEPS
ROOT::Core
ROOT::RHTTP
)
set(PRIVATE_DEPS
CbmFlibFlesTools
FairRoot::Base
FairMQ::FairMQ
ROOT::Gpad
ROOT::Hist
ROOT::Net
ROOT::RIO
)
set(EXE_NAME HistoServer)
set(SRCS CbmHistoServer.cxx runCbmHistoServer.cxx)
set(DEPENDENCIES
${DEPENDENCIES_ALL}
${FAIR_LIBS}
fles_ipc
Core
RIO
Net
Hist
RHTTP
)
GENERATE_EXECUTABLE()
set(EXECUTABLE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/MQ/histogramServer")
set(PUBLIC_DEPENDENCIES ${PUBLIC_DEPS})
set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPS})
set(INTERFACE_DEPENDENCIES ${INTERFACE_DEPS})
generate_cbm_executable()
set(EXE_NAME MqHistoServer)
set(SRCS CbmMqHistoServer.cxx runCbmMqHistoServer.cxx)
set(DEPENDENCIES
${DEPENDENCIES_ALL}
${FAIR_LIBS}
CbmFlibFlesTools
Core
RIO
Net
Hist
Gpad
RHTTP
)
GENERATE_EXECUTABLE()
set(PUBLIC_DEPENDENCIES ${PUBLIC_DEPS})
set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPS})
set(INTERFACE_DEPENDENCIES ${INTERFACE_DEPS})
generate_cbm_executable()
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include <mutex>
/* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Florian Uhlig [committer] */
#include "CbmHistoServer.h"
#include <mutex>
//#include "CbmHistoCanvasDrawer.h"
#include "FairLogger.h"
#include "RootSerializer.h"
#include <Logger.h>
#include "TH1.h"
#include "THttpServer.h"
#include "TMessage.h"
#include "TObjArray.h"
#include "RootSerializer.h"
std::mutex mtx;
CbmHistoServer::CbmHistoServer()
......@@ -26,11 +24,14 @@ CbmHistoServer::CbmHistoServer()
, fNMessages(0)
, fServer("http:8088")
// , fCanvasDrawer(nullptr)
, fStopThread(false) {}
, fStopThread(false)
{
}
CbmHistoServer::~CbmHistoServer() {}
void CbmHistoServer::InitTask() {
void CbmHistoServer::InitTask()
{
OnData(fInputChannelName, &CbmHistoServer::ReceiveData);
/*
......@@ -41,13 +42,10 @@ void CbmHistoServer::InitTask() {
*/
}
bool CbmHistoServer::ReceiveData(FairMQMessagePtr& msg, int /*index*/) {
bool CbmHistoServer::ReceiveData(FairMQMessagePtr& msg, int /*index*/)
{
TObject* tempObject = nullptr;
#ifdef HAVE_RootDeserializer
Deserialize<RootDeserializer>(*msg, tempObject);
#else
Deserialize<RootSerializer>(*msg, tempObject);
#endif
RootSerializer().Deserialize(*msg, tempObject);
if (TString(tempObject->ClassName()).EqualTo("TObjArray")) {
std::lock_guard<std::mutex> lk(mtx);
......@@ -62,7 +60,8 @@ bool CbmHistoServer::ReceiveData(FairMQMessagePtr& msg, int /*index*/) {
histogram_new = static_cast<TH1*>(histogram->Clone());
fArrayHisto.Add(histogram_new);
fServer.Register("Histograms", histogram_new);
} else {
}
else {
histogram_existing = static_cast<TH1*>(fArrayHisto.At(index1));
histogram_existing->Add(histogram);
}
......@@ -78,12 +77,14 @@ bool CbmHistoServer::ReceiveData(FairMQMessagePtr& msg, int /*index*/) {
return true;
}
void CbmHistoServer::PreRun() {
void CbmHistoServer::PreRun()
{
fStopThread = false;
fThread = std::thread(&CbmHistoServer::UpdateHttpServer, this);
}
void CbmHistoServer::UpdateHttpServer() {
void CbmHistoServer::UpdateHttpServer()
{
while (!fStopThread) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
std::lock_guard<std::mutex> lk(mtx);
......@@ -99,12 +100,14 @@ void CbmHistoServer::UpdateHttpServer() {
}
}
void CbmHistoServer::PostRun() {
void CbmHistoServer::PostRun()
{
fStopThread = true;
fThread.join();
}
int CbmHistoServer::FindHistogram(const std::string& name) {
int CbmHistoServer::FindHistogram(const std::string& name)
{
for (int i = 0; i < fArrayHisto.GetEntriesFast(); i++) {
TObject* obj = fArrayHisto.At(i);
if (TString(obj->GetName()).EqualTo(name)) { return i; }
......
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Florian Uhlig [committer] */
#ifndef FAIRMQEXHISTOSERVER
#define FAIRMQEXHISTOSERVER
......@@ -12,10 +9,10 @@
#include "THttpServer.h"
#include "TObjArray.h"
#include <thread>
#include <memory>
#include <string>
#include <thread>
//class FairMQExHistoCanvasDrawer;
......
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include <mutex>
/* Copyright (C) 2019-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Pierre-Alain Loizeau [committer] */
#include "CbmMqHistoServer.h"
#include "CbmFlesCanvasTools.h"
#include "BoostSerializer.h"
#include "FairLogger.h"
#include "FairMQProgOptions.h" // device->fConfig
#include "RootSerializer.h"
#include <Logger.h>
#include "TCanvas.h"
#include "TEnv.h"
#include "TFile.h"
#include "TH1.h"
#include "TH2.h"
......@@ -25,33 +19,30 @@
#include "TObjArray.h"
#include "TProfile.h"
#include "TRootSniffer.h"
#include "TSystem.h"
#include "BoostSerializer.h"
#include <boost/serialization/utility.hpp>
std::mutex mtx;
#include <mutex>
#include "RootSerializer.h"
std::mutex mtx;
/*
Bool_t bMqHistoServerResetHistos = kFALSE;
Bool_t bMqHistoServerSaveHistos = kFALSE;
*/
CbmMqHistoServer::CbmMqHistoServer()
: FairMQDevice()
, fsChannelNameHistosInput("histogram-in")
, fsChannelNameHistosConfig("histo-conf")
, fsChannelNameCanvasConfig("canvas-conf")
, fsHistoFileName("HistosMonitorPulser.root")
, fuHttpServerPort(8098)
, fArrayHisto()
, fvpsHistosFolder()
, fvpsCanvasConfig()
, fvHistos()
, fvCanvas()
, fNMessages(0)
, fServer(nullptr)
, fStopThread(false) {}
{
}
CbmMqHistoServer::~CbmMqHistoServer() {}
void CbmMqHistoServer::InitTask() {
void CbmMqHistoServer::InitTask()
{
/// Read options from executable
LOG(info) << "Init options for CbmMqHistoServer.";
fsChannelNameHistosInput = fConfig->GetValue<std::string>("ChNameIn");
......@@ -64,22 +55,31 @@ void CbmMqHistoServer::InitTask() {
OnData(fsChannelNameHistosInput, &CbmMqHistoServer::ReceiveData);
OnData(fsChannelNameHistosConfig, &CbmMqHistoServer::ReceiveHistoConfig);
OnData(fsChannelNameCanvasConfig, &CbmMqHistoServer::ReceiveCanvasConfig);
/// If multi-parts, go to method processing combined Config+Data
OnData(fsChannelNameHistosInput, &CbmMqHistoServer::ReceiveConfigAndData);
fServer = new THttpServer(Form("http:%u", fuHttpServerPort));
/// To avoid the server sucking all Histos from gROOT when no output file is used
fServer->GetSniffer()->SetScanGlobalDir(kFALSE);
const char* jsrootsys = gSystem->Getenv("JSROOTSYS");
if (!jsrootsys) jsrootsys = gEnv->GetValue("HttpServ.JSRootPath", jsrootsys);
LOG(info) << "JSROOT location: " << jsrootsys;
fServer->RegisterCommand("/Reset_Hist", "bMqHistoServerResetHistos=kTRUE");
fServer->RegisterCommand("/Save_Hist", "bMqHistoServerSaveHistos=kTRUE");
//fServer->RegisterCommand("/Reset_Hist", "bMqHistoServerResetHistos=kTRUE");
//fServer->RegisterCommand("/Save_Hist", "bMqHistoServerSaveHistos=kTRUE");
fServer->Restrict("/Reset_Moni_Hist", "allow=admin");
fServer->Restrict("/Save_Pulser_Hist", "allow=admin");
//fServer->Restrict("/Reset_Hist", "allow=admin");
//fServer->Restrict("/Save_Hist", "allow=admin");
}
bool CbmMqHistoServer::ReceiveData(FairMQMessagePtr& msg, int /*index*/) {
bool CbmMqHistoServer::ReceiveData(FairMQMessagePtr& msg, int /*index*/)
{
LOG(debug) << "CbmMqHistoServer::ReceiveData => Processing histograms update";
TObject* tempObject = nullptr;
Deserialize<RootSerializer>(*msg, tempObject);
// Deserialize<RootSerializer>(*msg, tempObject);
RootSerializer().Deserialize(*msg, tempObject);
if (TString(tempObject->ClassName()).EqualTo("TObjArray")) {
std::lock_guard<std::mutex> lk(mtx);
......@@ -88,8 +88,7 @@ bool CbmMqHistoServer::ReceiveData(FairMQMessagePtr& msg, int /*index*/) {
TObject* pObj = arrayHisto->At(i);
if (nullptr != dynamic_cast<TProfile*>(pObj)) {
if (!ReadHistogram<TProfile>(dynamic_cast<TProfile*>(pObj)))
return false;
if (!ReadHistogram<TProfile>(dynamic_cast<TProfile*>(pObj))) return false;
} // if( nullptr != dynamic_cast< TProfile *>( pObj ) )
else if (nullptr != dynamic_cast<TH2*>(pObj)) {
if (!ReadHistogram<TH2>(dynamic_cast<TH2*>(pObj))) return false;
......@@ -101,12 +100,14 @@ bool CbmMqHistoServer::ReceiveData(FairMQMessagePtr& msg, int /*index*/) {
LOG(warning) << "Unsupported object type for " << pObj->GetName();
} // for (Int_t i = 0; i < arrayHisto->GetEntriesFast(); i++)
LOG(debug) << "CbmMqHistoServer::ReceiveData => Deleting array";
/// Need to use Delete instead of Clear to avoid memory leak!!!
arrayHisto->Delete();
/// If new histos received, try to prepare as many canvases as possible
/// Should be expensive on start and cheap afterward
if (!fbAllCanvasReady) {
LOG(debug) << "CbmMqHistoServer::ReceiveData => Checking for canvases updates";
for (uint32_t uCanv = 0; uCanv < fvpsCanvasConfig.size(); ++uCanv) {
/// Jump canvases already ready
if (fvbCanvasReady[uCanv]) continue;
......@@ -117,14 +118,12 @@ bool CbmMqHistoServer::ReceiveData(FairMQMessagePtr& msg, int /*index*/) {
} // if( !fbAllCanvasReady )
} // if (TString(tempObject->ClassName()).EqualTo("TObjArray"))
else
LOG(fatal)
<< "CbmMqHistoServer::ReceiveData => Wrong object type at input: "
<< tempObject->ClassName();
LOG(fatal) << "CbmMqHistoServer::ReceiveData => Wrong object type at input: " << tempObject->ClassName();
fNMessages += 1;
if (nullptr != tempObject) delete tempObject;
/*
/// TODO: control flags communication with histo server
/// Idea: 1 req channel (per device or not mixup?), polling every N TS and/or M s
if (bMqHistoServerResetHistos) {
......@@ -140,19 +139,21 @@ bool CbmMqHistoServer::ReceiveData(FairMQMessagePtr& msg, int /*index*/) {
SaveHistograms();
bMqHistoServerSaveHistos = kFALSE;
} // if( bMqHistoServerSaveHistos )
*/
LOG(debug) << "CbmMqHistoServer::ReceiveData => Finished processing histograms update";
return true;
}
bool CbmMqHistoServer::ReceiveHistoConfig(FairMQMessagePtr& msg,
int /*index*/) {
bool CbmMqHistoServer::ReceiveHistoConfig(FairMQMessagePtr& msg, int /*index*/)
{
std::pair<std::string, std::string> tempObject;
Deserialize<BoostSerializer<std::pair<std::string, std::string>>>(*msg,
tempObject);
// Deserialize<BoostSerializer<std::pair<std::string, std::string>>>(*msg, tempObject);
BoostSerializer<std::pair<std::string, std::string>>().Deserialize(*msg, tempObject);
LOG(info) << " Received configuration for histo " << tempObject.first << " : "
<< tempObject.second;
LOG(info) << " Received configuration for histo " << tempObject.first << " : " << tempObject.second;
/// Check if histo name already received in previous messages
/// Linear search should be ok as config is shared only at startup
......@@ -176,15 +177,14 @@ bool CbmMqHistoServer::ReceiveHistoConfig(FairMQMessagePtr& msg,
return true;
}
bool CbmMqHistoServer::ReceiveCanvasConfig(FairMQMessagePtr& msg,
int /*index*/) {
bool CbmMqHistoServer::ReceiveCanvasConfig(FairMQMessagePtr& msg, int /*index*/)
{
std::pair<std::string, std::string> tempObject;
Deserialize<BoostSerializer<std::pair<std::string, std::string>>>(*msg,
tempObject);
// Deserialize<BoostSerializer<std::pair<std::string, std::string>>>(*msg, tempObject);
BoostSerializer<std::pair<std::string, std::string>>().Deserialize(*msg, tempObject);
LOG(info) << " Received configuration for canvas " << tempObject.first
<< " : " << tempObject.second;
LOG(info) << " Received configuration for canvas " << tempObject.first << " : " << tempObject.second;
/// Check if canvas name already received in previous messages
/// Linear search should be ok as config is shared only at startup
......@@ -194,7 +194,7 @@ bool CbmMqHistoServer::ReceiveCanvasConfig(FairMQMessagePtr& msg,
} // for( UInt_t uPrevCanv = 0; uPrevCanv < fvpsCanvasConfig.size(); ++uPrevCanv )
if (uPrevCanv < fvpsCanvasConfig.size()) {
LOG(warning) << " Ignored new configuration for histo " << tempObject.first
LOG(warning) << " Ignored new configuration for Canvas " << tempObject.first
<< " due to previously received one: " << tempObject.second;
/// Not sure if we should return false here...
} // if( uPrevCanv < fvpsCanvasConfig.size() )
......@@ -210,12 +210,82 @@ bool CbmMqHistoServer::ReceiveCanvasConfig(FairMQMessagePtr& msg,
return true;
}
void CbmMqHistoServer::PreRun() {
bool CbmMqHistoServer::ReceiveConfigAndData(FairMQParts& parts, int /*index*/)
{
/// Reject anything but a at least Header + Histo Config + Canvas Config + Histo Data
if (parts.Size() < 4) {
if (1 == parts.Size()) {
/// PAL, 09/04/2021, Debug message catching missed method overload/polymorphism:
/// contrary to my expectation, if 2 method bound to same channel, one with FairMQMessagePtr and one with
/// FairMQParts, all messages go to multipart version and FairMQMessagePtr is converted to size 1 FairMQParts
LOG(debug) << "CbmMqHistoServer::ReceiveConfigAndData => only 1 parts found in input, "
<< "assuming data only message routed to wrong method!";
return ReceiveData(parts.At(0), 0);
} // if( 1 == parts.Size() )
LOG(fatal) << "CbmMqHistoServer::ReceiveConfigAndData => Wrong number of parts: " << parts.Size()
<< " instead of at least 4 (Header + Histo Config + Canvas config + Data)!";
} // if( parts.Size() < 4 )
LOG(info) << "CbmMqHistoServer::ReceiveConfigAndData => Received composed message with " << parts.Size() << " parts";
/// Header contains a pair of
std::pair<uint32_t, uint32_t> pairHeader;
// Deserialize<BoostSerializer<std::pair<uint32_t, uint32_t>>>(*parts.At(0), pairHeader);
BoostSerializer<std::pair<uint32_t, uint32_t>>().Deserialize(*parts.At(0), pairHeader);
LOG(info) << "CbmMqHistoServer::ReceiveConfigAndData => Received configuration for " << pairHeader.first
<< " histos and " << pairHeader.second << " canvases";
uint32_t uOffsetHistoConfig = pairHeader.first;
if (0 == pairHeader.first) {
uOffsetHistoConfig = 1;
if (0 < (parts.At(uOffsetHistoConfig))->GetSize()) {
LOG(fatal) << "CbmMqHistoServer::ReceiveConfigAndData => No histo config expected but corresponding message is"
<< " not empty: " << (parts.At(uOffsetHistoConfig))->GetSize();
}
}
uint32_t uOffsetCanvasConfig = pairHeader.second;
if (0 == pairHeader.second) {
uOffsetCanvasConfig = 1;
if (0 < (parts.At(uOffsetHistoConfig + uOffsetCanvasConfig))->GetSize()) {
LOG(fatal) << "CbmMqHistoServer::ReceiveConfigAndData => No Canvas config expected but corresponding message is"
<< " not empty: " << (parts.At(uOffsetHistoConfig + uOffsetCanvasConfig))->GetSize();
}
}
if (static_cast<size_t>(parts.Size()) != 1 + uOffsetHistoConfig + uOffsetCanvasConfig + 1) {
LOG(fatal) << "CbmMqHistoServer::ReceiveConfigAndData => Number of parts not matching header: " << parts.Size()
<< " instead of " << 1 + uOffsetHistoConfig + uOffsetCanvasConfig + 1;
} // if( parts.Size() != 1 + pairHeader.first + pairHeader.second )
/// Decode parts for histograms configuration
for (uint32_t uHisto = 0; uHisto < pairHeader.first; ++uHisto) {
ReceiveHistoConfig(parts.At(1 + uHisto), 0);
} // for (UInt_t uHisto = 0; uHisto < pairHeader.first; ++uHisto)
/// Decode parts for histograms configuration
for (uint32_t uCanv = 0; uCanv < pairHeader.second; ++uCanv) {
ReceiveCanvasConfig(parts.At(1 + uOffsetHistoConfig + uCanv), 0);
} // for (UInt_t uCanv = 0; uCanv < pairHeader.second; ++uCanv)
/// Decode the histograms data now that the configuration is loaded
ReceiveData(parts.At(1 + uOffsetHistoConfig + uOffsetCanvasConfig), 0);
LOG(info) << "CbmMqHistoServer::ReceiveConfigAndData => Finished processing composed message with " << parts.Size()
<< " parts";
return true;
}
void CbmMqHistoServer::PreRun()
{
fStopThread = false;
fThread = std::thread(&CbmMqHistoServer::UpdateHttpServer, this);
}
void CbmMqHistoServer::UpdateHttpServer() {
void CbmMqHistoServer::UpdateHttpServer()
{
while (!fStopThread) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
std::lock_guard<std::mutex> lk(mtx);
......@@ -224,13 +294,17 @@ void CbmMqHistoServer::UpdateHttpServer() {
}
}
void CbmMqHistoServer::PostRun() {
void CbmMqHistoServer::PostRun()
{
SaveHistograms();
fStopThread = true;
fThread.join();
SaveHistograms();
}
template<class HistoT>
bool CbmMqHistoServer::ReadHistogram(HistoT* pHist) {
bool CbmMqHistoServer::ReadHistogram(HistoT* pHist)
{
int index1 = FindHistogram(pHist->GetName());
if (-1 == index1) {
HistoT* histogram_new = static_cast<HistoT*>(pHist->Clone());
......@@ -246,14 +320,12 @@ bool CbmMqHistoServer::ReadHistogram(HistoT* pHist) {
/// Check if name matches one in config for others
if (fvpsHistosFolder[uHist].first == histogram_new->GetName()) {
fvHistos[uHist] = std::pair<TNamed*, std::string>(
histogram_new, fvpsHistosFolder[uHist].second);
fServer->Register(Form("/%s", fvHistos[uHist].second.data()),
fvHistos[uHist].first);
fvHistos[uHist] = std::pair<TNamed*, std::string>(histogram_new, fvpsHistosFolder[uHist].second);
fServer->Register(Form("/%s", fvHistos[uHist].second.data()), fvHistos[uHist].first);
fvbHistoRegistered[uHist] = true;
LOG(info) << "registered histo " << fvHistos[uHist].first->GetName()
<< " in folder " << fvHistos[uHist].second;
LOG(info) << "registered histo " << fvHistos[uHist].first->GetName() << " in folder "
<< fvHistos[uHist].second;
/// Update flag telling whether all known histos are registered
......@@ -263,19 +335,18 @@ bool CbmMqHistoServer::ReadHistogram(HistoT* pHist) {
fbAllHistosRegistered = false;
break;
} // if( !fvbHistoRegistered[ uIdx ] )
} // for( uint32_t uIdx = 0; uIdx < fvbHistoRegistered.size(); ++uIdx )
} // for( uint32_t uIdx = 0; uIdx < fvbHistoRegistered.size(); ++uIdx )
break;
} // if( fvpsHistosFolder[ uHist ].first == histogram_new->GetName() )
} // for( uint32_t uCanv = 0; uCanv < fvpsCanvasConfig.size(); ++uCanv )
} // if( !fbAllCanvasReady )
} // if (-1 == index1)
} // for( uint32_t uCanv = 0; uCanv < fvpsCanvasConfig.size(); ++uCanv )
} // if( !fbAllCanvasReady )
} // if (-1 == index1)
else {
HistoT* histogram_existing = dynamic_cast<HistoT*>(fArrayHisto.At(index1));
if (nullptr == histogram_existing) {
LOG(error) << "CbmMqHistoServer::ReadHistogram => "
<< "Incompatible type found during update for histo "
<< pHist->GetName();
<< "Incompatible type found during update for histo " << pHist->GetName();
return false;
} // if( nullptr == histogram_existing )
......@@ -284,25 +355,26 @@ bool CbmMqHistoServer::ReadHistogram(HistoT* pHist) {
return true;
}
int CbmMqHistoServer::FindHistogram(const std::string& name) {
int CbmMqHistoServer::FindHistogram(const std::string& name)
{
for (int iHist = 0; iHist < fArrayHisto.GetEntriesFast(); ++iHist) {
TObject* obj = fArrayHisto.At(iHist);
if (TString(obj->GetName()).EqualTo(name)) {
return iHist;
} // if( TString( obj->GetName() ).EqualTo( name ) )
} // for( int iHist = 0; iHist < fArrayHisto.GetEntriesFast(); ++iHist )
if (TString(obj->GetName()).EqualTo(name)) { return iHist; } // if( TString( obj->GetName() ).EqualTo( name ) )
} // for( int iHist = 0; iHist < fArrayHisto.GetEntriesFast(); ++iHist )
return -1;
}
bool CbmMqHistoServer::ResetHistograms() {
bool CbmMqHistoServer::ResetHistograms()
{
for (int iHist = 0; iHist < fArrayHisto.GetEntriesFast(); ++iHist) {
dynamic_cast<TH1*>(fArrayHisto.At(iHist))->Reset();
} // for( int iHist = 0; iHist < fArrayHisto.GetEntriesFast(); ++iHist )
return true;
}
bool CbmMqHistoServer::PrepareCanvas(uint32_t uCanvIdx) {
CanvasConfig conf(
ExtractCanvasConfigFromString(fvpsCanvasConfig[uCanvIdx].second));
bool CbmMqHistoServer::PrepareCanvas(uint32_t uCanvIdx)
{
LOG(debug) << " Extracting configuration for canvas index " << uCanvIdx;
CanvasConfig conf(ExtractCanvasConfigFromString(fvpsCanvasConfig[uCanvIdx].second));
/// First check if all objects to be drawn are present
uint32_t uNbPads(conf.GetNbPads());
......@@ -319,9 +391,10 @@ bool CbmMqHistoServer::PrepareCanvas(uint32_t uCanvIdx) {
} // for( uint32_t uObjIdx = 0; uObjIdx < uNbObj; ++uObjIdx )
} // for( uint32_t uPadIdx = 0; uPadIdx < uNbPads; ++uPadIdx )
LOG(info) << " All histos found for canvas " << conf.GetName().data() << ", now preparing it";
/// Create new canvas and pads
TCanvas* pNewCanv =
new TCanvas(conf.GetName().data(), conf.GetTitle().data());
TCanvas* pNewCanv = new TCanvas(conf.GetName().data(), conf.GetTitle().data());
pNewCanv->Divide(conf.GetNbPadsX(), conf.GetNbPadsY());
/// Loop on pads
......@@ -342,31 +415,29 @@ bool CbmMqHistoServer::PrepareCanvas(uint32_t uCanvIdx) {
TObject* pObj = fArrayHisto[FindHistogram(sName)];
if (nullptr != dynamic_cast<TProfile*>(pObj)) {
dynamic_cast<TProfile*>(pObj)->Draw(
conf.GetOption(uPadIdx, uObjIdx).data());
dynamic_cast<TProfile*>(pObj)->Draw(conf.GetOption(uPadIdx, uObjIdx).data());
} // if( nullptr != dynamic_cast< TProfile *>( pObj ) )
else if (nullptr != dynamic_cast<TH2*>(pObj)) {
dynamic_cast<TH2*>(pObj)->Draw(
conf.GetOption(uPadIdx, uObjIdx).data());
dynamic_cast<TH2*>(pObj)->Draw(conf.GetOption(uPadIdx, uObjIdx).data());
} // if( nullptr != dynamic_cast< TH2 *>( pObj ) )
else if (nullptr != dynamic_cast<TH1*>(pObj)) {
dynamic_cast<TH1*>(pObj)->Draw(
conf.GetOption(uPadIdx, uObjIdx).data());
dynamic_cast<TH1*>(pObj)->Draw(conf.GetOption(uPadIdx, uObjIdx).data());
} // if( nullptr != dynamic_cast< TH1 *>( pObj ) )
else
LOG(warning) << "Unsupported object type for " << sName
<< " when preparing canvas " << conf.GetName();
LOG(warning) << " Unsupported object type for " << sName << " when preparing canvas " << conf.GetName();
LOG(info) << " Configured histo " << sName << " on pad " << (1 + uPadIdx) << " for canvas "
<< conf.GetName().data();
} // if( "nullptr" != sName )
} // for( uint32_t uObjIdx = 0; uObjIdx < uNbObj; ++uObjIdx )
} // for( uint32_t uPadIdx = 0; uPadIdx < uNbPads; ++uPadIdx )
fvCanvas[uCanvIdx] = std::pair<TCanvas*, std::string>(pNewCanv, "canvases");
fServer->Register(Form("/%s", fvCanvas[uCanvIdx].second.data()),
fvCanvas[uCanvIdx].first);
fServer->Register(Form("/%s", fvCanvas[uCanvIdx].second.data()), fvCanvas[uCanvIdx].first);
fvbCanvasRegistered[uCanvIdx] = true;
LOG(info) << "registered canvas " << fvCanvas[uCanvIdx].first->GetName()
<< " in folder " << fvCanvas[uCanvIdx].second;
LOG(info) << " Registered canvas " << fvCanvas[uCanvIdx].first->GetName() << " in folder "
<< fvCanvas[uCanvIdx].second;
/// Update flag telling whether all known canvases are registered
fbAllCanvasRegistered = true;
......@@ -380,15 +451,20 @@ bool CbmMqHistoServer::PrepareCanvas(uint32_t uCanvIdx) {
return true;
}
bool CbmMqHistoServer::SaveHistograms() {
bool CbmMqHistoServer::SaveHistograms()
{
/// Save old global file and folder pointer to avoid messing with FairRoot
TFile* oldFile = gFile;
TDirectory* oldDir = gDirectory;
/// (Re-)Create ROOT file to store the histos
TDirectory* oldDir = NULL;
TFile* histoFile = NULL;
// Store current directory position to allow restore later
oldDir = gDirectory;
TFile* histoFile = nullptr;
// open separate histo file in recreate mode
histoFile = new TFile(fsHistoFileName.data(), "RECREATE");
LOG(info) << "Save Histos in file " << fsHistoFileName.data();
if (nullptr == histoFile) return false;
/// Register the histos in the HTTP server
......@@ -416,8 +492,10 @@ bool CbmMqHistoServer::SaveHistograms() {
histoFile->cd();
} // for( UInt_t uHisto = 0; uHisto < fvCanvas.size(); ++uHisto )
// Restore original directory position
oldDir->cd();
/// Restore old global file and folder pointer to avoid messing with FairRoot
gFile = oldFile;
gDirectory = oldDir;
histoFile->Close();
return true;
......
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/* Copyright (C) 2019-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Pierre-Alain Loizeau [committer] */
#ifndef CBMMQHISTOSERVER_H
#define CBMMQHISTOSERVER_H
......@@ -12,10 +9,10 @@
#include "THttpServer.h"
#include "TObjArray.h"
#include <thread>
#include <memory>
#include <string>
#include <thread>
class TNamed;
class TCanvas;
......@@ -37,45 +34,45 @@ protected:
bool ReceiveCanvasConfig(FairMQMessagePtr& msg, int index);
bool ReceiveConfigAndData(FairMQParts& msg, int index);
virtual void PreRun();
virtual void PostRun();
private:
/// Parameters
std::string fsChannelNameHistosInput;
std::string fsChannelNameHistosConfig;
std::string fsChannelNameCanvasConfig;
std::string fsHistoFileName;
uint32_t fuHttpServerPort;
std::string fsChannelNameHistosInput = "histogram-in";
std::string fsChannelNameHistosConfig = "histo-conf";
std::string fsChannelNameCanvasConfig = "canvas-conf";
std::string fsHistoFileName = "MqHistos.root";
uint32_t fuHttpServerPort = 8098;
/// Array of histograms with unique names
TObjArray fArrayHisto;
/// Vector of string with ( HistoName, FolderPath ) to send to the histogram server
std::vector<std::pair<std::string, std::string>> fvpsHistosFolder;
std::vector<std::pair<std::string, std::string>> fvpsHistosFolder = {};
/// Vector of string pairs with ( CanvasName, CanvasConfig ) to send to the histogram server
/// Format of Can config is "Name;Title;NbPadX(U);NbPadY(U);ConfigPad1(s);....;ConfigPadXY(s)"
/// Format of Pad config is "GrixX(b),GridY(b),LogX(b),LogY(b),LogZ(b),HistoName(s),DrawOptions(s)"
std::vector<std::pair<std::string, std::string>> fvpsCanvasConfig;
std::vector<bool> fvbCanvasReady;
bool fbAllCanvasReady;
std::vector<std::pair<TNamed*, std::string>>
fvHistos; //! Vector of Histos pointers and folder path
std::vector<bool> fvbHistoRegistered;
bool fbAllHistosRegistered;
std::vector<std::pair<TCanvas*, std::string>>
fvCanvas; //! Vector of Canvas pointers and folder path
std::vector<bool> fvbCanvasRegistered;
bool fbAllCanvasRegistered;
std::vector<std::pair<std::string, std::string>> fvpsCanvasConfig = {};
std::vector<bool> fvbCanvasReady = {};
bool fbAllCanvasReady = false;
std::vector<std::pair<TNamed*, std::string>> fvHistos = {}; //! Vector of Histos pointers and folder path
std::vector<bool> fvbHistoRegistered = {};
bool fbAllHistosRegistered = false;
std::vector<std::pair<TCanvas*, std::string>> fvCanvas = {}; //! Vector of Canvas pointers and folder path
std::vector<bool> fvbCanvasRegistered = {};
bool fbAllCanvasRegistered = false;
/// Internal status
int fNMessages;
int fNMessages = 0;
THttpServer* fServer;
THttpServer* fServer = nullptr;
std::thread fThread;
bool fStopThread;
bool fStopThread = false;
template<class HistoT>
bool ReadHistogram(HistoT* pHist);
......
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Florian Uhlig [committer] */
#include "CbmHistoServer.h"
#include <memory>
#include "runFairMQDevice.h"
#include "CbmHistoServer.h"
namespace bpo = boost::program_options;
void addCustomOptions(bpo::options_description& /*options*/) {}
//std::unique_ptr<FairMQExHistoCanvasDrawer> getCanvasDrawer();
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) {
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
{
CbmHistoServer* histoServer = new CbmHistoServer();
// histoServer->SetCanvasDrawer(getCanvasDrawer());
......
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Pierre-Alain Loizeau [committer] */
#include "CbmMqHistoServer.h"
#include <memory>
#include "runFairMQDevice.h"
#include "CbmMqHistoServer.h"
namespace bpo = boost::program_options;
void addCustomOptions(bpo::options_description& options) {
options.add_options()(
"ChNameIn",
bpo::value<std::string>()->default_value("histogram-in"),
"MQ channel name for histos");
options.add_options()("ChNameHistCfg",
bpo::value<std::string>()->default_value("histo-conf"),
void addCustomOptions(bpo::options_description& options)
{
options.add_options()("ChNameIn", bpo::value<std::string>()->default_value("histogram-in"),
"MQ channel name for histos");
options.add_options()("ChNameHistCfg", bpo::value<std::string>()->default_value("histo-conf"),
"MQ channel name for histos config");
options.add_options()("ChNameCanvCfg",
bpo::value<std::string>()->default_value("canvas-conf"),
options.add_options()("ChNameCanvCfg", bpo::value<std::string>()->default_value("canvas-conf"),
"MQ channel name for canvases config");
options.add_options()(
"HistoFileName",
bpo::value<std::string>()->default_value("HistosMonitorPulser.root"),
".root File name for histo saving");
options.add_options()("histport",
bpo::value<uint32_t>()->default_value(8080),
"port for histos http server");
options.add_options()("HistoFileName", bpo::value<std::string>()->default_value("HistosMonitorPulser.root"),
".root File name for histo saving");
options.add_options()("histport", bpo::value<uint32_t>()->default_value(8080), "port for histos http server");
}
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) {
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
{
CbmMqHistoServer* histoServer = new CbmMqHistoServer();
return histoServer;
......
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/startMQSamplerUnpackerParserverHitBuilder.sh.in ${CMAKE_BINARY_DIR}/bin/MQ/topologies/startMQSamplerUnpackerParserverHitBuilder.sh)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/startMQ_Mcbm.sh.in ${CMAKE_BINARY_DIR}/bin/MQ/topologies/startMQ_Mcbm.sh)
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}/tof
${CBMBASE_DIR}
${CBMROOT_SOURCE_DIR}/tof/TofParam
${CBMROOT_SOURCE_DIR}/tof/TofTools
)
Set(SYSTEM_INCLUDE_DIRECTORIES
${SYSTEM_INCLUDE_DIRECTORIES}
${ZeroMQ_INCLUDE_DIR}
${Boost_INCLUDE_DIR}
${FAIRROOT_INCLUDE_DIR}
${FAIRMQ_INCLUDE_DIR}
${FAIRMQ_INCLUDE_DIR}/options
${IPC_INCLUDE_DIRECTORY}
${CBMROOT_SOURCE_DIR}/external/cppzmq
${CBMROOT_SOURCE_DIR}/tof/TofReco
)
include_directories(${INCLUDE_DIRECTORIES})
include_directories(SYSTEM ${SYSTEM_INCLUDE_DIRECTORIES})
set(LINK_DIRECTORIES
${ROOT_LIBRARY_DIR}
${FAIRROOT_LIBRARY_DIR}
${Boost_LIBRARY_DIRS}
)
link_directories(${LINK_DIRECTORIES})
)
# Set the install path within the build directory
set(EXECUTABLE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/MQ/hitbuilder")
# Set the install path within the installation directory
set(BIN_DESTINATION bin/MQ/hitbuilder)
Set(BOOST_LIBS
${Boost_SYSTEM_LIBRARY}
${Boost_SERIALIZATION_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${Boost_LOG_LIBRARY}
)
If(UNIX AND NOT APPLE)
List(APPEND BOOST_LIBS pthread)
EndIf()
set(FAIR_LIBS
Base
ParBase
FairMQ
)
If(FAIRLOGGER_FOUND)
set(FAIR_LIBS
${FAIR_LIBS}
FairLogger
)
EndIf()
set(EXE_NAME HitBuilderTof)
set(SRCS CbmDeviceHitBuilderTof.cxx runHitBuilderTof.cxx)
set(DEPENDENCIES
${DEPENDENCIES}
# FairMQ
${FAIR_LIBS}
${BOOST_LIBS}
# fles_ipc
CbmFlibCern2016
CbmBase
set(PUBLIC_DEPENDENCIES
CbmData
CbmTof
Geom
Core
MathCore
Tree
Physics
RIO
Net
Hist
)
GENERATE_EXECUTABLE()
CbmTofBase
CbmMQBase
FairRoot::Base
ROOT::Geom
)
set(PRIVATE_DEPENDENCIES
CbmBase
CbmTofReco
FairRoot::ParBase
FairRoot::Online
ROOT::Core
ROOT::Graf
ROOT::Hist
ROOT::MathCore
ROOT::Minuit
ROOT::Physics
)
set(INTERFACE_DEPENDENCIES
FairMQ::FairMQ
external::fles_ipc
ROOT::Net
ROOT::RIO
ROOT::Tree
)
generate_cbm_executable()
# Set the correct variables for the installation
set(VMCWORKDIR ${CMAKE_INSTALL_PREFIX}/share/cbmroot)
set(MY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_CURRENT_SOURCE_DIR ${VMCWORKDIR}/input)
set(TMPDIR "${CMAKE_BINARY_DIR}")
set(CMAKE_BINARY_DIR ${CMAKE_INSTALL_PREFIX})
# Configure file for installation directory
configure_file(${MY_SOURCE_DIR}/startMQSamplerUnpackerParserverHitBuilder.sh.in ${TMPDIR}/bin/MQ/topologies/install/startMQSamplerUnpackerParserverHitBuilder.sh)
configure_file(${MY_SOURCE_DIR}/startMQ_Mcbm.sh.in ${TMPDIR}/bin/MQ/topologies/install/startMQ_Mcbm.sh)
install(PROGRAMS ${TMPDIR}/bin/MQ/topologies/install/startMQSamplerUnpackerParserverHitBuilder.sh
${TMPDIR}/bin/MQ/topologies/install/startMQ_Mcbm.sh
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/MQ/topologies
)