/* * CrossSectionMgr.h * * Created on: Sep 13, 2019 * Author: Nuno Barros * * The logic with the cross sections is a bit convolved, so bear with * the explanation below: * * There are (at the moment), two cross section types (ES and IBD). * ES can have multiple instances (nue,nuebar,numu,numubar) at the same time. * Each of the type can have its own calculation strategy. * Since cross section objects are created when the generators are instanced, * it can happen that a cross section option is passed before a cross section object * exists. A race condition occurs and can lead to a failure. * * Some basic assumptions for the solution: * * - All instances of IBD have the same strategy. * - Each calculation is atomic (none of the cross section classes keep state machines). * * The ideal is that the very first use someone gives to a cross section, * a static instance is generated and is kept in a static manager so that * it can be retrieved as many times as needed. * * For that one needs a manager that is created at an early stage (for example within DU::Utility) * that is used to manage cross sections within RAT. That way, any time a cross section * option is passed, it will be passed through the manager which will ensure that an * appropriate object already exists. * This also means that instead of having a messenger attached to a given cross section * one will have a messenger attached to this manager that will then manage all the * cross sections * * - 11-Oct-2019 : Nuno Barros * - Initial revision * */ #ifndef SRC_UTIL_CROSSSECTIONMGR_HH_ #define SRC_UTIL_CROSSSECTIONMGR_HH_ #include #include #include class G4UImessenger; namespace RAT { class CrossSectionBase; class CrossSectionMgrMsgr; class ESCrossSec; class IBDCrossSec; class CrossSectionMgr { public: enum xs_type {ES,IBD}; inline static CrossSectionMgr* Get(); CrossSectionBase *GetCrossSection(xs_type t, const std::string reaction = ""); CrossSectionBase *GetCrossSection(const std::string name); // NB: the strategy is supposed to be the same for all instances of // a cross section calculation void SetStrategy(xs_type t, const short int strat); void SetStrategy(const std::string t, const short int strat); ESCrossSec *GetCrossSectionES(const std::string reaction = ""); IBDCrossSec *GetCrossSectionIBD(); void SetD(xs_type t,const std::string par, const double val); void SetD_ES(const std::string par, const double val) {SetD(ES,par,val);} void SetD_IBD(const std::string par, const double val) {SetD(IBD,par,val);} void SetI(xs_type t,const std::string par, const int val); void SetI_ES(const std::string par, const int val) {SetI(ES,par,val);} void SetI_IBD(const std::string par, const int val) {SetI(IBD,par,val);} void SetS(xs_type t,const std::string par, const std::string val); void SetS_ES(const std::string par, const std::string val) {SetS(ES,par,val);} void SetS_IBD(const std::string par, const std::string val) {SetS(IBD,par,val);} private: CrossSectionMgr(); virtual ~CrossSectionMgr(); // -- a map of vector with the names of each instance, separated by type static const std::map > fXsInstances; static std::map > init_map() { std::map > m; std::vector tmp1; tmp1.push_back("ibd"); m[IBD] = tmp1; std::vector tmp2; tmp2.push_back("es-nue"); tmp2.push_back("es-numu"); // NFB: Disabled for now. See comment in the .cc file // tmp2.push_back("es-nuebar"); // tmp2.push_back("es-numubar"); m[ES] = tmp2; return m; } static const std::string fESpref; G4UImessenger *fMessenger; std::map fXS; }; inline CrossSectionMgr* CrossSectionMgr::Get() { static CrossSectionMgr mgr; return &mgr; } } /* namespace RAT */ #endif /* SRC_UTIL_CROSSSECTIONMGR_HH_ */