CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/CondFormats/L1TObjects/interface/L1TriggerKey.h

Go to the documentation of this file.
00001 #ifndef CondFormats_L1TObjects_L1TriggerKey_h
00002 #define CondFormats_L1TObjects_L1TriggerKey_h
00003 
00004 #include <string>
00005 #include <map>
00006 
00007 /* L1 key used to load all other configuration data from offline db.
00008  * This class is just a proxy to the real data. It will contain mapping from data and record
00009  * pair to the payload token that could be used to read data. So the use case could be as follows:
00010  *   1. User read L1TriggerKey for given Tag and IOV pair.
00011  *   2. For each record and type that user whant to load, it ask method get for the payload.
00012  *   3. Reads the data with payloads extracted from step 2.
00013  *
00014  * It is not adviced for user to use this class and direct Pool DB manipulation. One should use
00015  * DataReader and DataWriter classes.
00016  *
00017  * The good point to note is that IOV of all L1 trigger condfiguration is controled bay IOV of L1TriggeKey.
00018  * If new configuration has to be created - new L1TriggerKey has to be saved/loaded. More then one key can use
00019  * the same paylaod token. This would just mean that data pointed by this payload token has not changed.
00020  */
00021 class L1TriggerKey
00022 {
00023 public:
00024     typedef std::map<std::string, std::string> RecordToKey;
00025 
00026     enum L1Subsystems
00027       {
00028         kCSCTF,
00029         kDTTF,
00030         kRPC,
00031         kGMT,
00032         kRCT,
00033         kGCT,
00034         kGT,
00035         kTSP0,
00036         kNumberSubsystems
00037       } ;
00038 
00039     // Empty strings cannot be stored in the CondDB, so define a null key string.
00040     static std::string kNullKey ;
00041 
00042     static std::string kEmptyKey ;
00043 
00044     // Constructors
00045     L1TriggerKey ()
00046       {
00047         for( int i = 0 ; i < kNumberSubsystems ; ++i )
00048           {
00049             m_subsystemKeys[ i ] = kNullKey ;
00050           }
00051       }
00052 
00053     /* Adds new record and type mapping to payload. If such exists, nothing happens */
00054     void add (const std::string & record, const std::string & type, const std::string & key)
00055     { m_recordToKey.insert (std::make_pair (record + "@" + type, key.empty() ? kNullKey : key)); }
00056 
00057     void add (const RecordToKey& map)
00058     {
00059       for( RecordToKey::const_iterator itr = map.begin() ;
00060            itr != map.end() ;
00061            ++itr )
00062         {
00063           m_recordToKey.insert( std::make_pair( itr->first, itr->second.empty() ? kNullKey : itr->second ) ) ;
00064         }
00065     }
00066 
00067     void setTSCKey( const std::string& tscKey )
00068     { m_tscKey = tscKey ; }
00069 
00070     void setSubsystemKey( L1Subsystems subsystem, const std::string& key )
00071     { m_subsystemKeys[ subsystem ] = key.empty() ? kNullKey : key ; }
00072 
00073     /* Gets payload key for record and type. If no such paylaod exists, emtpy string
00074      * is returned.
00075      */
00076     std::string get (const std::string & record, const std::string & type) const
00077     {
00078         RecordToKey::const_iterator it = m_recordToKey.find (record + "@" + type);
00079         if (it == m_recordToKey.end ())
00080             return std::string ();
00081         else
00082           return it->second == kNullKey ? kEmptyKey : it->second ;
00083     }
00084 
00085     const std::string& tscKey() const
00086       { return m_tscKey ; }
00087 
00088     const std::string& subsystemKey( L1Subsystems subsystem ) const
00089       { return m_subsystemKeys[ subsystem ] == kNullKey ? kEmptyKey : m_subsystemKeys[ subsystem ] ; }
00090 
00091     // NB: null keys are represented by kNullKey, not by an empty string
00092     const RecordToKey& recordToKeyMap() const
00093       { return m_recordToKey ; }
00094 
00095 protected:
00096     /* Mapping from records and types to tokens.
00097      * I as unvable to make type std::map<std::pair<std::string, std::string>, std::string> persistent
00098      * so record and type are concatanated with @ sign and resulting string is used as a key.
00099      */
00100 
00101   // wsun 03/2008: instead of tokens, store the configuration keys instead.
00102 /*     typedef std::map<std::string, std::string> RecordsToToken; */
00103 /*     RecordsToToken recordsToToken; */
00104     RecordToKey m_recordToKey;
00105 
00106 
00107     // wsun 03/2008: add data member for TSC key
00108     std::string m_tscKey ;
00109     std::string m_subsystemKeys[ kNumberSubsystems ] ;
00110 };
00111 
00112 #endif