1 |
#include "UserCode/L1RpcTriggerAnalysis/interface/Pattern.h"
|
2 |
|
3 |
#include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
|
4 |
#include "DataFormats/MuonDetId/interface/RPCDetId.h"
|
5 |
#include "DataFormats/MuonDetId/interface/CSCDetId.h"
|
6 |
#include "DataFormats/MuonDetId/interface/DTChamberId.h"
|
7 |
#include "UserCode/L1RpcTriggerAnalysis/interface/RPCDetIdUtil.h"
|
8 |
#include "UserCode/L1RpcTriggerAnalysis/interface/DTphDigiSpec.h"
|
9 |
#include "UserCode/L1RpcTriggerAnalysis/interface/CSCDigiSpec.h"
|
10 |
#include "UserCode/L1RpcTriggerAnalysis/interface/RPCDigiSpec.h"
|
11 |
|
12 |
bool Pattern::operator==(const Pattern& o) const{
|
13 |
unsigned int thissize = theData.size();
|
14 |
if (thissize != o.size()) return false;
|
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 |
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[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 |
*/
|
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 (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; }
|
64 |
case MuonSubdetId::DT: { out << std::endl <<" DT: "<<DTphDigiSpec(it->first, it->second); break; }
|
65 |
case MuonSubdetId::CSC: { out << std::endl <<" CSC: "<<CSCDigiSpec(it->first, it->second); break; }
|
66 |
};
|
67 |
}
|
68 |
return out;
|
69 |
}
|
70 |
|