#include <HistMan.h>
Public Types | |
| typedef std::map< std::string, HistInfo > | InfoMap |
| typedef InfoMap::const_iterator | InfoIter |
| typedef std::map< std::string, InfoMap > | DirMap |
| typedef DirMap::const_iterator | DirIter |
Public Member Functions | |
| bool | ReadFile (const std::string file) |
| bool | KeyExists (int key, const std::string &dir=".") const |
| bool | KeyExists (const std::string &key, const std::string &dir=".") const |
| unsigned int | NMiss () const |
| const Hist1d< double > | CreateHist1d (int key, const std::string &dir=".") |
| const Hist1d< double > | CreateHist1d (const std::string &key, const std::string &dir=".") |
| TH1 * | CreateTH1 (int key, const std::string &dir=".") |
| TH2 * | CreateTH2 (int key, const std::string &dir=".") |
| TH1 * | CreateTH1 (const std::string &key, const std::string &dir=".") |
| TH2 * | CreateTH2 (const std::string &key, const std::string &dir=".") |
| TH2 * | GetTH2 (int xkey, int ykey, const std::string &dir=".") |
| TH2 * | GetTH2 (const std::string &xkey, const std::string &ykey, const std::string &dir=".") |
| void | Print (std::ostream &o=std::cout) const |
Static Public Member Functions | |
| HistMan & | Instance () |
Private Member Functions | |
| HistMan () | |
| ~HistMan () | |
| HistMan (const HistMan &) | |
| const HistMan & | operator= (const HistMan &) |
| const Hist1d< double > | CreateHist1d (const HistInfo &info) |
| TH1 * | CreateTH1 (const HistInfo &info, const std::string &opt="double") |
| TH2 * | CreateTH2 (const HistInfo &info, const std::string &opt="float") |
| bool | ReadHistogramBlock (TiXmlElement &hist) |
| bool | ReadHistogram (const TiXmlElement &hist, HistInfo &info) |
| bool | ReadAxis (const TiXmlElement &hist, AxisInfo &info) |
| const std::vector< int > | GetIntVec (const std::string &list) const |
| const std::vector< std::string > | GetStringVec (const std::string &list) const |
| const std::string | Convert (int key, int width=0) const |
| unsigned short | ComputeWidth (int key) const |
Private Attributes | |
| unsigned int | fNMiss |
| unsigned short | fKeyWidth |
| DirMap | fDirMap |
Static Private Attributes | |
| HistMan * | fgInstance = 0 |
| do not stream | |
| Mutex | fMutex |
| do not stream | |
|
|
Definition at line 95 of file PhysicsNtuple/Hist/HistMan.h. Referenced by CreateHist1d(), CreateTH1(), CreateTH2(), GetTH2(), KeyExists(), and Print(). |
|
|
Definition at line 94 of file PhysicsNtuple/Hist/HistMan.h. |
|
|
Definition at line 93 of file PhysicsNtuple/Hist/HistMan.h. Referenced by CreateHist1d(), CreateTH1(), CreateTH2(), GetTH2(), and Print(). |
|
|
Definition at line 92 of file PhysicsNtuple/Hist/HistMan.h. Referenced by CreateHist1d(), CreateTH1(), CreateTH2(), GetTH2(), KeyExists(), Print(), and ReadHistogramBlock(). |
|
|
Definition at line 56 of file PhysicsNtuple/Hist/HistMan.cxx.
|
|
|
Definition at line 63 of file PhysicsNtuple/Hist/HistMan.cxx. 00064 {
00065 }
|
|
|
|
|
|
Definition at line 865 of file PhysicsNtuple/Hist/HistMan.cxx. Referenced by Convert(), and ReadHistogramBlock(). 00866 {
00867 //
00868 // Compute key width
00869 //
00870 return static_cast<unsigned int>(std::floor(std::log10(double(std::abs(key) + 1)))) + 1;
00871 }
|
|
||||||||||||
|
Definition at line 849 of file PhysicsNtuple/Hist/HistMan.cxx. References ComputeWidth(). Referenced by CreateTH1(), CreateTH2(), and GetTH2(). 00850 {
00851 stringstream strkey;
00852 if(width == 0)
00853 {
00854 strkey << setw(ComputeWidth(key)) << key;
00855 }
00856 else
00857 {
00858 strkey << setfill('0') << setw(width) << key;
00859 }
00860
00861 return strkey.str();
00862 }
|
|
|
Definition at line 643 of file PhysicsNtuple/Hist/HistMan.cxx. References Anp::AxisInfo::GetBins(), Anp::AxisInfo::GetMax(), Anp::AxisInfo::GetMin(), Anp::AxisInfo::GetNbins(), and Anp::HistInfo::GetXaxis(). 00644 {
00645 const AxisInfo &xaxis = info.GetXaxis();
00646
00647 if(!xaxis.GetBins().empty())
00648 {
00649 return Hist1d<double>(xaxis.GetBins());
00650 }
00651
00652 return Hist1d<double>(xaxis.GetNbins(), xaxis.GetMin(), xaxis.GetMax());
00653 }
|
|
||||||||||||
|
Definition at line 466 of file PhysicsNtuple/Hist/HistMan.cxx. References DirIter, fDirMap, fMutex, InfoIter, and InfoMap. 00467 {
00468 Anp::Lock<Mutex> lock(fMutex);
00469
00470 DirIter dit = fDirMap.find(dir);
00471 if(dit == fDirMap.end())
00472 {
00473 ++fNMiss;
00474 return Hist1d<double>(0, 0.0, 0.0);
00475 }
00476
00477 const InfoMap &imap = dit -> second;
00478
00479 InfoIter hit = imap.find(key);
00480 if(hit == imap.end())
00481 {
00482 ++fNMiss;
00483 return Hist1d<double>(0, 0.0, 0.0);
00484 }
00485
00486 return HistMan::CreateHist1d(hit -> second);
00487 }
|
|
||||||||||||
|
Definition at line 460 of file PhysicsNtuple/Hist/HistMan.cxx. 00461 {
00462 return HistMan::CreateHist1d(HistMan::Convert(key), dir);
00463 }
|
|
||||||||||||
|
Definition at line 656 of file PhysicsNtuple/Hist/HistMan.cxx. References Convert(), fKeyWidth, Anp::AxisInfo::GetBins(), Anp::HistInfo::GetKey(), Anp::AxisInfo::GetMax(), Anp::AxisInfo::GetMin(), Anp::HistInfo::GetName(), Anp::AxisInfo::GetNbins(), Anp::AxisInfo::GetTitle(), Anp::HistInfo::GetTitle(), Anp::HistInfo::GetXaxis(), Anp::HistInfo::GetYaxis(), and Anp::SetDir(). 00657 {
00658 string strkey = info.GetKey();
00659 string name = info.GetName();
00660 string title = info.GetTitle();
00661
00662 const int intkey = std::atoi(strkey.c_str());
00663 if(intkey != 0)
00664 {
00665 strkey = "key_" + Convert(intkey, fKeyWidth);
00666 }
00667 if(name.empty())
00668 {
00669 name = strkey;
00670 }
00671 if(title.empty())
00672 {
00673 title = info.GetName();
00674 }
00675
00676 const AxisInfo &xaxis = info.GetXaxis();
00677 const AxisInfo &yaxis = info.GetYaxis();
00678
00679 TH1 *h = 0;
00680 if(xaxis.GetBins().empty())
00681 {
00682 Anp::Lock<Anp::Mutex> lock(Anp::GetROOTMutex());
00683
00684 if(opt.find("profile") != string::npos)
00685 {
00686 h = new TProfile(name.c_str(), title.c_str(),
00687 xaxis.GetNbins(), xaxis.GetMin(), xaxis.GetMax());
00688 }
00689 else if(opt.find("float") != string::npos)
00690 {
00691 h = new TH1F(name.c_str(), title.c_str(),
00692 xaxis.GetNbins(), xaxis.GetMin(), xaxis.GetMax());
00693 }
00694 else
00695 {
00696 h = new TH1D(name.c_str(), title.c_str(),
00697 xaxis.GetNbins(), xaxis.GetMin(), xaxis.GetMax());
00698 }
00699 }
00700 else
00701 {
00702 Anp::Lock<Anp::Mutex> lock(Anp::GetROOTMutex());
00703
00704 const vector<double> &bvec = xaxis.GetBins();
00705
00706 double *darray = new double[bvec.size()];
00707
00708 for(unsigned int ibin = 0; ibin < bvec.size(); ++ibin)
00709 {
00710 darray[ibin] = bvec[ibin];
00711 }
00712
00713 if(opt.find("profile") != string::npos)
00714 {
00715 h = new TProfile(name.c_str(), title.c_str(), bvec.size() - 1, darray);
00716 }
00717 else if(opt.find("float") != string::npos)
00718 {
00719 h = new TH1F(name.c_str(), title.c_str(), bvec.size() - 1, darray);
00720 }
00721 else
00722 {
00723 h = new TH1D(name.c_str(), title.c_str(), bvec.size() - 1, darray);
00724 }
00725
00726 delete [] darray;
00727 }
00728
00729 //
00730 // Set NULL TDirectory
00731 //
00732 Anp::SetDir(h, 0);
00733
00734 if(xaxis.GetTitle().size() > 0)
00735 {
00736 h -> GetXaxis() -> SetTitle(xaxis.GetTitle().c_str());
00737 h -> GetXaxis() -> CenterTitle();
00738 }
00739 if(yaxis.GetTitle().size() > 0)
00740 {
00741 h -> GetYaxis() -> SetTitle(yaxis.GetTitle().c_str());
00742 h -> GetYaxis() -> CenterTitle();
00743 }
00744
00745 return h;
00746 }
|
|
||||||||||||
|
Definition at line 496 of file PhysicsNtuple/Hist/HistMan.cxx. References Anp::CreateTH1(), DirIter, fDirMap, fMutex, InfoIter, and InfoMap. 00497 {
00498 Anp::Lock<Mutex> lock(fMutex);
00499
00500 //
00501 // Extract option
00502 //
00503 string opt;
00504 string dir = dir_;
00505 if (dir.find("profile") != string::npos) opt += "profile";
00506 else if(dir.find("float") != string::npos) opt += "float";
00507
00508 if(!opt.empty() && dir.find(opt.c_str()) != string::npos)
00509 {
00510 dir.erase(dir.find(opt.c_str()), opt.size());
00511 }
00512
00513 if(dir.empty())
00514 {
00515 dir = ".";
00516 }
00517
00518 DirIter dit = fDirMap.find(dir);
00519 if(dit == fDirMap.end())
00520 {
00521 ++fNMiss;
00522 return 0;
00523 }
00524
00525 const InfoMap &imap = dit -> second;
00526
00527 InfoIter hit = imap.find(key);
00528 if(hit == imap.end())
00529 {
00530 ++fNMiss;
00531 return 0;
00532 }
00533
00534 return HistMan::CreateTH1(hit -> second, opt);
00535 }
|
|
||||||||||||
|
Definition at line 490 of file PhysicsNtuple/Hist/HistMan.cxx. References Anp::CreateTH1(). Referenced by Anp::MakeTH1(). 00491 {
00492 return HistMan::CreateTH1(HistMan::Convert(key), dir);
00493 }
|
|
||||||||||||
|
Definition at line 749 of file PhysicsNtuple/Hist/HistMan.cxx. References Convert(), fKeyWidth, Anp::HistInfo::GetKey(), Anp::AxisInfo::GetMax(), Anp::AxisInfo::GetMin(), Anp::HistInfo::GetName(), Anp::AxisInfo::GetNbins(), Anp::AxisInfo::GetTitle(), Anp::HistInfo::GetTitle(), Anp::HistInfo::GetXaxis(), Anp::HistInfo::GetYaxis(), and Anp::SetDir(). 00750 {
00751 string strkey = info.GetKey();
00752 string name = info.GetName();
00753 string title = info.GetTitle();
00754
00755 const int intkey = std::atoi(strkey.c_str());
00756 if(intkey != 0)
00757 {
00758 strkey = Convert(intkey, fKeyWidth);
00759 }
00760 if(name.empty())
00761 {
00762 name = strkey;
00763 }
00764 if(title.empty())
00765 {
00766 title = info.GetName();
00767 }
00768
00769 const AxisInfo &xaxis = info.GetXaxis();
00770 const AxisInfo &yaxis = info.GetYaxis();
00771
00772 TH2 *h = 0;
00773 if(!name.empty())
00774 {
00775 Anp::Lock<Anp::Mutex> lock(Anp::GetROOTMutex());
00776
00777 if(opt.find("double") != string::npos)
00778 {
00779 h = new TH2D(name.c_str(), title.c_str(),
00780 xaxis.GetNbins(), xaxis.GetMin(), xaxis.GetMax(),
00781 yaxis.GetNbins(), yaxis.GetMin(), yaxis.GetMax());
00782
00783 }
00784 else
00785 {
00786 h = new TH2F(name.c_str(), title.c_str(),
00787 xaxis.GetNbins(), xaxis.GetMin(), xaxis.GetMax(),
00788 yaxis.GetNbins(), yaxis.GetMin(), yaxis.GetMax());
00789 }
00790
00791 if(xaxis.GetTitle().size() > 0)
00792 {
00793 h -> GetXaxis() -> SetTitle(xaxis.GetTitle().c_str());
00794 h -> GetXaxis() -> CenterTitle();
00795 }
00796 if(yaxis.GetTitle().size() > 0)
00797 {
00798 h -> GetYaxis() -> SetTitle(yaxis.GetTitle().c_str());
00799 h -> GetYaxis() -> CenterTitle();
00800 }
00801 }
00802
00803 //
00804 // Set NULL TDirectory
00805 //
00806 Anp::SetDir(h, 0);
00807
00808 return h;
00809 }
|
|
||||||||||||
|
Definition at line 544 of file PhysicsNtuple/Hist/HistMan.cxx. References Anp::Draw::CreateTH2(), DirIter, fDirMap, fMutex, InfoIter, and InfoMap. 00545 {
00546 Anp::Lock<Mutex> lock(fMutex);
00547
00548 //
00549 // Extract option
00550 //
00551 string opt;
00552 string dir = dir_;
00553 if (dir.find("double") != string::npos) opt += "double";
00554
00555 if(!opt.empty() && dir.find(opt.c_str()) != string::npos)
00556 {
00557 dir.erase(dir.find(opt.c_str()), opt.size());
00558 }
00559
00560 if(dir.empty())
00561 {
00562 dir = ".";
00563 }
00564
00565
00566 DirIter dit = fDirMap.find(dir);
00567 if(dit == fDirMap.end())
00568 {
00569 ++fNMiss;
00570 return 0;
00571 }
00572
00573 const InfoMap &imap = dit -> second;
00574
00575 InfoIter hit = imap.find(key);
00576 if(hit == imap.end())
00577 {
00578 ++fNMiss;
00579 return 0;
00580 }
00581
00582 return HistMan::CreateTH2(hit -> second, opt);
00583 }
|
|
||||||||||||
|
Definition at line 538 of file PhysicsNtuple/Hist/HistMan.cxx. References Convert(), and Anp::Draw::CreateTH2(). Referenced by Anp::MakeTH2(). 00539 {
00540 return HistMan::CreateTH2(Convert(key), dir);
00541 }
|
|
|
Definition at line 812 of file PhysicsNtuple/Hist/HistMan.cxx. References UtilString::StringTok(). Referenced by ReadHistogramBlock(). 00813 {
00814 vector<string> namelist;
00815 UtilString::StringTok(namelist, list, ", ");
00816
00817 vector<int> ivec;
00818 for(vector<string>::const_iterator sit = namelist.begin(); sit != namelist.end(); ++sit)
00819 {
00820 const int newbase = std::atoi(sit -> c_str());
00821 if(newbase != 0)
00822 {
00823 ivec.push_back(newbase);
00824 }
00825 }
00826
00827 return ivec;
00828 }
|
|
|
Definition at line 831 of file PhysicsNtuple/Hist/HistMan.cxx. References UtilString::StringTok(). Referenced by ReadHistogramBlock(). 00832 {
00833 vector<string> namelist;
00834 UtilString::StringTok(namelist, list, ", ");
00835
00836 vector<string> nvec;
00837 for(vector<string>::const_iterator sit = namelist.begin(); sit != namelist.end(); ++sit)
00838 {
00839 if(!sit -> empty())
00840 {
00841 nvec.push_back(*sit);
00842 }
00843 }
00844
00845 return nvec;
00846 }
|
|
||||||||||||||||
|
Definition at line 592 of file PhysicsNtuple/Hist/HistMan.cxx. References Anp::Draw::CreateTH2(), DirIter, fDirMap, Anp::HistInfo::fKey, fMutex, Anp::HistInfo::fName, Anp::HistInfo::fTitle, Anp::HistInfo::fXaxis, Anp::HistInfo::fYaxis, Anp::HistInfo::GetKey(), Anp::HistInfo::GetXaxis(), Anp::HistInfo::GetYaxis(), InfoIter, InfoMap, and Anp::AxisInfo::Valid(). 00593 {
00594 Anp::Lock<Mutex> lock(fMutex);
00595
00596 DirIter dit = fDirMap.find(dir);
00597 if(dit == fDirMap.end())
00598 {
00599 ++fNMiss;
00600 return 0;
00601 }
00602
00603 const InfoMap &imap = dit -> second;
00604
00605 InfoIter xhit = imap.find(xkey);
00606 if(xhit == imap.end())
00607 {
00608 ++fNMiss;
00609 return 0;
00610 }
00611
00612 InfoIter yhit = imap.find(ykey);
00613 if(yhit == imap.end())
00614 {
00615 ++fNMiss;
00616 return 0;
00617 }
00618
00619 const HistInfo &xinfo = xhit -> second;
00620 const HistInfo &yinfo = yhit -> second;
00621
00622 HistInfo info;
00623
00624 info.fKey = "keys_" + xinfo.GetKey() + "_and_" + yinfo.GetKey();
00625 info.fXaxis = xinfo.GetXaxis();
00626 info.fYaxis = yinfo.GetXaxis();
00627 info.fName = info.GetKey();
00628 info.fTitle = info.GetKey();
00629
00630 if(xinfo.GetYaxis().Valid())
00631 {
00632 info.fXaxis = xinfo.GetYaxis();
00633 }
00634 if(yinfo.GetYaxis().Valid())
00635 {
00636 info.fYaxis = yinfo.GetYaxis();
00637 }
00638
00639 return HistMan::CreateTH2(info);
00640 }
|
|
||||||||||||||||
|
Definition at line 586 of file PhysicsNtuple/Hist/HistMan.cxx. References Convert(). 00587 {
00588 return HistMan::GetTH2(Convert(xkey), HistMan::Convert(ykey), dir);
00589 }
|
|
|
Definition at line 38 of file PhysicsNtuple/Hist/HistMan.cxx. References fgInstance, and fMutex. Referenced by Anp::MakeTH1(), and Anp::MakeTH2(). 00039 {
00040 if(!fgInstance)
00041 {
00042 Anp::Lock<Mutex> lock(fMutex);
00043
00044 if(!fgInstance)
00045 {
00046 fgInstance = new Anp::HistMan();
00047 }
00048 }
00049
00050 return *fgInstance;
00051 }
|
|
||||||||||||
|
Definition at line 444 of file PhysicsNtuple/Hist/HistMan.cxx. References DirIter, fDirMap, fMutex, and InfoMap. 00445 {
00446 Anp::Lock<Mutex> lock(fMutex);
00447
00448 DirIter dit = fDirMap.find(dir);
00449 if(dit == fDirMap.end())
00450 {
00451 return false;
00452 }
00453
00454 const InfoMap &imap = dit -> second;
00455
00456 return (imap.find(key) != imap.end());
00457 }
|
|
||||||||||||
|
Definition at line 438 of file PhysicsNtuple/Hist/HistMan.cxx. 00439 {
00440 return HistMan::KeyExists(HistMan::Convert(key), dir);
00441 }
|
|
|
Definition at line 874 of file PhysicsNtuple/Hist/HistMan.cxx. References fMutex. 00875 {
00876 Anp::Lock<Mutex> lock(fMutex);
00877 return fNMiss;
00878 }
|
|
|
|
|
|
Definition at line 881 of file PhysicsNtuple/Hist/HistMan.cxx. References DirIter, fDirMap, InfoIter, InfoMap, and Anp::AxisInfo::Print(). 00882 {
00883 o << "HistMan::Print" << endl;
00884 for(DirIter dit = fDirMap.begin(); dit != fDirMap.end(); ++dit)
00885 {
00886 o << "Directory = " << dit -> first << endl;
00887 const InfoMap &imap = dit -> second;
00888
00889 for(InfoIter it = imap.begin(); it != imap.end(); ++it)
00890 {
00891 it -> second.Print(o);
00892 }
00893 }
00894 }
|
|
||||||||||||
|
Definition at line 373 of file PhysicsNtuple/Hist/HistMan.cxx. References TiXmlElement::Attribute(), Anp::AxisInfo::fBins, Anp::AxisInfo::fMax, Anp::AxisInfo::fMin, Anp::AxisInfo::fNbins, Anp::AxisInfo::fTitle, Anp::AxisInfo::fValid, max, min, TiXmlElement::QueryFloatAttribute(), TiXmlElement::QueryIntAttribute(), UtilString::StringTok(), and TIXML_SUCCESS. Referenced by ReadHistogram(). 00374 {
00375 bool read_bin = false, read_bins = false;
00376
00377 int bin = 0;
00378 float min = 0.0, max = 0.0;
00379
00380 if(axis.QueryIntAttribute("bin", &bin) == TIXML_SUCCESS &&
00381 axis.QueryFloatAttribute("min", &min) == TIXML_SUCCESS &&
00382 axis.QueryFloatAttribute("max", &max) == TIXML_SUCCESS)
00383 {
00384 read_bin = true;
00385 }
00386
00387 const char *xtitle = axis.Attribute("title");
00388 if(xtitle)
00389 {
00390 info.fTitle = xtitle;
00391 }
00392
00393 vector<double> bvec;
00394
00395 const char *bins = axis.Attribute("bins");
00396 if(bins)
00397 {
00398 vector<string> datavec;
00399 UtilString::StringTok(datavec, bins, ", ");
00400
00401 for(vector<string>::const_iterator sit = datavec.begin(); sit != datavec.end(); ++sit)
00402 {
00403 if(sit -> size() > 0)
00404 {
00405 bvec.push_back(std::atof(sit -> c_str()));
00406 }
00407 }
00408
00409 std::sort(bvec.begin(), bvec.end());
00410
00411 //for(unsigned int i = 0; i < bvec.size(); ++i)
00412 //{
00413 //cout << "bin = " << i << " edge = " << bvec[i] << endl;
00414 //}
00415
00416 if(!bvec.empty())
00417 {
00418 read_bins = true;
00419 }
00420 }
00421
00422 if(read_bin)
00423 {
00424 info.fNbins = bin;
00425 info.fMin = min;
00426 info.fMax = max;
00427 info.fValid = true;
00428 }
00429 else if(read_bins)
00430 {
00431 info.fBins = bvec;
00432 }
00433
00434 return true;
00435 }
|
|
|
Definition at line 68 of file PhysicsNtuple/Hist/HistMan.cxx. References doc, fMutex, and ReadHistogramBlock(). 00069 {
00070 //
00071 // Parse xml file with histogram definitions. These are top level keys
00072 // which must be located within "histograms" object:
00073 // keybase - creates multiple keys for one histogram
00074 // dirbase - stores keys in "sub-directory"
00075 // h1d - histogram definition
00076 //
00077 Anp::Lock<Mutex> lock(fMutex);
00078
00079 TiXmlDocument doc(file.c_str());
00080 const bool loadok = doc.LoadFile();
00081 if(!loadok)
00082 {
00083 cerr << "HistMan::ReadFile - failed to load: " << file << endl;
00084 return false;
00085 }
00086
00087 for(TiXmlNode *pChild = doc.FirstChild(); pChild != 0; pChild = pChild -> NextSibling())
00088 {
00089 if(!pChild)
00090 {
00091 cerr << "HistMan::ReadFile - null child..." << endl;
00092 continue;
00093 }
00094
00095 if(pChild -> Type() != TiXmlNode::ELEMENT)
00096 {
00097 continue;
00098 }
00099
00100 if(pChild -> Value() && strcmp(pChild -> Value(), "histograms"))
00101 {
00102 continue;
00103 }
00104
00105 TiXmlElement* pHist = pChild -> ToElement();
00106 if(pHist)
00107 {
00108 ReadHistogramBlock(*pHist);
00109 }
00110 else
00111 {
00112 cerr << "HistMan::ReadFile - failed to cast root element for histograms" << endl;
00113 continue;
00114 }
00115 }
00116
00117 return true;
00118 }
|
|
||||||||||||
|
Definition at line 279 of file PhysicsNtuple/Hist/HistMan.cxx. References TiXmlElement::Attribute(), TiXmlNode::FirstChild(), Anp::HistInfo::fKey, Anp::HistInfo::fName, Anp::AxisInfo::fTitle, Anp::HistInfo::fTitle, Anp::HistInfo::fXaxis, Anp::HistInfo::fYaxis, ReadAxis(), and TiXmlNode::Value(). Referenced by ReadHistogramBlock(). 00280 {
00281 if(hist.Value() && strcmp(hist.Value(), "h1d") != 0)
00282 {
00283 return false;
00284 }
00285
00286 AxisInfo xaxis, yaxis;
00287
00288 bool axis1dok = false, axis2dok = false;
00289 for(const TiXmlNode *pChild = hist.FirstChild(); pChild != 0; pChild = pChild -> NextSibling())
00290 {
00291 if(!pChild)
00292 {
00293 cerr << "Null child..." << endl;
00294 continue;
00295 }
00296
00297 if(pChild -> Type() != TiXmlNode::ELEMENT)
00298 {
00299 continue;
00300 }
00301
00302 const TiXmlElement* axis = pChild -> ToElement();
00303 if(!axis)
00304 {
00305 cerr << "Failed to cast xml node to element..." << endl;
00306 continue;
00307 }
00308
00309 if(!axis -> Value())
00310 {
00311 cerr << "Node has no value" << endl;
00312 continue;
00313 }
00314
00315 if(strcmp(axis -> Value(), "axis1d") == 0 && ReadAxis(*axis, xaxis))
00316 {
00317 axis1dok = true;
00318 }
00319 if(strcmp(axis -> Value(), "axis2d") == 0 && ReadAxis(*axis, yaxis))
00320 {
00321 axis2dok = true;
00322 }
00323 }
00324
00325 if(!axis1dok)
00326 {
00327 cerr << "Failed to read 1d axis info" << endl;
00328 return false;
00329 }
00330 else
00331 {
00332 info.fXaxis = xaxis;
00333 }
00334
00335 if(axis2dok)
00336 {
00337 info.fYaxis = yaxis;
00338 }
00339
00340 const char *key = hist.Attribute("key");
00341 if(key)
00342 {
00343 info.fKey = string(key);
00344 }
00345 else
00346 {
00347 cerr << "HistMan::ReadHistogram() - key string is empty" << endl;
00348 return false;
00349 }
00350
00351 const char *name = hist.Attribute("name");
00352 if(name)
00353 {
00354 info.fName = name;
00355 }
00356
00357 const char *title = hist.Attribute("title");
00358 if(title)
00359 {
00360 info.fTitle = title;
00361 }
00362
00363 const char *axis = hist.Attribute("axis");
00364 if(axis)
00365 {
00366 info.fXaxis.fTitle = axis;
00367 }
00368
00369 return true;
00370 }
|
|
|
Definition at line 121 of file PhysicsNtuple/Hist/HistMan.cxx. References base, ComputeWidth(), fDirMap, TiXmlNode::FirstChild(), Anp::HistInfo::fKey, fKeyWidth, GetIntVec(), Anp::HistInfo::GetKey(), GetStringVec(), Anp::HistInfo::GetTitle(), InfoMap, and ReadHistogram(). Referenced by ReadFile(). 00122 {
00123 InfoMap hmap;
00124 vector<vector<int> > basevec;
00125 vector<string> dirvec;
00126
00127 for(TiXmlNode *pChild = block.FirstChild(); pChild != 0; pChild = pChild -> NextSibling())
00128 {
00129 if(!pChild)
00130 {
00131 cerr << "HistMan::ReadFile - null child..." << endl;
00132 continue;
00133 }
00134
00135 if(pChild -> Type() != TiXmlNode::ELEMENT)
00136 {
00137 continue;
00138 }
00139
00140 TiXmlElement* hist = pChild -> ToElement();
00141 if(!hist)
00142 {
00143 cerr << "HistMan::ReadFile - failed to cast xml node to element..." << endl;
00144 continue;
00145 }
00146
00147 if(!hist -> Value())
00148 {
00149 cerr << "HistMan::ReadFile - node has no value" << endl;
00150 continue;
00151 }
00152
00153 if(strcmp(hist -> Value(), "keybase") == 0 && hist -> Attribute("keys"))
00154 {
00155 const vector<int> ivec = GetIntVec(hist -> Attribute("keys"));
00156 if(!ivec.empty())
00157 {
00158 basevec.push_back(ivec);
00159 }
00160
00161 continue;
00162 }
00163
00164 if(strcmp(hist -> Value(), "dirbase") == 0 && hist -> Attribute("dirs"))
00165 {
00166 const vector<string> svec = GetStringVec(hist -> Attribute("dirs"));
00167 if(!svec.empty())
00168 {
00169 dirvec.insert(dirvec.end(), svec.begin(), svec.end());
00170 }
00171
00172 continue;
00173 }
00174
00175 HistInfo info;
00176 if(strcmp(hist -> Value(), "h1d") != 0 || !ReadHistogram(*hist, info))
00177 {
00178 continue;
00179 }
00180
00181 if(!hmap.insert(InfoMap::value_type(info.GetKey(), info)).second)
00182 {
00183 cerr << "HistMan::ReadFile - histogram key " << info.GetKey() << " already exists" << endl;
00184 }
00185
00186 const int intkey = std::atoi(info.GetKey().c_str());
00187 if(intkey != 0)
00188 {
00189 const unsigned int width = ComputeWidth(intkey);
00190 fKeyWidth = max<int>(width, fKeyWidth);
00191
00192 if(width != info.GetKey().size())
00193 {
00194 cerr << "HistMan::ReadFile - integer width and string size are not equal for key " <<info.GetKey()<<" "<<info.GetTitle()<< endl;
00195 }
00196 }
00197 }
00198
00199 vector<int> allvec;
00200 for(vector<vector<int> >::const_iterator bit = basevec.begin(); bit != basevec.end(); ++bit)
00201 {
00202 const vector<int> prevvec = allvec;
00203 const vector<int> &currvec = *bit;
00204
00205 for(vector<int>::const_iterator cit = currvec.begin(); cit != currvec.end(); ++cit)
00206 {
00207 if(prevvec.empty())
00208 {
00209 allvec.push_back(*cit);
00210 }
00211 else
00212 {
00213 for(vector<int>::const_iterator pit = prevvec.begin(); pit != prevvec.end(); ++pit)
00214 {
00215 allvec.push_back(*cit + *pit);
00216 }
00217 }
00218 }
00219 }
00220
00221 InfoMap nmap = hmap;
00222
00223 for(vector<int>::const_iterator it = allvec.begin(); it != allvec.end(); ++it)
00224 {
00225 const int base = *it;
00226
00227 for(InfoMap::const_iterator hit = hmap.begin(); hit != hmap.end(); ++hit)
00228 {
00229 const int oldkey = std::atoi((hit -> first).c_str());
00230 if(oldkey == 0)
00231 {
00232 continue;
00233 }
00234
00235 const int newkey = base + oldkey;
00236 HistInfo info = hit -> second;
00237
00238 stringstream strkey;
00239 strkey << newkey;
00240 info.fKey = strkey.str();
00241
00242 if(!nmap.insert(InfoMap::value_type(info.GetKey(), info)).second)
00243 {
00244 cerr << "HistMan::ReadFile - histogram key " << info.GetKey() << " already exists" << endl;
00245 }
00246
00247 const unsigned int width = ComputeWidth(newkey);
00248 fKeyWidth = max<int>(width, fKeyWidth);
00249
00250 if(width != info.GetKey().size())
00251 {
00252 cerr << "HistMan::ReadFile - integer width and string size are not equal" << endl;
00253 }
00254 }
00255 }
00256
00257 if(dirvec.empty())
00258 {
00259 dirvec.push_back(".");
00260 }
00261
00262 for(vector<string>::const_iterator dit = dirvec.begin(); dit != dirvec.end(); ++dit)
00263 {
00264 InfoMap &imap = fDirMap[*dit];
00265
00266 for(InfoMap::const_iterator nit = nmap.begin(); nit != nmap.end(); ++nit)
00267 {
00268 if(!imap.insert(InfoMap::value_type(*nit)).second)
00269 {
00270 cerr << "HistMan::ReadFile - failed to add " << nit -> first << " to " << *dit << endl;
00271 }
00272 }
00273 }
00274
00275 return true;
00276 }
|
|
|
Definition at line 153 of file PhysicsNtuple/Hist/HistMan.h. Referenced by CreateHist1d(), CreateTH1(), CreateTH2(), GetTH2(), KeyExists(), Print(), and ReadHistogramBlock(). |
|
|
do not stream
Definition at line 27 of file PhysicsNtuple/Hist/HistMan.cxx. Referenced by Instance(). |
|
|
Definition at line 151 of file PhysicsNtuple/Hist/HistMan.h. Referenced by CreateTH1(), CreateTH2(), and ReadHistogramBlock(). |
|
|
do not stream
Definition at line 28 of file PhysicsNtuple/Hist/HistMan.cxx. Referenced by CreateHist1d(), CreateTH1(), CreateTH2(), GetTH2(), Instance(), KeyExists(), NMiss(), and ReadFile(). |
|
|
Definition at line 149 of file PhysicsNtuple/Hist/HistMan.h. |
1.3.9.1