CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/DataFormats/Provenance/interface/BranchDescription.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Provenance_BranchDescription_h
00002 #define DataFormats_Provenance_BranchDescription_h
00003 
00004 /*----------------------------------------------------------------------
00005 
00006 BranchDescription: The full description of a Branch.
00007 This description also applies to every product instance on the branch.
00008 
00009 ----------------------------------------------------------------------*/
00010 #include "DataFormats/Provenance/interface/BranchID.h"
00011 #include "DataFormats/Provenance/interface/BranchType.h"
00012 #include "DataFormats/Provenance/interface/ParameterSetID.h"
00013 #include "DataFormats/Provenance/interface/ProcessConfigurationID.h"
00014 #include "DataFormats/Provenance/interface/ProductID.h"
00015 #include "DataFormats/Provenance/interface/ProvenanceFwd.h"
00016 #include "FWCore/Utilities/interface/TypeID.h"
00017 #include "FWCore/Utilities/interface/TypeWithDict.h"
00018 
00019 #include <iosfwd>
00020 #include <map>
00021 #include <set>
00022 #include <string>
00023 
00024 /*
00025   BranchDescription
00026 
00027   definitions:
00028   The event-independent description of an EDProduct.
00029 
00030 */
00031 
00032 namespace edm {
00033   class WrapperInterfaceBase;
00034   class BranchDescription {
00035   public:
00036     static int const invalidSplitLevel = -1;
00037     static int const invalidBasketSize = 0;
00038     enum MatchMode { Strict = 0,
00039                      Permissive };
00040 
00041     BranchDescription();
00042 
00043     BranchDescription(BranchType const& branchType,
00044                       std::string const& moduleLabel,
00045                       std::string const& processName,
00046                       std::string const& className,
00047                       std::string const& friendlyClassName,
00048                       std::string const& productInstanceName,
00049                       std::string const& moduleName,
00050                       ParameterSetID const& parameterSetID,
00051                       TypeWithDict const& theTypeWithDict,
00052                       bool produced = true,
00053                       std::set<std::string> const& aliases = std::set<std::string>());
00054 
00055     BranchDescription(BranchDescription const& aliasForBranch,
00056                       std::string const& moduleLabelAlias,
00057                       std::string const& poruductInstanceAlias);
00058 
00059     ~BranchDescription() {}
00060 
00061     void init() const {
00062       initBranchName();
00063       initFromDictionary();
00064     }
00065 
00066     void initBranchName() const;
00067 
00068     void initFromDictionary() const;
00069 
00070     void write(std::ostream& os) const;
00071 
00072     void merge(BranchDescription const& other);
00073 
00074     std::string const& moduleLabel() const {return moduleLabel_;}
00075     std::string const& processName() const {return processName_;}
00076     BranchID const& branchID() const {return branchID_;}
00077     BranchID const& aliasForBranchID() const {return aliasForBranchID_;}
00078     bool isAlias() const {return aliasForBranchID_.isValid() && produced();}
00079     BranchID const& originalBranchID() const {return aliasForBranchID_.isValid() ? aliasForBranchID_ : branchID_;}
00080     std::string const& fullClassName() const {return fullClassName_;}
00081     std::string const& className() const {return fullClassName();}
00082     std::string const& friendlyClassName() const {return friendlyClassName_;}
00083     std::string const& productInstanceName() const {return productInstanceName_;}
00084     bool& produced() const {return transient_.produced_;}
00085     bool present() const {return !transient_.dropped_;}
00086     bool& dropped() const {return transient_.dropped_;}
00087     bool& onDemand() const {return transient_.onDemand_;}
00088     bool& transient() const {return transient_.transient_;}
00089     TypeWithDict& wrappedType() const {return transient_.wrappedType_;}
00090     TypeWithDict& unwrappedType() const {return transient_.unwrappedType_;}
00091     TypeID wrappedTypeID() const {return TypeID(transient_.wrappedType_.typeInfo());}
00092     TypeID unwrappedTypeID() const {return TypeID(transient_.unwrappedType_.typeInfo());}
00093     int& splitLevel() const {return transient_.splitLevel_;}
00094     int& basketSize() const {return transient_.basketSize_;}
00095 
00096     ParameterSetID const& parameterSetID() const {return transient_.parameterSetID_;}
00097     std::string const& moduleName() const {return transient_.moduleName_;}
00098 
00099     std::map<ProcessConfigurationID, ParameterSetID>& parameterSetIDs() const {
00100       return transient_.parameterSetIDs_;
00101     }
00102     std::map<ProcessConfigurationID, std::string>& moduleNames() const {
00103       return transient_.moduleNames_;
00104     }
00105     ParameterSetID const& psetID() const;
00106     bool isPsetIDUnique() const {return parameterSetIDs().size() == 1;}
00107     std::set<std::string> const& branchAliases() const {return branchAliases_;}
00108     std::set<std::string>& branchAliases() {return branchAliases_;}
00109     std::string& branchName() const {return transient_.branchName_;}
00110     BranchType const& branchType() const {return branchType_;}
00111     std::string& wrappedName() const {return transient_.wrappedName_;}
00112     WrapperInterfaceBase*& wrapperInterfaceBase() const {return transient_.wrapperInterfaceBase_;}
00113 
00114     WrapperInterfaceBase const* getInterface() const;
00115     void setDropped() const {dropped() = true;}
00116     void setOnDemand() const {onDemand() = true;}
00117     void updateFriendlyClassName();
00118 
00119     void initializeTransients() const {transient_.reset();}
00120 
00121     struct Transients {
00122       Transients();
00123 
00124       void reset();
00125 
00126       // The parameter set id of the producer.
00127       // This is set if and only if produced_ is true.
00128       ParameterSetID parameterSetID_;
00129 
00130       // The module name of the producer.
00131       // This is set if and only if produced_ is true.
00132       std::string moduleName_;
00133 
00134       // The branch name, which is currently derivable fron the other attributes.
00135       std::string branchName_;
00136 
00137       // The wrapped class name, which is currently derivable fron the other attributes.
00138       std::string wrappedName_;
00139 
00140       // Was this branch produced in this process rather than in a previous process
00141       bool produced_;
00142 
00143       // Was this branch produced in this current process and by unscheduled production
00144       // This item is set only in the framework, not by FWLite.
00145       bool onDemand_;
00146 
00147       // Has the branch been dropped from the product tree in this file
00148       // (or if this is a merged product registry, in the first file).
00149       // This item is set only in the framework, not by FWLite.
00150       bool dropped_;
00151 
00152       // ID's of process configurations for products on this branch
00153       //  with corresponding parameter set IDs,
00154       // This is initialized if and only if produced_ is false.
00155       mutable std::map<ProcessConfigurationID, ParameterSetID> parameterSetIDs_;
00156 
00157       // ID's of process configurations for products on this branch
00158       //  with corresponding module names
00159       // This is initialized if and only if produced_ is false.
00160       mutable std::map<ProcessConfigurationID, std::string> moduleNames_;
00161 
00162       // Is the class of the branch marked as transient
00163       // in the data dictionary
00164       bool transient_;
00165 
00166       // A TypeWithDict object for the wrapped object
00167       TypeWithDict wrappedType_;
00168 
00169       // A TypeWithDict object for the unwrapped object
00170       TypeWithDict unwrappedType_;
00171 
00172       // A pointer to a polymorphic object to obtain typed Wrapper.
00173       mutable WrapperInterfaceBase* wrapperInterfaceBase_;
00174 
00175       // The split level of the branch, as marked
00176       // in the data dictionary.
00177       int splitLevel_;
00178 
00179       // The basket size of the branch, as marked
00180       // in the data dictionary.
00181       int basketSize_;
00182     };
00183 
00184   private:
00185     void throwIfInvalid_() const;
00186 
00187     // What tree is the branch in?
00188     BranchType branchType_;
00189 
00190     // A human friendly string that uniquely identifies the EDProducer
00191     // and becomes part of the identity of a product that it produces
00192     std::string moduleLabel_;
00193 
00194     // the physical process that this program was part of (e.g. production)
00195     std::string processName_;
00196 
00197     // An ID uniquely identifying the branch
00198     mutable BranchID branchID_;
00199 
00200     // the full name of the type of product this is
00201     std::string fullClassName_;
00202 
00203     // a readable name of the type of product this is
00204     std::string friendlyClassName_;
00205 
00206     // a user-supplied name to distinguish multiple products of the same type
00207     // that are produced by the same producer
00208     std::string productInstanceName_;
00209 
00210     // The branch ROOT alias(es), which are settable by the user.
00211     std::set<std::string> branchAliases_;
00212 
00213     // If this branch *is* an EDAlias, this field is the BranchID
00214     // of the branch for which this branch is an alias.
00215     // If this branch is not an EDAlias, the normal case, this field is 0.
00216     mutable BranchID aliasForBranchID_;
00217 
00218     mutable Transients transient_;
00219   };
00220 
00221   inline
00222   std::ostream&
00223   operator<<(std::ostream& os, BranchDescription const& p) {
00224     p.write(os);
00225     return os;
00226   }
00227 
00228   bool operator<(BranchDescription const& a, BranchDescription const& b);
00229 
00230   bool operator==(BranchDescription const& a, BranchDescription const& b);
00231 
00232   bool combinable(BranchDescription const& a, BranchDescription const& b);
00233 
00234   std::string match(BranchDescription const& a,
00235         BranchDescription const& b,
00236         std::string const& fileName,
00237         BranchDescription::MatchMode m);
00238 }
00239 #endif