File indexing completed on 2024-04-06 11:59:31
0001 #include "CalibTracker/SiPixelConnectivity/interface/PixelEndcapLinkMaker.h"
0002 #include "DataFormats/SiPixelDetId/interface/PixelModuleName.h"
0003 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0004 #include "CondFormats/SiPixelObjects/interface/PixelROC.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include <ostream>
0007
0008 using namespace std;
0009 using namespace sipixelobjects;
0010
0011 bool PixelEndcapLinkMaker::Order::operator()(const Item& u1, const Item& u2) const {
0012 bool res = true;
0013 const PixelEndcapName& n1 = *u1.name;
0014 const PixelEndcapName& n2 = *u2.name;
0015
0016 if (n1.halfCylinder() < n2.halfCylinder())
0017 res = true;
0018 else if (n1.halfCylinder() > n2.halfCylinder())
0019 res = false;
0020 else if (n1.diskName() < n2.diskName())
0021 res = true;
0022 else if (n1.diskName() > n2.diskName())
0023 res = false;
0024 else if (n1.bladeName() < n2.bladeName())
0025 res = true;
0026 else if (n1.bladeName() > n2.bladeName())
0027 res = false;
0028 else if (n1.pannelName() < n2.pannelName())
0029 res = true;
0030 else if (n1.pannelName() > n2.pannelName())
0031 res = false;
0032 else if (n1.plaquetteName() < n2.plaquetteName())
0033 res = true;
0034 else if (n1.plaquetteName() > n2.plaquetteName())
0035 res = false;
0036
0037 return res;
0038 }
0039
0040 PixelEndcapLinkMaker::Links PixelEndcapLinkMaker::links(const Names& n, const DetUnits& u) const {
0041 Links result;
0042 typedef Names::const_iterator CIN;
0043
0044
0045
0046
0047 vector<Item> linkItems;
0048 typedef vector<Item>::const_iterator CIU;
0049
0050 for (unsigned int idx = 0; idx < n.size(); idx++) {
0051 Item item;
0052 PixelEndcapName* e = dynamic_cast<PixelEndcapName*>(n[idx]);
0053 uint32_t d = u[idx];
0054 item.name = e;
0055 item.unit = d;
0056 Range rocIds(-1, -1);
0057 PixelModuleName::ModuleType type = e->moduleType();
0058 switch (type) {
0059 case (PixelModuleName::v1x2): {
0060 rocIds = Range(0, 1);
0061 break;
0062 }
0063 case (PixelModuleName::v1x5): {
0064 rocIds = Range(0, 4);
0065 break;
0066 }
0067 case (PixelModuleName::v2x3): {
0068 rocIds = Range(0, 5);
0069 break;
0070 }
0071 case (PixelModuleName::v2x4): {
0072 rocIds = Range(0, 7);
0073 break;
0074 }
0075 case (PixelModuleName::v2x5): {
0076 rocIds = Range(0, 9);
0077 break;
0078 }
0079 default:
0080 edm::LogError("PixelEndcapLinkMaker") << " *** UNEXPECTED roc: " << e->name();
0081 };
0082 item.rocIds = rocIds;
0083 linkItems.push_back(item);
0084 }
0085
0086
0087
0088
0089 sort(linkItems.begin(), linkItems.end(), Order());
0090
0091
0092
0093
0094 ostringstream str;
0095 for (CIU it = linkItems.begin(); it != linkItems.end(); it++) {
0096 str << (*it).name->name() << " r=" << (*it).rocIds << endl;
0097 }
0098 LogDebug(" sorted ENDCAP links: ") << str.str();
0099
0100 result.reserve(36);
0101 int lastPannelId = -1;
0102 int idLink = 0;
0103 int idRoc = 0;
0104 PixelFEDLink link(idLink);
0105
0106 for (CIU it = linkItems.begin(); it != linkItems.end(); it++) {
0107 PixelFEDLink::ROCs rocs;
0108 int pannelId = it->name->pannelName();
0109
0110 if (pannelId != lastPannelId) {
0111 lastPannelId = pannelId;
0112 if (idLink > 0)
0113 result.push_back(link);
0114 idRoc = 0;
0115 link = PixelFEDLink(++idLink);
0116 }
0117
0118 for (int id = (*it).rocIds.min(); id <= (*it).rocIds.max(); id++) {
0119 ++idRoc;
0120 rocs.push_back(PixelROC(it->unit, id, idRoc));
0121 }
0122
0123 link.add(rocs);
0124 }
0125
0126 if (idLink > 0)
0127 result.push_back(link);
0128 return result;
0129 }