20 #include "dabc/Factory.h"
33 fStoreInfo(
"no store created"),
47 if (!withcmds)
return;
51 h.
SetField(
"_title",
"Clear all histograms in the server");
52 h.
SetField(
"_icon",
"dabcsys/plugins/stream/icons/clear.png");
58 h.
SetField(
"_title",
"Save all histograms in the dabc.root file");
59 h.
SetField(
"_icon",
"dabcsys/plugins/stream/icons/save.png");
65 h.
SetField(
"_title",
"Start processing of data");
66 h.
SetField(
"_icon",
"dabcsys/plugins/stream/icons/start.png");
72 h.
SetField(
"_title",
"Stop processing of data");
73 h.
SetField(
"_icon",
"dabcsys/plugins/stream/icons/stop.png");
109 std::string xtitle, ytitle, xlbls, fillcolor, drawopt, hmin, hmax;
110 bool reuse{
false}, clear_protect{
false};
113 const char* separ = strchr(options,
';');
114 std::string part = options;
116 part.resize(separ-options);
122 if (part.find(
"xbin:")==0) { xlbls = part; xlbls.erase(0, 5); }
else
123 if (part.find(
"fill:")==0) { fillcolor = part; fillcolor.erase(0,5); }
else
124 if (part.find(
"opt:")==0) { drawopt = part; drawopt.erase(0,4); }
else
125 if (part.find(
"hmin:")==0) { hmin = part; hmin.erase(0,5); }
else
126 if (part.find(
"hmax:")==0) { hmax = part; hmax.erase(0,5); }
else
127 if (part.find(
"kind:")==0) { }
else
128 if (part.find(
"reuse")==0) { reuse =
true; }
else
129 if (part.find(
"clear_protect")==0) { clear_protect =
true; }
else
130 if (xtitle.empty()) xtitle = part;
else ytitle = part;
140 std::string sname = name;
141 auto pos = sname.find_last_of(
"/");
142 if ((pos != std::string::npos) && fSortOrder)
147 if (!h)
return nullptr;
152 h.
SetField(
"_make_request",
"DABC.ReqH");
153 h.
SetField(
"_after_request",
"DABC.ConvertH");
157 if (!xtitle.empty()) h.
SetField(
"xtitle", xtitle);
158 if (!ytitle.empty()) h.
SetField(
"ytitle", ytitle);
159 if (xlbls.length()>0) h.
SetField(
"xlabels", xlbls);
160 h.
SetField(
"fillcolor", fillcolor.empty() ? fDefaultFill : std::stoi(fillcolor));
161 if (drawopt.length() > 0) h.
SetField(
"drawopt", drawopt);
162 if (!hmin.empty()) h.
SetField(
"hmin", std::stof(hmin));
163 if (!hmax.empty()) h.
SetField(
"hmax", std::stof(hmax));
164 if (clear_protect) h.
SetField(
"_no_reset",
"true");
166 std::vector<double> bins;
167 bins.resize(nbins+5, 0.);
173 fTop.MarkChangedItems();
178 base::H2handle
stream::DabcProcMgr::MakeH2(
const char* name,
const char* title,
int nbins1,
double left1,
double right1,
int nbins2,
double left2,
double right2,
const char* options)
180 std::string xtitle, ytitle, xlbls, ylbls, fillcolor, drawopt, hmin, hmax, h2poly;
181 bool reuse{
false}, clear_protect{
false};
183 while (options !=
nullptr) {
184 const char* separ = strchr(options,
';');
185 std::string part = options;
187 part.resize(separ-options);
193 if (part.find(
"xbin:")==0) { xlbls = part; xlbls.erase(0, 5); }
else
194 if (part.find(
"ybin:")==0) { ylbls = part; ylbls.erase(0, 5); }
else
195 if (part.find(
"fill:")==0) { fillcolor = part; fillcolor.erase(0,5); }
else
196 if (part.find(
"opt:")==0) { drawopt = part; drawopt.erase(0,4); }
else
197 if (part.find(
"hmin:")==0) { hmin = part; hmin.erase(0,5); }
else
198 if (part.find(
"hmax:")==0) { hmax = part; hmax.erase(0,5); }
else
199 if (part.find(
"kind:")==0) { }
else
200 if (part.find(
"h2poly:")==0) { h2poly = part; h2poly.erase(0,7); }
else
201 if (part.find(
"reuse")==0) { reuse =
true; }
else
202 if (part.find(
"clear_protect")==0) { clear_protect =
true; }
else
203 if (xtitle.empty()) xtitle = part;
else ytitle = part;
213 std::string sname = name;
214 auto pos = sname.find_last_of(
"/");
215 if ((pos != std::string::npos) && fSortOrder)
220 if (!h)
return nullptr;
222 h.
SetField(
"_kind", h2poly.empty() ?
"ROOT.TH2D" :
"ROOT.TH2Poly");
225 h.
SetField(
"_make_request",
"DABC.ReqH");
226 h.
SetField(
"_after_request",
"DABC.ConvertH");
233 if (!xtitle.empty()) h.
SetField(
"xtitle", xtitle);
234 if (!ytitle.empty()) h.
SetField(
"ytitle", ytitle);
235 if (xlbls.length() > 0) h.
SetField(
"xlabels", xlbls);
236 if (ylbls.length() > 0) h.
SetField(
"ylabels", ylbls);
237 if (!fillcolor.empty()) h.
SetField(
"fillcolor", std::stoi(fillcolor));
238 h.
SetField(
"drawopt", drawopt.empty() ? std::string(
"colz") : drawopt);
239 if (!hmin.empty()) h.
SetField(
"hmin", std::stof(hmin));
240 if (!hmax.empty()) h.
SetField(
"hmax", std::stof(hmax));
241 if (!h2poly.empty()) h.
SetField(
"h2poly", h2poly);
242 if (clear_protect) h.
SetField(
"_no_reset",
"true");
244 std::vector<double> bins;
245 bins.resize(6+(nbins1+2)*(nbins2+2), 0.);
254 fTop.MarkChangedItems();
261 if (!handle)
return nullptr;
264 while (iter.
next()) {
276 auto item = FindHistogram(h1);
278 item.SetField(
"_title", title);
283 auto item = FindHistogram(h1);
286 item.SetField(
"_humantime", now.AsString(3,
true));
287 item.SetField(
"_time", now.AsUTCSeconds());
293 auto item = FindHistogram(h2);
295 item.SetField(
"_title", title);
300 auto item = FindHistogram(h2);
303 item.SetField(
"_humantime", now.AsString(3,
true));
304 item.SetField(
"_time", now.AsUTCSeconds());
313 if (item.
HasField(
"_no_reset"))
return true;
315 int indx = item.
GetField(
"_kind").
AsStr()==
"ROOT.TH1D" ? 3 : 6;
319 while (indx<len) arr[indx++]=0.;
325 ClearAllDabcHistograms(fTop);
332 while (iter.
next()) {
334 if (ClearHistogram(item)) isany =
true;
348 system(
"rm -f h.bin");
362 DOUT0(
"Calling: %s", args.c_str());
364 int res = system(args.c_str());
367 EOUT(
"Fail to convert DABC histograms in ROOT file, check h-date-time.bin file");
369 system(args.c_str());
371 system(
"rm -f h.bin");
379 std::string name = cmd.
GetName();
381 if ((name.find(
"HCMD_")!=0) && (name!=
"ROOTCMD"))
return false;
384 if (item.
null())
return false;
385 std::string res =
"null";
387 if (name ==
"ROOTCMD") {
388 if (item.
IsName(
"Clear")) {
390 ClearAllDabcHistograms(fTop);
392 }
else if (item.
IsName(
"Save")) {
394 SaveAllHistograms(fTop);
396 }
else if (item.
IsName(
"Start")) {
400 }
else if (item.
IsName(
"Stop")) {
402 fWorkingFlag =
false;
408 }
else if (name ==
"HCMD_ClearHistos") {
410 res = ClearAllDabcHistograms(item) ?
"true" :
"false";
414 if ((kind !=
"ROOT.TH2D") && (kind !=
"ROOT.TH1D"))
return false;
417 if (bins==0)
return false;
421 if ((name ==
"GetMean") || (name==
"GetRMS") || (name==
"GetEntries")) {
422 if (kind !=
"ROOT.TH1D")
return false;
427 double sum0(0), sum1(0), sum2(0);
429 for (
int n=0;n<nbins;n++) {
430 double x = left + (right-left)/nbins*(n+0.5);
433 sum2 += x*x*bins[n+4];
435 double mean(0), rms(0);
438 rms = sqrt(sum2/sum0 - mean*mean);
440 if (name ==
"GetEntries") res =
dabc::format(
"%14.7g",sum0);
441 else if (name ==
"GetMean") res =
dabc::format(
"%8.6g",mean);
446 res = ClearHistogram(item) ?
"true" :
"false";
461 if (funcname==0)
return false;
464 if (symbol == 0)
return false;
478 fStoreInfo =
"Fail to create root::TreeStore, check libDabcRoot plugin";
483 cmd.
SetStr(
"fname", storename);
484 cmd.
SetStr(
"ftitle",
"File with stored stream data");
486 cmd.
SetStr(
"ttitle",
"Tree with stream data");
488 if (!fStore.Execute(cmd)) {
489 fStoreInfo =
dabc::format(
"Fail to create ROOT file %s", storename);
494 fTree = (TTree*) cmd.
GetPtr(
"tree_ptr");
496 fStoreInfo =
dabc::format(
"Create ROOT file %s", storename);
504 fStore.Execute(
"Close");
506 fStoreInfo =
"ROOT store closed";
512 DOUT3(
"Create Branch1 %s", name);
516 cmd.
SetStr(
"class_name", class_name);
517 cmd.
SetPtr(
"obj", (
void*) obj);
518 return fStore.Execute(cmd);
523 DOUT3(
"Create Branch2 %s", name);
527 cmd.
SetPtr(
"member", member);
529 return fStore.Execute(cmd);
534 if (fStore.null())
return false;
537 if (!fStore.Execute(cmd))
return false;
539 fStoreInfo = cmd.
GetStr(
"StoreInfo");
void StreamCallFunc(void *)
Generic file storage for DABC buffers.
bool WriteBufPayload(const void *ptr, uint64_t sz)
bool OpenWriting(const char *fname)
bool WriteBufHeader(uint64_t size, uint64_t typ=0)
Reference on memory from memory pool.
unsigned NumSegments() const
Returns number of segment in buffer.
unsigned SegmentSize(unsigned n=0) const
Returns size on the segment, no any boundary checks.
unsigned GetTypeId() const
BufferSize_t GetTotalSize() const
Return total size of all buffer segments.
void * SegmentPtr(unsigned n=0) const
Returns pointer on the segment, no any boundary checks.
Represents command with its arguments.
void SetPtr(const std::string &name, void *p)
Set pointer argument for the command.
bool SetStr(const std::string &name, const char *value)
bool SetStrRawData(const std::string &str)
Set raw data with string content.
std::string GetStr(const std::string &name, const std::string &dflt="") const
Reference GetRef(const std::string &name)
Returns reference from the command, can be called only once.
void * GetPtr(const std::string &name, void *deflt=0) const
Get pointer argument from the command.
Class for holding GMT time with precision of nanoseconds.
std::string OnlyTimeAsString(const char *separ=nullptr, bool localtime=false) const
Fills only time as string.
std::string OnlyDateAsString(const char *separ=nullptr, bool localtime=false) const
Fills only date as string.
static void * FindSymbol(const std::string &symbol)
Represents objects hierarchy of remote (or local) DABC process.
void MarkChangedItems(uint64_t tm=0)
If any field was modified, item will be marked with new version.
Hierarchy CreateHChild(const std::string &name, bool allowslahes=false, bool sortorder=false)
Create child item in hierarchy with specified name If allowslahes enabled, instead of subfolders item...
dabc::Buffer SaveToBuffer(unsigned kind=stream_Full, uint64_t version=0, unsigned hlimit=0)
Save hierarchy in binary form, relative to specified version.
Hierarchy GetHChild(const std::string &name, bool allowslahes=false, bool force=false, bool sortorder=false)
Return child, if necessary creates with full subfolder If force specified, missing childs and folders...
void EnableHistory(unsigned length=100, bool withchilds=false)
Activate history production for selected element and its childs.
Iterator over objects hierarchy
Object * next(bool goinside=true)
Lock guard for posix mutex.
Reference CreateObject(const std::string &classname, const std::string &objname)
int64_t GetArraySize() const
double * GetDoubleArr() const
std::string AsStr(const std::string &dflt="") const
int64_t AsInt(int64_t dflt=0) const
double AsDouble(double dflt=0.) const
RecordField GetField(const std::string &name) const
RecordField * GetFieldPtr(const std::string &name) const
bool HasField(const std::string &name) const
bool SetField(const std::string &name, const RecordField &v)
const char * GetName() const
Return name of referenced object, if object not assigned, returns "---".
bool IsName(const char *name) const
Returns true if object name is the same as specified one.
bool null() const
Returns true if reference contains nullptr.
void AddErrLog(const char *msg) override
void SetH2Title(base::H2handle h2, const char *title) override
void SetTop(dabc::Hierarchy &top, bool withcmds=false)
void AddRunLog(const char *msg) override
bool ExecuteHCommand(dabc::Command cmd)
base::H2handle MakeH2(const char *name, const char *title, int nbins1, double left1, double right1, int nbins2, double left2, double right2, const char *options=nullptr) override
void SetH1Title(base::H1handle h1, const char *title) override
base::H1handle MakeH1(const char *name, const char *title, int nbins, double left, double right, const char *xtitle=nullptr) override
void ClearAllHistograms() override
bool CloseStore() override
bool CallFunc(const char *funcname, void *arg) override
void PrintLog(const char *msg) override
bool CreateBranch(const char *name, const char *class_name, void **obj) override
bool StoreEvent() override
bool CreateStore(const char *storename) override
bool ClearAllDabcHistograms(dabc::Hierarchy &folder)
dabc::Hierarchy FindHistogram(void *handle)
void TagH2Time(base::H2handle h2) override
bool ClearHistogram(dabc::Hierarchy &item)
void TagH1Time(base::H1handle h1) override
std::string format(const char *fmt,...)