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.2 by konec, Thu May 23 18:24:04 2013 UTC vs.
Revision 1.4 by konec, Mon May 27 11:02:41 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 + {
14 +  unsigned int thissize = theData.size();
15 +  if (thissize != o.size()) return false;
16 +  for (unsigned int idx=0; idx<thissize; idx++) {
17 +     if (theData[idx].first != o.theData[idx].first) return false;
18 +     if (theData[idx].second != o.theData[idx].second) return false;
19 +  }
20 +  return true;
21 + }
22  
23 < bool Pattern::add ( std::pair<uint32_t,  unsigned int > aData)
23 > Pattern Pattern::addOrCopy( std::pair<uint32_t,  unsigned int > aData)
24   {
25 <  for (DataType::const_iterator it=theData.begin(); it!= theData.end(); it++) {
26 <    if (it->first == aData.first) {
27 <      return false;
25 >  for (unsigned int idx=0; idx < theData.size(); ++idx) {
26 >    if (theData[idx].first == aData.first) {
27 >      Pattern modified =  *this;
28 >      modified.theData[idx].second = aData.second;
29 >      return modified;
30 > //      if (*this == modified) return Pattern(); // nothing to do
31 > //      else  return modified;                   // really duplicate
32      }
33    }
34    theData.push_back(aData);
35 <  return true;
35 >  return Pattern();
36   }
37  
38 < bool Pattern::add (  std::vector<Pattern> & vpat, std::pair<uint32_t,  unsigned int > aData)
38 > void Pattern::add (  std::vector<Pattern> & vpat, std::pair<uint32_t,  unsigned int > aData)
39   {
26  bool allOK = true;
40    std::vector<Pattern> copied;
41    for (std::vector<Pattern>::iterator ip = vpat.begin(); ip != vpat.end(); ++ip) {
42 <    if (! ip->add(aData) ) {
43 <      allOK = false;
31 <      Pattern modified = *ip;
32 <      for (auto ic =modified.theData.begin(); ic!=modified.theData.end(); ic++) {
33 <        if (ic->first==aData.first) {ic->second = aData.second; break; }
34 <      }
35 <      copied.push_back(modified);
36 <    }
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());
39  return allOK;
46   }
47  
48  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines