Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DataFormats_FWLite_InternalDataKey_h
0002 #define DataFormats_FWLite_InternalDataKey_h
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:     FWLite
0007 // Class  :     internal::DataKey
0008 //
0009 /**\class DataKey InternalDataKey.h DataFormats/FWLite/interface/InternalDataKey.h
0010 
0011    Description: Split from fwlite::Event to be reused in Event, LuminosityBlock, Run
0012 
0013    Usage:
0014    <usage>
0015 
0016 */
0017 //
0018 // Original Author:  Eric Vaandering
0019 //         Created:  Jan 29 09:01:20 CDT 2009
0020 //
0021 
0022 #include "FWCore/Reflection/interface/ObjectWithDict.h"
0023 #include "FWCore/Utilities/interface/TypeID.h"
0024 #include "FWCore/Utilities/interface/propagate_const.h"
0025 
0026 #include "TBranch.h"
0027 
0028 #include <cstring>
0029 
0030 namespace edm {
0031   class WrapperBase;
0032 }
0033 
0034 namespace fwlite {
0035   namespace internal {
0036     class DataKey {
0037     public:
0038       //NOTE: Do not take ownership of strings.  This is done to avoid
0039       // doing 'new's and string copies when we just want to lookup the data
0040       // This means something else is responsible for the pointers remaining
0041       // valid for the time for which the pointers are still in use
0042       DataKey(const edm::TypeID& iType, char const* iModule, char const* iProduct, char const* iProcess)
0043           : type_(iType),
0044             module_(iModule != nullptr ? iModule : kEmpty()),
0045             product_(iProduct != nullptr ? iProduct : kEmpty()),
0046             process_(iProcess != nullptr ? iProcess : kEmpty()) {}
0047 
0048       ~DataKey() {}
0049 
0050       bool operator<(const DataKey& iRHS) const {
0051         if (type_ < iRHS.type_) {
0052           return true;
0053         }
0054         if (iRHS.type_ < type_) {
0055           return false;
0056         }
0057         int comp = std::strcmp(module_, iRHS.module_);
0058         if (0 != comp) {
0059           return comp < 0;
0060         }
0061         comp = std::strcmp(product_, iRHS.product_);
0062         if (0 != comp) {
0063           return comp < 0;
0064         }
0065         comp = std::strcmp(process_, iRHS.process_);
0066         return comp < 0;
0067       }
0068       char const* kEmpty() const { return ""; }
0069       char const* module() const { return module_; }
0070       char const* product() const { return product_; }
0071       char const* process() const { return process_; }
0072       const edm::TypeID& typeID() const { return type_; }
0073 
0074     private:
0075       edm::TypeID type_;
0076       char const* module_;
0077       char const* product_;
0078       char const* process_;
0079     };
0080 
0081     struct Data {
0082       edm::propagate_const<TBranch*> branch_;
0083       Long64_t lastProduct_;
0084       edm::ObjectWithDict obj_;        // For wrapped object
0085       void* pObj_;                     // ROOT requires the address of the pointer be stable
0086       edm::WrapperBase const* pProd_;  // WrapperBase of the wrapped object
0087 
0088       ~Data() { obj_.destruct(true); }
0089     };
0090 
0091     class ProductGetter;
0092   }  // namespace internal
0093 
0094 }  // namespace fwlite
0095 
0096 #endif