diff --git a/create_database/tuple_reader/Makefile b/create_database/tuple_reader/Makefile index 2408bce..0977a2a 100644 --- a/create_database/tuple_reader/Makefile +++ b/create_database/tuple_reader/Makefile @@ -29,6 +29,10 @@ INCFLAGS += -I$(BOOST_ROOT) INCFLAGS += $(shell root-config --cflags) LDFLAGS += $(shell root-config --libs) +# custom cpp utilities +CUSTOM_CPP_UTIL_ROOT = /Users/dchao/bdtaunu/v4/custom_cpp_utilities +INCFLAGS += -I$(CUSTOM_CPP_UTIL_ROOT) + # particle data file PDT_FILE_PATHNAME = $(shell pwd | sed 's/\/[^/]*$$//')/tuple_reader/meta/pdt.dat CXXFLAGS += -D__PDT_FILE_PATHNAME='"$(PDT_FILE_PATHNAME)"' diff --git a/create_database/tuple_reader/McBTypeCatalogue.cc b/create_database/tuple_reader/McBTypeCatalogue.cc index 532639f..fbb8a2f 100644 --- a/create_database/tuple_reader/McBTypeCatalogue.cc +++ b/create_database/tuple_reader/McBTypeCatalogue.cc @@ -1,5 +1,6 @@ #include #include +#include #include "McBTypeCatalogue.h" @@ -22,176 +23,176 @@ McBTypeCatalogue::search_catalogue(std::vector lund_list) const { if (hasX) word.push_back(Alphabet::X); word.push_back(Alphabet::null); - return trie.search_word(word); + return catalogue.find(word); } void McBTypeCatalogue::RegisterDecays() { // nu_tau branch - trie.add_word({ + catalogue.insert({ Alphabet::nu_tau, Alphabet::tau, Alphabet::null }, BType::SL); - trie.add_word({ + catalogue.insert({ Alphabet::nu_tau, Alphabet::tau, Alphabet::D, Alphabet::null }, BType::Dtau); - trie.add_word({ + catalogue.insert({ Alphabet::nu_tau, Alphabet::tau, Alphabet::Dstar, Alphabet::null }, BType::Dstartau); - trie.add_word({ + catalogue.insert({ Alphabet::nu_tau, Alphabet::tau, Alphabet::Dstarstar, Alphabet::null }, BType::Dstarstar_res); - trie.add_word({ + catalogue.insert({ Alphabet::nu_tau, Alphabet::tau, Alphabet::X, Alphabet::null }, BType::SL); - trie.add_word({ + catalogue.insert({ Alphabet::nu_tau, Alphabet::tau, Alphabet::D, Alphabet::X, Alphabet::null }, BType::Dstarstar_nonres); - trie.add_word({ + catalogue.insert({ Alphabet::nu_tau, Alphabet::tau, Alphabet::Dstar, Alphabet::X, Alphabet::null }, BType::Dstarstar_nonres); - trie.add_word({ + catalogue.insert({ Alphabet::nu_tau, Alphabet::tau, Alphabet::Dstarstar, Alphabet::X, Alphabet::null }, BType::Dstarstar_res); // nu_ell branch - trie.add_word({ + catalogue.insert({ Alphabet::nu_ell, Alphabet::ell, Alphabet::null }, BType::SL); - trie.add_word({ + catalogue.insert({ Alphabet::nu_ell, Alphabet::ell, Alphabet::D, Alphabet::null }, BType::Dl); - trie.add_word({ + catalogue.insert({ Alphabet::nu_ell, Alphabet::ell, Alphabet::Dstar, Alphabet::null }, BType::Dstarl); - trie.add_word({ + catalogue.insert({ Alphabet::nu_ell, Alphabet::ell, Alphabet::Dstarstar, Alphabet::null }, BType::Dstarstar_res); - trie.add_word({ + catalogue.insert({ Alphabet::nu_ell, Alphabet::ell, Alphabet::X, Alphabet::null }, BType::SL); - trie.add_word({ + catalogue.insert({ Alphabet::nu_ell, Alphabet::ell, Alphabet::D, Alphabet::X, Alphabet::null }, BType::Dstarstar_nonres); - trie.add_word({ + catalogue.insert({ Alphabet::nu_ell, Alphabet::ell, Alphabet::Dstar, Alphabet::X, Alphabet::null }, BType::Dstarstar_nonres); - trie.add_word({ + catalogue.insert({ Alphabet::nu_ell, Alphabet::ell, Alphabet::Dstarstar, Alphabet::X, Alphabet::null }, BType::Dstarstar_res); // hadron branch - trie.add_word({ + catalogue.insert({ Alphabet::X, Alphabet::null }, BType::Had); - trie.add_word({ + catalogue.insert({ Alphabet::D, Alphabet::X, Alphabet::null }, BType::Had); - trie.add_word({ + catalogue.insert({ Alphabet::Dstar, Alphabet::X, Alphabet::null }, BType::Had); - trie.add_word({ + catalogue.insert({ Alphabet::Dstarstar, Alphabet::X, Alphabet::null }, BType::Had); - trie.add_word({ + catalogue.insert({ Alphabet::D, Alphabet::D, Alphabet::null }, BType::Had); - trie.add_word({ + catalogue.insert({ Alphabet::D, Alphabet::Dstar, Alphabet::null }, BType::Had); - trie.add_word({ + catalogue.insert({ Alphabet::D, Alphabet::Dstarstar, Alphabet::null }, BType::Had); - trie.add_word({ + catalogue.insert({ Alphabet::Dstar, Alphabet::Dstar, Alphabet::null }, BType::Had); - trie.add_word({ + catalogue.insert({ Alphabet::Dstar, Alphabet::Dstarstar, Alphabet::null }, BType::Had); - trie.add_word({ + catalogue.insert({ Alphabet::Dstarstar, Alphabet::Dstarstar, Alphabet::null }, BType::Had); - trie.add_word({ + catalogue.insert({ Alphabet::D, Alphabet::D, Alphabet::X, Alphabet::null }, BType::Had); - trie.add_word({ + catalogue.insert({ Alphabet::D, Alphabet::Dstar, Alphabet::X, Alphabet::null }, BType::Had); - trie.add_word({ + catalogue.insert({ Alphabet::D, Alphabet::Dstarstar, Alphabet::X, Alphabet::null }, BType::Had); - trie.add_word({ + catalogue.insert({ Alphabet::Dstar, Alphabet::Dstar, Alphabet::X, Alphabet::null }, BType::Had); - trie.add_word({ + catalogue.insert({ Alphabet::Dstar, Alphabet::Dstarstar, Alphabet::X, Alphabet::null }, BType::Had); - trie.add_word({ + catalogue.insert({ Alphabet::Dstarstar, Alphabet::Dstarstar, Alphabet::X, Alphabet::null }, BType::Had); @@ -199,7 +200,7 @@ void McBTypeCatalogue::RegisterDecays() { } McBTypeCatalogue::Alphabet McBTypeCatalogue::LundToAlphabet(int lund) const { - switch (abs(lund)) { + switch (std::abs(lund)) { case 12: // nu_e case 14: // nu_mu return Alphabet::nu_ell; diff --git a/create_database/tuple_reader/McBTypeCatalogue.h b/create_database/tuple_reader/McBTypeCatalogue.h index 07853c2..454f005 100644 --- a/create_database/tuple_reader/McBTypeCatalogue.h +++ b/create_database/tuple_reader/McBTypeCatalogue.h @@ -3,7 +3,7 @@ #include -#include "Trie.h" +#include class McBTypeCatalogue { @@ -27,7 +27,7 @@ class McBTypeCatalogue { void RegisterDecays(); Alphabet LundToAlphabet(int lund) const; - bdtaunu::Trie trie; + custom_cpp_utilities::trie catalogue; }; diff --git a/create_database/tuple_reader/RecoDTypeCatalogue.cc b/create_database/tuple_reader/RecoDTypeCatalogue.cc index 98982da..b07df0a 100644 --- a/create_database/tuple_reader/RecoDTypeCatalogue.cc +++ b/create_database/tuple_reader/RecoDTypeCatalogue.cc @@ -11,7 +11,7 @@ RecoDTypeCatalogue::search_d_catalogue(std::vector lund_list) const { for (auto l : lund_list) word.push_back(LundToAlphabet(l)); std::sort(word.begin(), word.end()); word.push_back(Alphabet::null); - return d_trie.search_word(word); + return d_catalogue.find(word); } RecoDTypeCatalogue::DstarType @@ -20,109 +20,109 @@ RecoDTypeCatalogue::search_dstar_catalogue(std::vector lund_list) const { for (auto l : lund_list) word.push_back(LundToAlphabet(l)); std::sort(word.begin(), word.end()); word.push_back(Alphabet::null); - return dstar_trie.search_word(word); + return dstar_catalogue.find(word); } void RecoDTypeCatalogue::RegisterDecays() { - // D trie - d_trie.add_word({ + // D catalogue + d_catalogue.insert({ Alphabet::Dc, Alphabet::K, Alphabet::pi, Alphabet::pi, Alphabet::null }, DType::Dc_Kpipi); - d_trie.add_word({ + d_catalogue.insert({ Alphabet::Dc, Alphabet::K, Alphabet::pi, Alphabet::pi, Alphabet::pi0, Alphabet::null }, DType::Dc_Kpipipi0); - d_trie.add_word({ + d_catalogue.insert({ Alphabet::Dc, Alphabet::Ks, Alphabet::K, Alphabet::null }, DType::Dc_KsK); - d_trie.add_word({ + d_catalogue.insert({ Alphabet::Dc, Alphabet::Ks, Alphabet::pi, Alphabet::null }, DType::Dc_Kspi); - d_trie.add_word({ + d_catalogue.insert({ Alphabet::Dc, Alphabet::Ks, Alphabet::pi, Alphabet::pi0, Alphabet::null }, DType::Dc_Kspipi0); - d_trie.add_word({ + d_catalogue.insert({ Alphabet::Dc, Alphabet::Ks, Alphabet::pi, Alphabet::pi, Alphabet::pi, Alphabet::null }, DType::Dc_Kspipipi); - d_trie.add_word({ + d_catalogue.insert({ Alphabet::Dc, Alphabet::K, Alphabet::K, Alphabet::pi, Alphabet::null }, DType::Dc_KKpi); - d_trie.add_word({ + d_catalogue.insert({ Alphabet::D0, Alphabet::K, Alphabet::pi, Alphabet::null }, DType::D0_Kpi); - d_trie.add_word({ + d_catalogue.insert({ Alphabet::D0, Alphabet::K, Alphabet::pi, Alphabet::pi0, Alphabet::null }, DType::D0_Kpipi0); - d_trie.add_word({ + d_catalogue.insert({ Alphabet::D0, Alphabet::K, Alphabet::pi, Alphabet::pi, Alphabet::pi, Alphabet::null }, DType::D0_Kpipipi); - d_trie.add_word({ + d_catalogue.insert({ Alphabet::D0, Alphabet::K, Alphabet::pi, Alphabet::pi, Alphabet::pi, Alphabet::pi0, Alphabet::null }, DType::D0_Kpipipipi0); - d_trie.add_word({ + d_catalogue.insert({ Alphabet::D0, Alphabet::Ks, Alphabet::pi, Alphabet::pi, Alphabet::null }, DType::D0_Kspipi); - d_trie.add_word({ + d_catalogue.insert({ Alphabet::D0, Alphabet::Ks, Alphabet::pi, Alphabet::pi, Alphabet::pi0, Alphabet::null }, DType::D0_Kspipipi0); - d_trie.add_word({ + d_catalogue.insert({ Alphabet::D0, Alphabet::Ks, Alphabet::pi0, Alphabet::null }, DType::D0_Kspi0); - d_trie.add_word({ + d_catalogue.insert({ Alphabet::D0, Alphabet::K, Alphabet::K, Alphabet::null }, DType::D0_KK); - // Dstar trie - dstar_trie.add_word({ + // Dstar catalogue + dstar_catalogue.insert({ Alphabet::Dstar0, Alphabet::D0, Alphabet::pi0, Alphabet::null }, DstarType::Dstar0_D0pi0); - dstar_trie.add_word({ + dstar_catalogue.insert({ Alphabet::Dstar0, Alphabet::D0, Alphabet::gamma, Alphabet::null }, DstarType::Dstar0_D0gamma); - dstar_trie.add_word({ + dstar_catalogue.insert({ Alphabet::Dstarc, Alphabet::D0, Alphabet::pi, Alphabet::null }, DstarType::Dstarc_D0pi); - dstar_trie.add_word({ + dstar_catalogue.insert({ Alphabet::Dstarc, Alphabet::Dc, Alphabet::pi0, Alphabet::null }, DstarType::Dstarc_Dcpi0); - dstar_trie.add_word({ + dstar_catalogue.insert({ Alphabet::Dstarc, Alphabet::Dc, Alphabet::gamma, Alphabet::null }, DstarType::Dstarc_Dcgamma); diff --git a/create_database/tuple_reader/RecoDTypeCatalogue.h b/create_database/tuple_reader/RecoDTypeCatalogue.h index b3a1a97..31ed87c 100644 --- a/create_database/tuple_reader/RecoDTypeCatalogue.h +++ b/create_database/tuple_reader/RecoDTypeCatalogue.h @@ -3,7 +3,7 @@ #include -#include "Trie.h" +#include class RecoDTypeCatalogue { @@ -51,8 +51,8 @@ class RecoDTypeCatalogue { void RegisterDecays(); Alphabet LundToAlphabet(int lund) const; - bdtaunu::Trie d_trie; - bdtaunu::Trie dstar_trie; + custom_cpp_utilities::trie d_catalogue; + custom_cpp_utilities::trie dstar_catalogue; }; diff --git a/create_database/tuple_reader/Trie.h b/create_database/tuple_reader/Trie.h deleted file mode 100644 index f3700ff..0000000 --- a/create_database/tuple_reader/Trie.h +++ /dev/null @@ -1,97 +0,0 @@ -#ifndef _BDTAUNU_TRIE_H_ -#define _BDTAUNU_TRIE_H_ - -#include -#include -#include - -namespace bdtaunu { - -template -class Trie { - - private: - struct node { - alphaT alpha; - valueT value; - std::vector links; - - node() : alpha(alphaT()), value(valueT()) {}; - node(alphaT a, valueT v = valueNull) : alpha(a), value(v) {}; - ~node() { for (auto l : links) delete l; } - }; - - node *root; - node *CopyNode(const node*); - - public: - Trie() { root = new node; } - ~Trie() { delete root; } - Trie(const Trie &t) { root = CopyNode(t.root); } - Trie &operator=(const Trie&); - - void add_word(std::vector word, valueT value); - valueT search_word(std::vector word) const; -}; - - -template -typename Trie::node* - Trie::CopyNode(const node *t) { - node *n = new node(t->alpha, t->value); - for (auto l : t->links) (n->links).push_back(CopyNode(l)); - return n; -} - -template -Trie& -Trie::operator=(const Trie &target) { - if (this != &target) { - delete root; - root = CopyNode(target.root); - } - return *this; -} - - -template -void Trie::add_word( - std::vector word, valueT value) { - node *p = root; - for (auto alpha : word) { - auto e_it = find_if((p->links).begin(), (p->links).end(), - [alpha] (const node *n) { return (n->alpha == alpha); }); - - if (e_it == (p->links).end()) { - node *n = new node(alpha); - if (alpha == alphaNull) n->value = value; - (p->links).push_back(n); - p = n; - } else { - p = *e_it; - } - } -} - - -template -valueT Trie::search_word( - std::vector word) const { - node *p = root; - for (auto alpha : word) { - auto e_it = find_if((p->links).begin(), (p->links).end(), - [alpha] (const node *n) { return (n->alpha == alpha); }); - if (e_it == (p->links.end())) return valueNull; - p = *e_it; - } - return p->value; -} - -} - -#endif diff --git a/create_database/tuple_reader/tests/Makefile b/create_database/tuple_reader/tests/Makefile index 588c40d..ebd3d65 100644 --- a/create_database/tuple_reader/tests/Makefile +++ b/create_database/tuple_reader/tests/Makefile @@ -21,6 +21,10 @@ TUPLE_READER_LIB_PATH = ../lib INCFLAGS += -I $(TUPLE_READER_INC_PATH) LDFLAGS += -L $(TUPLE_READER_LIB_PATH) $(TUPLE_READER_LIBNAME) +# custom cpp utilities +CUSTOM_CPP_UTIL_ROOT = /Users/dchao/bdtaunu/v4/custom_cpp_utilities +INCFLAGS += -I$(CUSTOM_CPP_UTIL_ROOT) + # cern root INCFLAGS += $(shell root-config --cflags) LDFLAGS += $(shell root-config --libs)