CMS 3D CMS Logo

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