#ifndef TDigitMananger_hxx_seen #define TDigitMananger_hxx_seen #include #include #include "EoaCore.hxx" #include "IDigit.hxx" #include "ICOMETEvent.hxx" #include "IDigitContainer.hxx" #include "IDigitProxy.hxx" #include "IHandle.hxx" namespace COMET { /// An exception from the digit manager. OA_EXCEPTION(EDigitManager, EDigit); /// A factory was registered more than once. OA_EXCEPTION(EMultipleDigitFact, EDigitManager); /// Attempting to cache digits without an event available OA_EXCEPTION(EDigitEventMissing, EDigitManager); class IDigitManager; class IDigitFactory; class IOADatabase; } /// A base class to provide a way to build digits from the MIDAS data accessed /// using oaRawEvent. The oaUnpack library will implement a digit factory /// for each class of data and register them with IDigitManager. The digit /// factory type is given by the name of the IDigitContainer that will be /// generated in the ICOMETEvent. class COMET::IDigitFactory { public: explicit IDigitFactory(std::string name); virtual ~IDigitFactory(); /// Return the name of the factory. There can only be one factory with a /// given name. The name of the factory will be used as the name of the /// IDigitContainer that is generated by the factory. std::string GetName(); /// Return a pointer to a new IDigitContainer. The name of the /// IDigitContainer will be set by the IDigitManager. If the factory /// fails for any reason, a NULL should be returned. virtual COMET::IDigitContainer* MakeDigits() = 0; private: /// The name of the factory. std::string fName; }; /// Manage the current set of IDigit objects and containers. This manager /// class is a singleton accessed through the IOADatabase class /// (TOADataBase::Digits() will return a reference). This is mostly an /// internal implementation class used to provide management to the /// IDigitProxy class and to provide a connection to the raw data access in /// oaRawEvent (using oaUnpack). This class will not be directly used by most /// people. The IDigitManager is owned by IOADatabase. class COMET::IDigitManager { friend class COMET::IOADatabase; friend class COMET::IDigitProxy; public: ~IDigitManager(); /// Register a IDigitFactory class. The IDigitFactory classes are used to /// fill the cache of digits. The will be registered by oaUnpack, and /// called as required by oaEvent to fill the digit cache. This method /// takes ownership of the digit factory. void RegisterFactory(COMET::IDigitFactory* factory); /// Save digits in the event as a temporary bank (default). void TemporaryDigits(void) {fPersistentDigits=false;} /// Save digits in the event as a persistent bank (and increase the event /// size). Saving persistent digits increases the size of the output file /// by a large factor (between 2 and 6 times larger), and should only be /// used as a diagnostic tool. void PersistentDigits(void) {fPersistentDigits=true;} /// @{A Low level interface used to implement ICOMETEvent::GetDigits(). /// The higher level digit interface, ICOMETEvent::GetDigits() should be /// prefered. This gets the digit container for a type of data ("fgd", /// "p0d", &c). If the digits are available, this will return a valid /// handle to the container, otherwise it will return a "NULL" handle. /// This first checks to see if the requested digits have already been /// unpacked using the available digit factories, and then if necessary, /// will use the factories to find the digits. By default, the cached /// digits are saved as temporary banks, but can be made persistent using /// IOADatabase::Get().Digits().PersistentDigits(). COMET::IHandle CacheDigits(std::string type); COMET::IHandle CacheDigits(COMET::ICOMETEvent& event, std::string type); /// @} /// Check if a IDigitFactory is available for a particular type of digits. bool FactoryAvailable(std::string type) const; private: typedef std::map FactoryMap; /// Construct a new IDigitManager. This is private since it should only /// be constructed by the friend class IOADatabase. IDigitManager(); /// Make the copy constructor private. IDigitManager(const IDigitManager&) {MayNotUse("Copy Constructor");} /// Translate a proxy into a digit pointer. Note that this has strange /// ownership rules since the ownership of the IDigit is not passed to the /// caller. IDigit* GetDigit(const IDigitProxy& proxy); /// Get the digit container for a proxy. This will return a handle to the /// IDigitContainer which will be valid if the digits are found. This is /// used to implement IDigitManager::GetDigit(). Users should use /// IDigitManager::CacheDigits() to access the IDigitContainer objects. COMET::IHandle FindDigits(const IDigitProxy& proxy); /// A map of factories available to build the cache of digits. FactoryMap fFactories; /// Flag that digits are kept as persistent banks. bool fPersistentDigits; }; #endif