Selector to fill a set of histograms and merging via file.
#define ProofSimpleFile_cxx
#include <TFormula.h>
ProofSimpleFile::ProofSimpleFile()
{
fNhist = 16;
fHistTop = 0;
fHistDir = 0;
fRandom = 0;
fFile = 0;
fProofFile = 0;
fFileDir = 0;
}
ProofSimpleFile::~ProofSimpleFile()
{
if (fRandom) delete fRandom;
}
Int_t ProofSimpleFile::CreateHistoArrays()
{
if (fNhist <= 0) {
Error(
"CreateHistoArrays",
"fNhist must be positive!");
return -1;
}
fHistTop =
new TH1F*[fNhist];
fHistDir =
new TH1F*[fNhist];
return 0;
}
{
if (fInput->FindObject("ProofSimpleFile_NHist")) {
}
else if ((iopt = option.
Index(
"nhist=")) !=
kNPOS) {
Ssiz_t from = iopt + strlen(
"nhist=");
if (option.
Tokenize(
s, from,
";") &&
s.IsDigit()) fNhist =
s.Atoi();
}
}
void ProofSimpleFile::SlaveBegin(
TTree * )
{
if (fInput->FindObject("ProofSimpleFile_NHist")) {
}
else if ((iopt = option.
Index(
"nhist=")) !=
kNPOS) {
Ssiz_t from = iopt + strlen(
"nhist=");
if (option.
Tokenize(
s, from,
";") &&
s.IsDigit()) fNhist =
s.Atoi();
}
if (out) fProofFile->SetOutputFileName(out->
GetTitle());
fFile = fProofFile->OpenFile("RECREATE");
if (fFile && fFile->IsZombie())
SafeDelete(fFile);
if (!fFile) {
" instance is invalid!", fProofFile->GetName());
Abort(amsg, kAbortProcess);
return;
}
if (CreateHistoArrays() != 0) {
Abort("ProofSimpleFile::SlaveBegin: could not create histograms", kAbortProcess);
return;
}
if (!(fFileDir = fFile->mkdir("blue"))) {
Abort("ProofSimpleFile::SlaveBegin: could not create directory 'blue' in file!",
kAbortProcess);
return;
}
for (
Int_t i=0; i < fNhist; i++) {
fHistTop[i] =
new TH1F(
Form(
"ht%d",i),
Form(
"ht%d",i), 100, -3., 3.);
fHistTop[i]->SetFillColor(
kRed);
fHistTop[i]->SetDirectory(fFile);
fHistDir[i] =
new TH1F(
Form(
"hd%d",i),
Form(
"hd%d",i), 100, -3., 3.);
fHistDir[i]->SetFillColor(
kBlue);
fHistDir[i]->SetDirectory(fFileDir);
}
}
{
for (
Int_t i=0; i < fNhist; i++) {
if (fRandom && fHistTop[i] && fHistDir[i]) {
fHistTop[i]->Fill(fRandom->Gaus(0.,1.));
fHistDir[i]->Fill(fRandom->Gaus(0.,1.));
}
}
}
void ProofSimpleFile::SlaveTerminate()
{
if (fFile) {
fFile->cd();
for (
Int_t i=0; i < fNhist; i++) {
if (fHistTop[i] && fHistTop[i]->GetEntries() > 0) {
fHistTop[i]->Write();
fHistTop[i]->SetDirectory(0);
}
}
fFileDir->cd();
for (
Int_t i=0; i < fNhist; i++) {
if (fHistDir[i] && fHistDir[i]->GetEntries() > 0) {
fHistDir[i]->Write();
fHistDir[i]->SetDirectory(0);
}
}
if (cleanup) {
Info(
"SlaveTerminate",
"nothing to save: just cleanup everything ...");
TUrl uf(*(fFile->GetEndpointUrl()));
} else {
Info(
"SlaveTerminate",
"objects saved into '%s%s': sending related TProofOutputFile ...",
fProofFile->GetFileName(), fProofFile->GetOptionsAnchor());
fProofFile->Print();
fOutput->Add(fProofFile);
}
}
}
void ProofSimpleFile::Terminate()
{
if ((fProofFile =
TString outputFile(fProofFile->GetOutputFileName());
TString outputName(fProofFile->GetName());
outputName += ".root";
Printf(
"outputFile: %s", outputFile.Data());
Error(
"Terminate",
"could not open file: %s", outputFile.Data());
return;
}
} else {
Error(
"Terminate",
"TProofOutputFile not found");
return;
}
if (CreateHistoArrays() != 0) {
Error(
"Terminate",
"could not create histograms");
return;
}
PlotHistos(0);
PlotHistos(1);
}
void ProofSimpleFile::PlotHistos(
Int_t opt)
{
if (opt == 0) {
TCanvas *
c1 =
new TCanvas(
"c1",
"ProofSimpleFile top dir canvas",200,10,700,700);
nside = (nside*nside < fNhist) ? nside+1 : nside;
c1->Divide(nside,nside,0,0);
for (
Int_t i=0; i < fNhist; i++) {
if (fHistTop[i])
fHistTop[i]->Draw();
}
} else if (opt == 1) {
TCanvas *
c2 =
new TCanvas(
"c2",
"ProofSimpleFile 'blue' sub-dir canvas",400,60,700,700);
nside = (nside*nside < fNhist) ? nside+1 : nside;
c2->Divide(nside,nside,0,0);
if ((fFileDir = (
TDirectory *) fFile->Get(
"blue"))) {
for (
Int_t i=0; i < fNhist; i++) {
if (fHistDir[i])
fHistDir[i]->Draw();
}
} else {
Error(
"PlotHistos",
"directory 'blue' not found in output file");
}
} else {
Error(
"PlotHistos",
"unknown option: %d", opt);
}
}
Selector to fill a set of histograms and merging via file.
void Info(const char *location, const char *msgfmt,...)
void Error(const char *location, const char *msgfmt,...)
char * Form(const char *fmt,...)
void Printf(const char *fmt,...)
R__EXTERN TSystem * gSystem
Describe directory structure in memory.
virtual void Close(Option_t *option="")
Delete all objects from memory and directory structure itself.
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose, Int_t netopt=0)
Create / open a file.
1-D histogram with a float per channel (see TH1 documentation)}
The TNamed class is the base class for all named ROOT classes.
virtual const char * GetTitle() const
Returns title of object.
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Named parameter, streamable and storable.
const AParamType & GetVal() const
Class to steer the merging of files produced on the workers.
Random number generator class based on M.
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual int Unlink(const char *name)
Unlink, i.e.
A TTree represents a columnar dataset.
This class represents a WWW compatible URL.
static constexpr double s
Double_t Sqrt(Double_t x)