Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-13 23:27:07

0001 // -*- C++ -*-
0002 //
0003 // Package:     Framework
0004 // Class  :     EarlyDeleteHelper
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Mon Feb  6 16:17:10 CST 2012
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "DataFormats/Provenance/interface/BranchID.h"
0017 #include "FWCore/Framework/interface/EventPrincipal.h"
0018 
0019 #include "FWCore/Framework/interface/EarlyDeleteHelper.h"
0020 
0021 using namespace edm;
0022 //
0023 // constants, enums and typedefs
0024 //
0025 
0026 //
0027 // static data member definitions
0028 //
0029 
0030 //
0031 // constructors and destructor
0032 //
0033 EarlyDeleteHelper::EarlyDeleteHelper(unsigned int* iBeginIndexItr,
0034                                      unsigned int* iEndIndexItr,
0035                                      std::vector<BranchToCount>* iBranchCounts)
0036     : pBeginIndex_(iBeginIndexItr),
0037       pEndIndex_(iEndIndexItr),
0038       pBranchCounts_(iBranchCounts),
0039       pathsLeftToComplete_(0),
0040       nPathsOn_(0) {}
0041 
0042 EarlyDeleteHelper::EarlyDeleteHelper(const EarlyDeleteHelper& rhs)
0043     : pBeginIndex_(rhs.pBeginIndex_),
0044       pEndIndex_(rhs.pEndIndex_),
0045       pBranchCounts_(rhs.pBranchCounts_),
0046       pathsLeftToComplete_(rhs.pathsLeftToComplete_.load()),
0047       nPathsOn_(rhs.nPathsOn_) {}
0048 
0049 //EarlyDeleteHelper::~EarlyDeleteHelper()
0050 //{
0051 //}
0052 
0053 //
0054 // assignment operators
0055 //
0056 // const EarlyDeleteHelper& EarlyDeleteHelper::operator=(const EarlyDeleteHelper& rhs)
0057 // {
0058 //   //An exception safe implementation is
0059 //   EarlyDeleteHelper temp(rhs);
0060 //   swap(rhs);
0061 //
0062 //   return *this;
0063 // }
0064 
0065 //
0066 // member functions
0067 //
0068 void EarlyDeleteHelper::moduleRan(EventPrincipal const& iEvent) {
0069   pathsLeftToComplete_ = 0;
0070   for (auto it = pBeginIndex_; it != pEndIndex_; ++it) {
0071     auto& count = (*pBranchCounts_)[*it];
0072     assert(count.count > 0);
0073     auto value = --(count.count);
0074     if (value == 0) {
0075       iEvent.deleteProduct(count.branch);
0076     }
0077   }
0078 }
0079 
0080 void EarlyDeleteHelper::pathFinished(EventPrincipal const& iEvent) {
0081   unsigned int value = pathsLeftToComplete_;
0082   while (value > 0) {
0083     if (pathsLeftToComplete_.compare_exchange_strong(value, value - 1)) {
0084       //we were the thread that changed the value
0085       if (value == 1) {
0086         //we can never reach this module now so declare it as run
0087         moduleRan(iEvent);
0088       }
0089       break;
0090     }
0091   }
0092 }
0093 
0094 void EarlyDeleteHelper::appendIndex(unsigned int iIndex) {
0095   *pEndIndex_ = iIndex;
0096   ++pEndIndex_;
0097 }
0098 
0099 void EarlyDeleteHelper::shiftIndexPointers(unsigned int iShift) {
0100   pEndIndex_ -= iShift;
0101   pBeginIndex_ -= iShift;
0102 }
0103 
0104 //
0105 // const member functions
0106 //
0107 
0108 //
0109 // static member functions
0110 //