Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:18

0001 #ifndef CondFormats_L1TObjects_L1TriggerKeyExt_h
0002 #define CondFormats_L1TObjects_L1TriggerKeyExt_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 L1TriggerKeyExt {
0024 public:
0025   typedef std::map<std::string, std::string> RecordToKey;
0026 
0027   enum L1Subsystems { kuGT, kuGMT, kCALO, kEMTF, kOMTF, kBMTF, kTWINMUX, 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   L1TriggerKeyExt() {
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     std::map<int, std::string>::const_iterator key = m_subsystemKeys.find(subsystem);
0073     return key == m_subsystemKeys.end() || key->second == kNullKey ? kEmptyKey : key->second;
0074   }
0075 
0076   // NB: null keys are represented by kNullKey, not by an empty string
0077   const RecordToKey& recordToKeyMap() const { return m_recordToKey; }
0078 
0079 protected:
0080   /* Mapping from records and types to tokens.
0081      * I as unvable to make type std::map<std::pair<std::string, std::string>, std::string> persistent
0082      * so record and type are concatanated with @ sign and resulting string is used as a key.
0083      */
0084 
0085   // wsun 03/2008: instead of tokens, store the configuration keys instead.
0086   /*     typedef std::map<std::string, std::string> RecordsToToken; */
0087   /*     RecordsToToken recordsToToken; */
0088   RecordToKey m_recordToKey;
0089 
0090   // wsun 03/2008: add data member for TSC key
0091   std::string m_tscKey;
0092   std::map<int, std::string> m_subsystemKeys;
0093 
0094   COND_SERIALIZABLE;
0095 };
0096 
0097 #endif