Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-02 04:38:20

0001 #ifndef DataFormats_FWLite_Record_h
0002 #define DataFormats_FWLite_Record_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWLite
0006 // Class  :     Record
0007 //
0008 /**\class Record Record.h DataFormats/FWLite/interface/Record.h
0009 
0010  Description: Contains conditions data which are related by life-time (i.e. IOV)
0011 
0012  Usage:
0013     Records are obtained from the fwlite::EventSetup.  
0014     See DataFormats/FWLite/interface/EventSetup.h for full usage.
0015 
0016 */
0017 //
0018 // Original Author:
0019 //         Created:  Thu Dec 10 15:58:15 CST 2009
0020 //
0021 
0022 // system include files
0023 #include <map>
0024 #include <string>
0025 #include <typeinfo>
0026 #include <vector>
0027 
0028 // user include files
0029 #include "DataFormats/FWLite/interface/IOVSyncValue.h"
0030 #include "FWCore/Utilities/interface/TypeID.h"
0031 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0032 
0033 // forward declarations
0034 class TTree;
0035 class TBranch;
0036 namespace edm {
0037   class EventID;
0038   class Timestamp;
0039 }  // namespace edm
0040 
0041 namespace cms {
0042   class Exception;
0043 }
0044 
0045 namespace fwlite {
0046 
0047   class Record {
0048   public:
0049     Record(const char* iName, TTree*);
0050     Record(const Record&) = delete;                   // stop default
0051     const Record& operator=(const Record&) = delete;  // stop default
0052 
0053     virtual ~Record();
0054 
0055     // ---------- const member functions ---------------------
0056     const std::string& name() const;
0057 
0058     template <typename HANDLE>
0059     bool get(HANDLE&, const char* iLabel = "") const;
0060 
0061     const IOVSyncValue& startSyncValue() const;
0062     const IOVSyncValue& endSyncValue() const;
0063 
0064     std::vector<std::pair<std::string, std::string>> typeAndLabelOfAvailableData() const;
0065     // ---------- static member functions --------------------
0066 
0067     // ---------- member functions ---------------------------
0068     void syncTo(const edm::EventID&, const edm::Timestamp&);
0069 
0070   private:
0071     cms::Exception* get(const edm::TypeID&, const char* iLabel, const void*&) const;
0072     void resetCaches();
0073     // ---------- member data --------------------------------
0074     std::string m_name;
0075     TTree* m_tree;
0076     std::map<IOVSyncValue, unsigned int> m_startIOVtoEntry;
0077     long m_entry;
0078     IOVSyncValue m_start;
0079     IOVSyncValue m_end;
0080 
0081     //This class is not inteded to be used across different threads
0082     CMS_SA_ALLOW mutable std::map<std::pair<edm::TypeID, std::string>, std::pair<TBranch*, void*>> m_branches;
0083   };
0084 
0085   template <typename HANDLE>
0086   bool Record::get(HANDLE& iHandle, const char* iLabel) const {
0087     const void* value = nullptr;
0088     cms::Exception* e = get(edm::TypeID(iHandle.typeInfo()), iLabel, value);
0089     if (nullptr == e) {
0090       iHandle = HANDLE(value);
0091     } else {
0092       iHandle = HANDLE(e);
0093     }
0094     return nullptr == e;
0095   }
0096 
0097 }  // namespace fwlite
0098 
0099 #endif