CMS 3D CMS Logo

PixelCalibConfiguration.h

Go to the documentation of this file.
00001 #ifndef PixelCalibConfiguration_h
00002 #define PixelCalibConfiguration_h
00003 
00009 #include <vector>
00010 #include <set>
00011 #include <map>
00012 #include <string>
00013 #include <utility>
00014 #include "CalibFormats/SiPixelObjects/interface/PixelCalibBase.h"
00015 #include "CalibFormats/SiPixelObjects/interface/PixelNameTranslation.h"
00016 #include "CalibFormats/SiPixelObjects/interface/PixelDetectorConfig.h"
00017 #include "CalibFormats/SiPixelObjects/interface/PixelFEDConfig.h"
00018 #include "CalibFormats/SiPixelObjects/interface/PixelFECConfig.h"
00019 #include "CalibFormats/SiPixelObjects/interface/PixelTKFECConfig.h"
00020 #include "CalibFormats/SiPixelObjects/interface/PixelFECConfigInterface.h"
00021 #include "CalibFormats/SiPixelObjects/interface/PixelROCName.h"
00022 #include "CalibFormats/SiPixelObjects/interface/PixelModuleName.h"
00023 #include "CalibFormats/SiPixelObjects/interface/PixelModuleName.h"
00024 #include "CalibFormats/SiPixelObjects/interface/PixelMaskBase.h"
00025 #include "CalibFormats/SiPixelObjects/interface/PixelTrimBase.h"
00026 #include "CalibFormats/SiPixelObjects/interface/PixelROCMaskBits.h"
00027 #include "CalibFormats/SiPixelObjects/interface/PixelROCTrimBits.h"
00028 #include "CalibFormats/SiPixelObjects/interface/PixelDACSettings.h"
00029 #include "CalibFormats/SiPixelObjects/interface/PixelConfigBase.h"
00030 #include "CalibFormats/SiPixelObjects/interface/PixelDACScanRange.h"
00031 #include "CalibFormats/SiPixelObjects/interface/PixelPortcardMap.h"
00032 #include "CalibFormats/SiPixelObjects/interface/PixelPortCardConfig.h"
00033 
00034 
00035 namespace pos{
00036   class PixelHdwAddress;
00037 
00038   //This class contains info about a ROC
00039   class PixelROCInfo {    
00040   public:
00041     bool use_;
00042     const PixelHdwAddress* hdwadd_;
00043     //FIXME these should be const but it has ripple effects...
00044     PixelROCTrimBits* trims_;
00045     PixelROCMaskBits* masks_;
00046     std::vector<std::pair<unsigned int, unsigned int> > defaultDACs_;
00047     std::string tbmChannel_;
00048   };
00049 
00050 
00063   class PixelCalibConfiguration : public PixelCalibBase, public PixelConfigBase {
00064 
00065   public:
00066 
00067     PixelCalibConfiguration(std::string filename="");
00068     PixelCalibConfiguration(std::vector<std::vector<std::string> > &);
00069 
00070     virtual ~PixelCalibConfiguration();
00071 
00072     // This must be run before using commands that require the ROC list.
00073     void buildROCAndModuleLists(const PixelNameTranslation* translation, const PixelDetectorConfig* detconfig);
00074 
00075     void nextFECState(std::map<unsigned int, PixelFECConfigInterface*>& pixelFECs,
00076                       PixelDetectorConfig* detconfig,
00077                       PixelNameTranslation* trans,
00078                       std::map<pos::PixelModuleName,pos::PixelMaskBase*>* masks,
00079                       std::map<pos::PixelModuleName,pos::PixelTrimBase*>* trims,
00080                       std::map<pos::PixelModuleName,pos::PixelDACSettings*>* dacss,
00081                       unsigned int state) const; 
00082 
00083     //return vector of fed# and channels controlled by this fed supervisor
00084     std::vector<std::pair<unsigned int,std::vector<unsigned int> > >& fedCardsAndChannels(unsigned int crate, PixelNameTranslation* translation, PixelFEDConfig* fedconfig,PixelDetectorConfig* detconfig) const;
00085 
00086     std::map <unsigned int, std::set<unsigned int> > getFEDsAndChannels (PixelNameTranslation *translation);
00087     
00088     // Returns a std::set of FED crates that are used by this Calib object
00089     std::set <unsigned int> getFEDCrates(const PixelNameTranslation *translation, const PixelFEDConfig *fedconfig) const;
00090 
00091     // Returns a std::set of FEC crates that are used by this Calib object
00092     std::set <unsigned int> getFECCrates(const PixelNameTranslation *translation, const PixelFECConfig* fecconfig) const;
00093 
00094     // Returns a std::set of TKFEC crates that are used by this Calib object
00095     std::set <unsigned int> getTKFECCrates(const PixelPortcardMap *portcardmap, const std::map<std::string,PixelPortCardConfig*>& mapNamePortCard, const PixelTKFECConfig* tkfecconfig) const;
00096 
00097     unsigned int nROC() const { assert(rocAndModuleListsBuilt_); return nROC_; }
00098     unsigned int nPixelPatterns() const { return rows_.size()*cols_.size(); }
00099     unsigned int nTriggersPerPattern() const { return ntrigger_; }
00100     unsigned int nScanPoints(std::string dac) const { return nScanPoints(iScan(dac)); }    
00101 
00102     unsigned int nScanPoints() const {unsigned int points=1;
00103       for(unsigned int i=0;i<dacs_.size();i++) {
00104         points*=nScanPoints(i);
00105       }
00106       return points;
00107     }
00108     unsigned int nConfigurations() const { return nPixelPatterns()*nScanPoints()*nROC();}
00109     unsigned int nTriggersTotal() const {return nConfigurations()*nTriggersPerPattern();}
00110 
00111     bool noHits() const {return (maxNumHitsPerROC()==0);} // returns true if no hits will be produced
00112     unsigned int maxNumHitsPerROC() const; // returns the maximum number of hits that will be produced in any pixel pattern
00113 
00114     // Return all the pixels that are enabled for this state.
00115     std::set< std::pair<unsigned int, unsigned int> > pixelsWithHits(unsigned int state) const;
00116     //                  column #      row #
00117 
00118     // Whether this ROC is currently being scanned.  (Always true when not in SingleROC mode.)
00119     bool scanningROCForState(PixelROCName roc, unsigned int state) const;
00120 
00121     unsigned int scanCounter(std::string dac, unsigned int state) const{
00122       return scanCounter(iScan(dac),state);
00123     }
00124 
00125     unsigned int scanValue(std::string dac, unsigned int state, PixelROCName roc) const {
00126       return scanValue(iScan(dac), state, roc);
00127     }
00128 
00129     // 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.
00130     unsigned int scanValue(std::string dac, unsigned int state) const {
00131       assert( !(dacs_[iScan(dac)].mixValuesAcrossROCs()) );
00132       return scanValue(iScan(dac), state, 0, 1);
00133     }
00134 
00135     unsigned int numberOfScanVariables() const {return dacs_.size();}
00136 
00137     bool containsScan(std::string name) const;
00138 
00139     std::string scanName(unsigned int iscan) const {return dacs_[iscan].name();}
00140     std::vector<unsigned int> scanValues(std::string dac) const {return scanValues(iScan(dac));}
00141 
00142     double scanValueMin(std::string dac) const {return scanValueMin(iScan(dac));}
00143     double scanValueMax(std::string dac) const {return scanValueMax(iScan(dac));}
00144     double scanValueStep(std::string dac) const {return scanValueStep(iScan(dac));}
00145     bool scanValuesMixedAcrossROCs(std::string dac) const {return scanValuesMixedAcrossROCs(iScan(dac));}
00146 
00147     unsigned int iScan(std::string dac) const;
00148 
00149     const std::vector<std::vector<unsigned int> > &columnList() const {return cols_;}
00150     const std::vector<std::vector<unsigned int> > &rowList() const {return rows_;}
00151     const std::vector<PixelROCName>& rocList() const {assert(rocAndModuleListsBuilt_); return rocs_;}
00152     const std::set <PixelModuleName>& moduleList() const {assert(rocAndModuleListsBuilt_); return modules_;}
00153     const std::set <PixelChannel>& channelList() const {assert( objectsDependingOnTheNameTranslationBuilt_ ); return channels_;}
00154 
00155     std::string mode() const {return mode_;}
00156 
00157     bool singleROC() const {return singleROC_;}
00158 
00159     unsigned int nParameters() const {return parameters_.size();}
00160 
00161     // Added by Dario Apr 24th, 2008
00162     std::map<std::string, std::string> parametersList() const {return parameters_;}
00163     // get the value of parameter parameterName, or "" if parameterName is not in the list
00164     std::string parameterValue(std::string parameterName) const;
00165 
00166     // Added by Dario May 8th, 2008
00167     std::string getStreamedContent(void) const {return calibFileContent_;} ;
00168 
00169     friend std::ostream& pos::operator<<(std::ostream& s, const PixelCalibConfiguration& calib);
00170 
00171     virtual void writeASCII(std::string dir="") const;
00172     void         writeXML(      pos::PixelConfigKey key, int version, std::string path)                     const {;}
00173     virtual void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out) const {;}
00174     virtual void writeXML(                                                              std::ofstream *out) const {;}
00175     virtual void writeXMLTrailer(                                                       std::ofstream *out) const {;}
00176 
00177 
00178   private:
00179 
00180     // Which set of rows we're on.
00181     unsigned int rowCounter(unsigned int state) const;
00182     
00183     // Which set of columns we're on.
00184     unsigned int colCounter(unsigned int state) const;
00185 
00186     // In SingleROC mode, which ROC we're on.  In normal mode, this equals 1.
00187     unsigned int scanROC(unsigned int state) const;
00188 
00189     unsigned int nScanPoints(unsigned int iscan) const { return dacs_[iscan].getNPoints(); }
00190 
00191     unsigned int scanCounter(unsigned int iscan, unsigned int state) const;
00192 
00193     unsigned int scanValue(unsigned int iscan, unsigned int state, unsigned int ROCNumber, unsigned int ROCsOnChannel) const;
00194     unsigned int scanValue(unsigned int iscan, unsigned int state, PixelROCName roc) const;
00195 
00196     std::vector<unsigned int> scanValues(unsigned int iscan) const {return dacs_[iscan].values();}
00197 
00198     double scanValueMin(unsigned int iscan) const {return dacs_[iscan].first();}
00199     double scanValueMax(unsigned int iscan) const {return dacs_[iscan].first()+
00200                                                    dacs_[iscan].step()*(nScanPoints(iscan)-1);}
00201     double scanValueStep(unsigned int iscan) const {return dacs_[iscan].step();}
00202     bool scanValuesMixedAcrossROCs(unsigned int iscan) const {return dacs_[iscan].mixValuesAcrossROCs();}
00203 
00204     // Used in constructor or in buildROCAndModuleLists()
00205     void buildROCAndModuleListsFromROCSet(const std::set<PixelROCName>& rocSet);
00206 
00207     void buildObjectsDependingOnTheNameTranslation(const PixelNameTranslation* aNameTranslation);
00208     
00209     unsigned int ROCNumberOnChannelAmongThoseCalibrated(PixelROCName roc) const;
00210     unsigned int numROCsCalibratedOnChannel(PixelROCName roc) const;
00211 
00212     bool singleROC_;
00213 
00214     std::vector<std::vector<unsigned int> > rows_;
00215     std::vector<std::vector<unsigned int> > cols_;
00216 
00217     mutable std::vector<PixelROCName> rocs_;
00218     mutable std::vector<PixelROCInfo> rocInfo_;
00219     std::set <PixelModuleName> modules_;
00220     bool rocAndModuleListsBuilt_;
00221     std::vector<std::string> rocListInstructions_;
00222     
00223     // Objects built using the name translation.
00224     std::set <PixelChannel> channels_;
00225     std::map <PixelROCName, unsigned int> ROCNumberOnChannelAmongThoseCalibrated_;
00226     std::map <PixelROCName, unsigned int> numROCsCalibratedOnChannel_;
00227     bool objectsDependingOnTheNameTranslationBuilt_;
00228     
00229     mutable std::vector<std::pair<unsigned int, std::vector<unsigned int> > > fedCardsAndChannels_;
00230 
00231 
00232     //unsigned int vcal_;
00233 
00234     std::vector<PixelDACScanRange> dacs_;
00235 
00236     //std::vector<std::string> dacname_;
00237     //std::vector<unsigned int> dacchannel_;
00238     //std::vector<unsigned int> dac_first_;
00239     //std::vector<unsigned int> dac_last_;
00240     //std::vector<unsigned int> dac_step_;
00241 
00242     unsigned int ntrigger_;
00243     unsigned int nROC_; //This is the maximal #ROCs on a given TBM
00244 
00245     bool highVCalRange_;
00246 
00247     void enablePixels(PixelFECConfigInterface* pixelFEC,
00248                       unsigned int irows, unsigned int icols,
00249                       pos::PixelROCMaskBits* masks,
00250                       pos::PixelROCTrimBits* trims,     
00251                       PixelHdwAddress theROC) const;
00252 
00253     void disablePixels(PixelFECConfigInterface* pixelFEC,
00254                        unsigned int irows, unsigned int icols,
00255                        pos::PixelROCTrimBits* trims,    
00256                        PixelHdwAddress theROC) const;
00257 
00258     void disablePixels(PixelFECConfigInterface* pixelFEC,
00259                        pos::PixelROCTrimBits* trims,    
00260                        PixelHdwAddress theROC) const;
00261 
00262     mutable std::vector<int> old_irows;
00263     mutable std::vector<int> old_icols;
00264 
00265     std::map<std::string, std::string> parameters_;
00266     //       name         value
00267 
00268     bool _bufferData;
00269 
00270     bool usesROCList_;
00271 
00272     // Added by Dario May 8th, 2008
00273     std::string calibFileContent_ ;
00274   };
00275 }
00276 /* @} */
00277 #endif

Generated on Tue Jun 9 17:25:23 2009 for CMSSW by  doxygen 1.5.4