Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:21

0001 #ifndef CondFormats_L1TObjects_L1TriggerKey_h
0002 #define CondFormats_L1TObjects_L1TriggerKey_h
0003 
0004 #include "CondFormats/Serialization/interface/Serializable.h"
0005 
0006 #include <string>
0007 #include <map>
0008 
0009 /* L1 key used to load all other configuration data from offline db.
0010  * This class is just a proxy to the real data. It will contain mapping from data and record
0011  * pair to the payload token that could be used to read data. So the use case could be as follows:
0012  *   1. User read L1TriggerKey for given Tag and IOV pair.
0013  *   2. For each record and type that user whant to load, it ask method get for the payload.
0014  *   3. Reads the data with payloads extracted from step 2.
0015  *
0016  * It is not adviced for user to use this class and direct Pool DB manipulation. One should use
0017  * DataReader and DataWriter classes.
0018  *
0019  * The good point to note is that IOV of all L1 trigger condfiguration is controled bay IOV of L1TriggeKey.
0020  * If new configuration has to be created - new L1TriggerKey has to be saved/loaded. More then one key can use
0021  * the same paylaod token. This would just mean that data pointed by this payload token has not changed.
0022  */
0023 class L1TriggerKey {
0024 public:
0025   typedef std::map<std::string, std::string> RecordToKey;
0026 
0027   enum L1Subsystems { kCSCTF, kDTTF, kRPC, kGMT, kRCT, kGCT, kGT, kTSP0, kNumberSubsystems };
0028 
0029   // Empty strings cannot be stored in the CondDB, so define a null key string.
0030   const static std::string kNullKey;
0031 
0032   const static std::string kEmptyKey;
0033 
0034   // Constructors
0035   L1TriggerKey() {
0036     for (int i = 0; i < kNumberSubsystems; ++i) {
0037       m_subsystemKeys[i] = kNullKey;
0038     }
0039   }
0040 
0041   /* Adds new record and type mapping to payload. If such exists, nothing happens */
0042   void add(const std::string& record, const std::string& type, const std::string& key) {
0043     m_recordToKey.insert(std::make_pair(record + "@" + type, key.empty() ? kNullKey : key));
0044   }
0045 
0046   void add(const RecordToKey& map) {
0047     for (RecordToKey::const_iterator itr = map.begin(); itr != map.end(); ++itr) {
0048       m_recordToKey.insert(std::make_pair(itr->first, itr->second.empty() ? kNullKey : itr->second));
0049     }
0050   }
0051 
0052   void setTSCKey(const std::string& tscKey) { m_tscKey = tscKey; }
0053 
0054   void setSubsystemKey(L1Subsystems subsystem, const std::string& key) {
0055     m_subsystemKeys[subsystem] = key.empty() ? kNullKey : key;
0056   }
0057 
0058   /* Gets payload key for record and type. If no such paylaod exists, emtpy string
0059      * is returned.
0060      */
0061   std::string get(const std::string& record, const std::string& type) const {
0062     RecordToKey::const_iterator it = m_recordToKey.find(record + "@" + type);
0063     if (it == m_recordToKey.end())
0064       return std::string();
0065     else
0066       return it->second == kNullKey ? kEmptyKey : it->second;
0067   }
0068 
0069   const std::string& tscKey() const { return m_tscKey; }
0070 
0071   const std::string& subsystemKey(L1Subsystems subsystem) const {
0072     return m_subsystemKeys[subsystem] == kNullKey ? kEmptyKey : m_subsystemKeys[subsystem];
0073   }
0074 
0075   // NB: null keys are represented by kNullKey, not by an empty string
0076   const RecordToKey& recordToKeyMap() const { return m_recordToKey; }
0077 
0078 protected:
0079   /* Mapping from records and types to tokens.
0080      * I as unvable to make type std::map<std::pair<std::string, std::string>, std::string> persistent
0081      * so record and type are concatanated with @ sign and resulting string is used as a key.
0082      */
0083 
0084   // wsun 03/2008: instead of tokens, store the configuration keys instead.
0085   /*     typedef std::map<std::string, std::string> RecordsToToken; */
0086   /*     RecordsToToken recordsToToken; */
0087   RecordToKey m_recordToKey;
0088 
0089   // wsun 03/2008: add data member for TSC key
0090   std::string m_tscKey;
0091   std::string m_subsystemKeys[kNumberSubsystems];
0092 
0093   COND_SERIALIZABLE;
0094 };
0095 
0096 #endif