16 #include "TObjArray.h"
21 if (lbls.empty() || !ax)
return;
22 TObjArray *lst = TString(lbls.c_str()).Tokenize(
",");
24 if (lst && (lst->GetSize() > 0))
25 for (
int n=0;n<nbins;++n)
26 ax->SetBinLabel(n+1, (n < lst->GetSize()) ? lst->At(n)->GetName() : Form(
"bin%d",n));
31 int main(
int argc,
char* argv[]) {
35 const char* inpfile(0), *outfile(0);
38 for (
int n=1;n<argc;n++) {
39 if ((strcmp(argv[n],
"-h")==0) && (n+1 < argc)) {
43 if ((strcmp(argv[n],
"-o")==0) && (n+1 < argc)) {
47 if (strcmp(argv[n],
"-skip-zero")==0) {
53 if ((inpfile==0) || (outfile==0)) {
54 printf(
"Some arguments:\n");
55 printf(
"-h filename - input file with stored hierarchy\n");
56 printf(
"-o filename.root - output ROOT file with histograms\n");
57 printf(
"-skip-zero - skip empty histograms\n");
64 printf(
"Cannot open file %s for reading\n", inpfile);
71 printf(
"Cannot read buffer header from file %s\n", inpfile);
79 printf(
"Cannot read buffer %lu from file %s\n", (
long unsigned) size, inpfile);
85 printf(
"Cannot decode hierarchy from buffer\n");
89 TFile* f = TFile::Open(outfile,
"recreate");
91 printf(
"Cannot create %s for output\n", outfile);
95 int cnt(0), emptycnt(0), currcnt(0);
100 if (item.
null())
continue;
102 if (!item.
HasField(
"_dabc_hist"))
continue;
106 for (
unsigned n=1;n<iter.
level();n++) {
110 if (n>1) dirname.Append(
"/");
111 dirname.Append(prnt->
GetName());
114 if (lastdir!=dirname) {
115 if ((lastdir.Length()>0) && (currcnt==0) && skipzero) {
116 if ((gDirectory->GetList()->GetSize()==0) && (gDirectory->GetListOfKeys()->GetSize()==0)) {
117 printf(
"Deleting empty directory %s\n", lastdir.Data());
118 f->rmdir(lastdir.Data());
122 if (!f->GetDirectory(dirname.Data()))
123 f->mkdir(dirname.Data());
124 f->cd(dirname.Data());
130 if (item.
Field(
"_kind").
AsStr() ==
"ROOT.TH1D") {
136 for (
int n=0;n<nbins+2;n++) {
137 if (bins[3+n]!=0.) { isany =
true;
break; }
139 if (!isany) { emptycnt++;
continue; }
148 for (
int n=0;n<nbins+2;n++) hist->SetBinContent(n,bins[3+n]);
154 if ((item.
Field(
"_kind").
AsStr() ==
"ROOT.TH2D") || (item.
Field(
"_kind").
AsStr() ==
"ROOT.TH2Poly")) {
160 for (
int n=0;n<(nbins1+2)*(nbins2+2);n++) {
161 if (bins[6+n]!=0.) { isany =
true;
break; }
163 if (!isany) { emptycnt++;
continue; }
175 for (
int n=0;n<(nbins1+2)*(nbins2+2);n++) hist->SetBinContent(n,bins[6+n]);
184 printf(
"TOTAL %d histograms converted, skipped %d, storing file %s ...\n", cnt, emptycnt, outfile);
188 printf(
"File %s stored\n", outfile);
Generic file storage for DABC buffers.
bool ReadBufPayload(void *ptr, uint64_t sz)
bool OpenReading(const char *fname)
bool ReadBufHeader(uint64_t *size, uint64_t *typ=0)
Reference on memory from memory pool.
static Buffer CreateBuffer(BufferSize_t sz)
This static method create independent buffer for any other memory pools Therefore it can be used in s...
void SetTypeId(unsigned tid)
void * SegmentPtr(unsigned n=0) const
Returns pointer on the segment, no any boundary checks.
Represents objects hierarchy of remote (or local) DABC process.
const RecordField & Field(const std::string &name) const
bool ReadFromBuffer(const dabc::Buffer &buf)
Read hierarchy from buffer.
Iterator over objects hierarchy
Object * next(bool goinside=true)
Object * parent(unsigned lvl)
Returns parents of current object.
Base class for most of the DABC classes.
const char * GetName() const
Returns name of the object, thread safe
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 * GetFieldPtr(const std::string &name) const
bool HasField(const std::string &name) const
const char * GetName() const
Return name of referenced object, if object not assigned, returns "---".
bool null() const
Returns true if reference contains nullptr.
int main(int argc, char *argv[])
void SetAxisLabels(TAxis *ax, std::string lbls, int nbins)