14 #if ROOT_VERSION_CODE >= ROOT_VERSION(5, 20, 0)
15 #define HAS_THNSPARSE 1
16 #include <THnSparse.h>
36 delete Histo.begin()->second;
45 if (!filename.empty())
63 filnam <<
Name() <<
"-"
64 << setfill(
'0') << setw(10)
65 << runnumber <<
".root";
69 cout <<
"Fun4AllHistoManager::dumpHistos() Writing root file: " <<
outfilename << endl;
72 ostringstream creator;
73 creator <<
"Created by " <<
Name();
81 map<const string, TNamed *>::const_iterator hiter;
82 for (hiter =
Histo.begin(); hiter !=
Histo.end(); ++hiter)
84 const std::string &hname = hiter->first;
85 const TNamed *hptr = hiter->second;
88 std::cout <<
PHWHERE <<
" Saving histo "
94 string::size_type
pos = hname.find_last_of(
'/');
96 if (pos != string::npos)
98 dirname = hname.substr(0, pos);
107 cout <<
" Histogram named " << hptr->GetName();
108 cout <<
" key " << hname;
111 cout <<
" being saved to directory " << dirname;
119 hfile.cd(dirname.c_str());
124 int byteswritten = hptr->Write();
127 cout <<
PHWHERE <<
"Error saving histogram "
135 cout <<
PHWHERE <<
"dumpHistos : histogram "
136 << hname <<
" is a null pointer! Won't be saved."
151 map<const string, TNamed *>::const_iterator histoiter =
Histo.find(hname);
152 if (histoiter !=
Histo.end() && replace == 0)
154 cerr <<
"Histogram " << hname <<
" already registered, I won't overwrite it" << endl;
155 cerr <<
"Use a different name and try again" << endl;
159 string::size_type
pos = hname.find_last_of(
'/');
160 string histoname = hname;
161 if (pos != string::npos)
163 histoname = hname.substr(pos + 1);
167 if (histoname != h1d->GetName())
169 cout <<
PHWHERE <<
"Histogram " << h1d->GetName()
170 <<
" at " << h1d <<
" renamed to " << histoname << endl;
175 h1d->SetName(histoname.c_str());
179 if (h1d->InheritsFrom(
"TTree"))
180 static_cast<TTree *>(h1d)->SetDirectory(0);
183 if (h1d->InheritsFrom(
"TH1"))
184 static_cast<TH1 *>(h1d)->Sumw2();
191 map<const string, TNamed *>::const_iterator histoiter =
Histo.find(name);
192 if (histoiter !=
Histo.end())
202 map<const string, TNamed *>::const_iterator histoiter =
Histo.begin();
203 unsigned int size =
Histo.size();
206 cout <<
"Map contains " << size <<
" Elements" << endl;
210 for (
unsigned int i = 0; i < ihisto; i++)
214 return histoiter->second;
218 cout <<
"Fun4AllHistoManager::getHisto: ERROR Invalid histogram number: "
219 << ihisto <<
", maximum number is " << size << endl;
227 map<const string, TNamed *>::const_iterator histoiter =
Histo.begin();
228 unsigned int size =
Histo.size();
231 cout <<
"Map contains " << size <<
" Elements" << endl;
235 for (
unsigned int i = 0; i < ihisto; i++)
239 return histoiter->first;
243 cout <<
"Fun4AllHistoManager::getHisto: ERROR Invalid histogram number: "
244 << ihisto <<
", maximum number is " << size << endl;
252 map<const string, TNamed *>::const_iterator histoiter =
Histo.find(hname);
253 if (histoiter !=
Histo.end())
255 return histoiter->second;
257 cout <<
"Fun4AllHistoManager::getHisto: ERROR Unknown Histogram " << hname
258 <<
", The following are implemented: " << endl;
265 if (what ==
"ALL" || what ==
"HISTOS")
268 cout <<
"--------------------------------------" << endl
270 cout <<
"List of Histos in Fun4AllHistoManager "
271 <<
Name() <<
":" << endl;
273 map<const string, TNamed *>::const_iterator hiter;
274 for (hiter =
Histo.begin(); hiter !=
Histo.end(); ++hiter)
276 cout << hiter->first <<
" is " << hiter->second << endl;
285 map<const string, TNamed *>::const_iterator hiter;
286 for (hiter =
Histo.begin(); hiter !=
Histo.end(); ++hiter)
288 TNamed *
h = hiter->second;
289 if (h->InheritsFrom(
"TH1"))
290 (dynamic_cast<TH1 *>(h))->
Reset();
292 else if (h->InheritsFrom(
"THnSparse"))
293 (dynamic_cast<THnSparse *>(h))->
Reset();