CMSSW/ FWCore/ Framework/ src/ Event.cc

001 #include "DataFormats/Provenance/interface/Provenance.h"
002 #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
003 #include "FWCore/Framework/interface/Event.h"
004 #include "FWCore/Framework/interface/EventPrincipal.h"
005 #include "FWCore/Framework/interface/LuminosityBlock.h"
006 #include "FWCore/ParameterSet/interface/Registry.h"
007 #include "FWCore/Utilities/interface/Algorithms.h"
008 #include "FWCore/Common/interface/TriggerResultsByName.h"
009 #include "FWCore/Utilities/interface/InputTag.h"
010 #include "DataFormats/Common/interface/TriggerResults.h"
011 
012 namespace edm {
013 
014     Event::Event(EventPrincipal& ep, ModuleDescription const& md) :
015         provRecorder_(ep, md),
016         aux_(ep.aux()),
017         luminosityBlock_(new LuminosityBlock(ep.luminosityBlockPrincipal(), md)),
018         gotBranchIDs_(),
019         gotViews_() {
020     }
021 
022     Event::~Event() {
023      // anything left here must be the result of a failure
024      // let's record them as failed attempts in the event principal
025       for_all(putProducts_, principal_get_adapter_detail::deleter());
026     }
027 
028     EventPrincipal&
029     Event::eventPrincipal() {
030       return dynamic_cast<EventPrincipal&>(provRecorder_.principal());
031     }
032 
033     EventPrincipal const&
034     Event::eventPrincipal() const {
035       return dynamic_cast<EventPrincipal const&>(provRecorder_.principal());
036     }
037 
038     ProductID
039     Event::makeProductID(ConstBranchDescription const& desc) const {
040       return eventPrincipal().branchIDToProductID(desc.branchID());
041     }
042 
043     Run const&
044     Event::getRun() const {
045       return getLuminosityBlock().getRun();
046     }
047 
048     EventSelectionIDVector const&
049     Event::eventSelectionIDs() const {
050       return eventPrincipal().eventSelectionIDs();
051     }
052 
053 
054   ProcessHistoryID const&
055   Event::processHistoryID() const {
056     return eventPrincipal().processHistoryID();
057   }
058 
059 
060   Provenance
061   Event::getProvenance(BranchID const& bid) const {
062     return provRecorder_.principal().getProvenance(bid);
063   }
064 
065   Provenance
066   Event::getProvenance(ProductID const& pid) const {
067     return eventPrincipal().getProvenance(pid);
068   }
069 
070   void
071   Event::getAllProvenance(std::vector<Provenance const*>& provenances) const {
072     provRecorder_.principal().getAllProvenance(provenances);
073   }
074 
075   bool
076   Event::getProcessParameterSet(std::string const& processName,
077                                 ParameterSet& ps) const {
078     // Get the ProcessHistory for this event.
079     ProcessHistoryRegistry* phr = ProcessHistoryRegistry::instance();
080     ProcessHistory ph;
081     if (!phr->getMapped(processHistoryID(), ph)) {
082       throw Exception(errors::NotFound)
083         << "ProcessHistoryID " << processHistoryID()
084         << " is claimed to describe " << id()
085         << "\nbut is not found in the ProcessHistoryRegistry.\n"
086         << "This file is malformed.\n";
087     }
088 
089     ProcessConfiguration config;
090     bool process_found = ph.getConfigurationForProcess(processName, config);
091     if (process_found) {
092       pset::Registry::instance()->getMapped(config.parameterSetID(), ps);
093       assert(!ps.empty());
094     }
095     return process_found;
096   }
097 
098   BasicHandle
099   Event::getByProductID_(ProductID const& oid) const {
100     return eventPrincipal().getByProductID(oid);
101   }
102 
103 
104   void
105   Event::commit_(std::vector<BranchID>* previousParentage, ParentageID* previousParentageId) {
106     commit_aux(putProducts(), true,previousParentage,previousParentageId);
107     commit_aux(putProductsWithoutParents(), false);
108   }
109 
110   void
111   Event::commit_aux(Event::ProductPtrVec& products, bool record_parents,
112                     std::vector<BranchID>* previousParentage, ParentageID* previousParentageId) {
113     // fill in guts of provenance here
114     EventPrincipal& ep = eventPrincipal();
115 
116     ProductPtrVec::iterator pit(products.begin());
117     ProductPtrVec::iterator pie(products.end());
118 
119     std::vector<BranchID> gotBranchIDVector;
120 
121     // Note that gotBranchIDVector will remain empty if
122     // record_parents is false (and may be empty if record_parents is
123     // true).
124 
125     //Check that previousParentageId is still good by seeing if previousParentage matches gotBranchIDs_
126     bool sameAsPrevious=( (0 != previousParentage) && (previousParentage->size() == gotBranchIDs_.size()) );
127     if (record_parents && !gotBranchIDs_.empty()) {
128       gotBranchIDVector.reserve(gotBranchIDs_.size());
129       std::vector<BranchID>::const_iterator itPrevious;
130       if(previousParentage) {
131         itPrevious = previousParentage->begin();
132       }
133       for (BranchIDSet::const_iterator it = gotBranchIDs_.begin(), itEnd = gotBranchIDs_.end();
134           it != itEnd; ++it) {
135         gotBranchIDVector.push_back(*it);
136         if(sameAsPrevious) {
137           if(*it != *itPrevious) {
138             sameAsPrevious=false;
139           } else {
140             ++itPrevious;
141           }
142         }
143       }
144       if(!sameAsPrevious && 0 != previousParentage) {
145         previousParentage->assign(gotBranchIDVector.begin(),gotBranchIDVector.end());
146       }
147     }
148 
149     //If we don't have a valid previousParentage then we want to use a temp value in order to
150     // avoid constantly recalculating the ParentageID which is a time consuming operation
151     ParentageID temp;
152     if(!previousParentage) {
153       assert(!sameAsPrevious);
154       previousParentageId = &temp;
155     }
156     while(pit!=pie) {
157       // set provenance
158       std::auto_ptr<ProductProvenance> productProvenancePtr;
159       if(!sameAsPrevious) {
160         productProvenancePtr = std::auto_ptr<ProductProvenance>(
161                                                                 new ProductProvenance(pit->second->branchID(),
162                                                                                       productstatus::present(),
163                                                                                       gotBranchIDVector));
164         *previousParentageId = productProvenancePtr->parentageID();
165         sameAsPrevious=true;
166       } else {
167         productProvenancePtr = std::auto_ptr<ProductProvenance>(
168                                                                 new ProductProvenance(pit->second->branchID(),
169                                                                                       productstatus::present(),
170                                                                                       *previousParentageId));
171       }
172       std::auto_ptr<EDProduct> pr(pit->first);
173       // Ownership has passed, so clear the pointer.
174       pit->first = 0;
175       ep.put(*pit->second, pr, productProvenancePtr);
176       ++pit;
177     }
178 
179     // the cleanup is all or none
180     products.clear();
181   }
182 
183   void
184   Event::addToGotBranchIDs(Provenance const& prov) const {
185     gotBranchIDs_.insert(prov.branchID());
186   }
187 
188   ProcessHistory const&
189   Event::processHistory() const {
190     return provRecorder_.processHistory();
191   }
192 
193 size_t
194   Event::size() const {
195     return putProducts().size()+provRecorder_.principal().size()+putProductsWithoutParents().size();
196   }
197 
198   BasicHandle
199   Event::getByLabelImpl(const std::type_info& iWrapperType, const std::type_info& iProductType, const InputTag& iTag) const {
200     BasicHandle h = provRecorder_.getByLabel_(TypeID(iProductType),iTag);
201     if (h.isValid()) {
202       addToGotBranchIDs(*(h.provenance()));
203     }
204     return h;
205   }
206 
207   TriggerNames const&
208   Event::triggerNames(edm::TriggerResults const& triggerResults) const
209   {
210     edm::TriggerNames const* names = triggerNames_(triggerResults);
211     if (names != 0) return *names;
212 
213     throw cms::Exception("TriggerNamesNotFound")
214       << "TriggerNames not found in ParameterSet registry";
215     return *names;
216   }
217 
218   TriggerResultsByName
219   Event::triggerResultsByName(std::string const& process) const {
220 
221     Handle<TriggerResults> hTriggerResults;
222     InputTag tag(std::string("TriggerResults"),
223                  std::string(""),
224                  process);
225 
226     getByLabel(tag, hTriggerResults);
227     if ( !hTriggerResults.isValid() ) {
228       return TriggerResultsByName(0,0);
229     }
230     edm::TriggerNames const* names = triggerNames_(*hTriggerResults);
231     return TriggerResultsByName(hTriggerResults.product(), names);
232   }
233 }

-- DavidCockerill - 24-Aug-2010

Edit | Attach | Watch | Print version | History: r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r1 - 2010-08-24 - DavidCockerill
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback