/search.css" rel="stylesheet" type="text/css"/> /search.js">
00001 00014 #ifndef DYBCHANNELQUALITYSVC_H 00015 #define DYBCHANNELQUALITYSVC_H 00016 00017 #include "ChOr.h" 00018 00019 #include "DybKernel/IChannelQualitySvc.h" 00020 #include "Context/ServiceMode.h" 00021 #include "DatabaseInterface/DbiResultKey.h" 00022 #include "Conventions/Electronics.h" 00023 #include "Conventions/HighVoltage.h" 00024 00025 #include "GaudiKernel/Service.h" 00026 00027 #include <map> 00028 00029 00036 class DybChanQualCache { 00037 public: 00038 // Make a cache based on the non-time components of the 00039 // ServiceMode and prime using them plus the timestamp. 00040 DybChanQualCache(const ServiceMode& sm, bool usehv, bool usenoisy); 00041 00042 // Maybe update cache based on a low level DBI update. Return 00043 // true if an update happened 00044 bool update(const TimeStamp& ts); 00045 00046 00047 // Return true if the cache is not fully populated 00048 bool empty(); 00049 00050 // Access cached data by FeeChannelID 00051 typedef std::map<DayaBay::FeeChannelId, float> HvValMap_t; 00052 HvValMap_t& setted_hv() { return m_hvset; } 00053 HvValMap_t& getted_hv() { return m_hvget; } 00054 HvValMap_t& noise() { return m_noise;} 00055 00056 // Return if the cache is inside [start, stop) 00057 bool covers(const TimeStamp& start, const TimeStamp& stop); 00058 00059 // Access map of channel to its quality (true is "good") 00060 typedef std::map<DayaBay::FeeChannelId, bool> DqCpMap_t; 00061 DqCpMap_t& channel_quality() { return m_dqcp; } 00062 00063 00064 00065 private: 00066 00067 void check_hvchid(DayaBay::HvChannelId hvch, const std::string& who); 00068 int feechid(int hvb, int hvc); 00069 bool update_hvloc(Context& ctx); 00070 bool update_hvfee(Context& ctx); 00071 bool update_hvset(Context& ctx, bool force); 00072 bool update_hvget(Context& ctx, bool force); 00073 00074 bool update_cmap(Context& ctx); 00075 bool update_dqcp(Context& ctx); 00076 00077 bool update_noise(Context& ctx, bool force); 00078 00079 // resolve HV channel to FEE channel IDs 00080 DayaBay::FeeChannelId hv2fee(DayaBay::HvChannelId hvch); 00081 00082 private: 00083 00084 ServiceMode m_timelessSM; 00085 00086 TimeStamp m_lastTS; 00087 00088 // The cached items 00089 mutable HvValMap_t m_hvset; 00090 mutable HvValMap_t m_hvget; 00091 mutable HvValMap_t m_noise; 00092 mutable DqCpMap_t m_dqcp; 00093 00094 // cache channel ordering for use by DqCp. 00095 typedef std::list<int> ChList_t; 00096 mutable ChList_t m_chlist; 00097 00098 DbiResultKey* m_hvlocKey; 00099 DbiResultKey* m_hvfeeKey; 00100 DbiResultKey* m_hvgetKey; 00101 DbiResultKey* m_hvsetKey; 00102 DbiResultKey* m_dqcpKey; // DqChannelPacked 00103 DbiResultKey* m_cmapKey; // ChannelMap 00104 00105 // cache the location ID to HV channel id 00106 typedef std::map< std::string, DayaBay::HvChannelId > Loc2hv_t; 00107 Loc2hv_t m_loc2hv; 00108 00109 // cache hv channel ID to fee channel id 00110 typedef std::map< DayaBay::HvChannelId, DayaBay::FeeChannelId > Hv2fee_t; 00111 Hv2fee_t m_hv2fee; 00112 00113 00114 bool m_useHV, m_useNoisy; 00115 }; 00116 00120 class DybChannelQuality : public IChannelQuality { 00121 00122 public: // Used by the service 00123 00124 // FIXME: use system of units!? 00125 DybChannelQuality(DybChanQualCache* cdc, 00126 std::vector<Dyb::ChannelOverride>& chor, 00127 float delta_hv = 15 /*V*/, 00128 bool usehv=false, bool usenoisy=false); 00129 virtual ~DybChannelQuality(); 00130 00131 DybChanQualCache& cache() { return *m_cdc; } 00132 00133 public: // IChannelQuality interface 00134 00136 virtual bool good(DayaBay::FeeChannelId chid) const; 00137 00139 virtual float hvRequested(DayaBay::FeeChannelId chid) const; 00140 00142 virtual float hvMeasured(DayaBay::FeeChannelId chid) const; 00143 00145 virtual float noise(DayaBay::FeeChannelId chid) const; 00146 00148 virtual IChannelQuality::ChannelSet_t channels() const; 00149 00150 virtual int goodDqCp(DayaBay::FeeChannelId chid) const; 00151 00152 private: 00153 00154 mutable DybChanQualCache* m_cdc; 00155 float m_deltaHV; 00156 bool m_useHV, m_useNoisy; 00157 std::vector<Dyb::ChannelOverride> m_chor; 00158 }; 00159 00160 00161 00162 class DybChannelQualitySvc : public Service, 00163 virtual public IChannelQualitySvc 00164 { 00165 public: 00166 DybChannelQualitySvc(const std::string& name, ISvcLocator *svc); 00167 virtual ~DybChannelQualitySvc(); 00168 00169 00170 // service interface 00171 virtual StatusCode initialize(); 00172 00173 // IChannelQualitySvc interface 00174 const IChannelQuality* channelQuality(const ServiceMode& sm); 00175 00176 00177 // Service interface 00178 StatusCode queryInterface(const InterfaceID& riid, void** ppvInterface); 00179 00180 private: 00181 00182 // Lookup in the cache using a timeless SM based on the given one 00183 const IChannelQuality* get(const ServiceMode& sm); 00184 00185 // evil company 00186 void clearChannel(const ServiceMode& timeless_sm); 00187 00188 private: 00189 00190 // Keep a timeless but per ServiceMode cache of the various 00191 // collections in order to minimize the chance that we will screw 00192 // over the user. We hold on to the cache through a 00193 // DybChannelQuality view object 00194 typedef std::map<ServiceMode,DybChannelQuality*> CacheMap_t; 00195 mutable CacheMap_t m_cache; 00196 00197 // Trivial caching 00198 mutable ServiceMode m_lastSM; 00199 00203 bool m_useHV; 00204 00209 bool m_useNoisy; 00210 00229 std::vector<std::string> m_chor_strings; 00230 std::vector<Dyb::ChannelOverride> m_chor; 00231 }; 00232 00233 00234 #endif // DYBCHANNELQUALITYSVC_H