32#include <ElogRecord.h>
35#define DECO_SOCK_WAIT_PERIOD 20
36#define DECO_SOCK_WAIT_LIMIT 15e3
38using namespace chrono;
93 zmq_ctx_destroy(
_ctx);
108 _ctx = zmq_ctx_new();
114 if (zmq_setsockopt(
_decoSocket, ZMQ_SUBSCRIBE,
nullptr, 0) == -1) {
119 if (zmq_setsockopt(
_decoSocket, ZMQ_RCVBUF, &rcvBuf,
sizeof(rcvBuf)) == -1)
120 DBGERR(
"zmq_setsockopt of ZMQ_RCVBUF")
121 if (zmq_setsockopt(
_decoSocket, ZMQ_SNDBUF, &rcvBuf,
sizeof(rcvBuf)) == -1)
122 DBGERR(
"zmq_setsockopt of ZMQ_SNDBUF")
124 gSystem->ExpandPathName(dirname);
125 printf(
"dir %s\n", dirname.
Data());
130 gSystem->ExpandPathName(refDir);
133 printf(
"Ref dir set to %s\n",
_refDir.Data());
136 TString PlaceMapFileName =
TString(
"Trig_PlaceMap_Run") + PeriodSetupExt;
151 printf(
"Monitor listens to %s\n", conStr.
Data());
155 Int_t frame_size = 0;
163 frame_size = zmq_msg_recv(&msg,
_decoSocket, ZMQ_DONTWAIT);
165 if (frame_size == -1) {
166 if (errno == EAGAIN) {
174 DBG(
"state changed to kBMNWAIT")
177 printf(
"Receive error № %d #%s\n", errno, zmq_strerror(errno));
183 t.
SetBuffer(zmq_msg_data(&msg), zmq_msg_size(&msg));
188 uint32_t runID = head->GetRunId();
194 DBG(
"state changed to kBMNWORK")
201 printf(
"change run %5u to %5u\n",
fRunID, runID);
221 zmq_ctx_destroy(
_ctx);
230 printf(
"Authorization file not found\nStarting server without authorization\n");
282 printf(
"file %s created\n", outHistName.
Data());
284 printf(
"file tempo.root created\n");
289 for (
auto h :
bhVec) {
310 LOGF(debug,
"Event type %u", (uint8_t)head->
GetEventType());
340 LOGF(debug,
"Real time %f s, CPU time %f s %s ClassName %s Class_Name %s ", rtime, ctime, h->GetName(),
341 h->ClassName(), h->Class_Name());
346 auto now = system_clock::now();
404 auto now = system_clock::now();
405 milliseconds time_since_last_process = duration_cast<milliseconds>(now -
fTicksLastProcess);
422 h->SetDir(
nullptr,
nullptr);
426 bhVecIsStat.push_back(strcmp(h->ClassName(),
"BmnHistMSC") == 0);
437 if (refRuns ==
nullptr) {
438 fprintf(stderr,
"Ref list is empty!\n");
450 LOGF(debug,
"run %04d Energy %f Voltage %f Beam %s Target %s Date %d", run->
GetRunNumber(),
462 printf(
"fHistOut Write result = %d\n",
fHistOut->Write());
476 TPRegexp reElementName(
".*(\\w+).*");
482 if (recs ==
nullptr) {
483 fprintf(stderr,
"Run not found in ELOG!\n");
490 beamParticle = ((
TObjString*)strings->
At(1))->GetString();
494 targetParticle = ((
TObjString*)strings->
At(1))->GetString();
499 if (beamParticle ==
"" || targetParticle ==
"" || beamEnergy == 0 || I_SP41 == 0) {
500 fprintf(stderr,
"Not enough run data in ELOG!\n");
503 printf(
"search Energy %f I %f beam %s target %s\n\n", beamEnergy, I_SP41, beamParticle.
Data(),
504 targetParticle.
Data());
508 arrayConditions.
Add((
TObject*)searchCondition);
511 arrayConditions.
Add((
TObject*)searchCondition);
514 arrayConditions.
Add((
TObject*)searchCondition);
535 printf(
"getalike \n");
537 printf(
"getalike request returned\n");
538 if (Run.get() ==
nullptr) {
542 if (!(Run->GetFieldVoltage() && Run->GetEnergy())) {
543 fprintf(stderr,
"Not enough info on current run!\n");
550 TString beamParticle = Run->GetBeamParticle();
551 printf(
"Beam particle %s\n", Run->GetBeamParticle().Data());
554 arrayConditions.
Add((
TObject*)searchCondition);
555 TString targetParticle = Run->GetTargetParticle();
556 printf(
"Target particle %s\n", targetParticle.
Data());
559 arrayConditions.
Add((
TObject*)searchCondition);
560 if (Run->GetEnergy()) {
561 printf(
"Beam Energy %f\n", *Run->GetEnergy());
562 Double_t beamEnergy = *Run->GetEnergy();
565 arrayConditions.
Add((
TObject*)searchCondition);
567 if (Run->GetFieldVoltage()) {
568 printf(
"Field voltage %f\n", *Run->GetFieldVoltage());
569 Double_t V_SP41 = *Run->GetFieldVoltage();
572 arrayConditions.
Add((
TObject*)searchCondition);
575 arrayConditions.
Add((
TObject*)searchCondition);
580 printf(
"search request returned\n");
#define DECO_SOCK_WAIT_PERIOD
#define DECO_SOCK_WAIT_LIMIT
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
BmnStatus
Define status code.
@ kBMNPAYLOAD
spill event.
@ kBMNPEDESTAL
pedestal event.
void SetHistFileNameAdd(TString add)
BmnStatus CreateFile(uint32_t runID=0)
void MonitorStreamZ(TString dir, TString refDir="", TString decoAddr="localhost", Int_t webPort=9000)
chrono::time_point< chrono::system_clock > fTicksLastUpdate
redraw each timeout seconds
const chrono::seconds fTimeToUpdate
void InitHistVectors(vector< BmnHist * > &vec, TString refName="")
void ProcessDigi(Int_t iEv)
const chrono::milliseconds fTimeToProcessRequests
vector< BmnHist * > bhVec
TObjArray * GetAlikeRunsByElog(uint32_t periodID, uint32_t rinID)
TObjArray * GetAlikeRunsByUniDB(uint32_t periodID, uint32_t rinID)
uint64_t fNItersSinceUpdate
vector< BmnHist * > bhVec4show
vector< bool > bhVecIsStat
BmnTrigRaw2Digit * fTrigMapper
chrono::time_point< chrono::system_clock > fTicksLastProcess
answer each timeout seconds
ElogRecord.h Class for the table: record_.
int * GetSp41()
get sp 41 of the current record
double * GetEnergy()
get energy of the current record
TString GetBeam()
get beam of the current record
TString GetTarget()
get target of the current record
static TObjArray * GetRecords(int period_number, int run_number, int findNeighbourRun=0)
get array of ElogRecord-s for a given or a neighbour run (the same period) from the database if findN...
virtual void SetTextAlign(Short_t align=11)
virtual void SetTextSize(Float_t tsize=1)
TObject * ReadObject(const TClass *cl) override
void SetBuffer(void *buf, UInt_t bufsize=0, Bool_t adopt=kTRUE, ReAllocCharFun_t reallocfunc=nullptr)
virtual void SetOwner(Bool_t enable=kTRUE)
TLatex * DrawLatex(Double_t x, Double_t y, const char *text)
Int_t GetEntriesFast() const
void Clear(Option_t *option="") override
void Delete(Option_t *option="") override
TObject * At(Int_t idx) const override
void Add(TObject *obj) override
virtual void Draw(Option_t *option="")
TObjArray * MatchS(const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10)
void Start(Bool_t reset=kTRUE)
static TString UItoa(UInt_t value, Int_t base)
const char * Data() const
virtual void Modified(Bool_t flag=1)=0
void Clear(Option_t *option="") override=0
UniRun.h Class for the table: run_.
double * GetEnergy()
get energy of the current run
static UniRun * GetRun(int period_number, int run_number)
get run from the database
int GetRunNumber()
get run number of the current run
static TObjArray * Search(UniSearchCondition &search_condition)
get runs corresponding to the specified single condition and set owner for search_condition to kTRUE
TString GetBeamParticle()
get beam particle of the current run
TDatime GetStartDatetime()
get start datetime of the current run
double * GetFieldVoltage()
get field voltage of the current run
TString GetTargetParticle()
get target particle of the current run
@ conditionGreaterOrEqual