00001 #ifndef DataFormats_Provenance_ProductID_h 00002 #define DataFormats_Provenance_ProductID_h 00003 00004 /*---------------------------------------------------------------------- 00005 00006 ProductID: A unique identifier for each EDProduct within a process. 00007 Used only in Ref, Ptr, and similar classes. 00008 00009 The high order 16 bits is the process index, identifying the process 00010 in which the product was created. Exception: An index of 0 means that 00011 the product was created prior to the new format (i.e. prior to CMSSW_3_0_0. 00012 00013 The low order 16 bits is the product index, identifying the product that 00014 in which the product was created. An index of zero means no product. 00015 00016 00017 The 00018 00019 ----------------------------------------------------------------------*/ 00020 00021 #include <iosfwd> 00022 00023 namespace edm { 00024 00025 typedef unsigned short ProcessIndex; 00026 typedef unsigned short ProductIndex; 00027 class ProductID { 00028 public: 00029 ProductID() : processIndex_(0), 00030 productIndex_(0) {} 00031 explicit 00032 ProductID(ProductIndex prodIndex) : processIndex_(0), productIndex_(prodIndex) {} 00033 ProductID(ProcessIndex procIndex, ProductIndex prodIndex) : 00034 processIndex_(procIndex), productIndex_(prodIndex) {} 00035 bool isValid() const {return productIndex_ != 0;} 00036 ProcessIndex processIndex() const {return processIndex_;} 00037 ProcessIndex productIndex() const {return productIndex_;} 00038 ProductIndex id() const {return productIndex_;} // backward compatibility 00039 void reset() {processIndex_ = productIndex_ = 0;} 00040 00041 void swap(ProductID& other); 00042 00043 private: 00044 ProcessIndex processIndex_; 00045 ProductIndex productIndex_; 00046 }; 00047 00048 inline 00049 void swap(ProductID& a, ProductID& b) { 00050 a.swap(b); 00051 } 00052 00053 inline 00054 bool operator==(ProductID const& lh, ProductID const& rh) { 00055 return lh.processIndex() == rh.processIndex() && lh.productIndex() == rh.productIndex(); 00056 } 00057 inline 00058 bool operator!=(ProductID const& lh, ProductID const& rh) { 00059 return !(lh == rh); 00060 } 00061 00062 bool operator<(ProductID const& lh, ProductID const& rh); 00063 00064 std::ostream& 00065 operator<<(std::ostream& os, ProductID const& id); 00066 } 00067 #endif