#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 71 of file HistMan/HistMan.cxx. References BaseFolder(), fFolder, fOwn, and mkdir_p(). 00072 {
00073 fFolder = &this->BaseFolder();
00074 fFolder = &mkdir_p(*fFolder,base_directory);
00075 fOwn = false;
00076 fFolder->SetOwner(true);
00077 }
|
|
||||||||||||
|
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 111 of file HistMan/HistMan.cxx. References BaseFolder(), directory_to_folder(), fFolder, fOwn, and mkdir_p(). 00112 {
00113 TDirectory* dir = dynamic_cast<TDirectory*>(file.Get("HistMan"));
00114 if (!dir) {
00115 cerr << "Failed to find HistMan folder in " << file.GetName() << endl;
00116 fFolder = &this->BaseFolder();
00117 fFolder = &mkdir_p(*fFolder,"");
00118 fOwn = false;
00119 fFolder->SetOwner(true);
00120 return;
00121 }
00122
00123 fFolder = directory_to_folder(*dir);
00124 if (attach) {
00125 fOwn = false;
00126 gROOT->Add(fFolder);
00127 }
00128 }
|
|
||||||||||||
|
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 60 of file HistMan/HistMan.cxx. References fFolder, Form(), and histcount. 00061 : fFolder(folder) 00062 , fOwn(own) 00063 { 00064 if (!fFolder) { 00065 fFolder = new TFolder(Form("HistFolder%d",histcount), 00066 Form("Histogram Folder #%d",histcount)); 00067 } 00068 fFolder->SetOwner(true); 00069 }
|
|
||||||||||||
|
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 130 of file HistMan/HistMan.cxx. References Adopt(), BaseFolder(), fFolder, fOwn, Get(), gSystem(), and mkdir_p(). 00131 {
00132 fFolder = &this->BaseFolder();
00133 fFolder = &mkdir_p(*fFolder,"");
00134 fOwn = false;
00135 fFolder->SetOwner(true);
00136 //
00137 for (int ifile=0; file_list[ifile]; ++ifile){
00138 // check first if there the file exists, if not, print out a
00139 // warning message and continue with the other files
00140 if (gSystem->AccessPathName(file_list[ifile])) {
00141 cout << "HistMan: Warning: file " << file_list[ifile]
00142 << " does not exist!" << endl;
00143 continue;
00144 }
00145 TFile file(file_list[ifile]);
00146 if (!file.IsOpen()) {
00147 cout << "HistMan: Warning: problems opening file "
00148 << file_list[ifile] << endl;
00149 continue;
00150 }
00151 HistMan hm(file,false);
00152 for (int ihist=0; hist_list[ihist]; ++ihist){
00153 // Get a pointer to the histogram in the old file
00154 TH1* hold = hm.Get<TH1>(hist_list[ihist]);
00155 if (!hold) {
00156 cout << "HistMan: Warning: histogram named "
00157 << hist_list[ihist] << " does not exist in file "
00158 << file_list[ifile] << endl;
00159 continue;
00160 }
00161
00162 // try to get a pointer to the hitogram in the new
00163 // HistMan. If it exists, add the old histogram to it. I
00164 // it doesn't, adopt the old histo
00165 TH1* hnew = this->Get<TH1>(hist_list[ihist]);
00166 if (hnew)
00167 hnew->Add(hold);
00168 else{
00169 string hname_fullp(hist_list[ihist]);
00170 string::size_type pos = hname_fullp.rfind("/");
00171 string hname_path;
00172 if (pos < hname_fullp.length())
00173 hname_path = hname_fullp.substr(0,pos);
00174 else
00175 hname_path = "";
00176
00177 this->Adopt(hname_path.c_str(),dynamic_cast<TH1*>(hold->Clone()));
00178 }
00179 }
00180 file.Close();
00181 }
00182 }
|
|
|
Destructor deletes folder if owned.
Definition at line 184 of file HistMan/HistMan.cxx. References fFolder. 00185 {
00186 if (fOwn) {
00187 //cerr<< "HistMan::~HistMan: Deleting file\n";
00188 delete fFolder;
00189 }
00190 fFolder = 0;
00191 }
|
|
||||||||||||
|
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 261 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(), TrackRecoPerf::Finish(), ShowerRecoPerf::Finish(), ShowerEnergyPerf::Finish(), HistMan(), TrackRecoPerf::MakeHistos(), ShowerRecoPerf::MakeHistos(), ShowerEnergyPerf::MakeHistos(), ShowerDirectionPerf::MakeHistos(), and THMtest::Test1(). 00262 {
00263 TH1* hist = dynamic_cast<TH1*>(obj);
00264 if (hist)
00265 hist->SetDirectory(0);
00266 TFolder* folder = &mkdir_p(*fFolder,dirpath);
00267 if (folder->FindObject(obj->GetName())) { // FindObject(Object*) not implemented!
00268 cerr << "Object: " << dirpath << "/"
00269 << obj->GetName() << " already exists\n";
00270 delete obj;
00271 return 0;
00272 }
00273 folder->Add(obj);
00274 return obj;
00275 }
|
|
|
Get the base HistMan. It will will create if not yet existing.
Definition at line 193 of file HistMan/HistMan.cxx. Referenced by HistMan(), RegisterWithRoot(), CDFMonitoringModuleImp::Update(), and PlotMan::UpdateCanvases(). 00194 {
00195 TFolder* folder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("HistMan"));
00196 if (folder) return *folder;
00197
00198 folder = new TFolder("HistMan","Base Histogram Manager Folder");
00199 gROOT->Add(folder);
00200 return *folder;
00201 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
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 276 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(). 00277 {
00278 TObject* o = fFolder->FindObject(pathname);
00279 if (!o) o = fFolder->FindObjectAny(pathname);
00280 TH1* h = dynamic_cast<TH1*>(o);
00281 if (!h) {
00282 cerr << "Fill1d(\""<<pathname<<"\") failed lookup\n";
00283 return false;
00284 }
00285 h->Fill(x,w);
00286 return true;
00287 }
|
|
||||||||||||||||||||
|
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 288 of file HistMan/HistMan.cxx. References fFolder. Referenced by NueSensitivity::Ana(), FitGC::DoFit(), ProtonDist::Fill(), and DeltaT::Fill(). 00289 {
00290 TObject* o = fFolder->FindObject(pathname);
00291 if (!o) o = fFolder->FindObjectAny(pathname);
00292 TH2* h = dynamic_cast<TH2*>(o);
00293 if (!h) {
00294 cerr << "Fill2d(\""<<pathname<<"\") failed lookup\n";
00295 return false;
00296 }
00297 h->Fill(x,y,w);
00298 return true;
00299 }
|
|
||||||||||||||||||||
|
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 301 of file HistMan/HistMan.cxx. References fFolder. 00302 {
00303 TObject* o = fFolder->FindObject(pathname);
00304 if (!o) o = fFolder->FindObjectAny(pathname);
00305 TProfile* h = dynamic_cast<TProfile*>(o);
00306 if (!h) {
00307 cerr << "FillProfile(\""<<pathname<<"\") failed lookup\n";
00308 return false;
00309 }
00310 h->Fill(x,y,w);
00311 return true;
00312 }
|
|
||||||||||
|
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 315 of file HistMan/HistMan.cxx. References parse_path(). Referenced by TargetModule::Fill(), and LossModule::Fill(). 00316 {
00317 //cerr << "Getting object at " << pathname << endl;
00318 if (!fFolder) return 0;
00319 vector<string> path = parse_path(pathname);
00320
00321 TFolder* folder = fFolder;
00322
00323 for (size_t ind=0; ind < path.size(); ++ind) {
00324 //cerr << "Checking " << path[ind] << endl;
00325 TObject* o = folder->FindObject(path[ind].c_str());
00326 TFolder* f = dynamic_cast<TFolder*>(o);
00327 if (!f) return o;
00328 folder = f;
00329 }
00330 return 0;
00331 }
|
|
|
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 202 of file HistMan/HistMan.cxx. References base, BaseFolder(), fFolder, and fOwn. 00203 {
00204 if (!fOwn) return;
00205 fOwn = false;
00206
00207 TFolder& base = this->BaseFolder();
00208 base.Add(fFolder);
00209 }
|
|
|
Write out hierachy to recreated file of given name.
Definition at line 253 of file HistMan/HistMan.cxx. References WriteOut(). 00254 {
00255 TFile f(filename,"recreate");
00256 this->WriteOut(f);
00257 f.Close();
00258 }
|
|
|
Write hierachy of histograms to given TFile.
Definition at line 248 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(). 00249 {
00250 if (!fFolder) return;
00251 folder_to_directory(fFolder,file);
00252 }
|
|
|
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