Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:55

0001 #ifndef FWCore_Common_ProcessBlockHelper_h
0002 #define FWCore_Common_ProcessBlockHelper_h
0003 
0004 /** \class edm::ProcessBlockHelper
0005 
0006 \author W. David Dagenhart, created 15 September, 2020
0007 
0008 */
0009 
0010 #include "DataFormats/Provenance/interface/ProvenanceFwd.h"
0011 #include "FWCore/Common/interface/ProcessBlockHelperBase.h"
0012 
0013 #include <set>
0014 #include <string>
0015 #include <vector>
0016 
0017 namespace edm {
0018 
0019   class ProcessBlockHelper : public ProcessBlockHelperBase {
0020   public:
0021     ProcessBlockHelperBase const* topProcessBlockHelper() const final;
0022     std::vector<std::string> const& topProcessesWithProcessBlockProducts() const final;
0023     unsigned int nProcessesInFirstFile() const final;
0024     std::vector<std::vector<unsigned int>> const& processBlockCacheIndices() const final;
0025     std::vector<std::vector<unsigned int>> const& nEntries() const final;
0026     std::vector<unsigned int> const& cacheIndexVectorsPerFile() const final;
0027     std::vector<unsigned int> const& cacheEntriesPerFile() const final;
0028     unsigned int processBlockIndex(std::string const& processName, EventToProcessBlockIndexes const&) const final;
0029     unsigned int outerOffset() const final;
0030 
0031     bool initializedFromInput() const { return initializedFromInput_; }
0032 
0033     bool firstFileDropProcessesAndReorderStored(StoredProcessBlockHelper& storedProcessBlockHelper,
0034                                                 std::set<std::string> const& processesToKeep,
0035                                                 std::vector<unsigned int> const& nEntries,
0036                                                 std::vector<unsigned int>& finalIndexToStoredIndex) const;
0037 
0038     bool dropProcessesAndReorderStored(StoredProcessBlockHelper& storedProcessBlockHelper,
0039                                        std::set<std::string> const& processesToKeep,
0040                                        std::vector<unsigned int> const& nEntries,
0041                                        std::vector<unsigned int>& finalIndexToStoredIndex,
0042                                        std::vector<std::string> const& firstFileFinalProcesses) const;
0043 
0044     void initializeFromPrimaryInput(StoredProcessBlockHelper const& storedProcessBlockHelper);
0045 
0046     void fillFromPrimaryInput(StoredProcessBlockHelper const& storedProcessBlockHelper,
0047                               std::vector<unsigned int> const& nEntries);
0048 
0049     void clearAfterOutputFilesClose();
0050 
0051   private:
0052     void dropProcessesAndReorderStoredImpl(StoredProcessBlockHelper& storedProcessBlockHelper,
0053                                            std::vector<std::string>& finalProcesses,
0054                                            std::vector<unsigned int> const& nEntries,
0055                                            std::vector<unsigned int> const& finalIndexToStoredIndex) const;
0056 
0057     void fillFromPrimaryInputWhenNotEmpty(std::vector<std::string> const& storedProcesses,
0058                                           std::vector<unsigned int> const& storedCacheIndices,
0059                                           std::vector<unsigned int> const& nEntries);
0060 
0061     void fillEntriesFromPrimaryInput(std::vector<unsigned int> nEntries);
0062 
0063     // A general comment about this class and its data members.
0064     // It was initially written to handle cases where all ProcessBlock
0065     // products from some process were dropped in a file after
0066     // the first input file but were present in the first input file.
0067     // At the moment this comment is being written, the file merging
0068     // rules do not allow this to happen and this situation never
0069     // occurs. However, this class intentionally maintains support
0070     // for this case, because we may find we need to change the file
0071     // merging requirements in the future. So there is support for
0072     // some indices to be invalid or other values to be zero even
0073     // though at the moment this should never occur.
0074 
0075     // Events hold an index into the outer vector
0076     // (an offset needs to added in the case of multiple input
0077     // files). The elements of the inner vector correspond to the
0078     // processes in processesWithProcessBlockProducts_ (exactly
0079     // 1 to 1 in the same order except it only includes those processes
0080     // from the input, if the current Process and/or SubProcesses are
0081     // added, then they are added to the container of cache indices when
0082     // the output module makes its modified copy). The values inside
0083     // the inner vector are the cache indices into the cache vectors
0084     // contained by user modules. This cache order is the same as the
0085     // processing order of ProcessBlocks in the current process.
0086     // It might contain invalid cache index values.
0087     std::vector<std::vector<unsigned int>> processBlockCacheIndices_;
0088 
0089     // Number of entries per ProcessBlock TTree.
0090     // The outer vector has an element for each input file.
0091     // The inner vector elements correspond 1-to-1 with
0092     // processesWithProcessBlockProducts_ and in the same
0093     // order. This might contain zeroes.
0094     std::vector<std::vector<unsigned int>> nEntries_;
0095 
0096     // The index into the next two vectors is the input file index
0097     // which is based on the order input files are read
0098     // These can contain zeroes.
0099     std::vector<unsigned int> cacheIndexVectorsPerFile_;
0100     std::vector<unsigned int> cacheEntriesPerFile_;
0101 
0102     unsigned int nProcessesInFirstFile_ = 0;
0103 
0104     bool initializedFromInput_ = false;
0105 
0106     // Index of the first outer vector element in the cache indices
0107     // container that is associated with the current input file. If
0108     // it points to the end, then there were no cache indices in the
0109     // current input file.
0110     unsigned int outerOffset_ = 0;
0111 
0112     // Offset for the cacheIndex, counts all entries in
0113     // ProcessBlock TTree's in all input files seen so far.
0114     unsigned int cacheIndexOffset_ = 0;
0115   };
0116 }  // namespace edm
0117 #endif