#include <HistMan.h>
Public Member Functions | |
| HistMan (const char *base_directory="") | |
| HistMan (TFile &file, bool attach=true) | |
| HistMan (TFolder *folder, bool own=true) | |
| HistMan (const char **file_list, const char **hist_list) | |
| ~HistMan () | |
| Destructor deletes folder if owned. | |
| TFolder & | BaseFolder () |
| Get the base HistMan. It will will create if not yet existing. | |
| void | RegisterWithRoot () |
| void | WriteOut (TFile &opened_file) |
| Write hierachy of histograms to given TFile. | |
| void | WriteOut (const char *filename) |
| Write out hierachy to recreated file of given name. | |
| TObject * | Adopt (const char *path, TObject *hist) |
| template<class THType> | |
| THType * | Get (const char *pathname) |
| TObject * | GetObject (const char *pathname) |
| Get the object at the given path. | |
| template<class THType> | |
| THType * | Book (const char *name, const char *title, int nbinsx, Axis_t xmin, Axis_t xmax, const char *path=".", Bool_t sumw2=kFALSE) |
| A simplified histogram API is exported with the methods below. | |
| template<class THType> | |
| THType * | Book (const char *name, const char *title, int nbinsx, Axis_t xmin, Axis_t xmax, int nbinsy, Axis_t ymin, Axis_t ymax, const char *path=".", Bool_t sumw2=kFALSE) |
| bool | Fill1d (const char *pathname, Axis_t x, Stat_t w=1.0) |
| bool | Fill2d (const char *pathname, Axis_t x, Axis_t y, Stat_t w=1.0) |
| bool | FillProfile (const char *pathname, Axis_t x, Axis_t y, Stat_t w=1.0) |
Private Attributes | |
| TFolder * | fFolder |
| bool | fOwn |
HistMan is a class that simplifies working with histograms. It provides a simple HBOOK like interface to booking and filling histograms. It also handles organizing them in a hierarchy based on named paths very much like the Unix filesystem. Finally it handles file I/O in a way that preserves this organization.
While in memory, the hierarchy is maintained with TFolders and on disk in TDirectories. The hierarchy can either be owned by the HistMan instance, and thus have the same persistency as the instance itself or it can be owned by ROOT. This latter case is the most useful one as it lets one create and destroy HistMan instance at will while the hierarchy is built up.
Regardless of the memory management, a HistMan instance is logically rooted at some point of the hierarchy. That is, any instance can only know about histograms and sub hierarchies that are on the branch on which the instance sits.
Definition at line 38 of file HistMan/HistMan.h.
|
|
Create a HistMan with a TFolder created in the given base directory. This implies that ownership is given to gROOT's memory. Histograms will be visible in "//root/ROOT memory/HistMan/base_directory/" This is the most typical way to use HistMan. Definition at line 70 of file HistMan/HistMan.cxx. References BaseFolder(), fFolder, fOwn, and mkdir_p(). 00071 {
00072 fFolder = &this->BaseFolder();
00073 fFolder = &mkdir_p(*fFolder,base_directory);
00074 fOwn = false;
00075 fFolder->SetOwner(true);
00076 }
|
|
||||||||||||
|
Create a Histman and try to attach the "HistMan" directory in the given file (such as would exist if the file was created by HistMan::WriteOut()). If fail, will act like Histman("") above. If successfull, the file is still used to store the histograms so must be kept open while they are to be used. If attach is false, the hierarchy is not attached to ROOT Memory. Definition at line 110 of file HistMan/HistMan.cxx. References BaseFolder(), directory_to_folder(), fFolder, fOwn, and mkdir_p(). 00111 {
00112 TDirectory* dir = dynamic_cast<TDirectory*>(file.Get("HistMan"));
00113 if (!dir) {
00114 cerr << "Failed to find HistMan folder in " << file.GetName() << endl;
00115 fFolder = &this->BaseFolder();
00116 fFolder = &mkdir_p(*fFolder,"");
00117 fOwn = false;
00118 fFolder->SetOwner(true);
00119 return;
00120 }
00121
00122 fFolder = directory_to_folder(*dir);
00123 if (attach) {
00124 fOwn = false;
00125 gROOT->Add(fFolder);
00126 }
00127 }
|
|
||||||||||||
|
Create a HistMan. If "own" is true the folder is deleted along with this object. This will root the hierarchy in a uniquely named root folder (like HistFolderXXX). Definition at line 59 of file HistMan/HistMan.cxx. References fFolder, Form(), and histcount. 00060 : fFolder(folder) 00061 , fOwn(own) 00062 { 00063 if (!fFolder) { 00064 fFolder = new TFolder(Form("HistFolder%d",histcount), 00065 Form("Histogram Folder #%d",histcount)); 00066 } 00067 fFolder->SetOwner(true); 00068 }
|
|
||||||||||||
|
Create a HistMan and add a list of histograms from a list of files that have a "HistMan" directory. If the file does not exist, it will print out a warning and ignore this file. If the histogram does not exist in the file, it will do the same. Both the list of files and histograms should end with a 0, e.g. const char* file_list[] = {"file1","file2",0}; Definition at line 129 of file HistMan/HistMan.cxx. References Adopt(), BaseFolder(), fFolder, fOwn, Get(), gSystem(), and mkdir_p(). 00130 {
00131 fFolder = &this->BaseFolder();
00132 fFolder = &mkdir_p(*fFolder,"");
00133 fOwn = false;
00134 fFolder->SetOwner(true);
00135 //
00136 for (int ifile=0; file_list[ifile]; ++ifile){
00137 // check first if there the file exists, if not, print out a
00138 // warning message and continue with the other files
00139 if (gSystem->AccessPathName(file_list[ifile])) {
00140 cout << "HistMan: Warning: file " << file_list[ifile]
00141 << " does not exist!" << endl;
00142 continue;
00143 }
00144 TFile file(file_list[ifile]);
00145 if (!file.IsOpen()) {
00146 cout << "HistMan: Warning: problems opening file "
00147 << file_list[ifile] << endl;
00148 continue;
00149 }
00150 HistMan hm(file,false);
00151 for (int ihist=0; hist_list[ihist]; ++ihist){
00152 // Get a pointer to the histogram in the old file
00153 TH1* hold = hm.Get<TH1>(hist_list[ihist]);
00154 if (!hold) {
00155 cout << "HistMan: Warning: histogram named "
00156 << hist_list[ihist] << " does not exist in file "
00157 << file_list[ifile] << endl;
00158 continue;
00159 }
00160
00161 // try to get a pointer to the hitogram in the new
00162 // HistMan. If it exists, add the old histogram to it. I
00163 // it doesn't, adopt the old histo
00164 TH1* hnew = this->Get<TH1>(hist_list[ihist]);
00165 if (hnew)
00166 hnew->Add(hold);
00167 else{
00168 string hname_fullp(hist_list[ihist]);
00169 string::size_type pos = hname_fullp.rfind("/");
00170 string hname_path;
00171 if (pos < hname_fullp.length())
00172 hname_path = hname_fullp.substr(0,pos);
00173 else
00174 hname_path = "";
00175
00176 this->Adopt(hname_path.c_str(),dynamic_cast<TH1*>(hold->Clone()));
00177 }
00178 }
00179 file.Close();
00180 }
00181 }
|
|
|
Destructor deletes folder if owned.
Definition at line 183 of file HistMan/HistMan.cxx. References fFolder. 00184 {
00185 if (fOwn) {
00186 //cerr<< "HistMan::~HistMan: Deleting file\n";
00187 delete fFolder;
00188 }
00189 fFolder = 0;
00190 }
|
|
||||||||||||
|
Adopt an already created histogram (or really any TObject), return NULL (and delete hist) if a histogram with same name as "hist" at path already exists, otherwise return the object. An empty or NULL string can be passed for the path to place the object in HistMan instance's top level folder. Definition at line 260 of file HistMan/HistMan.cxx. References fFolder, and mkdir_p(). Referenced by NueSensitivity::Analysis(), TempModule::BeginJob(), TargetModule::BeginJob(), NpotModule::BeginJob(), LossModule::BeginJob(), HornModule::BeginJob(), HadMuMonModule::BeginJob(), Npot::Book(), HistMan(), and THMtest::Test1(). 00261 {
00262 TH1* hist = dynamic_cast<TH1*>(obj);
00263 if (hist)
00264 hist->SetDirectory(0);
00265 TFolder* folder = &mkdir_p(*fFolder,dirpath);
00266 if (folder->FindObject(obj->GetName())) { // FindObject(Object*) not implemented!
00267 cerr << "Object: " << dirpath << "/"
00268 << obj->GetName() << " already exists\n";
00269 delete obj;
00270 return 0;
00271 }
00272 folder->Add(obj);
00273 return obj;
00274 }
|
|
|
Get the base HistMan. It will will create if not yet existing.
Definition at line 192 of file HistMan/HistMan.cxx. Referenced by HistMan(), RegisterWithRoot(), UtilHist::ScaleHists(), CDFMonitoringModuleImp::Update(), and PlotMan::UpdateCanvases(). 00193 {
00194 TFolder* folder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("HistMan"));
00195 if (folder) return *folder;
00196
00197 folder = new TFolder("HistMan","Base Histogram Manager Folder");
00198 gROOT->Add(folder);
00199 return *folder;
00200 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Book 2D histograms of type THType. Return pointer to created histogram (HistMan retains ownership) or 0 if "path/name" conflicts with previously existing histogram. Definition at line 132 of file HistMan/HistMan.h. 00135 {
00136 THType* h = new THType(name,title,nbinsx,xmin,xmax, nbinsy,ymin,ymax);
00137 if ( sumw2 ) {
00138 h->Sumw2();
00139 }
00140 TObject* o = Adopt(path, h);
00141 return dynamic_cast<THType*>(o);
00142 }
|
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||
|
Lookup a 1D histogram by pathname="path/name" and Fill() it. If lookup or any casting fails, false is returned and an error message is printed at Msg level Warning. Definition at line 275 of file HistMan/HistMan.cxx. References fFolder. Referenced by NueReadwPID::Ana(), NueReadTJPID::Ana(), CompareMST::Ana(), BDataQualityModule::Ana(), BDAnaModule::Ana(), BDCheckDB::CheckSpill(), FitGC::DoFit(), ProtonDist::Fill(), fill(), MaxDaeDt::Fill(), DeltaT::Fill(), BDataQualityModule::FillFile(), CompareMD::FillFromList(), FitGC::GetSiglin(), horn_off(), THMtest::Test1(), THMtest::Test2(), and tortgt_ok(). 00276 {
00277 TObject* o = fFolder->FindObject(pathname);
00278 if (!o) o = fFolder->FindObjectAny(pathname);
00279 TH1* h = dynamic_cast<TH1*>(o);
00280 if (!h) {
00281 cerr << "Fill1d(\""<<pathname<<"\") failed lookup\n";
00282 return false;
00283 }
00284 h->Fill(x,w);
00285 return true;
00286 }
|
|
||||||||||||||||||||
|
Lookup a 2D histogram by pathname="path/name" and Fill() it. If lookup or any casting fails, false is returned and an error message is printed at Msg level Warning. Definition at line 287 of file HistMan/HistMan.cxx. References fFolder. Referenced by NueSensitivity::Ana(), FitGC::DoFit(), ProtonDist::Fill(), and DeltaT::Fill(). 00288 {
00289 TObject* o = fFolder->FindObject(pathname);
00290 if (!o) o = fFolder->FindObjectAny(pathname);
00291 TH2* h = dynamic_cast<TH2*>(o);
00292 if (!h) {
00293 cerr << "Fill2d(\""<<pathname<<"\") failed lookup\n";
00294 return false;
00295 }
00296 h->Fill(x,y,w);
00297 return true;
00298 }
|
|
||||||||||||||||||||
|
Lookup a profile histogram by pathname="path/name" and Fill() it. If lookup or any casting fails, false is returned and an error message is printed at Msg level Warning. Definition at line 300 of file HistMan/HistMan.cxx. References fFolder. 00301 {
00302 TObject* o = fFolder->FindObject(pathname);
00303 if (!o) o = fFolder->FindObjectAny(pathname);
00304 TProfile* h = dynamic_cast<TProfile*>(o);
00305 if (!h) {
00306 cerr << "FillProfile(\""<<pathname<<"\") failed lookup\n";
00307 return false;
00308 }
00309 h->Fill(x,y,w);
00310 return true;
00311 }
|
|
||||||||||
|
Try to find histogram of with pathname="path/name" in this instances branch of the hierarchy. Path is relative to this objects TFolder. Returns NULL if histogram does not exist or if there is a type mismatch. Definition at line 103 of file HistMan/HistMan.h. Referenced by BDAnaModule::Ana(), NueSensitivity::Analysis(), BDataQualityModule::BeginFile(), FitGC::DoFit(), BDataQualityModule::EndFile(), Npot::Fill(), BDataQualityModule::FillFile(), ValVtxModule::FillPlots(), folder_to_directory(), Pedestals::GeneratePeds(), FitGC::GetSiglin(), HistMan(), DevCount::Init(), TorCheck::Init(), DbCheck::Init(), PerTime::Init(), Earliest::Init(), make_prints(), FitGC::OpenFile(), pedmaker(), FitGC::PlotPL(), THMtest::Test1(), THMtest::Test1_1(), THMtest::Test2(), THMtest::Test3(), and FitGC::WriteDB(). 00103 {
00104 return dynamic_cast<THType*>(this->GetObject(pathname));
00105 }
|
|
|
Get the object at the given path.
Definition at line 314 of file HistMan/HistMan.cxx. References parse_path(). Referenced by TargetModule::Fill(), and LossModule::Fill(). 00315 {
00316 //cerr << "Getting object at " << pathname << endl;
00317 if (!fFolder) return 0;
00318 vector<string> path = parse_path(pathname);
00319
00320 TFolder* folder = fFolder;
00321
00322 for (size_t ind=0; ind < path.size(); ++ind) {
00323 //cerr << "Checking " << path[ind] << endl;
00324 TObject* o = folder->FindObject(path[ind].c_str());
00325 TFolder* f = dynamic_cast<TFolder*>(o);
00326 if (!f) return o;
00327 folder = f;
00328 }
00329 return 0;
00330 }
|
|
|
Register the base folder with gROOT, gives up ownership and folder becomes visible in //root/ROOT Memory/HistMan in a TBrowser. This is only needed if the instance is created with HistMan(TFolder*,bool). Definition at line 201 of file HistMan/HistMan.cxx. References base, BaseFolder(), fFolder, and fOwn. 00202 {
00203 if (!fOwn) return;
00204 fOwn = false;
00205
00206 TFolder& base = this->BaseFolder();
00207 base.Add(fFolder);
00208 }
|
|
|
Write out hierachy to recreated file of given name.
Definition at line 252 of file HistMan/HistMan.cxx. References WriteOut(). 00253 {
00254 TFile f(filename,"recreate");
00255 this->WriteOut(f);
00256 f.Close();
00257 }
|
|
|
Write hierachy of histograms to given TFile.
Definition at line 247 of file HistMan/HistMan.cxx. References fFolder, and folder_to_directory(). Referenced by BDLivePlot::BDLivePlot(), HistManModule::EndFile(), ValVtxModule::EndJob(), NueSensitivity::EndJob(), HistManModule::EndJob(), CompareAll::EndJob(), BDAnaModule::EndJob(), pedmaker(), StndBmsSpin::Scan(), STND_BMS::Scan(), BMS_STND::Scan(), THMtest::Test2(), write_plots(), FitGC::writehm(), PlotterManager::WriteOut(), PlotMan::WriteOut(), PedStudy::WriteOut(), WriteOut(), and BDCheckDB::~BDCheckDB(). 00248 {
00249 if (!fFolder) return;
00250 folder_to_directory(fFolder,file);
00251 }
|
|
|
Definition at line 39 of file HistMan/HistMan.h. Referenced by Adopt(), Fill1d(), Fill2d(), FillProfile(), HistMan(), RegisterWithRoot(), WriteOut(), and ~HistMan(). |
|
|
Definition at line 40 of file HistMan/HistMan.h. Referenced by HistMan(), and RegisterWithRoot(). |
1.3.9.1