CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/FWCore/Framework/src/Event.cc

Go to the documentation of this file.
00001 #include "DataFormats/Provenance/interface/Provenance.h"
00002 #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/EventPrincipal.h"
00005 #include "FWCore/Framework/interface/LuminosityBlock.h"
00006 #include "FWCore/ParameterSet/interface/Registry.h"
00007 #include "FWCore/Utilities/interface/Algorithms.h"
00008 #include "FWCore/Common/interface/TriggerResultsByName.h"
00009 #include "FWCore/Utilities/interface/InputTag.h"
00010 #include "DataFormats/Common/interface/TriggerResults.h"
00011 
00012 namespace edm {
00013 
00014     Event::Event(EventPrincipal& ep, ModuleDescription const& md) :
00015         provRecorder_(ep, md),
00016         aux_(ep.aux()),
00017         luminosityBlock_(new LuminosityBlock(ep.luminosityBlockPrincipal(), md)),
00018         gotBranchIDs_(),
00019         gotViews_() {
00020     }
00021 
00022     Event::~Event() {
00023      // anything left here must be the result of a failure
00024      // let's record them as failed attempts in the event principal
00025       for_all(putProducts_, principal_get_adapter_detail::deleter());
00026     }
00027 
00028     EventPrincipal&
00029     Event::eventPrincipal() {
00030       return dynamic_cast<EventPrincipal&>(provRecorder_.principal());
00031     }
00032 
00033     EventPrincipal const&
00034     Event::eventPrincipal() const {
00035       return dynamic_cast<EventPrincipal const&>(provRecorder_.principal());
00036     }
00037 
00038     ProductID
00039     Event::makeProductID(ConstBranchDescription const& desc) const {
00040       return eventPrincipal().branchIDToProductID(desc.branchID());
00041     }
00042 
00043     Run const&
00044     Event::getRun() const {
00045       return getLuminosityBlock().getRun();
00046     }
00047 
00048     EventSelectionIDVector const&
00049     Event::eventSelectionIDs() const {
00050       return eventPrincipal().eventSelectionIDs();
00051     }
00052 
00053 
00054   ProcessHistoryID const&
00055   Event::processHistoryID() const {
00056     return eventPrincipal().processHistoryID();
00057   }
00058 
00059 
00060   Provenance
00061   Event::getProvenance(BranchID const& bid) const {
00062     return provRecorder_.principal().getProvenance(bid);
00063   }
00064 
00065   Provenance
00066   Event::getProvenance(ProductID const& pid) const {
00067     return eventPrincipal().getProvenance(pid);
00068   }
00069 
00070   void
00071   Event::getAllProvenance(std::vector<Provenance const*>& provenances) const {
00072     provRecorder_.principal().getAllProvenance(provenances);
00073   }
00074 
00075   bool
00076   Event::getProcessParameterSet(std::string const& processName,
00077                                 ParameterSet& ps) const {
00078     // Get the ProcessHistory for this event.
00079     ProcessHistoryRegistry* phr = ProcessHistoryRegistry::instance();
00080     ProcessHistory ph;
00081     if (!phr->getMapped(processHistoryID(), ph)) {
00082       throw Exception(errors::NotFound)
00083         << "ProcessHistoryID " << processHistoryID()
00084         << " is claimed to describe " << id()
00085         << "\nbut is not found in the ProcessHistoryRegistry.\n"
00086         << "This file is malformed.\n";
00087     }
00088 
00089     ProcessConfiguration config;
00090     bool process_found = ph.getConfigurationForProcess(processName, config);
00091     if (process_found) {
00092       pset::Registry::instance()->getMapped(config.parameterSetID(), ps);
00093       assert(!ps.empty());
00094     }
00095     return process_found;
00096   }
00097 
00098   BasicHandle
00099   Event::getByProductID_(ProductID const& oid) const {
00100     return eventPrincipal().getByProductID(oid);
00101   }
00102 
00103 
00104   void
00105   Event::commit_(std::vector<BranchID>* previousParentage, ParentageID* previousParentageId) {
00106     commit_aux(putProducts(), true,previousParentage,previousParentageId);
00107     commit_aux(putProductsWithoutParents(), false);
00108   }
00109 
00110   void
00111   Event::commit_aux(Event::ProductPtrVec& products, bool record_parents,
00112                     std::vector<BranchID>* previousParentage, ParentageID* previousParentageId) {
00113     // fill in guts of provenance here
00114     EventPrincipal& ep = eventPrincipal();
00115 
00116     ProductPtrVec::iterator pit(products.begin());
00117     ProductPtrVec::iterator pie(products.end());
00118 
00119     std::vector<BranchID> gotBranchIDVector;
00120 
00121     // Note that gotBranchIDVector will remain empty if
00122     // record_parents is false (and may be empty if record_parents is
00123     // true).
00124 
00125     //Check that previousParentageId is still good by seeing if previousParentage matches gotBranchIDs_
00126     bool sameAsPrevious=( (0 != previousParentage) && (previousParentage->size() == gotBranchIDs_.size()) );
00127     if (record_parents && !gotBranchIDs_.empty()) {
00128       gotBranchIDVector.reserve(gotBranchIDs_.size());
00129       std::vector<BranchID>::const_iterator itPrevious;
00130       if(previousParentage) {
00131         itPrevious = previousParentage->begin();
00132       }
00133       for (BranchIDSet::const_iterator it = gotBranchIDs_.begin(), itEnd = gotBranchIDs_.end();
00134           it != itEnd; ++it) {
00135         gotBranchIDVector.push_back(*it);
00136         if(sameAsPrevious) {
00137           if(*it != *itPrevious) {
00138             sameAsPrevious=false;
00139           } else {
00140             ++itPrevious;
00141           }
00142         }
00143       }
00144       if(!sameAsPrevious && 0 != previousParentage) {
00145         previousParentage->assign(gotBranchIDVector.begin(),gotBranchIDVector.end());
00146       }
00147     }
00148 
00149     //If we don't have a valid previousParentage then we want to use a temp value in order to
00150     // avoid constantly recalculating the ParentageID which is a time consuming operation
00151     ParentageID temp;
00152     if(!previousParentage) {
00153       assert(!sameAsPrevious);
00154       previousParentageId = &temp;
00155     }
00156     while(pit!=pie) {
00157       // set provenance
00158       std::auto_ptr<ProductProvenance> productProvenancePtr;
00159       if(!sameAsPrevious) {
00160         productProvenancePtr = std::auto_ptr<ProductProvenance>(
00161                                                                 new ProductProvenance(pit->second->branchID(),
00162                                                                                       productstatus::present(),
00163                                                                                       gotBranchIDVector));
00164         *previousParentageId = productProvenancePtr->parentageID();
00165         sameAsPrevious=true;
00166       } else {
00167         productProvenancePtr = std::auto_ptr<ProductProvenance>(
00168                                                                 new ProductProvenance(pit->second->branchID(),
00169                                                                                       productstatus::present(),
00170                                                                                       *previousParentageId));
00171       }
00172       std::auto_ptr<EDProduct> pr(pit->first);
00173       // Ownership has passed, so clear the pointer.
00174       pit->first = 0;
00175       ep.put(*pit->second, pr, productProvenancePtr);
00176       ++pit;
00177     }
00178 
00179     // the cleanup is all or none
00180     products.clear();
00181   }
00182 
00183   void
00184   Event::addToGotBranchIDs(Provenance const& prov) const {
00185     gotBranchIDs_.insert(prov.branchID());
00186   }
00187 
00188   ProcessHistory const&
00189   Event::processHistory() const {
00190     return provRecorder_.processHistory();
00191   }
00192 
00193 size_t
00194   Event::size() const {
00195     return putProducts().size()+provRecorder_.principal().size()+putProductsWithoutParents().size();
00196   }
00197 
00198   BasicHandle
00199   Event::getByLabelImpl(const std::type_info& iWrapperType, const std::type_info& iProductType, const InputTag& iTag) const {
00200     BasicHandle h = provRecorder_.getByLabel_(TypeID(iProductType),iTag);
00201     if (h.isValid()) {
00202       addToGotBranchIDs(*(h.provenance()));
00203     }
00204     return h;
00205   }
00206 
00207   TriggerNames const&
00208   Event::triggerNames(edm::TriggerResults const& triggerResults) const
00209   {
00210     edm::TriggerNames const* names = triggerNames_(triggerResults);
00211     if (names != 0) return *names;
00212 
00213     throw cms::Exception("TriggerNamesNotFound")
00214       << "TriggerNames not found in ParameterSet registry";
00215     return *names;
00216   }
00217 
00218   TriggerResultsByName
00219   Event::triggerResultsByName(std::string const& process) const {
00220 
00221     Handle<TriggerResults> hTriggerResults;
00222     InputTag tag(std::string("TriggerResults"),
00223                  std::string(""),
00224                  process);
00225 
00226     getByLabel(tag, hTriggerResults);
00227     if ( !hTriggerResults.isValid() ) {
00228       return TriggerResultsByName(0,0);
00229     }
00230     edm::TriggerNames const* names = triggerNames_(*hTriggerResults);
00231     return TriggerResultsByName(hTriggerResults.product(), names);
00232   }
00233 }