#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 |
| bool | KeyExists (const std::string &key) const |
| const Hist1d< double > | CreateHist1d (int key) |
| const Hist1d< double > | CreateHist1d (const std::string &key) |
| TH1 * | CreateTH1 (int key, const std::string &opt="double") |
| TH2 * | CreateTH2 (int key, const std::string &opt="float") |
| TH1 * | CreateTH1 (const std::string &key, const std::string &opt="double") |
| TH2 * | CreateTH2 (const std::string &key, const std::string &opt="float") |
| TH2 * | GetTH2 (int xkey, int ykey, const std::string &opt="float") |
| TH2 * | GetTH2 (const std::string &xkey, const std::string &ykey, const std::string &opt="float") |
| unsigned int | NMiss () const |
| void | Print (std::ostream &o=std::cout) const |
Static Public Member Functions | |
| HistMan & | Instance (TDirectory *dir_ptr=0) |
| HistMan & | Instance (const std::string dir, TDirectory *dir_ptr=0) |
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) |
| TH2 * | CreateTH2 (const HistInfo &info, const std::string &opt) |
| 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 | |
| std::string | fCurrDir |
| TDirectory * | fDir |
| unsigned int | fNMiss |
| unsigned short | fKeyWidth |
| DirMap | fDirMap |
| do not stream | |
Static Private Attributes | |
| HistMan * | fgInstance = 0 |
|
|
Definition at line 94 of file PhysicsNtuple/Hist/HistMan.h. Referenced by CreateHist1d(), CreateTH1(), CreateTH2(), GetTH2(), KeyExists(), and Print(). |
|
|
Definition at line 93 of file PhysicsNtuple/Hist/HistMan.h. |
|
|
Definition at line 92 of file PhysicsNtuple/Hist/HistMan.h. Referenced by CreateHist1d(), CreateTH1(), CreateTH2(), GetTH2(), and Print(). |
|
|
Definition at line 91 of file PhysicsNtuple/Hist/HistMan.h. Referenced by CreateHist1d(), CreateTH1(), CreateTH2(), GetTH2(), KeyExists(), Print(), and ReadHistogramBlock(). |
|
|
Definition at line 54 of file PhysicsNtuple/Hist/HistMan.cxx.
|
|
|
Definition at line 63 of file PhysicsNtuple/Hist/HistMan.cxx. 00064 {
00065 }
|
|
|
|
|
|
Definition at line 802 of file PhysicsNtuple/Hist/HistMan.cxx. Referenced by Convert(), and ReadHistogramBlock(). 00803 {
00804 //
00805 // Compute key width
00806 //
00807
00808 return static_cast<unsigned int>(std::floor(std::log10(double(std::abs(key) + 1)))) + 1;
00809 }
|
|
||||||||||||
|
Definition at line 786 of file PhysicsNtuple/Hist/HistMan.cxx. References ComputeWidth(). Referenced by CreateHist1d(), CreateTH1(), CreateTH2(), GetTH2(), and KeyExists(). 00787 {
00788 stringstream strkey;
00789 if(width == 0)
00790 {
00791 strkey << setw(ComputeWidth(key)) << key;
00792 }
00793 else
00794 {
00795 strkey << setfill('0') << setw(width) << key;
00796 }
00797
00798 return strkey.str();
00799 }
|
|
|
Definition at line 597 of file PhysicsNtuple/Hist/HistMan.cxx. References Anp::AxisInfo::GetBins(), Anp::AxisInfo::GetMax(), Anp::AxisInfo::GetMin(), Anp::AxisInfo::GetNbins(), and Anp::HistInfo::GetXaxis(). 00598 {
00599 const AxisInfo &xaxis = info.GetXaxis();
00600
00601 if(!xaxis.GetBins().empty())
00602 {
00603 return Hist1d<double>(xaxis.GetBins());
00604 }
00605
00606 return Hist1d<double>(xaxis.GetNbins(), xaxis.GetMin(), xaxis.GetMax());
00607 }
|
|
|
Definition at line 464 of file PhysicsNtuple/Hist/HistMan.cxx. References CreateHist1d(), DirIter, fCurrDir, fDirMap, InfoIter, and InfoMap. 00465 {
00466 DirIter dit = fDirMap.find(fCurrDir);
00467 if(dit == fDirMap.end())
00468 {
00469 ++fNMiss;
00470 return Hist1d<double>(0, 0.0, 0.0);
00471 }
00472
00473 const InfoMap &imap = dit -> second;
00474
00475 InfoIter hit = imap.find(key);
00476 if(hit == imap.end())
00477 {
00478 ++fNMiss;
00479 return Hist1d<double>(0, 0.0, 0.0);
00480 }
00481
00482 return CreateHist1d(hit -> second);
00483 }
|
|
|
Definition at line 458 of file PhysicsNtuple/Hist/HistMan.cxx. References Convert(). Referenced by CreateHist1d(). 00459 {
00460 return CreateHist1d(Convert(key));
00461 }
|
|
||||||||||||
|
Definition at line 610 of file PhysicsNtuple/Hist/HistMan.cxx. References Convert(), fDir, 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(), and Anp::HistInfo::GetYaxis(). 00611 {
00612 string strkey = info.GetKey();
00613 string name = info.GetName();
00614 string title = info.GetTitle();
00615
00616 const int intkey = std::atoi(strkey.c_str());
00617 if(intkey != 0)
00618 {
00619 strkey = "key_" + Convert(intkey, fKeyWidth);
00620 }
00621 if(name.empty())
00622 {
00623 name = strkey;
00624 }
00625 if(title.empty())
00626 {
00627 title = info.GetName();
00628 }
00629
00630 const AxisInfo &xaxis = info.GetXaxis();
00631 const AxisInfo &yaxis = info.GetYaxis();
00632
00633 TH1 *h = 0;
00634
00635 if(xaxis.GetBins().empty())
00636 {
00637 if(opt.find("profile") != string::npos)
00638 {
00639 h = new TProfile(name.c_str(), title.c_str(),
00640 xaxis.GetNbins(), xaxis.GetMin(), xaxis.GetMax());
00641 }
00642 else if(opt.find("double") != string::npos)
00643 {
00644 h = new TH1D(name.c_str(), title.c_str(),
00645 xaxis.GetNbins(), xaxis.GetMin(), xaxis.GetMax());
00646 }
00647 else
00648 {
00649 h = new TH1F(name.c_str(), title.c_str(),
00650 xaxis.GetNbins(), xaxis.GetMin(), xaxis.GetMax());
00651 }
00652 }
00653 else
00654 {
00655 const vector<double> &bvec = xaxis.GetBins();
00656
00657 double *darray = new double[bvec.size()];
00658
00659 for(unsigned int ibin = 0; ibin < bvec.size(); ++ibin)
00660 {
00661 darray[ibin] = bvec[ibin];
00662 }
00663
00664 if(opt.find("profile") != string::npos)
00665 {
00666 h = new TProfile(name.c_str(), title.c_str(), bvec.size() - 1, darray);
00667 }
00668 else if(opt.find("double") != string::npos)
00669 {
00670 h = new TH1D(name.c_str(), title.c_str(), bvec.size() - 1, darray);
00671 }
00672 else
00673 {
00674 h = new TH1F(name.c_str(), title.c_str(), bvec.size() - 1, darray);
00675 }
00676
00677 delete [] darray;
00678 }
00679
00680 h -> SetDirectory(fDir);
00681 if(xaxis.GetTitle().size() > 0)
00682 {
00683 h -> GetXaxis() -> SetTitle(xaxis.GetTitle().c_str());
00684 h -> GetXaxis() -> CenterTitle();
00685 }
00686 if(yaxis.GetTitle().size() > 0)
00687 {
00688 h -> GetYaxis() -> SetTitle(yaxis.GetTitle().c_str());
00689 h -> GetYaxis() -> CenterTitle();
00690 }
00691
00692 return h;
00693 }
|
|
||||||||||||
|
Definition at line 492 of file PhysicsNtuple/Hist/HistMan.cxx. References CreateTH1(), DirIter, fCurrDir, fDirMap, InfoIter, and InfoMap. 00493 {
00494 DirIter dit = fDirMap.find(fCurrDir);
00495 if(dit == fDirMap.end())
00496 {
00497 ++fNMiss;
00498 return 0;
00499 }
00500
00501 const InfoMap &imap = dit -> second;
00502
00503 InfoIter hit = imap.find(key);
00504 if(hit == imap.end())
00505 {
00506 ++fNMiss;
00507 return 0;
00508 }
00509
00510 return CreateTH1(hit -> second, opt);
00511 }
|
|
||||||||||||
|
Definition at line 486 of file PhysicsNtuple/Hist/HistMan.cxx. References Convert(). Referenced by Anp::PlotVtx::CreateHist(), Anp::PlotTruth::CreateHist(), Anp::PlotTrackGeom::CreateHist(), Anp::PlotTrack::CreateHist(), Anp::PlotShower::CreateHist(), Anp::PlotReson::CreateHist(), Anp::PlotResol::CreateHist(), Anp::PlotBasic::CreateHist(), CreateTH1(), Anp::PlotTruth::GetTH1(), and Anp::PlotEvent::GetTH1().
|
|
||||||||||||
|
Definition at line 696 of file PhysicsNtuple/Hist/HistMan.cxx. References Convert(), fDir, 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(), and Anp::HistInfo::GetYaxis(). 00697 {
00698 string strkey = info.GetKey();
00699 string name = info.GetName();
00700 string title = info.GetTitle();
00701
00702 const int intkey = std::atoi(strkey.c_str());
00703 if(intkey != 0)
00704 {
00705 strkey = Convert(intkey, fKeyWidth);
00706 }
00707 if(name.empty())
00708 {
00709 name = strkey;
00710 }
00711 if(title.empty())
00712 {
00713 title = info.GetName();
00714 }
00715
00716 const AxisInfo &xaxis = info.GetXaxis();
00717 const AxisInfo &yaxis = info.GetYaxis();
00718
00719 TH2 *h = 0;
00720 if(opt.find("double") != string::npos)
00721 {
00722 h = new TH2D(name.c_str(), title.c_str(),
00723 xaxis.GetNbins(), xaxis.GetMin(), xaxis.GetMax(),
00724 yaxis.GetNbins(), yaxis.GetMin(), yaxis.GetMax());
00725 }
00726 else
00727 {
00728 h = new TH2F(name.c_str(), title.c_str(),
00729 xaxis.GetNbins(), xaxis.GetMin(), xaxis.GetMax(),
00730 yaxis.GetNbins(), yaxis.GetMin(), yaxis.GetMax());
00731 }
00732
00733 h -> SetDirectory(fDir);
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 520 of file PhysicsNtuple/Hist/HistMan.cxx. References CreateTH2(), DirIter, fCurrDir, fDirMap, InfoIter, and InfoMap. 00521 {
00522 DirIter dit = fDirMap.find(fCurrDir);
00523 if(dit == fDirMap.end())
00524 {
00525 ++fNMiss;
00526 return 0;
00527 }
00528
00529 const InfoMap &imap = dit -> second;
00530
00531 InfoIter hit = imap.find(key);
00532 if(hit == imap.end())
00533 {
00534 ++fNMiss;
00535 return 0;
00536 }
00537
00538 return CreateTH2(hit -> second, opt);
00539 }
|
|
||||||||||||
|
Definition at line 514 of file PhysicsNtuple/Hist/HistMan.cxx. References Convert(). Referenced by Anp::PlotVtx::CreateHist(), Anp::PlotTrackGeom::CreateHist(), Anp::PlotTrack::CreateHist(), Anp::PlotReson::CreateHist(), Anp::PlotEvent::CreateHist(), CreateTH2(), and GetTH2().
|
|
|
Definition at line 749 of file PhysicsNtuple/Hist/HistMan.cxx. References UtilString::StringTok(). Referenced by ReadHistogramBlock(). 00750 {
00751 vector<string> namelist;
00752 UtilString::StringTok(namelist, list, ", ");
00753
00754 vector<int> ivec;
00755 for(vector<string>::const_iterator sit = namelist.begin(); sit != namelist.end(); ++sit)
00756 {
00757 const int newbase = std::atoi(sit -> c_str());
00758 if(newbase != 0)
00759 {
00760 ivec.push_back(newbase);
00761 }
00762 }
00763
00764 return ivec;
00765 }
|
|
|
Definition at line 768 of file PhysicsNtuple/Hist/HistMan.cxx. References UtilString::StringTok(). Referenced by ReadHistogramBlock(). 00769 {
00770 vector<string> namelist;
00771 UtilString::StringTok(namelist, list, ", ");
00772
00773 vector<string> nvec;
00774 for(vector<string>::const_iterator sit = namelist.begin(); sit != namelist.end(); ++sit)
00775 {
00776 if(!sit -> empty())
00777 {
00778 nvec.push_back(*sit);
00779 }
00780 }
00781
00782 return nvec;
00783 }
|
|
||||||||||||||||
|
Definition at line 548 of file PhysicsNtuple/Hist/HistMan.cxx. References CreateTH2(), DirIter, fCurrDir, fDirMap, Anp::HistInfo::fKey, 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(). 00549 {
00550 DirIter dit = fDirMap.find(fCurrDir);
00551 if(dit == fDirMap.end())
00552 {
00553 ++fNMiss;
00554 return 0;
00555 }
00556
00557 const InfoMap &imap = dit -> second;
00558
00559 InfoIter xhit = imap.find(xkey);
00560 if(xhit == imap.end())
00561 {
00562 ++fNMiss;
00563 return 0;
00564 }
00565
00566 InfoIter yhit = imap.find(ykey);
00567 if(yhit == imap.end())
00568 {
00569 ++fNMiss;
00570 return 0;
00571 }
00572
00573 const HistInfo &xinfo = xhit -> second;
00574 const HistInfo &yinfo = yhit -> second;
00575
00576 HistInfo info;
00577
00578 info.fKey = "keys_" + xinfo.GetKey() + "_and_" + yinfo.GetKey();
00579 info.fXaxis = xinfo.GetXaxis();
00580 info.fYaxis = yinfo.GetXaxis();
00581 info.fName = info.GetKey();
00582 info.fTitle = info.GetKey();
00583
00584 if(xinfo.GetYaxis().Valid())
00585 {
00586 info.fXaxis = xinfo.GetYaxis();
00587 }
00588 if(yinfo.GetYaxis().Valid())
00589 {
00590 info.fYaxis = yinfo.GetYaxis();
00591 }
00592
00593 return CreateTH2(info, opt);
00594 }
|
|
||||||||||||||||
|
Definition at line 542 of file PhysicsNtuple/Hist/HistMan.cxx. References Convert().
|
|
||||||||||||
|
Definition at line 38 of file PhysicsNtuple/Hist/HistMan.cxx. References fCurrDir, fDir, and fgInstance. 00039 {
00040 if(!fgInstance)
00041 {
00042 fgInstance = new Anp::HistMan();
00043 }
00044
00045 fgInstance -> fCurrDir = dir;
00046 fgInstance -> fDir = dir_ptr;
00047
00048 return *fgInstance;
00049 }
|
|
|
Definition at line 25 of file PhysicsNtuple/Hist/HistMan.cxx. References fCurrDir, fDir, and fgInstance. 00026 {
00027 if(!fgInstance)
00028 {
00029 fgInstance = new Anp::HistMan();
00030 }
00031
00032 fgInstance -> fCurrDir = ".";
00033 fgInstance -> fDir = dir_ptr;
00034
00035 return *fgInstance;
00036 }
|
|
|
Definition at line 443 of file PhysicsNtuple/Hist/HistMan.cxx. References DirIter, fCurrDir, fDirMap, and InfoMap. 00444 {
00445 DirIter dit = fDirMap.find(fCurrDir);
00446 if(dit == fDirMap.end())
00447 {
00448 return false;
00449 }
00450
00451 const InfoMap &imap = dit -> second;
00452
00453 return (imap.find(key) != imap.end());
00454 }
|
|
|
Definition at line 437 of file PhysicsNtuple/Hist/HistMan.cxx. References Convert().
|
|
|
Definition at line 812 of file PhysicsNtuple/Hist/HistMan.cxx. Referenced by Anp::PlotVtx::CreateHist(), Anp::PlotTruth::CreateHist(), Anp::PlotTrackGeom::CreateHist(), Anp::PlotTrack::CreateHist(), Anp::PlotShower::CreateHist(), Anp::PlotReson::CreateHist(), Anp::PlotResol::CreateHist(), Anp::PlotEvent::CreateHist(), and Anp::PlotBasic::CreateHist(). 00813 {
00814 return fNMiss;
00815 }
|
|
|
|
|
|
Definition at line 818 of file PhysicsNtuple/Hist/HistMan.cxx. References DirIter, fDirMap, InfoIter, InfoMap, and Anp::AxisInfo::Print(). 00819 {
00820 o << "HistMan::Print" << endl;
00821 for(DirIter dit = fDirMap.begin(); dit != fDirMap.end(); ++dit)
00822 {
00823 o << "Directory = " << dit -> first << endl;
00824 const InfoMap &imap = dit -> second;
00825
00826 for(InfoIter it = imap.begin(); it != imap.end(); ++it)
00827 {
00828 it -> second.Print(o);
00829 }
00830 }
00831 }
|
|
||||||||||||
|
Definition at line 372 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(), NR::sort(), UtilString::StringTok(), and TIXML_SUCCESS. Referenced by ReadHistogram(). 00373 {
00374 bool read_bin = false, read_bins = false;
00375
00376 int bin = 0;
00377 float min = 0.0, max = 0.0;
00378
00379 if(axis.QueryIntAttribute("bin", &bin) == TIXML_SUCCESS &&
00380 axis.QueryFloatAttribute("min", &min) == TIXML_SUCCESS &&
00381 axis.QueryFloatAttribute("max", &max) == TIXML_SUCCESS)
00382 {
00383 read_bin = true;
00384 }
00385
00386 const char *xtitle = axis.Attribute("title");
00387 if(xtitle)
00388 {
00389 info.fTitle = xtitle;
00390 }
00391
00392 vector<double> bvec;
00393
00394 const char *bins = axis.Attribute("bins");
00395 if(bins)
00396 {
00397 vector<string> datavec;
00398 UtilString::StringTok(datavec, bins, ", ");
00399
00400 for(vector<string>::const_iterator sit = datavec.begin(); sit != datavec.end(); ++sit)
00401 {
00402 if(sit -> size() > 0)
00403 {
00404 bvec.push_back(std::atof(sit -> c_str()));
00405 }
00406 }
00407
00408 std::sort(bvec.begin(), bvec.end());
00409
00410 //for(unsigned int i = 0; i < bvec.size(); ++i)
00411 //{
00412 //cout << "bin = " << i << " edge = " << bvec[i] << endl;;
00413 //}
00414
00415 if(!bvec.empty())
00416 {
00417 read_bins = true;
00418 }
00419 }
00420
00421 if(read_bin)
00422 {
00423 info.fNbins = bin;
00424 info.fMin = min;
00425 info.fMax = max;
00426 info.fValid = true;
00427 }
00428 else if(read_bins)
00429 {
00430 info.fBins = bvec;
00431 }
00432
00433 return true;
00434 }
|
|
|
Definition at line 68 of file PhysicsNtuple/Hist/HistMan.cxx. References doc, 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
00078 TiXmlDocument doc(file.c_str());
00079 const bool loadok = doc.LoadFile();
00080 if(!loadok)
00081 {
00082 cerr << "HistMan::ReadFile - failed to load: " << file << endl;
00083 return false;
00084 }
00085
00086 for(TiXmlNode *pChild = doc.FirstChild(); pChild != 0; pChild = pChild -> NextSibling())
00087 {
00088 if(!pChild)
00089 {
00090 cerr << "HistMan::ReadFile - null child..." << endl;
00091 continue;
00092 }
00093
00094 if(pChild -> Type() != TiXmlNode::ELEMENT)
00095 {
00096 continue;
00097 }
00098
00099 if(pChild -> Value() && strcmp(pChild -> Value(), "histograms"))
00100 {
00101 continue;
00102 }
00103
00104 TiXmlElement* pHist = pChild -> ToElement();
00105 if(pHist)
00106 {
00107 ReadHistogramBlock(*pHist);
00108 }
00109 else
00110 {
00111 cerr << "HistMan::ReadFile - failed to cast root element for histograms" << endl;
00112 continue;
00113 }
00114 }
00115
00116 return true;
00117 }
|
|
||||||||||||
|
Definition at line 278 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(). 00279 {
00280 if(hist.Value() && strcmp(hist.Value(), "h1d") != 0)
00281 {
00282 return false;
00283 }
00284
00285 AxisInfo xaxis, yaxis;
00286
00287 bool axis1dok = false, axis2dok = false;
00288 for(const TiXmlNode *pChild = hist.FirstChild(); pChild != 0; pChild = pChild -> NextSibling())
00289 {
00290 if(!pChild)
00291 {
00292 cerr << "Null child..." << endl;
00293 continue;
00294 }
00295
00296 if(pChild -> Type() != TiXmlNode::ELEMENT)
00297 {
00298 continue;
00299 }
00300
00301 const TiXmlElement* axis = pChild -> ToElement();
00302 if(!axis)
00303 {
00304 cerr << "Failed to cast xml node to element..." << endl;
00305 continue;
00306 }
00307
00308 if(!axis -> Value())
00309 {
00310 cerr << "Node has no value" << endl;
00311 continue;
00312 }
00313
00314 if(strcmp(axis -> Value(), "axis1d") == 0 && ReadAxis(*axis, xaxis))
00315 {
00316 axis1dok = true;
00317 }
00318 if(strcmp(axis -> Value(), "axis2d") == 0 && ReadAxis(*axis, yaxis))
00319 {
00320 axis2dok = true;
00321 }
00322 }
00323
00324 if(!axis1dok)
00325 {
00326 cerr << "Failed to read 1d axis info" << endl;
00327 return false;
00328 }
00329 else
00330 {
00331 info.fXaxis = xaxis;
00332 }
00333
00334 if(axis2dok)
00335 {
00336 info.fYaxis = yaxis;
00337 }
00338
00339 const char *key = hist.Attribute("key");
00340 if(key)
00341 {
00342 info.fKey = string(key);
00343 }
00344 else
00345 {
00346 cerr << "HistMan::ReadHistogram() - key string is empty" << endl;
00347 return false;
00348 }
00349
00350 const char *name = hist.Attribute("name");
00351 if(name)
00352 {
00353 info.fName = name;
00354 }
00355
00356 const char *title = hist.Attribute("title");
00357 if(title)
00358 {
00359 info.fTitle = title;
00360 }
00361
00362 const char *axis = hist.Attribute("axis");
00363 if(axis)
00364 {
00365 info.fXaxis.fTitle = axis;
00366 }
00367
00368 return true;
00369 }
|
|
|
Definition at line 120 of file PhysicsNtuple/Hist/HistMan.cxx. References base, ComputeWidth(), fDirMap, TiXmlNode::FirstChild(), Anp::HistInfo::fKey, fKeyWidth, GetIntVec(), Anp::HistInfo::GetKey(), GetStringVec(), InfoMap, and ReadHistogram(). Referenced by ReadFile(). 00121 {
00122 InfoMap hmap;
00123 vector<vector<int> > basevec;
00124 vector<string> dirvec;
00125
00126 for(TiXmlNode *pChild = block.FirstChild(); pChild != 0; pChild = pChild -> NextSibling())
00127 {
00128 if(!pChild)
00129 {
00130 cerr << "HistMan::ReadFile - null child..." << endl;
00131 continue;
00132 }
00133
00134 if(pChild -> Type() != TiXmlNode::ELEMENT)
00135 {
00136 continue;
00137 }
00138
00139 TiXmlElement* hist = pChild -> ToElement();
00140 if(!hist)
00141 {
00142 cerr << "HistMan::ReadFile - failed to cast xml node to element..." << endl;
00143 continue;
00144 }
00145
00146 if(!hist -> Value())
00147 {
00148 cerr << "HistMan::ReadFile - node has no value" << endl;
00149 continue;
00150 }
00151
00152 if(strcmp(hist -> Value(), "keybase") == 0 && hist -> Attribute("keys"))
00153 {
00154 const vector<int> ivec = GetIntVec(hist -> Attribute("keys"));
00155 if(!ivec.empty())
00156 {
00157 basevec.push_back(ivec);
00158 }
00159
00160 continue;
00161 }
00162
00163 if(strcmp(hist -> Value(), "dirbase") == 0 && hist -> Attribute("dirs"))
00164 {
00165 const vector<string> svec = GetStringVec(hist -> Attribute("dirs"));
00166 if(!svec.empty())
00167 {
00168 dirvec.insert(dirvec.end(), svec.begin(), svec.end());
00169 }
00170
00171 continue;
00172 }
00173
00174 HistInfo info;
00175 if(strcmp(hist -> Value(), "h1d") != 0 || !ReadHistogram(*hist, info))
00176 {
00177 continue;
00178 }
00179
00180 if(!hmap.insert(InfoMap::value_type(info.GetKey(), info)).second)
00181 {
00182 cerr << "HistMan::ReadFile - histogram key " << info.GetKey() << " already exists" << endl;
00183 }
00184
00185 const int intkey = std::atoi(info.GetKey().c_str());
00186 if(intkey != 0)
00187 {
00188 const unsigned int width = ComputeWidth(intkey);
00189 fKeyWidth = max<int>(width, fKeyWidth);
00190
00191 if(width != info.GetKey().size())
00192 {
00193 cerr << "HistMan::ReadFile - integer width and string size are not equal" << endl;
00194 }
00195 }
00196 }
00197
00198 vector<int> allvec;
00199 for(vector<vector<int> >::const_iterator bit = basevec.begin(); bit != basevec.end(); ++bit)
00200 {
00201 const vector<int> prevvec = allvec;
00202 const vector<int> &currvec = *bit;
00203
00204 for(vector<int>::const_iterator cit = currvec.begin(); cit != currvec.end(); ++cit)
00205 {
00206 if(prevvec.empty())
00207 {
00208 allvec.push_back(*cit);
00209 }
00210 else
00211 {
00212 for(vector<int>::const_iterator pit = prevvec.begin(); pit != prevvec.end(); ++pit)
00213 {
00214 allvec.push_back(*cit + *pit);
00215 }
00216 }
00217 }
00218 }
00219
00220 InfoMap nmap = hmap;
00221
00222 for(vector<int>::const_iterator it = allvec.begin(); it != allvec.end(); ++it)
00223 {
00224 const int base = *it;
00225
00226 for(InfoMap::const_iterator hit = hmap.begin(); hit != hmap.end(); ++hit)
00227 {
00228 const int oldkey = std::atoi((hit -> first).c_str());
00229 if(oldkey == 0)
00230 {
00231 continue;
00232 }
00233
00234 const int newkey = base + oldkey;
00235 HistInfo info = hit -> second;
00236
00237 stringstream strkey;
00238 strkey << newkey;
00239 info.fKey = strkey.str();
00240
00241 if(!nmap.insert(InfoMap::value_type(info.GetKey(), info)).second)
00242 {
00243 cerr << "HistMan::ReadFile - histogram key " << info.GetKey() << " already exists" << endl;
00244 }
00245
00246 const unsigned int width = ComputeWidth(newkey);
00247 fKeyWidth = max<int>(width, fKeyWidth);
00248
00249 if(width != info.GetKey().size())
00250 {
00251 cerr << "HistMan::ReadFile - integer width and string size are not equal" << endl;
00252 }
00253 }
00254 }
00255
00256 if(dirvec.empty())
00257 {
00258 dirvec.push_back(".");
00259 }
00260
00261 for(vector<string>::const_iterator dit = dirvec.begin(); dit != dirvec.end(); ++dit)
00262 {
00263 InfoMap &imap = fDirMap[*dit];
00264
00265 for(InfoMap::const_iterator nit = nmap.begin(); nit != nmap.end(); ++nit)
00266 {
00267 if(!imap.insert(InfoMap::value_type(*nit)).second)
00268 {
00269 cerr << "HistMan::ReadFile - failed to add " << nit -> first << " to " << *dit << endl;
00270 }
00271 }
00272 }
00273
00274 return true;
00275 }
|
|
|
Definition at line 149 of file PhysicsNtuple/Hist/HistMan.h. Referenced by CreateHist1d(), CreateTH1(), CreateTH2(), GetTH2(), Instance(), and KeyExists(). |
|
|
Definition at line 151 of file PhysicsNtuple/Hist/HistMan.h. Referenced by CreateTH1(), CreateTH2(), and Instance(). |
|
|
do not stream
Definition at line 159 of file PhysicsNtuple/Hist/HistMan.h. Referenced by CreateHist1d(), CreateTH1(), CreateTH2(), GetTH2(), KeyExists(), Print(), and ReadHistogramBlock(). |
|
|
Definition at line 20 of file PhysicsNtuple/Hist/HistMan.cxx. Referenced by Instance(). |
|
|
Definition at line 155 of file PhysicsNtuple/Hist/HistMan.h. Referenced by CreateTH1(), CreateTH2(), and ReadHistogramBlock(). |
|
|
Definition at line 153 of file PhysicsNtuple/Hist/HistMan.h. |
1.3.9.1