Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-04-22 06:27:17

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 Historical Note: The code related to ProcessBlock was originally written
0009 to support SubProcesses being present in the job. The SubProcess feature
0010 was removed from the CMS Framework in 2025. This support for SubProcesses
0011 added complexity in the ProcessBlock code that is currently unnecessary.
0012 For example, it contains counters that are never greater than one, vectors
0013 that will never have more than one entry, the concept of the top ProcessBlockHelper
0014 when there will only ever be one... There are a couple reasons we didn't clean
0015 this up in 2025:
0016 
0017     1. We are considering implementing a new feature similar to SubProcess,
0018     but better. Hopefully, something that will be used.  The new feature might
0019     make use of the ability of the ProcessBlock code to handle multiple
0020     processes in the same job. We're not sure when this will happen or if
0021     the current version of the code will be useful, but we're keeping it just
0022     in case.
0023 
0024     2. The current version of the code works well when there are not any SubProcesses.
0025     Even when the Framework supported the feature, there usually were not any
0026     configured. The risk of breaking something while simplifying the code is
0027     significant. Also, it didn't seem worth the investment of expensive
0028     developer time to clean this up. We had more important things that needed
0029     to be done...
0030 
0031 We might revisit this when the new feature is implemented or if we decide not
0032 to implement it at all.
0033 
0034 The class SubProcessBlockHelper was deleted in 2025, but it is still in
0035 the git history and was the other class that inherited from ProcessBlockHelperBase.
0036 */
0037 
0038 #include "DataFormats/Provenance/interface/ProvenanceFwd.h"
0039 #include "FWCore/Common/interface/ProcessBlockHelperBase.h"
0040 
0041 #include <set>
0042 #include <string>
0043 #include <vector>
0044 
0045 namespace edm {
0046 
0047   class ProcessBlockHelper : public ProcessBlockHelperBase {
0048   public:
0049     ProcessBlockHelperBase const* topProcessBlockHelper() const final;
0050     std::vector<std::string> const& topProcessesWithProcessBlockProducts() const final;
0051     unsigned int nProcessesInFirstFile() const final;
0052     std::vector<std::vector<unsigned int>> const& processBlockCacheIndices() const final;
0053     std::vector<std::vector<unsigned int>> const& nEntries() const final;
0054     std::vector<unsigned int> const& cacheIndexVectorsPerFile() const final;
0055     std::vector<unsigned int> const& cacheEntriesPerFile() const final;
0056     unsigned int processBlockIndex(std::string const& processName, EventToProcessBlockIndexes const&) const final;
0057     unsigned int outerOffset() const final;
0058 
0059     bool initializedFromInput() const { return initializedFromInput_; }
0060 
0061     bool firstFileDropProcessesAndReorderStored(StoredProcessBlockHelper& storedProcessBlockHelper,
0062                                                 std::set<std::string> const& processesToKeep,
0063                                                 std::vector<unsigned int> const& nEntries,
0064                                                 std::vector<unsigned int>& finalIndexToStoredIndex) const;
0065 
0066     bool dropProcessesAndReorderStored(StoredProcessBlockHelper& storedProcessBlockHelper,
0067                                        std::set<std::string> const& processesToKeep,
0068                                        std::vector<unsigned int> const& nEntries,
0069                                        std::vector<unsigned int>& finalIndexToStoredIndex,
0070                                        std::vector<std::string> const& firstFileFinalProcesses) const;
0071 
0072     void initializeFromPrimaryInput(StoredProcessBlockHelper const& storedProcessBlockHelper);
0073 
0074     void fillFromPrimaryInput(StoredProcessBlockHelper const& storedProcessBlockHelper,
0075                               std::vector<unsigned int> const& nEntries);
0076 
0077     void clearAfterOutputFilesClose();
0078 
0079   private:
0080     void dropProcessesAndReorderStoredImpl(StoredProcessBlockHelper& storedProcessBlockHelper,
0081                                            std::vector<std::string>& finalProcesses,
0082                                            std::vector<unsigned int> const& nEntries,
0083                                            std::vector<unsigned int> const& finalIndexToStoredIndex) const;
0084 
0085     void fillFromPrimaryInputWhenNotEmpty(std::vector<std::string> const& storedProcesses,
0086                                           std::vector<unsigned int> const& storedCacheIndices,
0087                                           std::vector<unsigned int> const& nEntries);
0088 
0089     void fillEntriesFromPrimaryInput(std::vector<unsigned int> nEntries);
0090 
0091     // A general comment about this class and its data members.
0092     // It was initially written to handle cases where all ProcessBlock
0093     // products from some process were dropped in a file after
0094     // the first input file but were present in the first input file.
0095     // At the moment this comment is being written, the file merging
0096     // rules do not allow this to happen and this situation never
0097     // occurs. However, this class intentionally maintains support
0098     // for this case, because we may find we need to change the file
0099     // merging requirements in the future. So there is support for
0100     // some indices to be invalid or other values to be zero even
0101     // though at the moment this should never occur.
0102 
0103     // Events hold an index into the outer vector
0104     // (an offset needs to added in the case of multiple input
0105     // files). The elements of the inner vector correspond to the
0106     // processes in processesWithProcessBlockProducts_ (exactly
0107     // 1 to 1 in the same order except it only includes those processes
0108     // from the input, if the current Process is
0109     // added, then it is added to the container of cache indices when
0110     // the output module makes its modified copy). The values inside
0111     // the inner vector are the cache indices into the cache vectors
0112     // contained by user modules. This cache order is the same as the
0113     // processing order of ProcessBlocks in the current process.
0114     // It might contain invalid cache index values.
0115     std::vector<std::vector<unsigned int>> processBlockCacheIndices_;
0116 
0117     // Number of entries per ProcessBlock TTree.
0118     // The outer vector has an element for each input file.
0119     // The inner vector elements correspond 1-to-1 with
0120     // processesWithProcessBlockProducts_ and in the same
0121     // order. This might contain zeroes.
0122     std::vector<std::vector<unsigned int>> nEntries_;
0123 
0124     // The index into the next two vectors is the input file index
0125     // which is based on the order input files are read
0126     // These can contain zeroes.
0127     std::vector<unsigned int> cacheIndexVectorsPerFile_;
0128     std::vector<unsigned int> cacheEntriesPerFile_;
0129 
0130     unsigned int nProcessesInFirstFile_ = 0;
0131 
0132     bool initializedFromInput_ = false;
0133 
0134     // Index of the first outer vector element in the cache indices
0135     // container that is associated with the current input file. If
0136     // it points to the end, then there were no cache indices in the
0137     // current input file.
0138     unsigned int outerOffset_ = 0;
0139 
0140     // Offset for the cacheIndex, counts all entries in
0141     // ProcessBlock TTree's in all input files seen so far.
0142     unsigned int cacheIndexOffset_ = 0;
0143   };
0144 }  // namespace edm
0145 #endif