#ifndef TMidasBankProxyRegistry_hxx_seen #define TMidasBankProxyRegistry_hxx_seen #include #include #include "IMidasBankProxy.hxx" namespace COMET { class IMidasBankProxyRegistry; } /// ACKNOWLEDGEMENTS: The IMidasBankProxyRegistry and the /// IMidasBankProxy objects it /// registers are based on the MINOS classes /// RawBlockRegistry and RawBlockProxy. /// /// This singleton class holds a registry of proxies that are /// subclassed from IMidasBankProxy and that between them are capable /// of creating all currently active raw (DAQ) TXxxBank classes. All /// MIDAS banks have 4 character names and for every MIDAS bank name /// there is a corresponding TXxxBank but the mapping is not 1:1. /// Instead a family of bank names that match the bank mask map to a /// single class. A bank mask is constructed by specifying the /// characters in at least 2 locations in the name and leaving the /// others as '_' which denotes a wildcard. /// /// So the bank mask E_D_ would match the bank name e.g. E3D0 /// /// The system for creating the TXxxBankProxy class code and /// registering objects of each class with this registry requires that the /// the implementation file of every TXxxBank class invokes the macro /// REGISTER_MIDAS_BANK and supplies the raw data class and the family mask /// for example /// /// REGISTER_MIDAS_BANK(TRawEcalBlock,E_D_) /// /// This macro:- ///
    ///
  1. Generates the code for class TXxxBankProxy. /// On instantiation objects of the class register themselves with /// this registry. /// ///
  2. Generates a single file static object of the TXxxBankProxy /// class. ///
/// Creation of a static objects exploits the fact that all such static /// objects are created by the loader before running the main program. The /// net effect is that by simply including the macro in every TXxxBank /// implementation will define the associated proxy class, create a single /// instance of that class and register it with the central /// TMidasBankRegistry where it can then be used to create appropriate /// TXxxBank as required. class COMET::IMidasBankProxyRegistry { public: virtual ~IMidasBankProxyRegistry(); /// Access to the singleton registry. static COMET::IMidasBankProxyRegistry& Instance(); /// Register a new proxy void Register(IMidasBankProxy *midasBankProxy); /// Return the number of proxies currently being managed Int_t GetNumProxies() const { return fMidasBankProxyTable.size(); } /// Return the proxy (or NULL if none) that matches the supplied MIDAS bank name COMET::IMidasBankProxy *LookUp(const std::string midasBankName) const; /// Display the contents of the registry void Print(); private: /// Singleton: Private ctor. IMidasBankProxyRegistry(); IMidasBankProxyRegistry(const IMidasBankProxyRegistry&); IMidasBankProxyRegistry& operator=(const IMidasBankProxyRegistry&); /// Singleton: pointer to instance. static IMidasBankProxyRegistry *fInstance; /// The registry of proxies std::list fMidasBankProxyTable; ClassDef(IMidasBankProxyRegistry,1) }; //////////////////////////////////////////////////////////////////////// // // Define a macro to register banks // //////////////////////////////////////////////////////////////////////// #define REGISTER_MIDAS_BANK(CLASS, MASK) \ static class CLASS##Proxy : public COMET::IMidasBankProxy { \ public: \ CLASS##Proxy() : \ COMET::IMidasBankProxy(#CLASS,#MASK) { \ COMET::IMidasBankProxyRegistry::Instance().Register(this); \ } \ COMET::IMidasBank *CreateMidasBank(const ULong64_t *bank = NULL, \ const char* title = #CLASS) const { \ COMET::IMidasBank *rdb = new COMET::CLASS(bank,title); \ return rdb; \ } \ } gs_##CLASS##Proxy_obj; #endif