00001 #include "FWCore/Framework/interface/RunPrincipal.h"
00002 #include "FWCore/Framework/interface/Group.h"
00003
00004 namespace edm {
00005 void
00006 RunPrincipal::addOrReplaceGroup(std::auto_ptr<Group> g) {
00007
00008 Group* group = getExistingGroup(*g);
00009 if (group != 0) {
00010
00011 if (!group->productUnavailable()) {
00012 assert(group->product() != 0);
00013 }
00014 if (!g->productUnavailable()) {
00015 assert(g->product() != 0);
00016 }
00017
00018 group->mergeGroup(g.get());
00019 } else {
00020 addGroup_(g);
00021 }
00022 }
00023
00024
00025 void
00026 RunPrincipal::addGroup(ConstBranchDescription const& bd) {
00027 std::auto_ptr<Group> g(new Group(bd));
00028 addOrReplaceGroup(g);
00029 }
00030
00031 void
00032 RunPrincipal::addGroup(std::auto_ptr<EDProduct> prod,
00033 ConstBranchDescription const& bd,
00034 std::auto_ptr<EventEntryInfo> entryInfo) {
00035 std::auto_ptr<Group> g(new Group(prod, bd, entryInfo));
00036 addOrReplaceGroup(g);
00037 }
00038
00039 void
00040 RunPrincipal::addGroup(ConstBranchDescription const& bd,
00041 std::auto_ptr<EventEntryInfo> entryInfo) {
00042 std::auto_ptr<Group> g(new Group(bd, entryInfo));
00043 addOrReplaceGroup(g);
00044 }
00045
00046 void
00047 RunPrincipal::put(std::auto_ptr<EDProduct> edp,
00048 ConstBranchDescription const& bd,
00049 std::auto_ptr<EventEntryInfo> entryInfo) {
00050
00051 if (edp.get() == 0) {
00052 throw edm::Exception(edm::errors::InsertFailure,"Null Pointer")
00053 << "put: Cannot put because auto_ptr to product is null."
00054 << "\n";
00055 }
00056 this->addToProcessHistory();
00057 branchMapperPtr()->insert(*entryInfo);
00058
00059 this->addGroup(edp, bd, entryInfo);
00060 }
00061
00062 Provenance
00063 RunPrincipal::getProvenance(BranchID const& bid) const {
00064 SharedConstGroupPtr const& g = getGroup(bid, false, true, true);
00065 if (g.get() == 0) {
00066 throw edm::Exception(edm::errors::ProductNotFound,"InvalidID")
00067 << "getProvenance: no product with given branch id: "<< bid << "\n";
00068 }
00069
00070 if (g->onDemand()) {
00071 unscheduledFill(g->productDescription().moduleLabel());
00072 }
00073
00074
00075 if (g->onDemand()) {
00076 throw edm::Exception(edm::errors::ProductNotFound)
00077 << "getProvenance: no product with given BranchID: "<< bid <<"\n";
00078 }
00079
00080 return *g->provenance();
00081 }
00082
00083
00084
00085
00086 void
00087 RunPrincipal::getAllProvenance(std::vector<Provenance const*> & provenances) const {
00088 provenances.clear();
00089 for (Base::const_iterator i = begin(), iEnd = end(); i != iEnd; ++i) {
00090 if (i->second->provenanceAvailable()) {
00091 resolveProvenance(*i->second);
00092 if (i->second->provenance()->branchEntryInfoSharedPtr() &&
00093 i->second->provenance()->isPresent() &&
00094 i->second->provenance()->product().present())
00095 provenances.push_back(i->second->provenance());
00096 }
00097 }
00098 }
00099
00100 void
00101 RunPrincipal::resolveProvenance(Group const& g) const {
00102 if (!g.entryInfoPtr()) {
00103
00104 g.setProvenance(branchMapperPtr()->branchToEntryInfo(g.productDescription().branchID()));
00105 }
00106 }
00107
00108 void
00109 RunPrincipal::mergeRun(boost::shared_ptr<RunPrincipal> rp) {
00110
00111 aux_.mergeAuxiliary(rp->aux());
00112
00113 for (Base::const_iterator i = rp->begin(), iEnd = rp->end(); i != iEnd; ++i) {
00114
00115 std::auto_ptr<Group> g(new Group());
00116 g->swap(*i->second);
00117
00118 addOrReplaceGroup(g);
00119 }
00120 }
00121 }