14 #if ROOT_VERSION_CODE >= ROOT_VERSION(5, 20, 0)
15 #define HAS_THNSPARSE 1
16 #include <THnSparse.h>
34 delete Histo.begin()->second;
43 if (!filename.empty())
52 std::ostringstream filnam;
61 filnam <<
Name() <<
"-"
62 << std::setfill(
'0') << std::setw(10)
63 << runnumber <<
".root";
67 std::cout <<
"Fun4AllHistoManager::dumpHistos() Writing root file: " <<
outfilename << std::endl;
69 const int compress = 9;
70 std::ostringstream creator;
71 creator <<
"Created by " <<
Name();
72 TFile hfile(
outfilename.c_str(), openmode.c_str(), creator.str().c_str(), compress);
79 std::map<const std::string, TNamed *>::const_iterator hiter;
80 for (hiter =
Histo.begin(); hiter !=
Histo.end(); ++hiter)
83 const TNamed *hptr = hiter->second;
86 std::cout <<
PHWHERE <<
" Saving histo "
92 std::string::size_type
pos = hname.find_last_of(
'/');
94 if (pos != std::string::npos)
96 dirname = hname.substr(0, pos);
105 std::cout <<
" Histogram named " << hptr->GetName();
106 std::cout <<
" key " << hname;
109 std::cout <<
" being saved to directory " << dirname;
111 std::cout << std::endl;
117 hfile.cd(dirname.c_str());
122 int byteswritten = hptr->Write();
125 std::cout <<
PHWHERE <<
"Error saving histogram "
133 std::cout <<
PHWHERE <<
"dumpHistos : histogram "
134 << hname <<
" is a null pointer! Won't be saved."
149 std::map<const std::string, TNamed *>::const_iterator histoiter =
Histo.find(hname);
150 if (histoiter !=
Histo.end() && replace == 0)
152 std::cout <<
"Histogram " << hname <<
" already registered, I won't overwrite it" << std::endl;
153 std::cout <<
"Use a different name and try again" << std::endl;
157 std::string::size_type
pos = hname.find_last_of(
'/');
159 if (pos != std::string::npos)
161 histoname = hname.substr(pos + 1);
165 if (histoname != h1d->GetName())
167 std::cout <<
PHWHERE <<
"Histogram " << h1d->GetName()
168 <<
" at " << h1d <<
" renamed to " << histoname << std::endl;
173 h1d->SetName(histoname.c_str());
177 if (h1d->InheritsFrom(
"TTree"))
183 if (h1d->InheritsFrom(
"TH1"))
185 static_cast<TH1 *
>(
h1d)->Sumw2();
193 std::map<const std::string, TNamed *>::const_iterator histoiter =
Histo.find(name);
194 if (histoiter !=
Histo.end())
204 std::map<const std::string, TNamed *>::const_iterator histoiter =
Histo.begin();
208 std::cout <<
"Map contains " << size <<
" Elements" << std::endl;
212 for (
unsigned int i = 0;
i < ihisto;
i++)
216 return histoiter->second;
220 std::cout <<
"Fun4AllHistoManager::getHisto: ERROR Invalid histogram number: "
221 << ihisto <<
", maximum number is " << size << std::endl;
229 std::map<const std::string, TNamed *>::const_iterator histoiter =
Histo.begin();
233 std::cout <<
"Map contains " << size <<
" Elements" << std::endl;
237 for (
unsigned int i = 0;
i < ihisto;
i++)
241 return histoiter->first;
245 std::cout <<
"Fun4AllHistoManager::getHisto: ERROR Invalid histogram number: "
246 << ihisto <<
", maximum number is " << size << std::endl;
254 std::map<const std::string, TNamed *>::const_iterator histoiter =
Histo.find(hname);
255 if (histoiter !=
Histo.end())
257 return histoiter->second;
259 std::cout <<
"Fun4AllHistoManager::getHisto: ERROR Unknown Histogram " << hname
260 <<
", The following are implemented: " << std::endl;
267 if (what ==
"ALL" || what ==
"HISTOS")
270 std::cout <<
"--------------------------------------" << std::endl
272 std::cout <<
"List of Histos in Fun4AllHistoManager "
273 <<
Name() <<
":" << std::endl;
275 std::map<const std::string, TNamed *>::const_iterator hiter;
276 for (hiter =
Histo.begin(); hiter !=
Histo.end(); ++hiter)
278 std::cout << hiter->first <<
" is " << hiter->second << std::endl;
280 std::cout << std::endl;
287 std::map<const std::string, TNamed *>::const_iterator hiter;
288 for (hiter =
Histo.begin(); hiter !=
Histo.end(); ++hiter)
290 TNamed *
h = hiter->second;
291 if (h->InheritsFrom(
"TH1"))
293 (
dynamic_cast<TH1 *
>(
h))->Reset();
295 else if (h->InheritsFrom(
"THnSparse"))
297 (
dynamic_cast<THnSparse *
>(
h))->Reset();