Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#include "DataFormats/Provenance/interface/StoredMergeableRunProductMetadata.h"

namespace edm {

  StoredMergeableRunProductMetadata::StoredMergeableRunProductMetadata() : allValidAndUseIndexIntoFile_(true) {}

  StoredMergeableRunProductMetadata::StoredMergeableRunProductMetadata(
      std::vector<std::string> const& processesWithMergeableRunProducts)
      : processesWithMergeableRunProducts_(processesWithMergeableRunProducts), allValidAndUseIndexIntoFile_(true) {}

  StoredMergeableRunProductMetadata::SingleRunEntry::SingleRunEntry() : beginProcess_(0), endProcess_(0) {}

  StoredMergeableRunProductMetadata::SingleRunEntry::SingleRunEntry(unsigned long long iBeginProcess,
                                                                    unsigned long long iEndProcess)
      : beginProcess_(iBeginProcess), endProcess_(iEndProcess) {}

  StoredMergeableRunProductMetadata::SingleRunEntryAndProcess::SingleRunEntryAndProcess()
      : beginLumi_(0), endLumi_(0), process_(0), valid_(false), useIndexIntoFile_(false) {}

  StoredMergeableRunProductMetadata::SingleRunEntryAndProcess::SingleRunEntryAndProcess(unsigned long long iBeginLumi,
                                                                                        unsigned long long iEndLumi,
                                                                                        unsigned int iProcess,
                                                                                        bool iValid,
                                                                                        bool iUseIndexIntoFile)
      : beginLumi_(iBeginLumi),
        endLumi_(iEndLumi),
        process_(iProcess),
        valid_(iValid),
        useIndexIntoFile_(iUseIndexIntoFile) {}

  void StoredMergeableRunProductMetadata::optimizeBeforeWrite() {
    if (allValidAndUseIndexIntoFile_) {
      processesWithMergeableRunProducts_.clear();
      singleRunEntries_.clear();
      singleRunEntryAndProcesses_.clear();
      lumis_.clear();
    }
  }

  bool StoredMergeableRunProductMetadata::getLumiContent(
      unsigned long long runEntry,
      std::string const& process,
      bool& valid,
      std::vector<LuminosityBlockNumber_t>::const_iterator& lumisBegin,
      std::vector<LuminosityBlockNumber_t>::const_iterator& lumisEnd) const {
    valid = true;
    if (allValidAndUseIndexIntoFile_) {
      return false;
    }

    SingleRunEntry const& singleRunEntry = singleRunEntries_.at(runEntry);
    for (unsigned long long j = singleRunEntry.beginProcess(); j < singleRunEntry.endProcess(); ++j) {
      SingleRunEntryAndProcess const& singleRunEntryAndProcess = singleRunEntryAndProcesses_.at(j);
      // This string comparison could be optimized away by storing an index mapping in
      // MergeableRunProductMetadata that gets recalculated each time a new input
      // file is opened
      if (processesWithMergeableRunProducts_.at(singleRunEntryAndProcess.process()) == process) {
        valid = singleRunEntryAndProcess.valid();
        if (singleRunEntryAndProcess.useIndexIntoFile()) {
          return false;
        } else {
          lumisBegin = lumis_.begin() + singleRunEntryAndProcess.beginLumi();
          lumisEnd = lumis_.begin() + singleRunEntryAndProcess.endLumi();
          return true;
        }
      }
    }
    return false;
  }
}  // namespace edm