CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
edm::ProcessBlockHelper Class Reference

#include <ProcessBlockHelper.h>

Inheritance diagram for edm::ProcessBlockHelper:
edm::ProcessBlockHelperBase

Public Member Functions

std::vector< unsigned int > const & cacheEntriesPerFile () const final
 
std::vector< unsigned int > const & cacheIndexVectorsPerFile () const final
 
void clearAfterOutputFilesClose ()
 
bool dropProcessesAndReorderStored (StoredProcessBlockHelper &storedProcessBlockHelper, std::set< std::string > const &processesToKeep, std::vector< unsigned int > const &nEntries, std::vector< unsigned int > &finalIndexToStoredIndex, std::vector< std::string > const &firstFileFinalProcesses) const
 
void fillFromPrimaryInput (StoredProcessBlockHelper const &storedProcessBlockHelper, std::vector< unsigned int > const &nEntries)
 
bool firstFileDropProcessesAndReorderStored (StoredProcessBlockHelper &storedProcessBlockHelper, std::set< std::string > const &processesToKeep, std::vector< unsigned int > const &nEntries, std::vector< unsigned int > &finalIndexToStoredIndex) const
 
bool initializedFromInput () const
 
void initializeFromPrimaryInput (StoredProcessBlockHelper const &storedProcessBlockHelper)
 
std::vector< std::vector
< unsigned int > > const & 
nEntries () const final
 
unsigned int nProcessesInFirstFile () const final
 
unsigned int outerOffset () const final
 
std::vector< std::vector
< unsigned int > > const & 
processBlockCacheIndices () const final
 
unsigned int processBlockIndex (std::string const &processName, EventToProcessBlockIndexes const &) const final
 
ProcessBlockHelperBase const * topProcessBlockHelper () const final
 
std::vector< std::string > const & topProcessesWithProcessBlockProducts () const final
 
- Public Member Functions inherited from edm::ProcessBlockHelperBase
std::vector< std::string > const & addedProcesses () const
 
void emplaceBackAddedProcessName (std::string const &processName)
 
void emplaceBackProcessName (std::string const &processName)
 
std::vector< std::string > const & processesWithProcessBlockProducts () const
 
std::string selectProcess (ProductRegistry const &, ProductLabels const &, TypeID const &) const
 
void setAddedProcesses (std::vector< std::string > const &val)
 
void setProcessesWithProcessBlockProducts (std::vector< std::string > const &val)
 
void updateForNewProcess (ProductRegistry const &, std::string const &processName)
 
virtual ~ProcessBlockHelperBase ()
 

Private Member Functions

void dropProcessesAndReorderStoredImpl (StoredProcessBlockHelper &storedProcessBlockHelper, std::vector< std::string > &finalProcesses, std::vector< unsigned int > const &nEntries, std::vector< unsigned int > const &finalIndexToStoredIndex) const
 
void fillEntriesFromPrimaryInput (std::vector< unsigned int > nEntries)
 
void fillFromPrimaryInputWhenNotEmpty (std::vector< std::string > const &storedProcesses, std::vector< unsigned int > const &storedCacheIndices, std::vector< unsigned int > const &nEntries)
 

Private Attributes

std::vector< unsigned int > cacheEntriesPerFile_
 
unsigned int cacheIndexOffset_ = 0
 
std::vector< unsigned int > cacheIndexVectorsPerFile_
 
bool initializedFromInput_ = false
 
std::vector< std::vector
< unsigned int > > 
nEntries_
 
unsigned int nProcessesInFirstFile_ = 0
 
unsigned int outerOffset_ = 0
 
std::vector< std::vector
< unsigned int > > 
processBlockCacheIndices_
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::ProcessBlockHelperBase
static constexpr unsigned int invalidCacheIndex ()
 
static constexpr unsigned int invalidProcessIndex ()
 

Detailed Description

Author
W. David Dagenhart, created 15 September, 2020

Definition at line 19 of file ProcessBlockHelper.h.

Member Function Documentation

std::vector< unsigned int > const & edm::ProcessBlockHelper::cacheEntriesPerFile ( ) const
finalvirtual

Implements edm::ProcessBlockHelperBase.

Definition at line 30 of file ProcessBlockHelper.cc.

References cacheEntriesPerFile_.

30 { return cacheEntriesPerFile_; }
std::vector< unsigned int > cacheEntriesPerFile_
std::vector< unsigned int > const & edm::ProcessBlockHelper::cacheIndexVectorsPerFile ( ) const
finalvirtual

Implements edm::ProcessBlockHelperBase.

Definition at line 26 of file ProcessBlockHelper.cc.

References cacheIndexVectorsPerFile_.

26  {
28  }
std::vector< unsigned int > cacheIndexVectorsPerFile_
void edm::ProcessBlockHelper::clearAfterOutputFilesClose ( )

Definition at line 158 of file ProcessBlockHelper.cc.

References cacheEntriesPerFile_, cacheIndexOffset_, cacheIndexVectorsPerFile_, nEntries_, outerOffset_, and processBlockCacheIndices_.

158  {
160  nEntries_.clear();
162  cacheEntriesPerFile_.clear();
163  outerOffset_ = 0;
164  cacheIndexOffset_ = 0;
165  }
std::vector< unsigned int > cacheEntriesPerFile_
std::vector< std::vector< unsigned int > > nEntries_
std::vector< unsigned int > cacheIndexVectorsPerFile_
std::vector< std::vector< unsigned int > > processBlockCacheIndices_
bool edm::ProcessBlockHelper::dropProcessesAndReorderStored ( StoredProcessBlockHelper storedProcessBlockHelper,
std::set< std::string > const &  processesToKeep,
std::vector< unsigned int > const &  nEntries,
std::vector< unsigned int > &  finalIndexToStoredIndex,
std::vector< std::string > const &  firstFileFinalProcesses 
) const

Definition at line 83 of file ProcessBlockHelper.cc.

References dropProcessesAndReorderStoredImpl(), edm::StoredProcessBlockHelper::processesWithProcessBlockProducts(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by edm::RootFile::dropProcessesAndReorder().

87  {
88  std::vector<std::string> const& storedProcesses = storedProcessBlockHelper.processesWithProcessBlockProducts();
89 
90  std::vector<std::string> finalProcesses;
91  // Always will allocate enough space (sometimes too much)
92  finalProcesses.reserve(storedProcesses.size());
93  finalIndexToStoredIndex.reserve(storedProcesses.size());
94 
95  // The outer loop here establishes the order
96  // Only allows processes that got into finalProcesses for the first file
97  for (unsigned int iFirst = 0; iFirst < firstFileFinalProcesses.size(); ++iFirst) {
98  // Only includes processes also in storedProcesses
99  for (unsigned int iStored = 0; iStored < storedProcesses.size(); ++iStored) {
100  std::string const& storedProcess = storedProcesses[iStored];
101  if (firstFileFinalProcesses[iFirst] == storedProcess) {
102  // Also requires processes have kept ProcessBlock products
103  if (processesToKeep.find(storedProcess) != processesToKeep.end()) {
104  finalProcesses.emplace_back(storedProcess);
105  finalIndexToStoredIndex.emplace_back(iStored);
106  break;
107  }
108  }
109  }
110  }
111 
112  bool isModified = true;
113  if (storedProcesses == finalProcesses) {
114  isModified = false;
115  return isModified;
116  }
117 
118  dropProcessesAndReorderStoredImpl(storedProcessBlockHelper, finalProcesses, nEntries, finalIndexToStoredIndex);
119  return isModified;
120  }
std::vector< std::vector< unsigned int > > const & nEntries() const final
void dropProcessesAndReorderStoredImpl(StoredProcessBlockHelper &storedProcessBlockHelper, std::vector< std::string > &finalProcesses, std::vector< unsigned int > const &nEntries, std::vector< unsigned int > const &finalIndexToStoredIndex) const
void edm::ProcessBlockHelper::dropProcessesAndReorderStoredImpl ( StoredProcessBlockHelper storedProcessBlockHelper,
std::vector< std::string > &  finalProcesses,
std::vector< unsigned int > const &  nEntries,
std::vector< unsigned int > const &  finalIndexToStoredIndex 
) const
private

Definition at line 170 of file ProcessBlockHelper.cc.

References cms::cuda::assert(), edm::ProcessBlockHelperBase::invalidCacheIndex(), dqmiolumiharvest::j, isotrackApplyRegressor::k, eostools::move(), hltrates_dqm_sourceclient-live_cfg::offset, edm::StoredProcessBlockHelper::processBlockCacheIndices(), edm::StoredProcessBlockHelper::processesWithProcessBlockProducts(), edm::StoredProcessBlockHelper::setProcessBlockCacheIndices(), and edm::StoredProcessBlockHelper::setProcessesWithProcessBlockProducts().

Referenced by dropProcessesAndReorderStored(), and firstFileDropProcessesAndReorderStored().

174  {
175  std::vector<std::string> const& storedProcesses = storedProcessBlockHelper.processesWithProcessBlockProducts();
176  std::vector<unsigned int> const& storedCacheIndices = storedProcessBlockHelper.processBlockCacheIndices();
177 
178  assert(!storedProcesses.empty());
179  std::vector<unsigned int> newCacheIndices;
180  if (!finalProcesses.empty()) {
181  // ProcessBlocks are read in the order of storedProcesses and within
182  // each process in entry order in the TTree. This establishes the cache
183  // order that the values in storedCacheIndices refer to. The "offset" refers
184  // to cache index value of the first ProcessBlock in a TTree.
185  std::vector<unsigned int> oldOffsets;
186  oldOffsets.reserve(storedProcesses.size());
187  unsigned int offset = 0;
188  for (auto const& entries : nEntries) {
189  oldOffsets.emplace_back(offset);
190  offset += entries;
191  }
192 
193  unsigned int nFinalProcesses = finalProcesses.size();
194  std::vector<unsigned int> newOffsets;
195  newOffsets.reserve(nFinalProcesses);
196  offset = 0;
197  for (unsigned int iNew = 0; iNew < nFinalProcesses; ++iNew) {
198  newOffsets.emplace_back(offset);
199  offset += nEntries[finalIndexToStoredIndex[iNew]];
200  }
201 
202  unsigned int nOuterLoop = storedCacheIndices.size() / storedProcesses.size();
203  assert(nOuterLoop * storedProcesses.size() == storedCacheIndices.size());
204  newCacheIndices.reserve(nOuterLoop * nFinalProcesses);
205  unsigned int storedOuterOffset = 0;
206 
207  for (unsigned int k = 0; k < nOuterLoop; ++k) {
208  for (unsigned int j = 0; j < nFinalProcesses; ++j) {
209  unsigned int storedIndex = finalIndexToStoredIndex[j];
210  unsigned int oldCacheIndex = storedCacheIndices[storedOuterOffset + storedIndex];
211  unsigned int newCacheIndex = invalidCacheIndex();
212  if (oldCacheIndex != invalidCacheIndex()) {
213  newCacheIndex = oldCacheIndex - oldOffsets[storedIndex] + newOffsets[j];
214  }
215  newCacheIndices.emplace_back(newCacheIndex);
216  }
217  storedOuterOffset += storedProcesses.size();
218  }
219  }
220  storedProcessBlockHelper.setProcessBlockCacheIndices(std::move(newCacheIndices));
221  storedProcessBlockHelper.setProcessesWithProcessBlockProducts(std::move(finalProcesses));
222  }
static constexpr unsigned int invalidCacheIndex()
assert(be >=bs)
std::vector< std::vector< unsigned int > > const & nEntries() const final
def move
Definition: eostools.py:511
void edm::ProcessBlockHelper::fillEntriesFromPrimaryInput ( std::vector< unsigned int >  nEntries)
private

Definition at line 271 of file ProcessBlockHelper.cc.

References cacheEntriesPerFile_, cacheIndexOffset_, eostools::move(), and nEntries_.

Referenced by fillFromPrimaryInput(), and fillFromPrimaryInputWhenNotEmpty().

271  {
272  unsigned int entriesThisFile = 0;
273  for (auto const& entries : nEntries) {
274  entriesThisFile += entries;
275  }
276  nEntries_.push_back(std::move(nEntries));
277  cacheEntriesPerFile_.push_back(entriesThisFile);
278  cacheIndexOffset_ += entriesThisFile;
279  }
std::vector< unsigned int > cacheEntriesPerFile_
std::vector< std::vector< unsigned int > > nEntries_
std::vector< std::vector< unsigned int > > const & nEntries() const final
def move
Definition: eostools.py:511
void edm::ProcessBlockHelper::fillFromPrimaryInput ( StoredProcessBlockHelper const &  storedProcessBlockHelper,
std::vector< unsigned int > const &  nEntries 
)

Definition at line 132 of file ProcessBlockHelper.cc.

References cacheIndexVectorsPerFile_, fillEntriesFromPrimaryInput(), fillFromPrimaryInputWhenNotEmpty(), edm::ProcessBlockHelperBase::invalidCacheIndex(), eostools::move(), nProcessesInFirstFile_, outerOffset_, edm::StoredProcessBlockHelper::processBlockCacheIndices(), processBlockCacheIndices_, and edm::StoredProcessBlockHelper::processesWithProcessBlockProducts().

133  {
134  // I've written this so it will continue to work even if we someday relax
135  // the strict merging requirement in the ProductRegistry (there
136  // is a little extra complexity that may be unnecessary...).
137 
138  std::vector<std::string> const& storedProcesses = storedProcessBlockHelper.processesWithProcessBlockProducts();
139  std::vector<unsigned int> const& storedCacheIndices = storedProcessBlockHelper.processBlockCacheIndices();
140 
142 
143  if (nProcessesInFirstFile_ == 0) {
144  // There were no ProcessBlock products in the first file. Nothing to do.
145  return;
146  } else if (!storedProcesses.empty()) {
147  // Subsequent input file with ProcessBlock products
148  fillFromPrimaryInputWhenNotEmpty(storedProcesses, storedCacheIndices, nEntries);
149  } else if (storedProcesses.empty()) {
150  // Subsequent input file without ProcessBlock products
152  cacheIndexVectorsPerFile_.push_back(1);
153  std::vector<unsigned int> newNEntries(nProcessesInFirstFile_, 0);
155  }
156  }
static constexpr unsigned int invalidCacheIndex()
void fillEntriesFromPrimaryInput(std::vector< unsigned int > nEntries)
std::vector< std::vector< unsigned int > > const & nEntries() const final
std::vector< unsigned int > cacheIndexVectorsPerFile_
def move
Definition: eostools.py:511
std::vector< std::vector< unsigned int > > processBlockCacheIndices_
void fillFromPrimaryInputWhenNotEmpty(std::vector< std::string > const &storedProcesses, std::vector< unsigned int > const &storedCacheIndices, std::vector< unsigned int > const &nEntries)
void edm::ProcessBlockHelper::fillFromPrimaryInputWhenNotEmpty ( std::vector< std::string > const &  storedProcesses,
std::vector< unsigned int > const &  storedCacheIndices,
std::vector< unsigned int > const &  nEntries 
)
private

Definition at line 224 of file ProcessBlockHelper.cc.

References cms::cuda::assert(), cacheIndexOffset_, cacheIndexVectorsPerFile_, fillEntriesFromPrimaryInput(), edm::ProcessBlockHelperBase::invalidCacheIndex(), edm::ProcessBlockHelperBase::invalidProcessIndex(), dqmiolumiharvest::j, isotrackApplyRegressor::k, eostools::move(), nProcessesInFirstFile_, outerOffset_, processBlockCacheIndices_, edm::ProcessBlockHelperBase::processesWithProcessBlockProducts(), and findQualityFiles::size.

Referenced by fillFromPrimaryInput().

226  {
228 
229  // Calculate a translation from an index into the process names from the first file
230  // to an index into the process names from the current file. Note the value will
231  // be left invalid if the process name is not found in the current file.
232  std::vector<unsigned int> firstFileToStored(nProcessesInFirstFile_, invalidProcessIndex());
233  std::vector<unsigned int> newNEntries(nProcessesInFirstFile_, 0);
234  for (unsigned int j = 0; j < nProcessesInFirstFile_; ++j) {
235  for (unsigned int k = 0; k < storedProcesses.size(); ++k) {
236  if (processesWithProcessBlockProducts()[j] == storedProcesses[k]) {
237  firstFileToStored[j] = k;
238  newNEntries[j] = nEntries[k];
239  break;
240  }
241  }
242  }
243 
244  // Append the cache indices from the current input file to the
245  // cache indices container from the previous files.
246  unsigned int nCacheIndexVectors = storedCacheIndices.size() / storedProcesses.size();
247  assert(storedProcesses.size() * nCacheIndexVectors == storedCacheIndices.size());
248  processBlockCacheIndices_.resize(processBlockCacheIndices_.size() + nCacheIndexVectors);
249  unsigned int storedIndex = 0;
250  for (unsigned int k = 0; k < nCacheIndexVectors; ++k) {
251  processBlockCacheIndices_[outerOffset_ + k].reserve(nProcessesInFirstFile_);
252  for (unsigned int j = 0; j < nProcessesInFirstFile_; ++j) {
253  unsigned int iStored = firstFileToStored[j];
254  if (iStored == invalidProcessIndex()) {
256  } else {
257  unsigned int oldCacheIndex = storedCacheIndices[storedIndex];
258  ++storedIndex;
259  unsigned int newCacheIndex = invalidCacheIndex();
260  if (oldCacheIndex != invalidCacheIndex()) {
261  newCacheIndex = oldCacheIndex + cacheIndexOffset_;
262  }
263  processBlockCacheIndices_[outerOffset_ + k].push_back(newCacheIndex);
264  }
265  }
266  }
267  cacheIndexVectorsPerFile_.push_back(nCacheIndexVectors);
269  }
static constexpr unsigned int invalidProcessIndex()
static constexpr unsigned int invalidCacheIndex()
void fillEntriesFromPrimaryInput(std::vector< unsigned int > nEntries)
assert(be >=bs)
std::vector< std::vector< unsigned int > > const & nEntries() const final
std::vector< unsigned int > cacheIndexVectorsPerFile_
def move
Definition: eostools.py:511
std::vector< std::string > const & processesWithProcessBlockProducts() const
tuple size
Write out results.
std::vector< std::vector< unsigned int > > processBlockCacheIndices_
bool edm::ProcessBlockHelper::firstFileDropProcessesAndReorderStored ( StoredProcessBlockHelper storedProcessBlockHelper,
std::set< std::string > const &  processesToKeep,
std::vector< unsigned int > const &  nEntries,
std::vector< unsigned int > &  finalIndexToStoredIndex 
) const

Definition at line 47 of file ProcessBlockHelper.cc.

References dropProcessesAndReorderStoredImpl(), LaserDQM_cfg::process, and edm::StoredProcessBlockHelper::processesWithProcessBlockProducts().

Referenced by edm::RootFile::dropProcessesAndReorder().

51  {
52  std::vector<std::string> const& storedProcesses = storedProcessBlockHelper.processesWithProcessBlockProducts();
53 
54  bool isModified = false;
55  unsigned int finalSize = 0;
56  for (auto const& process : storedProcesses) {
57  if (processesToKeep.find(process) == processesToKeep.end()) {
58  isModified = true;
59  } else {
60  ++finalSize;
61  }
62  }
63  if (!isModified) {
64  return isModified;
65  }
66 
67  std::vector<std::string> finalProcesses;
68  finalProcesses.reserve(finalSize);
69  finalIndexToStoredIndex.reserve(finalSize);
70  for (unsigned int iStored = 0; iStored < storedProcesses.size(); ++iStored) {
71  if (processesToKeep.find(storedProcesses[iStored]) != processesToKeep.end()) {
72  finalProcesses.emplace_back(storedProcesses[iStored]);
73  finalIndexToStoredIndex.emplace_back(iStored);
74  }
75  }
76  dropProcessesAndReorderStoredImpl(storedProcessBlockHelper, finalProcesses, nEntries, finalIndexToStoredIndex);
77  return isModified;
78  }
std::vector< std::vector< unsigned int > > const & nEntries() const final
tuple process
Definition: LaserDQM_cfg.py:3
void dropProcessesAndReorderStoredImpl(StoredProcessBlockHelper &storedProcessBlockHelper, std::vector< std::string > &finalProcesses, std::vector< unsigned int > const &nEntries, std::vector< unsigned int > const &finalIndexToStoredIndex) const
bool edm::ProcessBlockHelper::initializedFromInput ( ) const
inline

Definition at line 31 of file ProcessBlockHelper.h.

References initializedFromInput_.

Referenced by edm::RootFile::dropProcessesAndReorder().

void edm::ProcessBlockHelper::initializeFromPrimaryInput ( StoredProcessBlockHelper const &  storedProcessBlockHelper)
std::vector< std::vector< unsigned int > > const & edm::ProcessBlockHelper::nEntries ( ) const
finalvirtual

Implements edm::ProcessBlockHelperBase.

Definition at line 24 of file ProcessBlockHelper.cc.

References nEntries_.

24 { return nEntries_; }
std::vector< std::vector< unsigned int > > nEntries_
unsigned int edm::ProcessBlockHelper::nProcessesInFirstFile ( ) const
finalvirtual

Implements edm::ProcessBlockHelperBase.

Definition at line 18 of file ProcessBlockHelper.cc.

References nProcessesInFirstFile_.

18 { return nProcessesInFirstFile_; }
unsigned int edm::ProcessBlockHelper::outerOffset ( ) const
finalvirtual

Implements edm::ProcessBlockHelperBase.

Definition at line 42 of file ProcessBlockHelper.cc.

References outerOffset_.

42 { return outerOffset_; }
std::vector< std::vector< unsigned int > > const & edm::ProcessBlockHelper::processBlockCacheIndices ( ) const
finalvirtual

Implements edm::ProcessBlockHelperBase.

Definition at line 20 of file ProcessBlockHelper.cc.

References processBlockCacheIndices_.

20  {
22  }
std::vector< std::vector< unsigned int > > processBlockCacheIndices_
unsigned int edm::ProcessBlockHelper::processBlockIndex ( std::string const &  processName,
EventToProcessBlockIndexes const &  eventToProcessBlockIndexes 
) const
finalvirtual

Implements edm::ProcessBlockHelperBase.

Definition at line 32 of file ProcessBlockHelper.cc.

References edm::EventToProcessBlockIndexes::index(), edm::ProcessBlockHelperBase::invalidCacheIndex(), nProcessesInFirstFile_, processBlockCacheIndices_, and edm::ProcessBlockHelperBase::processesWithProcessBlockProducts().

33  {
34  for (unsigned int iProcess = 0; iProcess < nProcessesInFirstFile_; ++iProcess) {
36  return processBlockCacheIndices_[eventToProcessBlockIndexes.index()][iProcess];
37  }
38  }
39  return invalidCacheIndex();
40  }
static constexpr unsigned int invalidCacheIndex()
std::vector< std::string > const & processesWithProcessBlockProducts() const
std::vector< std::vector< unsigned int > > processBlockCacheIndices_
ProcessBlockHelperBase const * edm::ProcessBlockHelper::topProcessBlockHelper ( ) const
finalvirtual

Implements edm::ProcessBlockHelperBase.

Definition at line 12 of file ProcessBlockHelper.cc.

12 { return this; }
std::vector< std::string > const & edm::ProcessBlockHelper::topProcessesWithProcessBlockProducts ( ) const
finalvirtual

Implements edm::ProcessBlockHelperBase.

Definition at line 14 of file ProcessBlockHelper.cc.

References edm::ProcessBlockHelperBase::processesWithProcessBlockProducts().

14  {
16  }
std::vector< std::string > const & processesWithProcessBlockProducts() const

Member Data Documentation

std::vector<unsigned int> edm::ProcessBlockHelper::cacheEntriesPerFile_
private
unsigned int edm::ProcessBlockHelper::cacheIndexOffset_ = 0
private
std::vector<unsigned int> edm::ProcessBlockHelper::cacheIndexVectorsPerFile_
private
bool edm::ProcessBlockHelper::initializedFromInput_ = false
private

Definition at line 104 of file ProcessBlockHelper.h.

Referenced by initializedFromInput(), and initializeFromPrimaryInput().

std::vector<std::vector<unsigned int> > edm::ProcessBlockHelper::nEntries_
private
unsigned int edm::ProcessBlockHelper::nProcessesInFirstFile_ = 0
private
unsigned int edm::ProcessBlockHelper::outerOffset_ = 0
private
std::vector<std::vector<unsigned int> > edm::ProcessBlockHelper::processBlockCacheIndices_
private