// // File: FdConfig.hh // // Purpose: Header file for FdConfig.cc, // declaration of the class FdConfig // // $Id: FdConfig.hh 11973 2011-01-28 14:33:23Z mathes $ // /** @file FdConfig.hh * Declaration of the class FdConfig. * @author H.-J. Mathes, FzK */ #ifndef _FdUtil_FdConfig_hh_ #define _FdUtil_FdConfig_hh_ #include #ifndef NO_VERSION # include #endif // NO_VERSION #include #include namespace FdUtil { /** Class to inquire Mirror and Eye Id. The constructor (and initialisation) works in the following way: @li initially it is assumed that the soft is not running on a EyePC or a MirrorPC. The ids are set to 1 (their default values). @li the hostname (via gethostname()) is checked to find out if it is a MirrorPC and to inquire its number @li using gethostent() the returned fully qualified hostname is parsed for the Mirror id and the Eye id assuming that (case insensitive) the Mirrors have names like MirrorPC# and are residing in a network Eye#-auger.org. The Mirror id is only searched for if it has not been determined before. @li Additionally the Eye id is determined from parsing the /etc/networks entries via the getnetent() system function. @li If this could not be resolved, the default ids 1 are assumed both for the Eye and for the Mirror. Important remark:
If the software is not running on any AUGER DAQ host, the defaults EyeId=1 and MirrorId=1 are assumed and returned from all relevant methods. This can be steered by the environment variables $FD_EYE_ID and $FD_MIRROR_ID. If they are set, their values will overwrite the coded defaults.
A special case happens when the software runs on any of the test installation system (ipeauger1 at the moment, hpepec29 in the past). In this special case EyeId=1 is assumed, too. */ class FdConfig : public FdUtil::Singleton { friend class FdUtil::Singleton; friend const char* FdUtil::GetFullQualifiedHostname(); public: /** Enumeration with the IDs used for the various sites. */ enum { kID_LosLeones = 1, kID_LosMorados = 2, kID_LomaAmarilla = 3, kID_Coihueco = 4, kID_HEAT = 5, kID_Karlsruhe = 7 }; /** @return the current Eye id (range 1..kFD_NEYES). */ unsigned int GetEyeId() { return fEyeId; } /** @return the current Mirror id (range 1..6). */ unsigned int GetMirrorId() { return fMirrorId; } /** @return the composite (Eye x Mirror Id) mirror number. */ Fd::MirrorNumber GetMirrorNumber() { return &fMirrorNumber; } /** Get the name of the telescope site. */ static const char *GetEyeNameById(unsigned int,bool nospaces=false); /** @return true, if this program is running on an EyePC. */ bool IsEyePC() { return fIsEye; } /** @return true if this program is running on a MirrorPC. */ bool IsMirrorPC() { return fIsMirror; } /** Set the print level (level of verbosity) for all instances of * this class. */ static void SetPrintLevel(int level=1) { fgPrintLevel = level; } protected: /** Determine the Eye id from the passed string (either hostname, fully * qalified hostname or network name. */ void DetermineEyeId(const char *); /** Determine the Mirror id from the passed string (either hostname of fully * qualified hostname). */ void DetermineMirrorId(const char *); private: /** Constructor (private) for class FdConfig. */ FdConfig(); /** Destructor of the class FdConfig. */ virtual ~FdConfig() { } std::string fFQHostname; unsigned int fDefaultEyeId; unsigned int fDefaultMirrorId; unsigned int fEyeId; unsigned int fMirrorId; Fd::MirrorNumberRec fMirrorNumber; bool fIsEye; bool fIsMirror; static int fgPrintLevel; }; /** Function to inquire the current Eye Id. */ inline unsigned int GetEyeId() { return FdUtil::FdConfig::GetInstance().GetEyeId(); } /** Function to get the name of the current eye. * * @param nospaces if set to true, all blanks are removed from the returned * string. * * @return the eye name, this must not be deleted ! * * This is the Eye id to Eye name mapping: * 1 = Los Leones * 2 = Los Morados * 3 = Loma Amarilla * 4 = Coihueco * 5 = HEAT * 7 = Karlsruhe */ const char *GetEyeName(bool nospaces = false); /** Function to get the name of the eye with the passed id. */ const char *GetEyeName(unsigned int,bool nospaces = false); /** Function to inquire the current Mirror Id. */ inline unsigned int GetMirrorId() { return FdConfig::GetInstance().GetMirrorId(); } /** Function to inquire the current composite mirror number. */ inline Fd::MirrorNumber GetMirrorNumber() { return FdConfig::GetInstance().GetMirrorNumber(); } /** Return true if this program is running on an EyePC. */ inline bool IsEyePC() { return FdConfig::GetInstance().IsEyePC(); } /** Return true if this program is running on a MirrorPC. */ inline bool IsMirrorPC() { return FdConfig::GetInstance().IsMirrorPC(); } /** Get the fully qualified hostname, i.e. including the network name. */ inline const char* GetFullQualifiedHostname() { return FdConfig::GetInstance().fFQHostname.c_str(); } } // namespace FdUtil #endif // _FdUtil_FdConfig_hh_