Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:26

0001 //
0002 //
0003 //
0004 //
0005 //
0006 
0007 #include "CalibFormats/SiPixelObjects/interface/PixelHdwAddress.h"
0008 #include <string>
0009 #include <cassert>
0010 #include <ostream>
0011 #include <iostream>
0012 
0013 using namespace pos;
0014 
0015 //====================================================================================
0016 PixelHdwAddress::PixelHdwAddress()
0017     : mfec_(0),
0018       mfecchannel_(0),
0019       portaddress_(0),
0020       hubaddress_(0),
0021       rocid_(0),
0022       fednumber_(0),
0023       fedchannel_(0),
0024       fedrocnumber_(0) {}
0025 
0026 //====================================================================================
0027 PixelHdwAddress::PixelHdwAddress(int fecnumber,
0028                                  int mfec,
0029                                  int mfecchannel,
0030                                  int hubaddress,
0031                                  int portaddress,
0032                                  int rocid,
0033                                  int fednumber,
0034                                  int fedchannel,
0035                                  int fedrocnumber)
0036     : fecnumber_(fecnumber),
0037       mfec_(mfec),
0038       mfecchannel_(mfecchannel),
0039       portaddress_(portaddress),
0040       hubaddress_(hubaddress),
0041       rocid_(rocid),
0042       fednumber_(fednumber),
0043       fedchannel_(fedchannel),
0044       fedrocnumber_(fedrocnumber) {
0045   //std::cout << "Created PixelHdwAddress:"<<std::endl;
0046   //std::cout << *this << std::endl;
0047 }
0048 
0049 //====================================================================================
0050 std::ostream& pos::operator<<(std::ostream& s, const PixelHdwAddress& pixelroc) {
0051   s << "[PixelHdwAddress::operator<<]" << std::endl;
0052   s << "fecnumber   :" << pixelroc.fecnumber_ << std::endl;
0053   s << "mfec        :" << pixelroc.mfec_ << std::endl;
0054   s << "mfecchannel :" << pixelroc.mfecchannel_ << std::endl;
0055   s << "portaddress :" << pixelroc.portaddress_ << std::endl;
0056   s << "hubaddress  :" << pixelroc.hubaddress_ << std::endl;
0057   s << "rocid       :" << pixelroc.rocid_ << std::endl;
0058   s << "fednumber   :" << pixelroc.fednumber_ << std::endl;
0059   s << "fedchannel  :" << pixelroc.fedchannel_ << std::endl;
0060   s << "fedrocnumber:" << pixelroc.fedrocnumber_ << std::endl;
0061 
0062   return s;
0063 }
0064 
0065 //====================================================================================
0066 const PixelHdwAddress& PixelHdwAddress::operator=(const PixelHdwAddress& aROC) {
0067   fecnumber_ = aROC.fecnumber_;
0068   mfec_ = aROC.mfec_;
0069   mfecchannel_ = aROC.mfecchannel_;
0070   portaddress_ = aROC.portaddress_;
0071   hubaddress_ = aROC.hubaddress_;
0072   rocid_ = aROC.rocid_;
0073   fednumber_ = aROC.fednumber_;
0074   fedchannel_ = aROC.fedchannel_;
0075   fedrocnumber_ = aROC.fedrocnumber_;
0076 
0077   return *this;
0078 }
0079 
0080 //====================================================================================
0081 // Added by Dario
0082 void PixelHdwAddress::setAddress(std::string what, int value) {
0083   std::string mthn = "[PixelHdwAddress::setAddress()]\t\t\t    ";
0084   if (what == "fecnumber") {
0085     fecnumber_ = value;
0086   } else if (what == "mfec") {
0087     mfec_ = value;
0088   } else if (what == "mfecchannel") {
0089     mfecchannel_ = value;
0090   } else if (what == "portaddress") {
0091     portaddress_ = value;
0092   } else if (what == "hubaddress") {
0093     hubaddress_ = value;
0094   } else if (what == "rocid") {
0095     rocid_ = value;
0096   } else if (what == "fednumber") {
0097     fednumber_ = value;
0098   } else if (what == "fedchannel") {
0099     fedchannel_ = value;
0100   } else if (what == "fedrocnumber") {
0101     fedrocnumber_ = value;
0102   } else {
0103     std::cout << __LINE__ << "]\t" << mthn << "Could not set a value for " << what << " (invalid keyword)" << std::endl;
0104     assert(0);
0105   }
0106 }
0107 
0108 //====================================================================================
0109 void PixelHdwAddress::compare(std::string what, bool& changed, unsigned int newValue, unsigned int& oldValue) {
0110   std::string mthn = "[PixelHdwAddress::compare()]\t\t\t    ";
0111   changed = false;
0112   oldValue = 0;
0113 
0114   if (what == "fecnumber") {
0115     if (fecnumber_ != newValue) {
0116       changed = true;
0117       oldValue = fecnumber_;
0118       return;
0119     }
0120   } else if (what == "mfec") {
0121     if (mfec_ != newValue) {
0122       changed = true;
0123       oldValue = mfec_;
0124       return;
0125     }
0126   } else if (what == "mfecchannel") {
0127     if (mfecchannel_ != newValue) {
0128       changed = true;
0129       oldValue = mfecchannel_;
0130       return;
0131     }
0132   } else if (what == "portaddress") {
0133     if (portaddress_ != newValue) {
0134       changed = true;
0135       oldValue = portaddress_;
0136       return;
0137     }
0138   } else if (what == "hubaddress") {
0139     if (hubaddress_ != newValue) {
0140       changed = true;
0141       oldValue = hubaddress_;
0142       return;
0143     }
0144   } else if (what == "rocid") {
0145     if (rocid_ != newValue) {
0146       changed = true;
0147       oldValue = rocid_;
0148       return;
0149     }
0150   } else if (what == "fednumber") {
0151     if (fednumber_ != newValue) {
0152       changed = true;
0153       oldValue = fednumber_;
0154       return;
0155     }
0156   } else if (what == "fedchannel") {
0157     if (fedchannel_ != newValue) {
0158       changed = true;
0159       oldValue = fedchannel_;
0160       return;
0161     }
0162   } else if (what == "fedrocnumber") {
0163     if (fedrocnumber_ != newValue) {
0164       changed = true;
0165       oldValue = fedrocnumber_;
0166       return;
0167     }
0168   } else {
0169     std::cout << __LINE__ << "]\t" << mthn << "Could not compare value for " << what << " (invalid keyword)"
0170               << std::endl;
0171     assert(0);
0172   }
0173 }
0174 
0175 //====================================================================================
0176 bool PixelHdwAddress::operator()(const PixelHdwAddress& roc1, const PixelHdwAddress& roc2) const {
0177   if (roc1.fednumber_ < roc2.fednumber_)
0178     return true;
0179   if (roc1.fednumber_ > roc2.fednumber_)
0180     return false;
0181   if (roc1.fedchannel_ < roc2.fedchannel_)
0182     return true;
0183   if (roc1.fedchannel_ > roc2.fedchannel_)
0184     return false;
0185 
0186   return (roc1.fedrocnumber_ < roc2.fedrocnumber_);
0187 }