Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:09

0001 #ifndef DataFormats_FWLite_EventSetup_h
0002 #define DataFormats_FWLite_EventSetup_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWLite
0006 // Class  :     EventSetup
0007 //
0008 /**\class EventSetup EventSetup.h DataFormats/FWLite/interface/EventSetup.h
0009 
0010  Description: Provides access to conditions information from fwlite
0011 
0012  Usage:
0013     This class provides a friendly interface for accessing conditions information
0014     which have been stored into a ROOT TFile.
0015     
0016     As in the full framework, conditions data are collected in the EventSetup.  The
0017     EventSetup holds 'Records' where each 'Record' holds data where all the data
0018     in one 'Record' is valid for the same period of time (referred to as an 
0019     'Interval of Validity' or IOV for short).
0020     
0021     The normal usage of this class is as follows
0022     
0023     TFile condFile("conditions.root");
0024     
0025     fwlite::EventSetup es(&condFile);
0026     
0027     fwlite::RecordID fooID = es.recordID("FooRecord");
0028     
0029     for(...) {  //looping over some event data
0030        //eventID and timestamp are obtained from the event
0031        es.syncTo(eventID, timestamp);
0032        
0033        fwlite::ESHandle<Foo> fooHandle;
0034        es.get(fooID).get(fooHandle);
0035        
0036        //now access the info in Foo
0037       std::cout << fooHandle->value()<<std::endl;
0038     }
0039 
0040     NOTE: This class is not safe to use across threads
0041 */
0042 //
0043 // Original Author:
0044 //         Created:  Thu Dec 10 15:57:46 CST 2009
0045 //
0046 
0047 // system include files
0048 #include <vector>
0049 #include <string>
0050 
0051 // user include files
0052 #include "DataFormats/Provenance/interface/EventID.h"
0053 #include "DataFormats/Provenance/interface/Timestamp.h"
0054 #include "FWCore/Utilities/interface/propagate_const.h"
0055 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0056 
0057 // forward declarations
0058 class TFile;
0059 
0060 namespace edm {
0061   class EventBase;
0062 }
0063 
0064 namespace fwlite {
0065   class Record;
0066   typedef unsigned int RecordID;
0067 
0068   class EventSetup {
0069   public:
0070     EventSetup(TFile*);
0071 
0072     EventSetup(const EventSetup&) = delete;  // stop default
0073 
0074     const EventSetup& operator=(const EventSetup&) = delete;  // stop default
0075 
0076     virtual ~EventSetup();
0077 
0078     // ---------- const member functions ---------------------
0079     const Record& get(const RecordID&) const;
0080 
0081     /**Returns the lookup id of the record whose name is iRecordName.  The returned id
0082       is only valid for the instance of an EventSetup object to which the recordID call was made.
0083       If you later create a new EventSetup instance even for the same file the RecordIDs can be different.
0084       */
0085     RecordID recordID(const char* iRecordName) const;
0086 
0087     /**Returns true if a record with the name iRecordName is available in the file
0088       */
0089     bool exists(const char* iRecordName) const;
0090 
0091     std::vector<std::string> namesOfAvailableRecords() const;
0092     // ---------- static member functions --------------------
0093 
0094     // ---------- member functions ---------------------------
0095     //void syncTo(unsigned long iRun, unsigned long iLumi);
0096     //void syncTo(const edm::EventID&);
0097 
0098     /** Ensures that all Records will access the appropriate data for this instant in time
0099       */
0100     void syncTo(const edm::EventID&, const edm::Timestamp&);
0101 
0102     //void autoSyncTo(const edm::EventBase&);
0103 
0104   private:
0105     // ---------- member data --------------------------------
0106     edm::EventID m_syncedEvent;
0107     edm::Timestamp m_syncedTimestamp;
0108 
0109     //This class is not inteded to be used across different threads
0110     CMS_SA_ALLOW mutable TFile* m_file;
0111 
0112     CMS_SA_ALLOW mutable std::vector<Record*> m_records;
0113   };
0114 }  // namespace fwlite
0115 
0116 #endif