19#include "StorableTimeslice.hpp"
21#include "FairMQLogger.h"
22#include "FairMQProgOptions.h"
23#include "FairParGenericSet.h"
31#include "BoostSerializer.h"
32#include <boost/archive/binary_iarchive.hpp>
33#include <boost/serialization/utility.hpp>
40#include "RootSerializer.h"
42 using std::runtime_error::runtime_error;
48 : fbIgnoreOverlapMs {false}
49 , fsChannelNameDataInput {
"psdcomponent"}
50 , fsChannelNameHistosInput {
"histogram-in"}
51 , fsChannelNameHistosConfig {
"histo-conf"}
52 , fsChannelNameCanvasConfig {
"canvas-conf"}
53 , fuPublishFreqTs {100}
54 , fdMinPublishTime {0.5}
55 , fdMaxPublishTime {5.0}
56 , fuHistoryHistoSize {3600}
57 , fviHistoChargeArgs(3, 0)
58 , fviHistoAmplArgs(3, 0)
59 , fviHistoZLArgs(3, 0)
60 , fsAllowedChannels {fsChannelNameDataInput}
64 , fLastPublishTime {
std::chrono::system_clock::now()}
75 LOG(info) <<
"Init options for CbmMqStarHistoServer.";
84 fviHistoZLArgs = fConfig->GetValue<std::vector<int>>(
"HistZlArgs");
94 LOG(info) <<
"Histograms publication frequency in TS: " <<
fuPublishFreqTs;
95 LOG(info) <<
"Histograms publication min. interval in s: " <<
fdMinPublishTime;
96 LOG(info) <<
"Histograms publication max. interval in s: " <<
fdMaxPublishTime;
108 int noChannel = fChannels.size();
109 LOG(info) <<
"Number of defined channels: " << noChannel;
110 for (
auto const& entry : fChannels) {
111 LOG(info) <<
"Channel name: " << entry.first;
120 LOG(error) << e.what();
128 std::size_t pos1 = channelName.find(entry);
129 if (pos1 != std::string::npos) {
130 const vector<std::string>::const_iterator
pos =
133 LOG(info) <<
"Found " << entry <<
" in " << channelName;
134 LOG(info) <<
"Channel name " << channelName <<
" found in list of allowed channel names at position " << idx;
138 LOG(info) <<
"Channel name " << channelName <<
" not found in list of allowed channel names.";
139 LOG(error) <<
"Stop device.";
145 LOG(info) <<
"Init parameter containers for CbmDeviceMonitorPsd.";
149 for (
int iparC = 0; iparC <
fParCList->GetEntries(); iparC++) {
150 FairParGenericSet* tempObj = (FairParGenericSet*) (
fParCList->At(iparC));
152 std::string paramName {tempObj->GetName()};
157 std::string message = paramName +
",111";
158 LOG(info) <<
"Requesting parameter container " << paramName <<
", sending message: " << message;
160 FairMQMessagePtr req(NewSimpleMessage(message));
161 FairMQMessagePtr rep(NewMessage());
163 FairParGenericSet* newObj =
nullptr;
165 if (Send(req,
"parameters") > 0) {
166 if (Receive(rep,
"parameters") >= 0) {
167 if (rep->GetSize() != 0) {
169 newObj =
static_cast<FairParGenericSet*
>(tmsg.ReadObject(tmsg.GetClass()));
170 LOG(info) <<
"Received unpack parameter from the server:";
174 LOG(error) <<
"Received empty reply. Parameter not available";
211 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
216 std::pair<std::string, std::string> psHistoConfig(vHistos[uHisto].
first->GetName(), vHistos[uHisto].second);
220 FairMQMessagePtr messageHist(NewMessage());
222 BoostSerializer<std::pair<std::string, std::string>>().Serialize(*messageHist, psHistoConfig);
226 LOG(error) <<
"Problem sending histo config";
230 LOG(info) <<
"Config of hist " << psHistoConfig.first.data() <<
" in folder " << psHistoConfig.second.data();
236 for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
239 std::string sCanvName = (vCanvases[uCanv].first)->GetName();
242 std::pair<std::string, std::string> psCanvConfig(sCanvName, sCanvConf);
247 FairMQMessagePtr messageCan(NewMessage());
249 BoostSerializer<std::pair<std::string, std::string>>().Serialize(*messageCan, psCanvConfig);
253 LOG(error) <<
"Problem sending canvas config";
257 LOG(info) <<
"Config string of Canvas " << psCanvConfig.first.data() <<
" is " << psCanvConfig.second.data();
268 LOG(debug) <<
"Received message number " <<
fulNumMessages <<
" with size " << msg->GetSize();
272 std::string msgStr(
static_cast<char*
>(msg->GetData()), msg->GetSize());
273 std::istringstream iss(msgStr);
274 boost::archive::binary_iarchive inputArchive(iss);
277 fles::StorableTimeslice component {0};
278 inputArchive >> component;
286 std::chrono::system_clock::time_point currentTime = std::chrono::system_clock::now();
287 std::chrono::duration<double_t> elapsedSeconds = currentTime -
fLastPublishTime;
300 FairMQMessagePtr message(NewMessage());
302 RootSerializer().Serialize(*message, &
fArrayHisto);
306 LOG(error) <<
"Problem sending data";
323 for (uint32_t uCompIdx = 0; uCompIdx < ts.num_components(); ++uCompIdx) {
324 if (
kusSysId == ts.descriptor(uCompIdx, 0).sys_id) {
332 LOG(error) <<
"Failed processing TS " << ts.index() <<
" in unpacker algorithm class";
std::vector< std::pair< std::string, std::string > > fvpsHistosFolder
Vector of string pairs with ( HistoName, FolderPath ) to send to the histogram server.
TObjArray fArrayHisto
Array of histograms to send to the histogram server.
std::string fsChannelNameHistosInput
double_t fdMaxPublishTime
bool HandleData(FairMQMessagePtr &, int)
double_t fdMinPublishTime
Bool_t fbMonitorFitMode
Switch ON the filling waveforms histograms.
std::string fsChannelNameDataInput
Switch ON the filling waveform fitting histograms.
std::vector< std::pair< std::string, std::string > > fvpsCanvasConfig
bool IsChannelNameAllowed(std::string channelName)
static const uint16_t kusSysId
Constants.
std::chrono::system_clock::time_point fLastPublishTime
std::vector< std::string > fsAllowedChannels
List of MQ channels names.
std::string fsChannelNameCanvasConfig
uint64_t fulNumMessages
Statistics & first TS rejection.
Bool_t fbMonitorMode
Control flags.
Bool_t fbMonitorChanMode
Ignore Overlap Ms: all fuOverlapMsNb MS at the end of timeslice.
Bool_t fbMonitorWfmMode
Switch ON the filling channelwise histograms.
Bool_t fbComponentsAddedToList
std::vector< Int_t > fviHistoChargeArgs
UInt_t fuHistoryHistoSize
std::vector< Int_t > fviHistoZLArgs
std::string fsChannelNameHistosConfig
TList * fParCList
Parameters management.
Bool_t fbIgnoreOverlapMs
Switch ON the filling of a minimal set of histograms.
CbmMcbm2018MonitorAlgoPsd * fMonitorAlgo
Processing algo.
virtual ~CbmDeviceMonitorPsd()
Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
std::vector< Int_t > fviHistoAmplArgs
void SetZLHistoArgs(std::vector< Int_t > inVec)
void SetMonitorFitMode(Bool_t bFlagIn=kTRUE)
Bool_t CreateHistograms()
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
void SetAmplHistoArgs(std::vector< Int_t > inVec)
void SetMonitorWfmMode(Bool_t bFlagIn=kTRUE)
Bool_t ProcessTs(const fles::Timeslice &ts)
void SetMonitorChanMode(Bool_t bFlagIn=kTRUE)
void SetHistoryHistoSize(UInt_t inHistorySizeSec=1800)
void SetChargeHistoArgs(std::vector< Int_t > inVec)
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Bool_t ResetHistograms(Bool_t bResetTime=kTRUE)
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
std::vector< std::pair< TCanvas *, std::string > > GetCanvasVector()
void ClearVector()
For unpacker algos.
void ChangeState(FairMQDevice *device, cbm::mq::Transition transition)