Record

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
#ifndef DataFormats_FWLite_Record_h
#define DataFormats_FWLite_Record_h
// -*- C++ -*-
//
// Package:     FWLite
// Class  :     Record
//
/**\class Record Record.h DataFormats/FWLite/interface/Record.h

 Description: Contains conditions data which are related by life-time (i.e. IOV)

 Usage:
    Records are obtained from the fwlite::EventSetup.  
    See DataFormats/FWLite/interface/EventSetup.h for full usage.

*/
//
// Original Author:
//         Created:  Thu Dec 10 15:58:15 CST 2009
//

// system include files
#include <map>
#include <string>
#include <typeinfo>
#include <vector>

// user include files
#include "DataFormats/FWLite/interface/IOVSyncValue.h"
#include "FWCore/Utilities/interface/TypeID.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

// forward declarations
class TTree;
class TBranch;
namespace edm {
  class EventID;
  class Timestamp;
}  // namespace edm

namespace cms {
  class Exception;
}

namespace fwlite {

  class Record {
  public:
    Record(const char* iName, TTree*);
    Record(const Record&) = delete;                   // stop default
    const Record& operator=(const Record&) = delete;  // stop default

    virtual ~Record();

    // ---------- const member functions ---------------------
    const std::string& name() const;

    template <typename HANDLE>
    bool get(HANDLE&, const char* iLabel = "") const;

    const IOVSyncValue& startSyncValue() const;
    const IOVSyncValue& endSyncValue() const;

    std::vector<std::pair<std::string, std::string>> typeAndLabelOfAvailableData() const;
    // ---------- static member functions --------------------

    // ---------- member functions ---------------------------
    void syncTo(const edm::EventID&, const edm::Timestamp&);

  private:
    cms::Exception* get(const edm::TypeID&, const char* iLabel, const void*&) const;
    void resetCaches();
    // ---------- member data --------------------------------
    std::string m_name;
    TTree* m_tree;
    std::map<IOVSyncValue, unsigned int> m_startIOVtoEntry;
    long m_entry;
    IOVSyncValue m_start;
    IOVSyncValue m_end;

    //This class is not inteded to be used across different threads
    CMS_SA_ALLOW mutable std::map<std::pair<edm::TypeID, std::string>, std::pair<TBranch*, void*>> m_branches;
  };

  template <typename HANDLE>
  bool Record::get(HANDLE& iHandle, const char* iLabel) const {
    const void* value = nullptr;
    cms::Exception* e = get(edm::TypeID(iHandle.typeInfo()), iLabel, value);
    if (nullptr == e) {
      iHandle = HANDLE(value);
    } else {
      iHandle = HANDLE(e);
    }
    return nullptr == e;
  }

}  // namespace fwlite

#endif