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 384 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().

384  {
385  TypeInBranchTypeLookup::const_iterator itFind = std::lower_bound(branchLookup_.begin(),
386  branchLookup_.end(),
387  std::make_pair(iKey, BranchDescriptionIndex(0)),
388  CompareFirst());
389  if(itFind == branchLookup_.end() || iKey < itFind->first) {
390  return std::make_pair(productLookupIndexList_.end(), productLookupIndexList_.end());
391  }
392  const_iterator itStart = productLookupIndexList_.begin() + itFind->second;
394  if(++itFind != branchLookup_.end()) {
395  itEnd = productLookupIndexList_.begin() + itFind->second;
396  }
397  return std::make_pair(itStart, itEnd);
398  }
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 401 of file TransientProductLookupMap.cc.

References equal_range().

403  {
404  std::pair<const_iterator, const_iterator> itPair = this->equal_range(iKey);
405 
406  if (itPair.first == itPair.second) {
407  return itPair;
408  }
409 
410  // Advance lower bound only
411  itPair.first = std::lower_bound(itPair.first, itPair.second, std::make_pair(&moduleLabel, &productInstanceName), CompareModuleLabelAndProductInstanceName());
412  // Protect against no match
413  if (!(itPair.first < itPair.second) ||
414  itPair.first->branchDescription()->moduleLabel() != moduleLabel ||
415  itPair.first->branchDescription()->productInstanceName() != productInstanceName) {
416  itPair.second = itPair.first;
417  }
418  return itPair;
419  }
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 ...
const std::string * moduleLabel() const
Definition: HLTadd.h:40
int edm::TransientProductLookupMap::fillCount ( ) const
inline
void TransientProductLookupMap::fillFrom ( FillFromMap const &  iMap)

Definition at line 313 of file TransientProductLookupMap.cc.

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

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

313  {
314 
316 
317  //Increment the fill count so users can check if the map has been modified.
318  ++fillCount_;
319 
320  productLookupIndexList_.clear();
321  productLookupIndexList_.reserve(iMap.size());
322  branchLookup_.clear();
323  branchLookup_.reserve(iMap.size()); //this is an upperbound
324 
325  std::set<std::string, std::greater<std::string> > processNames;
326  TypeInBranchType lastSeen(TypeID(), NumBranchTypes);
327 
328  //since the actual strings are stored elsewhere, there is no reason to make a copy
329  static std::string const kEmpty;
330  std::string const* lastSeenModule = &kEmpty;
331  std::string const* lastSeenProductInstance = &kEmpty;
332  for(FillFromMap::const_iterator it = iMap.begin(), itEnd = iMap.end();
333  it != itEnd;
334  ++it) {
335  bool isFirst = ((lastSeen < it->first.first) || (it->first.first < lastSeen));
336  if(isFirst) {
337  lastSeen = it->first.first;
338  branchLookup_.push_back(std::make_pair(lastSeen, BranchDescriptionIndex(productLookupIndexList_.size())));
339  } else {
340  //see if this is the first of a group that only differ by ProcessName
341  isFirst = (*lastSeenModule != it->first.second->moduleLabel() ||
342  *lastSeenProductInstance != it->first.second->productInstanceName());
343  }
344  productLookupIndexList_.push_back(ProductLookupIndex(it->first.second,
345  it->second,
346  0,
347  isFirst)
348  );
349  if(isFirst) {
350  lastSeenModule = &(it->first.second->moduleLabel());
351  lastSeenProductInstance = &(it->first.second->productInstanceName());
352  }
353  processNames.insert(it->first.second->processName());
354  }
355 
356  std::vector<ProcessHistoryID>::iterator itPH = historyIDsForBranchType_.begin();
357  std::vector<ProcessHistoryID>::iterator itPHEnd = historyIDsForBranchType_.end();
358 
359  std::vector<std::vector<std::string> >::iterator itPN = processNameOrderingForBranchType_.begin();
360  std::vector<std::vector<std::string> >::iterator itPNEnd = processNameOrderingForBranchType_.end();
361 
362  for(;itPH != itPHEnd; ++itPH, ++itPN) {
363  *itPH = ProcessHistoryID();
364  itPN->assign(processNames.begin(), processNames.end());
365  }
366 
367  //Now that we know all the IDs time to set the values
369  }
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 cond::rpcobtemp::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 
242  //we want to add the items at the back
243  std::vector<std::string>::reverse_iterator itR = temp.rbegin();
244  std::vector<std::string>::reverse_iterator itREnd = temp.rend();
245  ProcessHistory::const_reverse_iterator itRH = iHistory.rbegin();
246  ProcessHistory::const_reverse_iterator itRHEnd = iHistory.rend();
247 
248  if(processNameOrdering.end() != std::find(processNameOrdering.begin(), processNameOrdering.end(), iNewProcessName)) {
249  *itR = iNewProcessName;
250  ++itR;
251  if (iNewProcessName == itRH->processName()) {
252  ++itRH;
253  }
254  }
255  for(; itRH != itRHEnd; ++itRH) {
256  if(processNameOrdering.end() != std::find(processNameOrdering.begin(), processNameOrdering.end(), itRH->processName())) {
257 
258  *itR = itRH->processName();
259  ++itR;
260  }
261  }
262 
263  //have to fill in the missing processes from processNameOrdering_
264  // we do this at the beginning because we lookup data in the reverse order
265  // so we want the ones we know are there to be searched first
266  std::vector<std::string>::iterator itOld = processNameOrdering.begin();
267  it = temp.begin();
268  std::vector<std::string>::iterator itStart = temp.begin()+(itREnd - itR);
269  while(it != itStart) {
270  assert(itOld != processNameOrdering.end());
271  if(temp.end() == std::find(itStart, temp.end(), *itOld)) {
272  //didn't find it so need to add this to our list
273  *it = *itOld;
274  ++it;
275  }
276  ++itOld;
277  }
278 
279  processNameOrdering.swap(temp);
280 
281  //now we need to go through our data structure and change the processing orders
282  //first find the range for this BranchType
283  std::pair<TypeInBranchTypeLookup::iterator, TypeInBranchTypeLookup::iterator> branchRange =
284  std::equal_range(branchLookup_.begin(), branchLookup_.end(), std::make_pair(TypeInBranchType(TypeID(), iBranch), BranchDescriptionIndex(0)), BranchTypeOnlyCompare());
285 
286  if(branchRange.first == branchRange.second) {
287  return;
288  }
289  //convert this into Index iterators since that is the structure we must reorder
290  ProductLookupIndexList::iterator itIndex = productLookupIndexList_.begin() + branchRange.first->second;
291  ProductLookupIndexList::iterator itIndexEnd = productLookupIndexList_.end();
292  if(branchRange.second != branchLookup_.end()) {
293  itIndexEnd = productLookupIndexList_.begin() + branchRange.second->second;
294  }
295 
296  while(itIndex != itIndexEnd) {
297  itIndex->setIsFirst(false);
298  ProductLookupIndexList::iterator itNext = itIndex;
299  while(itNext != itIndexEnd && !itNext->isFirst()) {
300  ++itNext;
301  }
302  std::sort(itIndex, itNext, CompareProcessList(&processNameOrdering));
303  itIndex->setIsFirst(true);
304  itIndex = itNext;
305  }
306 
307  //Now that we know all the IDs time to set the values
308  fillInProcessIndexes(productLookupIndexList_.begin() + branchRange.first->second, itIndexEnd, processNameOrdering);
309 
310  }
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_.

Referenced by BeautifulSoup.BeautifulStoneSoup::__init__().

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().