Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef PixelCalibConfiguration_h
0002 #define PixelCalibConfiguration_h
0003 /*! \file CalibFormats/SiPixelObjects/interface/PixelCalibConfiguration.h
0004 *   \brief This class implements the steps that are used in a scan over Threshold and CalDelay
0005 *
0006 *   A longer explanation will be placed here later
0007 */
0008 
0009 #include <vector>
0010 #include <set>
0011 #include <map>
0012 #include <string>
0013 #include <sstream>
0014 #include <utility>
0015 #include "CalibFormats/SiPixelObjects/interface/PixelCalibBase.h"
0016 #include "CalibFormats/SiPixelObjects/interface/PixelNameTranslation.h"
0017 #include "CalibFormats/SiPixelObjects/interface/PixelDetectorConfig.h"
0018 #include "CalibFormats/SiPixelObjects/interface/PixelFEDConfig.h"
0019 #include "CalibFormats/SiPixelObjects/interface/PixelFECConfig.h"
0020 #include "CalibFormats/SiPixelObjects/interface/PixelTKFECConfig.h"
0021 #include "CalibFormats/SiPixelObjects/interface/PixelFECConfigInterface.h"
0022 #include "CalibFormats/SiPixelObjects/interface/PixelROCName.h"
0023 #include "CalibFormats/SiPixelObjects/interface/PixelModuleName.h"
0024 #include "CalibFormats/SiPixelObjects/interface/PixelModuleName.h"
0025 #include "CalibFormats/SiPixelObjects/interface/PixelMaskBase.h"
0026 #include "CalibFormats/SiPixelObjects/interface/PixelTrimBase.h"
0027 #include "CalibFormats/SiPixelObjects/interface/PixelROCMaskBits.h"
0028 #include "CalibFormats/SiPixelObjects/interface/PixelROCTrimBits.h"
0029 #include "CalibFormats/SiPixelObjects/interface/PixelDACSettings.h"
0030 #include "CalibFormats/SiPixelObjects/interface/PixelConfigBase.h"
0031 #include "CalibFormats/SiPixelObjects/interface/PixelDACScanRange.h"
0032 #include "CalibFormats/SiPixelObjects/interface/PixelPortcardMap.h"
0033 #include "CalibFormats/SiPixelObjects/interface/PixelPortCardConfig.h"
0034 
0035 namespace pos {
0036   class PixelHdwAddress;
0037 
0038   //This class contains info about a ROC
0039   class PixelROCInfo {
0040   public:
0041     bool use_;
0042     const PixelHdwAddress* hdwadd_;
0043     //FIXME these should be const but it has ripple effects...
0044     PixelROCTrimBits* trims_;
0045     PixelROCMaskBits* masks_;
0046     std::vector<std::pair<unsigned int, unsigned int> > defaultDACs_;
0047     std::string tbmChannel_;
0048   };
0049 
0050   /*!  \ingroup ConfigurationObjects "Configuration Objects"
0051 *    \ingroup CalibrationObjects "Calibration Objects"
0052 *    \brief This class implements the steps that are used in a scan over Threshold and CalDelay
0053 *
0054 *    It features a double inheritance, both from ConfigurationObjects and CalibrationObjects
0055 *
0056 *  @{
0057 *
0058 *   \class PixelCalibConfiguration PixelCalibConfiguration.h "interface/PixelCalibConfiguration.h"
0059 *
0060 *   A longer explanation will be placed here later
0061 */
0062   class PixelCalibConfiguration;
0063   std::ostream& operator<<(std::ostream& s, const PixelCalibConfiguration& calib);
0064 
0065   class PixelCalibConfiguration : public PixelCalibBase, public PixelConfigBase {
0066   public:
0067     PixelCalibConfiguration(std::string filename = "");
0068     PixelCalibConfiguration(std::vector<std::vector<std::string> >&);
0069 
0070     ~PixelCalibConfiguration() override;
0071 
0072     // This must be run before using commands that require the ROC list.
0073     void buildROCAndModuleLists(const PixelNameTranslation* translation, const PixelDetectorConfig* detconfig);
0074 
0075     void nextFECState(std::map<unsigned int, PixelFECConfigInterface*>& pixelFECs,
0076                       PixelDetectorConfig* detconfig,
0077                       PixelNameTranslation* trans,
0078                       std::map<pos::PixelModuleName, pos::PixelMaskBase*>* masks,
0079                       std::map<pos::PixelModuleName, pos::PixelTrimBase*>* trims,
0080                       std::map<pos::PixelModuleName, pos::PixelDACSettings*>* dacss,
0081                       unsigned int state) const;
0082 
0083     //return vector of fed# and channels controlled by this fed supervisor
0084     std::vector<std::pair<unsigned int, std::vector<unsigned int> > >& fedCardsAndChannels(
0085         unsigned int crate,
0086         PixelNameTranslation* translation,
0087         PixelFEDConfig* fedconfig,
0088         PixelDetectorConfig* detconfig) const;
0089 
0090     std::map<unsigned int, std::set<unsigned int> > getFEDsAndChannels(PixelNameTranslation* translation);
0091 
0092     // Returns a std::set of FED crates that are used by this Calib object
0093     std::set<unsigned int> getFEDCrates(const PixelNameTranslation* translation, const PixelFEDConfig* fedconfig) const;
0094 
0095     // Returns a std::set of FEC crates that are used by this Calib object
0096     std::set<unsigned int> getFECCrates(const PixelNameTranslation* translation, const PixelFECConfig* fecconfig) const;
0097 
0098     // Returns a std::set of TKFEC crates that are used by this Calib object
0099     std::set<unsigned int> getTKFECCrates(const PixelPortcardMap* portcardmap,
0100                                           const std::map<std::string, PixelPortCardConfig*>& mapNamePortCard,
0101                                           const PixelTKFECConfig* tkfecconfig) const;
0102 
0103     unsigned int nROC() const {
0104       assert(rocAndModuleListsBuilt_);
0105       return nROC_;
0106     }
0107     unsigned int nPixelPatterns() const { return rows_.size() * cols_.size(); }
0108     unsigned int nTriggersPerPattern() const { return ntrigger_; }
0109     unsigned int nScanPoints(std::string dac) const { return nScanPoints(iScan(dac)); }
0110 
0111     unsigned int nScanPoints() const {
0112       unsigned int points = 1;
0113       for (unsigned int i = 0; i < dacs_.size(); i++) {
0114         points *= nScanPoints(i);
0115       }
0116       return points;
0117     }
0118     unsigned int nConfigurations() const { return nPixelPatterns() * nScanPoints() * nROC(); }
0119     unsigned int nTriggersTotal() const { return nConfigurations() * nTriggersPerPattern(); }
0120 
0121     bool noHits() const { return (maxNumHitsPerROC() == 0); }  // returns true if no hits will be produced
0122     unsigned int maxNumHitsPerROC()
0123         const;  // returns the maximum number of hits that will be produced in any pixel pattern
0124 
0125     // Return all the pixels that are enabled for this state.
0126     std::set<std::pair<unsigned int, unsigned int> > pixelsWithHits(unsigned int state) const;
0127     //                  column #      row #
0128 
0129     // Whether this ROC is currently being scanned.  (Always true when not in SingleROC mode.)
0130     bool scanningROCForState(PixelROCName roc, unsigned int state) const;
0131 
0132     unsigned int scanCounter(std::string dac, unsigned int state) const { return scanCounter(iScan(dac), state); }
0133 
0134     unsigned int scanValue(std::string dac, unsigned int state, PixelROCName roc) const {
0135       return scanValue(iScan(dac), state, roc);
0136     }
0137 
0138     // This function should not be used -- provided for backwards compatibility only.  It asserts if the scan values for this dac are mixed across different ROCs.
0139     unsigned int scanValue(std::string dac, unsigned int state) const {
0140       assert(!(dacs_[iScan(dac)].mixValuesAcrossROCs()));
0141       return scanValue(iScan(dac), state, 0, 1);
0142     }
0143 
0144     unsigned int numberOfScanVariables() const { return dacs_.size(); }
0145 
0146     bool containsScan(std::string name) const;
0147 
0148     std::string scanName(unsigned int iscan) const { return dacs_[iscan].name(); }
0149     std::vector<unsigned int> scanValues(std::string dac) const { return scanValues(iScan(dac)); }
0150 
0151     double scanValueMin(std::string dac) const { return scanValueMin(iScan(dac)); }
0152     double scanValueMax(std::string dac) const { return scanValueMax(iScan(dac)); }
0153     double scanValueStep(std::string dac) const { return scanValueStep(iScan(dac)); }
0154     bool scanValuesMixedAcrossROCs(std::string dac) const { return scanValuesMixedAcrossROCs(iScan(dac)); }
0155 
0156     unsigned int iScan(std::string dac) const;
0157 
0158     const std::vector<std::vector<unsigned int> >& columnList() const { return cols_; }
0159     const std::vector<std::vector<unsigned int> >& rowList() const { return rows_; }
0160     const std::vector<PixelROCName>& rocList() const {
0161       assert(rocAndModuleListsBuilt_);
0162       return rocs_;
0163     }
0164     const std::set<PixelModuleName>& moduleList() const {
0165       assert(rocAndModuleListsBuilt_);
0166       return modules_;
0167     }
0168     const std::set<PixelChannel>& channelList() const {
0169       assert(objectsDependingOnTheNameTranslationBuilt_);
0170       return channels_;
0171     }
0172 
0173     std::string mode() const override { return mode_; }
0174 
0175     bool singleROC() const { return singleROC_; }
0176 
0177     unsigned int nParameters() const { return parameters_.size(); }
0178 
0179     // Added by Dario Apr 24th, 2008
0180     std::map<std::string, std::string> parametersList() const { return parameters_; }
0181     // get the value of parameter parameterName, or "" if parameterName is not in the list
0182     std::string parameterValue(std::string parameterName) const;
0183 
0184     // Added by Dario May 8th, 2008
0185     std::string getStreamedContent(void) const { return calibFileContent_; };
0186 
0187     friend std::ostream& pos::operator<<(std::ostream& s, const PixelCalibConfiguration& calib);
0188 
0189     void writeASCII(std::string dir = "") const override;
0190     void writeXML(pos::PixelConfigKey key, int version, std::string path) const override { ; }
0191     void writeXMLHeader(pos::PixelConfigKey key,
0192                         int version,
0193                         std::string path,
0194                         std::ofstream* out,
0195                         std::ofstream* out1 = nullptr,
0196                         std::ofstream* out2 = nullptr) const override;
0197     void writeXML(std::ofstream* out, std::ofstream* out1 = nullptr, std::ofstream* out2 = nullptr) const override;
0198     void writeXMLTrailer(std::ofstream* out,
0199                          std::ofstream* out1 = nullptr,
0200                          std::ofstream* out2 = nullptr) const override;
0201 
0202   private:
0203     // Which set of rows we're on.
0204     unsigned int rowCounter(unsigned int state) const;
0205 
0206     // Which set of columns we're on.
0207     unsigned int colCounter(unsigned int state) const;
0208 
0209     // In SingleROC mode, which ROC we're on.  In normal mode, this equals 1.
0210     unsigned int scanROC(unsigned int state) const;
0211 
0212     unsigned int nScanPoints(unsigned int iscan) const { return dacs_[iscan].getNPoints(); }
0213 
0214     unsigned int scanCounter(unsigned int iscan, unsigned int state) const;
0215 
0216     unsigned int scanValue(unsigned int iscan,
0217                            unsigned int state,
0218                            unsigned int ROCNumber,
0219                            unsigned int ROCsOnChannel) const;
0220     unsigned int scanValue(unsigned int iscan, unsigned int state, PixelROCName roc) const;
0221 
0222     std::vector<unsigned int> scanValues(unsigned int iscan) const { return dacs_[iscan].values(); }
0223 
0224     double scanValueMin(unsigned int iscan) const { return dacs_[iscan].first(); }
0225     double scanValueMax(unsigned int iscan) const {
0226       return dacs_[iscan].first() + dacs_[iscan].step() * (nScanPoints(iscan) - 1);
0227     }
0228     double scanValueStep(unsigned int iscan) const { return dacs_[iscan].step(); }
0229     bool scanValuesMixedAcrossROCs(unsigned int iscan) const { return dacs_[iscan].mixValuesAcrossROCs(); }
0230 
0231     // Used in constructor or in buildROCAndModuleLists()
0232     void buildROCAndModuleListsFromROCSet(const std::set<PixelROCName>& rocSet);
0233 
0234     void buildObjectsDependingOnTheNameTranslation(const PixelNameTranslation* aNameTranslation);
0235 
0236     unsigned int ROCNumberOnChannelAmongThoseCalibrated(PixelROCName roc) const;
0237     unsigned int numROCsCalibratedOnChannel(PixelROCName roc) const;
0238 
0239     bool singleROC_;
0240 
0241     std::vector<std::vector<unsigned int> > rows_;
0242     std::vector<std::vector<unsigned int> > cols_;
0243 
0244     mutable std::vector<PixelROCName> rocs_;
0245     mutable std::vector<PixelROCInfo> rocInfo_;
0246     std::set<PixelModuleName> modules_;
0247     bool rocAndModuleListsBuilt_;
0248     std::vector<std::string> rocListInstructions_;
0249 
0250     // Objects built using the name translation.
0251     std::set<PixelChannel> channels_;
0252     std::map<PixelROCName, unsigned int> ROCNumberOnChannelAmongThoseCalibrated_;
0253     std::map<PixelROCName, unsigned int> numROCsCalibratedOnChannel_;
0254     bool objectsDependingOnTheNameTranslationBuilt_;
0255 
0256     mutable std::vector<std::pair<unsigned int, std::vector<unsigned int> > > fedCardsAndChannels_;
0257 
0258     //unsigned int vcal_;
0259 
0260     std::vector<PixelDACScanRange> dacs_;
0261 
0262     //std::vector<std::string> dacname_;
0263     //std::vector<unsigned int> dacchannel_;
0264     //std::vector<unsigned int> dac_first_;
0265     //std::vector<unsigned int> dac_last_;
0266     //std::vector<unsigned int> dac_step_;
0267 
0268     unsigned int ntrigger_;
0269     unsigned int nROC_;  //This is the maximal #ROCs on a given TBM
0270 
0271     bool highVCalRange_;
0272 
0273     void enablePixels(PixelFECConfigInterface* pixelFEC,
0274                       unsigned int irows,
0275                       unsigned int icols,
0276                       pos::PixelROCMaskBits* masks,
0277                       pos::PixelROCTrimBits* trims,
0278                       const PixelHdwAddress& theROC) const;
0279 
0280     void disablePixels(PixelFECConfigInterface* pixelFEC,
0281                        unsigned int irows,
0282                        unsigned int icols,
0283                        pos::PixelROCTrimBits* trims,
0284                        const PixelHdwAddress& theROC) const;
0285 
0286     void disablePixels(PixelFECConfigInterface* pixelFEC,
0287                        pos::PixelROCTrimBits* trims,
0288                        const PixelHdwAddress& theROC) const;
0289 
0290     mutable std::vector<int> old_irows;
0291     mutable std::vector<int> old_icols;
0292 
0293     std::map<std::string, std::string> parameters_;
0294     //       name         value
0295 
0296     bool _bufferData;
0297 
0298     bool usesROCList_;
0299 
0300     // Added by Dario May 8th, 2008
0301     std::string calibFileContent_;
0302   };
0303 }  // namespace pos
0304 /* @} */
0305 #endif