CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/FWCore/Framework/src/Group.cc

Go to the documentation of this file.
00001 /*----------------------------------------------------------------------
00002 ----------------------------------------------------------------------*/
00003 #include "FWCore/Framework/interface/Group.h"
00004 
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "FWCore/Utilities/interface/TypeID.h"
00007 
00008 #include <cassert>
00009 
00010 using Reflex::Type;
00011 using Reflex::TypeTemplate;
00012 
00013 namespace edm {
00014   Group::Group() {}
00015 
00016   Group::~Group() {}
00017   InputGroup::~InputGroup() {}
00018   ProducedGroup::~ProducedGroup() {}
00019   ScheduledGroup::~ScheduledGroup() {}
00020   UnscheduledGroup::~UnscheduledGroup() {}
00021   SourceGroup::~SourceGroup() {}
00022 
00023   void
00024   ProducedGroup::putProduct_(
00025         WrapperOwningHolder const& edp,
00026         ProductProvenance const& productProvenance) {
00027     if(product()) {
00028       throw Exception(errors::InsertFailure)
00029           << "Attempt to insert more than one product on branch " << productData().branchDescription()->branchName() << "\n";
00030     }
00031     assert(branchDescription().produced());
00032     assert(edp.isValid());
00033     assert(!provenance()->productProvenanceValid());
00034     assert(status() != Present);
00035     assert(status() != Uninitialized);
00036     setProductProvenance(productProvenance);
00037     assert(provenance()->productProvenanceValid());
00038     if(productData().getInterface() != 0) {
00039       assert(productData().getInterface() == edp.interface());
00040     }
00041     productData().wrapper_ = edp.product();
00042     status_() = Present;
00043   }
00044 
00045   void
00046   ProducedGroup::mergeProduct_(
00047         WrapperOwningHolder const& edp,
00048         ProductProvenance& productProvenance) {
00049     assert(provenance()->productProvenanceValid());
00050     assert(status() == Present);
00051     setProductProvenance(productProvenance);
00052     mergeTheProduct(edp);
00053   }
00054 
00055   bool
00056   ProducedGroup::putOrMergeProduct_() const {
00057     return productUnavailable();
00058   }
00059 
00060   void
00061   ProducedGroup::mergeProduct_(WrapperOwningHolder const&) const {
00062     assert(0);
00063   }
00064 
00065   void
00066   ProducedGroup::putProduct_(WrapperOwningHolder const&) const {
00067     assert(0);
00068   }
00069 
00070   void
00071   InputGroup::putProduct_(
00072         WrapperOwningHolder const& edp,
00073         ProductProvenance const& productProvenance) {
00074     assert(!product());
00075     assert(!provenance()->productProvenanceValid());
00076     setProductProvenance(productProvenance);
00077     assert(provenance()->productProvenanceValid());
00078     setProduct(edp);
00079   }
00080 
00081   void
00082   InputGroup::mergeProduct_(
00083         WrapperOwningHolder const&,
00084         ProductProvenance&) {
00085     assert(0);
00086   }
00087 
00088   void
00089   InputGroup::mergeProduct_(WrapperOwningHolder const& edp) const {
00090     mergeTheProduct(edp);
00091   }
00092 
00093   bool
00094   InputGroup::putOrMergeProduct_() const {
00095     return(!product());
00096   }
00097 
00098   void
00099   InputGroup::putProduct_(WrapperOwningHolder const& edp) const {
00100     assert(!product());
00101     setProduct(edp);
00102   }
00103 
00104   void
00105   Group::mergeTheProduct(WrapperOwningHolder const& edp) const {
00106     if(wrapper().isMergeable()) {
00107       wrapper().mergeProduct(edp.wrapper());
00108     } else if(wrapper().hasIsProductEqual()) {
00109       if(!wrapper().isProductEqual(edp.wrapper())) {
00110         LogError("RunLumiMerging")
00111               << "Group::mergeGroup\n"
00112               << "Two run/lumi products for the same run/lumi which should be equal are not\n"
00113               << "Using the first, ignoring the second\n"
00114               << "className = " << branchDescription().className() << "\n"
00115               << "moduleLabel = " << moduleLabel() << "\n"
00116               << "instance = " << productInstanceName() << "\n"
00117               << "process = " << processName() << "\n";
00118       }
00119     } else {
00120       LogWarning("RunLumiMerging")
00121           << "Group::mergeGroup\n"
00122           << "Run/lumi product has neither a mergeProduct nor isProductEqual function\n"
00123           << "Using the first, ignoring the second in merge\n"
00124           << "className = " << branchDescription().className() << "\n"
00125           << "moduleLabel = " << moduleLabel() << "\n"
00126           << "instance = " << productInstanceName() << "\n"
00127           << "process = " << processName() << "\n";
00128     }
00129   }
00130 
00131   void
00132   InputGroup::setProduct(WrapperOwningHolder const& prod) const {
00133     assert (!product());
00134     if(!prod.isValid() || !prod.isPresent()) {
00135       setProductUnavailable();
00136     }
00137     assert(productData().getInterface() == prod.interface() || !prod.isValid());
00138     productData().wrapper_ = prod.product();
00139   }
00140 
00141   void
00142   Group::setProductProvenance(ProductProvenance const& prov) const {
00143     productData().prov_.setProductProvenance(prov);
00144   }
00145 
00146   // This routine returns true if it is known that currently there is no real product.
00147   // If there is a real product, it returns false.
00148   // If it is not known if there is a real product, it returns false.
00149   bool
00150   InputGroup::productUnavailable_() const {
00151     if(productIsUnavailable()) {
00152       return true;
00153     }
00154     // If there is a product, we know if it is real or a dummy.
00155     if(product()) {
00156       bool unavailable = !(wrapper().isPresent());
00157       if(unavailable) {
00158         setProductUnavailable();
00159       }
00160       return unavailable;
00161     }
00162     return false;
00163   }
00164 
00165   // This routine returns true if it is known that currently there is no real product.
00166   // If there is a real product, it returns false.
00167   // If it is not known if there is a real product, it returns false.
00168   bool
00169   ProducedGroup::productUnavailable_() const {
00170     // If unscheduled production, the product is potentially available.
00171     if(onDemand()) return false;
00172     // The product is available if and only if a product has been put.
00173     bool unavailable = !(product() && wrapper().isPresent());
00174     return unavailable;
00175   }
00176 
00177   bool
00178   Group::provenanceAvailable() const {
00179     // If this product is from a the current process,
00180     // the provenance is available if and only if a product has been put.
00181     if(branchDescription().produced()) {
00182       return product() && wrapper().isPresent();
00183     }
00184     // If this product is from a prior process, the provenance is available,
00185     // although the per event part may have been dropped.
00186     return true;
00187   }
00188 
00189   Type
00190   Group::productType() const {
00191     return Type::ByTypeInfo(wrapper().interface()->wrappedTypeInfo());
00192   }
00193 
00194   void
00195   Group::reallyCheckType(WrapperOwningHolder const& prod) const {
00196     // Check if the types match.
00197     TypeID typeID(prod.dynamicTypeInfo());
00198     if(typeID != branchDescription().typeID()) {
00199       // Types do not match.
00200       throw Exception(errors::EventCorruption)
00201           << "Product on branch " << branchDescription().branchName() << " is of wrong type.\n"
00202           << "It is supposed to be of type " << branchDescription().className() << ".\n"
00203           << "It is actually of type " << typeID.className() << ".\n";
00204     }
00205   }
00206 
00207   void
00208   Group::setProvenance(boost::shared_ptr<BranchMapper> mapper, ProductID const& pid) {
00209     //assert(!productData().prov_);
00210     productData().prov_.setProductID(pid);
00211     productData().prov_.setStore(mapper);
00212   }
00213 
00214   void
00215   Group::setProvenance(boost::shared_ptr<BranchMapper> mapper) {
00216     productData().prov_.setStore(mapper);
00217   }
00218 
00219   Provenance*
00220   Group::provenance() const {
00221     return &(productData().prov_);
00222   }
00223 
00224   void
00225   Group::write(std::ostream& os) const {
00226     // This is grossly inadequate. It is also not critical for the
00227     // first pass.
00228     os << std::string("Group for product with ID: ")
00229        << productID();
00230   }
00231 }