Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //
0002 //
0003 //
0004 //
0005 
0006 #include "CalibFormats/SiPixelObjects/interface/PixelConfigurationVerifier.h"
0007 #include "CalibFormats/SiPixelObjects/interface/PixelChannel.h"
0008 #include "CalibFormats/SiPixelObjects/interface/PixelROCStatus.h"
0009 #include <set>
0010 #include <cassert>
0011 
0012 using namespace pos;
0013 using namespace std;
0014 
0015 void PixelConfigurationVerifier::checkChannelEnable(PixelFEDCard *theFEDCard,
0016                                                     PixelNameTranslation *theNameTranslation,
0017                                                     PixelDetectorConfig *theDetConfig) {
0018   std::string mthn = "[PixelConfigurationVerifier::checkChannelEnable()]\t\t    ";
0019   set<PixelChannel> channels = theNameTranslation->getChannels(*theDetConfig);
0020 
0021   unsigned int fedid = theFEDCard->fedNumber;
0022 
0023   //use slots 1-36
0024 
0025   vector<bool> usedChannel(37);
0026   for (unsigned int i = 1; i < 37; i++) {
0027     usedChannel[i] = false;
0028   }
0029 
0030   set<PixelChannel>::const_iterator iChannel = channels.begin();
0031 
0032   map<int, int> nrocs;
0033   for (; iChannel != channels.end(); ++iChannel) {
0034     PixelHdwAddress hdw = theNameTranslation->getHdwAddress(*iChannel);
0035     if (fedid == hdw.fednumber()) {
0036       unsigned int fedchannel = hdw.fedchannel();
0037       assert(fedchannel > 0 && fedchannel < 37);
0038       usedChannel[fedchannel] = true;
0039       nrocs[fedchannel] = theNameTranslation->getROCsFromChannel(*iChannel).size();
0040     }
0041   }
0042 
0043   map<PixelROCName, PixelROCStatus> roclistcopy = theDetConfig->getROCsList();
0044   //Now check the channels
0045 
0046   for (unsigned int jChannel = 1; jChannel < 37; jChannel++) {
0047     bool used = theFEDCard->useChannel(jChannel);
0048     //    if (!used) cout << "Channel="<<jChannel<<" is not used"<<endl;
0049     if (used) {
0050       //            cout << "Channel="<<jChannel<<" is used"<<endl;
0051       //check that nROCs is the same from theNameTranslation and theFEDCard
0052       if (nrocs[jChannel] != theFEDCard->NRocs[jChannel - 1]) {
0053         cout << "[PixelConfigurationVerifier] Warning in FED#" << fedid << ", channel#" << jChannel
0054              << ": number of ROCs mismatch: theNameTranslation=" << nrocs[jChannel]
0055              << "; theFEDCard=" << theFEDCard->NRocs[jChannel - 1] << endl;
0056       }
0057     }
0058 
0059     //only do these checks if the channel exists
0060     if (theNameTranslation->FEDChannelExist(fedid, jChannel)) {
0061       //make sure that all rocs on a channel have the same noAnalogSignal status
0062       vector<PixelROCName> rocsOnThisChannel = theNameTranslation->getROCsFromFEDChannel(fedid, jChannel);
0063       bool onehasNAS = false, onedoesnothaveNAS = false;
0064       vector<PixelROCName>::const_iterator jROC = rocsOnThisChannel.begin();
0065       for (; jROC != rocsOnThisChannel.end(); ++jROC) {
0066         PixelROCStatus thisROCstatus = roclistcopy[*jROC];
0067         if (thisROCstatus.get(PixelROCStatus::noAnalogSignal))
0068           onehasNAS = true;
0069         else
0070           onedoesnothaveNAS = true;
0071       }
0072       if (onehasNAS && onedoesnothaveNAS) {
0073         cout << "[PixelConfigurationVerifier] Error in FED#" << fedid << ", channel#" << jChannel
0074              << ": not all ROCs have the same noAnalogSignal state." << endl;
0075         assert(0);
0076       }
0077 
0078       //now if onehasNAS is true, then all must be noAnalogSignal --> turn off this FED channel!
0079       if (onehasNAS) {
0080         cout << "[PixelConfigurationVerifier] FEDid=" << fedid << ", channel=" << jChannel
0081              << ": Channel disabled because ROCs are set to noAnalogSignal" << endl;
0082         theFEDCard->setChannel(jChannel, false);  //false should disable the channel
0083       }
0084 
0085       if (!onehasNAS && (used != usedChannel[jChannel])) {
0086         cout << __LINE__ << "]\t" << mthn << "*******************************************************" << endl;
0087         cout << __LINE__ << "]\t" << mthn << "WARNING for fedid=" << fedid << " and channel=" << jChannel
0088              << " found that fedcard has channel as " << endl;
0089         if (used)
0090           cout << __LINE__ << "]\t" << mthn << "used while configuration not using this channel" << endl;
0091         if (!used)
0092           cout << __LINE__ << "]\t" << mthn << "not used while configuration uses this channel" << endl;
0093         cout << __LINE__ << "]\t" << mthn << "The fedcard will be modifed to agree with configuration" << endl;
0094         cout << __LINE__ << "]\t" << mthn << "*******************************************************" << endl;
0095         theFEDCard->setChannel(jChannel, usedChannel[jChannel]);
0096       }
0097     }
0098   }
0099 }