ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/L1RpcTriggerAnalysis/src/Pattern.cc
(Generate patch)

Comparing UserCode/L1RpcTriggerAnalysis/src/Pattern.cc (file contents):
Revision 1.4 by konec, Mon May 27 11:02:41 2013 UTC vs.
Revision 1.6 by akalinow, Tue Jun 25 11:06:03 2013 UTC

# Line 9 | Line 9
9   #include "UserCode/L1RpcTriggerAnalysis/interface/CSCDigiSpec.h"
10   #include "UserCode/L1RpcTriggerAnalysis/interface/RPCDigiSpec.h"
11  
12 < bool Pattern::operator==(const Pattern& o) const
13 < {
12 > bool Pattern::operator==(const Pattern& o) const{
13    unsigned int thissize = theData.size();
14    if (thissize != o.size()) return false;
15 <  for (unsigned int idx=0; idx<thissize; idx++) {
16 <     if (theData[idx].first != o.theData[idx].first) return false;
17 <     if (theData[idx].second != o.theData[idx].second) return false;
18 <  }
15 >
16 >  for (auto it = theData.cbegin(); it != theData.cend(); ++it){
17 >    auto itComp = o.theData.find(it->first);    
18 >    if(itComp==o.theData.cend()) return false;
19 >    if(itComp->second!=it->second) return false;    
20 >  }
21 >
22    return true;
23   }
24  
25 < Pattern Pattern::addOrCopy( std::pair<uint32_t,  unsigned int > aData)
26 < {
27 <  for (unsigned int idx=0; idx < theData.size(); ++idx) {
28 <    if (theData[idx].first == aData.first) {
29 <      Pattern modified =  *this;
30 <      modified.theData[idx].second = aData.second;
31 <      return modified;
30 < //      if (*this == modified) return Pattern(); // nothing to do
31 < //      else  return modified;                   // really duplicate
32 <    }
25 > Pattern Pattern::addOrCopy( std::pair<uint32_t,  unsigned int > aData){
26 >
27 >  auto it = theData.find(aData.first);    
28 >  if(it!= theData.cend()){
29 >    Pattern modified =  *this;
30 >    modified.theData[aData.first] = aData.second;
31 >    return modified;
32    }
33 <  theData.push_back(aData);
33 >  theData[aData.first] = aData.second;
34    return Pattern();
35   }
36  
37   void Pattern::add (  std::vector<Pattern> & vpat, std::pair<uint32_t,  unsigned int > aData)
38   {
39 +  /*
40    std::vector<Pattern> copied;
41    for (std::vector<Pattern>::iterator ip = vpat.begin(); ip != vpat.end(); ++ip) {
42      Pattern modified =  ip->addOrCopy(aData);
43      if (modified && (find(copied.begin(), copied.end(), modified) == copied.end()) ) copied.push_back(modified);
44    }
45    if (copied.size() != 0) vpat.insert(vpat.end(), copied.begin(), copied.end());
46 < }
46 >  */
47  
48 +  //Use indexing to avoid problem with iterator invalidation afer adding new elements to vector
49 +  uint32_t vSize = vpat.size();
50 +  for(uint32_t index = 0;index<vSize;++index){
51 +    Pattern modified =  vpat[index].addOrCopy(aData);
52 +    if (modified && (find(vpat.begin(), vpat.end(), modified) == vpat.end()) ) vpat.push_back(modified);
53 +  }
54 + }
55  
56  
57   std::ostream & operator << (std::ostream &out, const Pattern &o)
58   {
59    out <<" Pattern:  size: "<<o.size();
60 <  for (Pattern::DataType::const_iterator it=o.theData.begin(); it!= o.theData.end(); it++) {
60 >  for (auto it = o.theData.cbegin(); it != o.theData.cend(); ++it){
61      DetId detId( it->first);
62      switch (detId.subdetId()) {
63        case MuonSubdetId::RPC: { out << std::endl <<" RPC: "<<RPCDigiSpec(it->first, it->second);  break; }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines