CMS 3D CMS Logo

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

#include <TransientProductLookupMap.h>

Public Types

typedef
ProductLookupIndexList::const_iterator 
const_iterator
 
typedef std::map< std::pair
< TypeInBranchType,
ConstBranchDescription const * >
, ProductTransientIndex,
CompareTypeInBranchTypeConstBranchDescription
FillFromMap
 
typedef std::vector
< ProductLookupIndex
ProductLookupIndexList
 
typedef std::vector< std::pair
< TypeInBranchType,
BranchDescriptionIndex > > 
TypeInBranchTypeLookup
 

Public Member Functions

const_iterator begin () const
 
const_iterator end () const
 
std::pair< const_iterator,
const_iterator
equal_range (TypeInBranchType const &) const
 returns a pair of iterators that define the range for items matching the TypeInBranchType More...
 
std::pair< const_iterator,
const_iterator
equal_range (TypeInBranchType const &, std::string const &, std::string const &) const
 
int fillCount () const
 
void fillFrom (FillFromMap const &)
 
void reorderIfNecessary (BranchType, ProcessHistory const &, std::string const &iNewProcessName)
 reorders the ProductLookupIndexes for the BranchType based on the processing ordering More...
 
void reset ()
 
 TransientProductLookupMap ()
 

Private Attributes

TypeInBranchTypeLookup branchLookup_
 
int fillCount_
 
std::vector< ProcessHistoryIDhistoryIDsForBranchType_
 
std::vector< std::vector
< std::string > > 
processNameOrderingForBranchType_
 
ProductLookupIndexList productLookupIndexList_
 

Detailed Description

Definition at line 49 of file TransientProductLookupMap.h.

Member Typedef Documentation

typedef ProductLookupIndexList::const_iterator edm::TransientProductLookupMap::const_iterator

Definition at line 55 of file TransientProductLookupMap.h.

Definition at line 59 of file TransientProductLookupMap.h.

Definition at line 53 of file TransientProductLookupMap.h.

Definition at line 52 of file TransientProductLookupMap.h.

Constructor & Destructor Documentation

TransientProductLookupMap::TransientProductLookupMap ( )

Definition at line 60 of file TransientProductLookupMap.cc.

60  :
61  branchLookup_(),
63  historyIDsForBranchType_(static_cast<unsigned int>(NumBranchTypes), ProcessHistoryID()),
64  processNameOrderingForBranchType_(static_cast<unsigned int>(NumBranchTypes), std::vector<std::string>()),
65  fillCount_(0) {
66  }
ProductLookupIndexList productLookupIndexList_
std::vector< ProcessHistoryID > historyIDsForBranchType_
std::vector< std::vector< std::string > > processNameOrderingForBranchType_
Hash< ProcessHistoryType > ProcessHistoryID

Member Function Documentation

const_iterator edm::TransientProductLookupMap::begin ( void  ) const
inline

Definition at line 85 of file TransientProductLookupMap.h.

References productLookupIndexList_.

Referenced by edm::Principal::findGroupByLabel().

85 {return productLookupIndexList_.begin();}
ProductLookupIndexList productLookupIndexList_
const_iterator edm::TransientProductLookupMap::end ( void  ) const
inline
std::pair< TransientProductLookupMap::const_iterator, TransientProductLookupMap::const_iterator > TransientProductLookupMap::equal_range ( TypeInBranchType const &  iKey) const

returns a pair of iterators that define the range for items matching the TypeInBranchType

Definition at line 383 of file TransientProductLookupMap.cc.

References branchLookup_, and productLookupIndexList_.

Referenced by equal_range(), edm::Principal::findGroup(), edm::Principal::findGroupByLabel(), edm::Principal::findGroups(), and edm::PrincipalGetAdapter::getBranchDescription().

383  {
384  TypeInBranchTypeLookup::const_iterator itFind = std::lower_bound(branchLookup_.begin(),
385  branchLookup_.end(),
386  std::make_pair(iKey, BranchDescriptionIndex(0)),
387  CompareFirst());
388  if(itFind == branchLookup_.end() || iKey < itFind->first) {
389  return std::make_pair(productLookupIndexList_.end(), productLookupIndexList_.end());
390  }
391  const_iterator itStart = productLookupIndexList_.begin() + itFind->second;
393  if(++itFind != branchLookup_.end()) {
394  itEnd = productLookupIndexList_.begin() + itFind->second;
395  }
396  return std::make_pair(itStart, itEnd);
397  }
ProductLookupIndexList productLookupIndexList_
ProductLookupIndexList::const_iterator const_iterator
unsigned int BranchDescriptionIndex
std::pair< TransientProductLookupMap::const_iterator, TransientProductLookupMap::const_iterator > TransientProductLookupMap::equal_range ( TypeInBranchType const &  iKey,
std::string const &  moduleLabel,
std::string const &  productInstanceName 
) const

returns a pair of iterators that define the range for items matching the TypeInBranchType, the module label, and the product instance name

Definition at line 400 of file TransientProductLookupMap.cc.

References equal_range().

402  {
403  std::pair<const_iterator, const_iterator> itPair = this->equal_range(iKey);
404 
405  if (itPair.first == itPair.second) {
406  return itPair;
407  }
408 
409  // Advance lower bound only
410  itPair.first = std::lower_bound(itPair.first, itPair.second, std::make_pair(&moduleLabel, &productInstanceName), CompareModuleLabelAndProductInstanceName());
411  // Protect against no match
412  if (!(itPair.first < itPair.second) ||
413  itPair.first->branchDescription()->moduleLabel() != moduleLabel ||
414  itPair.first->branchDescription()->productInstanceName() != productInstanceName) {
415  itPair.second = itPair.first;
416  }
417  return itPair;
418  }
std::pair< const_iterator, const_iterator > equal_range(TypeInBranchType const &) const
returns a pair of iterators that define the range for items matching the TypeInBranchType ...
int edm::TransientProductLookupMap::fillCount ( ) const
inline
void TransientProductLookupMap::fillFrom ( FillFromMap const &  iMap)

Definition at line 312 of file TransientProductLookupMap.cc.

References branchLookup_, fillCount_, edm::fillInProcessIndexes(), historyIDsForBranchType_, isFirst(), edm::NumBranchTypes, processNameOrderingForBranchType_, and productLookupIndexList_.

Referenced by edm::ProductRegistry::initializeLookupTables().

312  {
313 
315 
316  //Increment the fill count so users can check if the map has been modified.
317  ++fillCount_;
318 
319  productLookupIndexList_.clear();
320  productLookupIndexList_.reserve(iMap.size());
321  branchLookup_.clear();
322  branchLookup_.reserve(iMap.size()); //this is an upperbound
323 
324  std::set<std::string, std::greater<std::string> > processNames;
325  TypeInBranchType lastSeen(TypeID(), NumBranchTypes);
326 
327  //since the actual strings are stored elsewhere, there is no reason to make a copy
328  static std::string const kEmpty;
329  std::string const* lastSeenModule = &kEmpty;
330  std::string const* lastSeenProductInstance = &kEmpty;
331  for(FillFromMap::const_iterator it = iMap.begin(), itEnd = iMap.end();
332  it != itEnd;
333  ++it) {
334  bool isFirst = ((lastSeen < it->first.first) || (it->first.first < lastSeen));
335  if(isFirst) {
336  lastSeen = it->first.first;
337  branchLookup_.push_back(std::make_pair(lastSeen, BranchDescriptionIndex(productLookupIndexList_.size())));
338  } else {
339  //see if this is the first of a group that only differ by ProcessName
340  isFirst = (*lastSeenModule != it->first.second->moduleLabel() ||
341  *lastSeenProductInstance != it->first.second->productInstanceName());
342  }
343  productLookupIndexList_.push_back(ProductLookupIndex(it->first.second,
344  it->second,
345  0,
346  isFirst)
347  );
348  if(isFirst) {
349  lastSeenModule = &(it->first.second->moduleLabel());
350  lastSeenProductInstance = &(it->first.second->productInstanceName());
351  }
352  processNames.insert(it->first.second->processName());
353  }
354 
355  std::vector<ProcessHistoryID>::iterator itPH = historyIDsForBranchType_.begin();
356  std::vector<ProcessHistoryID>::iterator itPHEnd = historyIDsForBranchType_.end();
357 
358  std::vector<std::vector<std::string> >::iterator itPN = processNameOrderingForBranchType_.begin();
359  //std::vector<std::vector<std::string> >::iterator itPNEnd = processNameOrderingForBranchType_.end();
360 
361  for(;itPH != itPHEnd; ++itPH, ++itPN) {
362  *itPH = ProcessHistoryID();
363  itPN->assign(processNames.begin(), processNames.end());
364  }
365 
366  //Now that we know all the IDs time to set the values
368  }
bool isFirst(HepMC::GenParticle *x)
ProductLookupIndexList productLookupIndexList_
std::vector< ProcessHistoryID > historyIDsForBranchType_
std::vector< std::vector< std::string > > processNameOrderingForBranchType_
Hash< ProcessHistoryType > ProcessHistoryID
static void fillInProcessIndexes(TransientProductLookupMap::ProductLookupIndexList::iterator iIt, TransientProductLookupMap::ProductLookupIndexList::iterator iEnd, std::vector< std::string > const &iNameOrder)
unsigned int BranchDescriptionIndex
void TransientProductLookupMap::reorderIfNecessary ( BranchType  iBranch,
ProcessHistory const &  iHistory,
std::string const &  iNewProcessName 
)

reorders the ProductLookupIndexes for the BranchType based on the processing ordering

Definition at line 180 of file TransientProductLookupMap.cc.

References edm::ProcessHistory::begin(), branchLookup_, edm::ProcessHistory::empty(), edm::ProcessHistory::end(), fillCount_, edm::fillInProcessIndexes(), spr::find(), historyIDsForBranchType_, edm::ProcessHistory::id(), processNameOrderingForBranchType_, productLookupIndexList_, edm::ProcessHistory::rbegin(), edm::ProcessHistory::rend(), python.multivaluedict::sort(), and groupFilesInBlocks::temp.

180  {
181 
182  ProcessHistoryID& historyID = historyIDsForBranchType_[iBranch];
183  if(iHistory.id() == historyID) {
184  //std::cout <<"no reordering since history unchanged"<<std::endl;
185  return;
186  }
187 
188  if(iHistory.empty()) {
189  //std::cout <<"no reordering since history empty"<<std::endl;
190  historyID = iHistory.id();
191  return;
192  }
193  std::vector<std::string>& processNameOrdering = processNameOrderingForBranchType_[iBranch];
194 
195  //iHistory may be missing entries in processNameOrdering if two files were merged together and one file
196  // had fewer processing steps than the other one.
197  //iHistory may have more entries than processNameOrdering if all data products for those extra entries
198  // were dropped
199 
200  //if iHistory already in same order as processNameOrdering than we don't have to do anything
201  std::vector<std::string>::iterator it = processNameOrdering.begin();
202  std::vector<std::string>::iterator itEnd = processNameOrdering.end();
203  ProcessHistory::const_iterator itH = iHistory.begin();
204  ProcessHistory::const_iterator itHEnd = iHistory.end();
205 
206  {
207  std::vector<std::string>::iterator itStart = it;
208  bool mustReorder = false;
209  while(it != itEnd && itH != itHEnd) {
210  if(*it == itH->processName()) {
211  ++it;
212  } else {
213  //see if we already passed it
214  for(std::vector<std::string>::iterator itOld = itStart; itOld != it; ++itOld) {
215  if(*itOld == itH->processName()) {
216  mustReorder = true;
217  break;
218  }
219  }
220  if(mustReorder) {
221  break;
222  }
223  }
224  ++itH;
225  }
226  if(!mustReorder && it != itEnd && *it == iNewProcessName) {
227  ++it;
228  }
229  //can only reach the end if we found all the items in the correct order
230  if(it == itEnd) {
231  return;
232  }
233  }
234 
235  //must re-sort
236  //Increment the fill count so users can check if the map has been modified.
237  ++fillCount_;
238  historyID = iHistory.id();
239  std::vector<std::string> temp(processNameOrdering.size(), std::string());
240 
241  //we want to add the items at the back
242  std::vector<std::string>::reverse_iterator itR = temp.rbegin();
243  std::vector<std::string>::reverse_iterator itREnd = temp.rend();
244  ProcessHistory::const_reverse_iterator itRH = iHistory.rbegin();
245  ProcessHistory::const_reverse_iterator itRHEnd = iHistory.rend();
246 
247  if(processNameOrdering.end() != std::find(processNameOrdering.begin(), processNameOrdering.end(), iNewProcessName)) {
248  *itR = iNewProcessName;
249  ++itR;
250  if (iNewProcessName == itRH->processName()) {
251  ++itRH;
252  }
253  }
254  for(; itRH != itRHEnd; ++itRH) {
255  if(processNameOrdering.end() != std::find(processNameOrdering.begin(), processNameOrdering.end(), itRH->processName())) {
256 
257  *itR = itRH->processName();
258  ++itR;
259  }
260  }
261 
262  //have to fill in the missing processes from processNameOrdering_
263  // we do this at the beginning because we lookup data in the reverse order
264  // so we want the ones we know are there to be searched first
265  std::vector<std::string>::iterator itOld = processNameOrdering.begin();
266  it = temp.begin();
267  std::vector<std::string>::iterator itStart = temp.begin()+(itREnd - itR);
268  while(it != itStart) {
269  assert(itOld != processNameOrdering.end());
270  if(temp.end() == std::find(itStart, temp.end(), *itOld)) {
271  //didn't find it so need to add this to our list
272  *it = *itOld;
273  ++it;
274  }
275  ++itOld;
276  }
277 
278  processNameOrdering.swap(temp);
279 
280  //now we need to go through our data structure and change the processing orders
281  //first find the range for this BranchType
282  std::pair<TypeInBranchTypeLookup::iterator, TypeInBranchTypeLookup::iterator> branchRange =
283  std::equal_range(branchLookup_.begin(), branchLookup_.end(), std::make_pair(TypeInBranchType(TypeID(), iBranch), BranchDescriptionIndex(0)), BranchTypeOnlyCompare());
284 
285  if(branchRange.first == branchRange.second) {
286  return;
287  }
288  //convert this into Index iterators since that is the structure we must reorder
289  ProductLookupIndexList::iterator itIndex = productLookupIndexList_.begin() + branchRange.first->second;
290  ProductLookupIndexList::iterator itIndexEnd = productLookupIndexList_.end();
291  if(branchRange.second != branchLookup_.end()) {
292  itIndexEnd = productLookupIndexList_.begin() + branchRange.second->second;
293  }
294 
295  while(itIndex != itIndexEnd) {
296  itIndex->setIsFirst(false);
297  ProductLookupIndexList::iterator itNext = itIndex;
298  while(itNext != itIndexEnd && !itNext->isFirst()) {
299  ++itNext;
300  }
301  std::sort(itIndex, itNext, CompareProcessList(&processNameOrdering));
302  itIndex->setIsFirst(true);
303  itIndex = itNext;
304  }
305 
306  //Now that we know all the IDs time to set the values
307  fillInProcessIndexes(productLookupIndexList_.begin() + branchRange.first->second, itIndexEnd, processNameOrdering);
308 
309  }
collection_type::const_iterator const_iterator
collection_type::const_reverse_iterator const_reverse_iterator
ProductLookupIndexList productLookupIndexList_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::vector< ProcessHistoryID > historyIDsForBranchType_
std::vector< std::vector< std::string > > processNameOrderingForBranchType_
Hash< ProcessHistoryType > ProcessHistoryID
static void fillInProcessIndexes(TransientProductLookupMap::ProductLookupIndexList::iterator iIt, TransientProductLookupMap::ProductLookupIndexList::iterator iEnd, std::vector< std::string > const &iNameOrder)
unsigned int BranchDescriptionIndex
void TransientProductLookupMap::reset ( void  )

Definition at line 76 of file TransientProductLookupMap.cc.

References branchLookup_, fillCount_, historyIDsForBranchType_, i, edm::NumBranchTypes, processNameOrderingForBranchType_, and productLookupIndexList_.

76  {
77  branchLookup_.clear();
79  for (unsigned int i = 0; i < static_cast<unsigned int>(NumBranchTypes); ++i) {
80  historyIDsForBranchType_[i].reset();
82  }
83  fillCount_ = 0;
84  }
int i
Definition: DBlmapReader.cc:9
ProductLookupIndexList productLookupIndexList_
std::vector< ProcessHistoryID > historyIDsForBranchType_
std::vector< std::vector< std::string > > processNameOrderingForBranchType_

Member Data Documentation

TypeInBranchTypeLookup edm::TransientProductLookupMap::branchLookup_
private

Definition at line 93 of file TransientProductLookupMap.h.

Referenced by equal_range(), fillFrom(), reorderIfNecessary(), and reset().

int edm::TransientProductLookupMap::fillCount_
private

Definition at line 97 of file TransientProductLookupMap.h.

Referenced by fillCount(), fillFrom(), reorderIfNecessary(), and reset().

std::vector<ProcessHistoryID> edm::TransientProductLookupMap::historyIDsForBranchType_
private

Definition at line 95 of file TransientProductLookupMap.h.

Referenced by fillFrom(), reorderIfNecessary(), and reset().

std::vector<std::vector<std::string> > edm::TransientProductLookupMap::processNameOrderingForBranchType_
private

Definition at line 96 of file TransientProductLookupMap.h.

Referenced by fillFrom(), reorderIfNecessary(), and reset().

ProductLookupIndexList edm::TransientProductLookupMap::productLookupIndexList_
private

Definition at line 94 of file TransientProductLookupMap.h.

Referenced by begin(), end(), equal_range(), fillFrom(), reorderIfNecessary(), and reset().