Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:30

0001 #ifndef DataFormats_Provenance_StoredMergeableRunProductMetadata_h
0002 #define DataFormats_Provenance_StoredMergeableRunProductMetadata_h
0003 
0004 /** \class edm::StoredMergeableRunProductMetadata
0005 
0006 This class holds information used to decide how to merge together
0007 run products when multiple run entries with the same run number
0008 and ProcessHistoryID are read from input files contiguously. This
0009 class is persistent and stores the information that needs to be
0010 remembered from one process to the next. Most of the work related
0011 to this decision is performed by the class MergeableRunProductMetadata.
0012 The main purpose of this class is to hold the information that
0013 needs to be persistently stored. PoolSource and PoolOutputModule
0014 interface with this class to read and write it.
0015 
0016 Note that the information is not stored for each product.
0017 The information is stored for each run entry in Run TTree
0018 in the input file and also for each process in which at least
0019 one mergeable run product was selected to be written to the
0020 output file. It is not necessary to save information
0021 for each product individually, it will be the same for every
0022 product created in the same process and in the same run entry.
0023 
0024 The main piece of information stored is the list of luminosity
0025 block numbers processed when the product was created. Often,
0026 this list can be obtained from the IndexIntoFile and we do not
0027 need to duplicate this information here and so as an optimization
0028 we don't. There are also cases where we can detect that the merging
0029 has created invalid run products where part of the content
0030 has probably been double counted. We save a value to record
0031 this problem.
0032 
0033 To improve performance, the data structure has been flattened
0034 into 4 vectors instead of containing a vector containing vectors
0035 containing vectors.
0036 
0037 When the user of this class fails to find a run entry with a
0038 particular process, the assumption should be made that the lumi
0039 numbers are in IndexIntoFile and valid.
0040 
0041 Another optimization is that if in all cases the lumi numbers
0042 can be obtained from IndexIntoFile and are valid, then all
0043 the vectors are cleared and a boolean value is set to indicate
0044 this.
0045 
0046 \author W. David Dagenhart, created 23 May, 2018
0047 
0048 */
0049 
0050 #include "DataFormats/Provenance/interface/RunLumiEventNumber.h"
0051 
0052 #include <string>
0053 #include <vector>
0054 
0055 namespace edm {
0056 
0057   class StoredMergeableRunProductMetadata {
0058   public:
0059     // This constructor exists for ROOT I/O
0060     StoredMergeableRunProductMetadata();
0061 
0062     // This constructor is used when creating a new object
0063     // each time an output file is opened.
0064     StoredMergeableRunProductMetadata(std::vector<std::string> const& processesWithMergeableRunProducts);
0065 
0066     std::vector<std::string> const& processesWithMergeableRunProducts() const {
0067       return processesWithMergeableRunProducts_;
0068     }
0069 
0070     class SingleRunEntry {
0071     public:
0072       SingleRunEntry();
0073       SingleRunEntry(unsigned long long iBeginProcess, unsigned long long iEndProcess);
0074 
0075       unsigned long long beginProcess() const { return beginProcess_; }
0076       unsigned long long endProcess() const { return endProcess_; }
0077 
0078     private:
0079       // indexes into singleRunEntryAndProcesses_ for a single run entry
0080       unsigned long long beginProcess_;
0081       unsigned long long endProcess_;
0082     };
0083 
0084     class SingleRunEntryAndProcess {
0085     public:
0086       SingleRunEntryAndProcess();
0087       SingleRunEntryAndProcess(unsigned long long iBeginLumi,
0088                                unsigned long long iEndLumi,
0089                                unsigned int iProcess,
0090                                bool iValid,
0091                                bool iUseIndexIntoFile);
0092 
0093       unsigned long long beginLumi() const { return beginLumi_; }
0094       unsigned long long endLumi() const { return endLumi_; }
0095 
0096       unsigned int process() const { return process_; }
0097 
0098       bool valid() const { return valid_; }
0099       bool useIndexIntoFile() const { return useIndexIntoFile_; }
0100 
0101     private:
0102       // indexes into lumis_ for products created in one process and
0103       // written into a single run entry.
0104       unsigned long long beginLumi_;
0105       unsigned long long endLumi_;
0106 
0107       // index into processesWithMergeableRunProducts_
0108       unsigned int process_;
0109 
0110       // If false this indicates the way files were split and merged
0111       // has created run products that are invalid and probably
0112       // double count some of their content.
0113       bool valid_;
0114 
0115       // If true the lumi numbers can be obtained from IndexIntoFile
0116       // and are not stored in the vector named lumis_
0117       bool useIndexIntoFile_;
0118     };
0119 
0120     // These four functions are called by MergeableRunProductMetadata which
0121     // fills the vectors.
0122     std::vector<SingleRunEntry>& singleRunEntries() { return singleRunEntries_; }
0123     std::vector<SingleRunEntryAndProcess>& singleRunEntryAndProcesses() { return singleRunEntryAndProcesses_; }
0124     std::vector<LuminosityBlockNumber_t>& lumis() { return lumis_; }
0125     bool& allValidAndUseIndexIntoFile() { return allValidAndUseIndexIntoFile_; }
0126 
0127     // Called by RootOutputFile immediately before writing the object
0128     // when an output file is closed.
0129     void optimizeBeforeWrite();
0130 
0131     bool getLumiContent(unsigned long long runEntry,
0132                         std::string const& process,
0133                         bool& valid,
0134                         std::vector<LuminosityBlockNumber_t>::const_iterator& lumisBegin,
0135                         std::vector<LuminosityBlockNumber_t>::const_iterator& lumisEnd) const;
0136 
0137   private:
0138     std::vector<std::string> processesWithMergeableRunProducts_;
0139     std::vector<SingleRunEntry> singleRunEntries_;  // index is the run entry
0140     std::vector<SingleRunEntryAndProcess> singleRunEntryAndProcesses_;
0141     std::vector<LuminosityBlockNumber_t> lumis_;
0142     bool allValidAndUseIndexIntoFile_;
0143   };
0144 }  // namespace edm
0145 #endif