CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes

EcalSRCondTools Class Reference

#include <EcalSRCondTools.h>

Inheritance diagram for EcalSRCondTools:
edm::EDAnalyzer

List of all members.

Public Member Functions

virtual void analyze (const edm::Event &evt, const edm::EventSetup &es)
 EcalSRCondTools (const edm::ParameterSet &)
 ~EcalSRCondTools ()

Static Public Member Functions

static void importParameterSet (EcalSRSettings &sr, const edm::ParameterSet &ps)
static void importSrpConfigFile (EcalSRSettings &sr, std::istream &f, bool debug=false)
static double normalizeWeights (int hwWeight)

Static Private Member Functions

static std::string tokenize (const std::string &s, const std::string &delim, int &pos)
static std::string trim (std::string s)

Private Attributes

edm::ParameterSet ps_

Detailed Description

Definition at line 15 of file EcalSRCondTools.h.


Constructor & Destructor Documentation

EcalSRCondTools::EcalSRCondTools ( const edm::ParameterSet ps)

Constructor

Parameters:
psanalyser configuration

Definition at line 62 of file EcalSRCondTools.cc.

                                                         :ps_(ps){
}
EcalSRCondTools::~EcalSRCondTools ( )

Destructor

Definition at line 66 of file EcalSRCondTools.cc.

                                 {
}

Member Function Documentation

void EcalSRCondTools::analyze ( const edm::Event evt,
const edm::EventSetup es 
) [virtual]

Called by CMSSW event loop

Parameters:
evtthe event
esevents setup

Implements edm::EDAnalyzer.

Definition at line 70 of file EcalSRCondTools.cc.

References EcalSRSettings::automaticMasks_, EcalSRSettings::automaticSrpSelect_, EcalSRSettings::bxGlobalOffset_, gather_cfg::cout, EcalCondDB::db, generateEDF::done, Exception, f, alignmentValidation::fname, edm::EventSetup::get(), EcalTPGPhysicsConst::getMap(), edm::ParameterSet::getParameter(), importParameterSet(), importSrpConfigFile(), edm::ESHandleBase::isValid(), mode, edm::ESHandle< T >::product(), and ps_.

                                                                      {
  static bool done = false;
  if(done) return;
  EcalSRSettings* sr = new EcalSRSettings;

  string mode = ps_.getParameter<string>("mode");
  bool iomode;
  const bool iomode_read = false;
  const bool iomode_write = true;

  if(mode == "online_config" || mode == "combine_config"){
    iomode =iomode_write;
    string fname = ps_.getParameter<string>("onlineSrpConfigFile");
    ifstream f(fname.c_str());
    if(!f.good()){
      throw cms::Exception("EcalSRCondTools") << "Failed to open file " << fname;
    }
    importSrpConfigFile(*sr, f, true);
  }

  if(mode=="python_config" || mode=="combine_config"){
    iomode = iomode_write;
    importParameterSet(*sr, ps_);
  }

  if(mode=="read"){
    iomode = iomode_read;
  }

  if(!(mode=="python_config" || mode == "online_config" || mode == "combine_config" || (mode=="read"))){
    throw cms::Exception("Config") << "Invalid value," << mode << ",  for parameter mode. "
                                   << "Valid values: online_config, python_config, combine_config, read";
  }

  if(iomode==iomode_write){
    sr->bxGlobalOffset_ = ps_.getParameter<int>("bxGlobalOffset");
    sr->automaticSrpSelect_ = ps_.getParameter<int>("automaticSrpSelect");
    sr->automaticMasks_ = ps_.getParameter<int>("automaticMasks");
    
    edm::Service<cond::service::PoolDBOutputService> db;
    if( !db.isAvailable() ){
      throw cms::Exception("CondDBAccess") << "Failed to connect to PoolDBOutputService\n";
    }
    //fillup DB
    //create new infinite IOV
    cond::Time_t firstSinceTime = db->beginOfTime();
    db->writeOne(sr,firstSinceTime,"EcalSRSettingsRcd");
    done = true;
  } else {//read mode
    edm::ESHandle<EcalSRSettings> hSr;
    es.get<EcalSRSettingsRcd>().get(hSr);
    if(!hSr.isValid()){
      cout << "EcalSRSettings record not found. Check the Cond DB Global tag.\n";
    } else{
      const EcalSRSettings* sr = hSr.product();
      cout << "ECAL Seletive readout settings:\n";
      cout << *sr << "\n" << endl;
    }
    
    //trigger tower thresholds (from FENIX configuration):
    edm::ESHandle<EcalTPGPhysicsConst> hTp;
    es.get<EcalTPGPhysicsConstRcd>().get(hTp);
    if(!hTp.isValid()){
      cout << "EcalTPGPhysicsConst record not found. Check the Cond DB Global tag.\n";
    } else{
      const EcalTPGPhysicsConst * tp = hTp.product();
      const EcalTPGPhysicsConstMap mymap = tp->getMap();
      if(mymap.size()!=2){
        cout << "Error: TPG physics record is of unexpected size: "
             << mymap.size()  << " elements instead of two (one for EB, one for EE)\n";
      } else{
        EcalTPGPhysicsConstMap::const_iterator it=mymap.begin();
        cout << "----------------------------------------------------------------------\n"
          "Trigger tower Et thresholds extracted from TPG configuration \n"
          "(EcalSRCondTools modules supports only read mode for these parameters):\n\n";
        cout<< "EB: " << "LT = " << it->second.ttf_threshold_Low << " GeV "
            << "HT = "<< it->second.ttf_threshold_High << " GeV\n";
        ++it;
        cout<< "EE: " << "LT = " << it->second.ttf_threshold_Low << " GeV "
            << "HT = "<< it->second.ttf_threshold_High << " GeV\n";
        
      }
    }
  }
}
void EcalSRCondTools::importParameterSet ( EcalSRSettings sr,
const edm::ParameterSet ps 
) [static]

Converts CMSSW python file selective readout setting ("parameter set") into a condition database object. Configuration from parameter set covers only part of the config, mainly the configuration needed for SR emulation in the MC. The parameters not supported by python configuration are left untouched in the sr object.

Parameters:
sr[in] ECAL selective readout setting object to set
psCMSSW parameter set containing the SR parameters to set

Definition at line 156 of file EcalSRCondTools.cc.

References EcalSRSettings::actions_, filterCSVwithJSON::copy, EcalSRSettings::dccNormalizedWeights_, EcalSRSettings::deltaEta_, EcalSRSettings::deltaPhi_, EcalSRSettings::ebDccAdcToGeV_, EcalSRSettings::ecalDccZs1stSample_, EcalSRSettings::eeDccAdcToGeV_, edm::ParameterSet::getParameter(), EcalSRSettings::srpHighInterestChannelZS_, EcalSRSettings::srpLowInterestChannelZS_, and EcalSRSettings::symetricZS_.

Referenced by analyze(), and EcalSelectiveReadoutProducer::EcalSelectiveReadoutProducer().

                                                                                     {
  sr.deltaPhi_.resize(1);
  sr.deltaPhi_[0] = ps.getParameter<int >("deltaPhi");
  sr.deltaEta_.resize(1);
  sr.deltaEta_[0] = ps.getParameter<int >("deltaEta");
  sr.ecalDccZs1stSample_.resize(1);
  sr.ecalDccZs1stSample_[0] = ps.getParameter<int >("ecalDccZs1stSample");
  sr.ebDccAdcToGeV_ = ps.getParameter<double >("ebDccAdcToGeV");
  sr.eeDccAdcToGeV_ = ps.getParameter<double >("eeDccAdcToGeV");
  sr.dccNormalizedWeights_.resize(1);
  const std::vector<double>& w = ps.getParameter<std::vector<double>  >("dccNormalizedWeights");
  sr.dccNormalizedWeights_[0].resize(w.size());
  std::copy(w.begin(), w.end(), sr.dccNormalizedWeights_[0].begin());
  sr.symetricZS_.resize(1);
  sr.symetricZS_[0] = ps.getParameter<bool >("symetricZS");
  sr.srpLowInterestChannelZS_.resize(2);
  const int eb = 0;
  const int ee = 1;
  sr.srpLowInterestChannelZS_[eb] = ps.getParameter<double >("srpBarrelLowInterestChannelZS");
  sr.srpLowInterestChannelZS_[ee] = ps.getParameter<double >("srpEndcapLowInterestChannelZS");
  sr.srpHighInterestChannelZS_.resize(2);
  sr.srpHighInterestChannelZS_[eb] = ps.getParameter<double >("srpBarrelHighInterestChannelZS");
  sr.srpHighInterestChannelZS_[ee] = ps.getParameter<double >("srpEndcapHighInterestChannelZS");
  //sr.trigPrimBypass_.resize(1);
  //sr.trigPrimBypass_[0] = ps.getParameter<bool >("trigPrimBypass");
  //sr.trigPrimBypassMode_.resize(1);
  //sr.trigPrimBypassMode_[0] = ps.getParameter<int >("trigPrimBypassMode");
  //sr.trigPrimBypassLTH_.resize(1);
  //sr.trigPrimBypassLTH_[0] = ps.getParameter<double >("trigPrimBypassLTH");
  //sr.trigPrimBypassHTH_.resize(1);
  //sr.trigPrimBypassHTH_[0] = ps.getParameter<double >("trigPrimBypassHTH");
  //sr.trigPrimBypassWithPeakFinder_.resize(1);
  //sr.trigPrimBypassWithPeakFinder_[0] = ps.getParameter<bool >("trigPrimBypassWithPeakFinder");
  //sr.defaultTtf_.resize(1);
  //sr.defaultTtf_[0] = ps.getParameter<int >("defaultTtf");
  sr.actions_ = ps.getParameter<std::vector<int> >("actions");
}
void EcalSRCondTools::importSrpConfigFile ( EcalSRSettings sr,
std::istream &  f,
bool  debug = false 
) [static]

Imports an SRP configuration file (stored in database "CLOB") into a Selective readout setting object.

Parameters:
sr[in] ECAL selective readout setting object to set
fconfiguration file stream. A stringstream can be used if the configuration is available as an stl string of a c-string: stringstream buf; buf << s;
debugverbosity flag. If true, imported parameter are displayed on stdout.

Definition at line 194 of file EcalSRCondTools.cc.

References EcalSRSettings::actions_, EcalSRSettings::automaticMasks_, EcalSRSettings::automaticSrpSelect_, EcalSRSettings::bxOffsets_, gather_cfg::cout, EcalSRSettings::dccMasks_, dccNum, EcalSRSettings::deltaEta_, EcalSRSettings::deltaPhi_, Exception, geometryCSVtoXML::line, nChs, EcalSRSettings::nDccs_, EcalSRSettings::nSrps_, EcalSRSettings::nTccs_, pos, EcalSRSettings::srfMasks_, EcalSRSettings::srpMasksFromConfig_, EcalSRSettings::substitutionSrfs_, EcalSRSettings::tccMasksFromConfig_, tccNum, EcalSRSettings::testerDccTestSrpIds_, EcalSRSettings::testerSrpEmuSrpIds_, EcalSRSettings::testerSrpTestSrpIds_, EcalSRSettings::testerTccEmuSrpIds_, tokenize(), trim(), and relativeConstraints::value.

Referenced by analyze(), and popcon::EcalSRPHandler::getNewObjects().

                                                                                  {
  //initialize vectors:
  sr.deltaEta_ = vector<int>(1,0);
  sr.deltaPhi_ = vector<int>(1,0);
  sr.actions_ = vector<int>(4, 0);
  sr.tccMasksFromConfig_ = vector<short>(EcalSRSettings::nTccs_, 0);
  sr.srpMasksFromConfig_ = vector<vector<short> >(EcalSRSettings::nSrps_, vector<short>(8, 0));
  sr.dccMasks_ = vector<short>(EcalSRSettings::nDccs_);
  sr.srfMasks_ = vector<short>(EcalSRSettings::nDccs_);
  sr.substitutionSrfs_ = vector<vector<short> >(EcalSRSettings::nSrps_, vector<short>(68,0));
  sr.testerTccEmuSrpIds_ = vector<int>(EcalSRSettings::nSrps_, 0);
  sr.testerSrpEmuSrpIds_ = vector<int>(EcalSRSettings::nSrps_, 0);
  sr.testerDccTestSrpIds_ = vector<int>(EcalSRSettings::nSrps_, 0);
  sr.testerSrpTestSrpIds_ = vector<int>(EcalSRSettings::nSrps_, 0);
  sr.bxOffsets_ = vector<short>(EcalSRSettings::nSrps_, 0);
  sr.automaticMasks_ = 0;
  sr.automaticSrpSelect_ = 0;
  
  //string line;
  int iLine = 0;
  int iValueSet = -1;
  const int nValueSets = 6*EcalSRSettings::nSrps_+9;
  string line;
  stringstream sErr("");
  while(!f.eof() && sErr.str().empty()){
    getline(f, line);
    ++iLine;
    line = trim(line);
    if(line[0] == '#' || line.empty()){//comment line and empty line to ignore
      continue;
    } else{
      ++iValueSet;
    }
    if(iValueSet>=nValueSets) break;
    uint32_t value;
    string sValue;
    int pos = 0;
    int iCh = 0;
    int nChs[nValueSets] = {
      //TCC masks: 0-11
      12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
      //SRP masks: 12-23
      8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
      //DCC masks: 24-35
      12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
      //SRF Masks: 36-47
      6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,
      //substitution SRFs: 48-59
      68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
      //Tester card to emulate or test: 60-71
      4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,
      //Bx offsets: 72
      12,
      //algo type: 73
      1,
      //action flags: 74
      4,
      //pattern file directory: 75
      1,
      //VME slots: 76
      12,
      //card types: 77
      12,
      //config Mode
      1,
      //VME Interface card
      1,
      //Spy Mode
      12,
    };

    while(((sValue = tokenize(line, " \t", pos))!=string(""))
          && (iCh<nChs[iValueSet]) && sErr.str().empty()){
      value = strtoul(sValue.c_str(), 0, 0);
      const int iSrp = iValueSet%EcalSRSettings::nSrps_;
      if(iValueSet<12){//TCC
        assert((unsigned)iSrp < sizeof(tccNum) / sizeof(tccNum[0]));
        assert((unsigned)iCh < sizeof(tccNum[0]) / sizeof(tccNum[0][0]));
        int tcc = tccNum[iSrp][iCh];
        if(tcc>=0) {
          if(d) cout << "tccMasksFromConfig_[" << tcc << "] <- "
                     << value << "\n";
          sr.tccMasksFromConfig_[tcc-1] = value;
        }
      } else if(iValueSet<24){//SRP-SRP
        if(d) cout << "srpMasks_[" << iSrp << "][" << iCh << "] <- "
                   << value << "\n";
        sr.srpMasksFromConfig_[iSrp][iCh] = value;
      } else if(iValueSet<36) {//DCC output
        assert((unsigned)iSrp < sizeof(dccNum) / sizeof(dccNum[0]));
        assert((unsigned)iCh < sizeof(dccNum[0]) / sizeof(dccNum[0][0]));
        int dcc = dccNum[iSrp][iCh];
        if(dcc > 0){
          assert((unsigned)(dcc-1) < sr.dccMasks_.size());
          if(d) cout << "dccMasks_[" << (dcc-1) << "] <- "
                     << value << "\n";
          sr.dccMasks_[dcc-1] = value;
        }
      } else if(iValueSet<48){//SRF masks
        assert((unsigned)iSrp < sizeof(dccNum) / sizeof(dccNum[0]));
        assert((unsigned)iCh < sizeof(dccNum[0]) / sizeof(dccNum[0][0]));
        int dcc = dccNum[iSrp][iCh];
        if(dcc > 0){
          if(d) cout << "srfMasks_[" << (dcc-1) << "] <- "
                     << value << "\n";
          assert((unsigned)(dcc-1) < sr.srfMasks_.size());
          sr.srfMasks_[dcc-1] = value;
        }
      } else if(iValueSet<60){//substiution SRFs
        assert((unsigned)iSrp < sr.substitutionSrfs_.size());
        assert((unsigned)iCh <  sr.substitutionSrfs_[0].size());
        if(d) cout << "substitutionMasks_[" << iSrp << "][" << iCh << "] <- "
                   << value << "\n";
        sr.substitutionSrfs_[iSrp][iCh] = value;
      } else if(iValueSet<72){//Tester card config
        switch(iCh){
        case 0:
          assert((unsigned)iSrp < sr.testerTccEmuSrpIds_.size());
          if(d) cout << "testerTccEmuSrpIds_[" << iSrp << "] <- "
                     << value << "\n";
          sr.testerTccEmuSrpIds_[iSrp] = value;
          break;
        case 1:
          assert((unsigned)iSrp < sr.testerSrpEmuSrpIds_.size());
          if(d) cout << "testerSrpEmuSrpIds_[" << iSrp << "] <- "
                     << value << "\n";
          sr.testerSrpEmuSrpIds_[iSrp] = value;
          break;
        case 2:
          assert((unsigned)iSrp < sr.testerDccTestSrpIds_.size());
          if(d) cout << "testerDccTestSrpIds_[" << iSrp << "] <- "
                     << value << "\n";
          sr.testerDccTestSrpIds_[iSrp] = value;
          break;
        case 3:
          assert((unsigned)iSrp < sr.testerSrpTestSrpIds_.size());
          if(d) cout << "testerSrpTestSrpIds_[" << iSrp << "] <- "
                     << value << "\n";
          sr.testerSrpTestSrpIds_[iSrp] = value;
          break;
        default:
          sErr << "Syntax error in SRP system configuration "
               << " line " << iLine << ".";
        }
      } else if(iValueSet<73){//bx offsets
        assert((unsigned)iCh < sr.bxOffsets_.size());
        if(d) cout << "bxOffset_[" << iCh << "] <- "
                   << value << "\n";
        sr.bxOffsets_[iCh] = value;
      } else if(iValueSet<74){//algo type
        int algo = value;
        switch(algo){
        case 0:
          sr.deltaEta_[0] = sr.deltaPhi_[0] = 1;
          break;
        case 1:
          sr.deltaEta_[0] = sr.deltaPhi_[0]  = 2;
          break;
        default:
          throw cms::Exception("OutOfRange") << "Value of parameter algo ," << algo
                                             << ", is invalid. Valid values are 0 and 1.";
        }
        if(d) cout << "deltaEta_[0] <- " << sr.deltaEta_[0] << "\t"
                   << "deltaPhi_[0] <- " << sr.deltaPhi_[0] << "\n";
      } else if(iValueSet<75){//action flags
        assert((unsigned)iCh < sr.actions_.size());
        if(d) cout << "actions_[" << iCh << "] <- "
                   << value << "\n";
        sr.actions_[iCh] = value;
      } else if(iValueSet<76){//pattern file directory
//      emuDir_ = sValue;
//      if(d) cout << "emuDir_ <= "
//                 << value << "\n";
      } else if(iValueSet<77){//VME slots
        //      slotIds_[iCh] = value;
  //    if(d) cout << "slotIds_[" << iCh << "] <= "
        //                 << value << "\n";
      } else if(iValueSet<78){//card types
        //      cardTypes_[iCh] = sValue[0];
        //      if(d) cout << "cardTypes_[" << iCh << "] <= "
        //                 << value << "\n";
      } else if (iValueSet<79){//config mode
        //TODO validity check on value
        //      configMode_ = (ConfigMode)value;
        //      if(d) cout << "config mode <= " << value << "\n";
      } else if (iValueSet<80){//VME I/F
        //TODO validity check on value
        //     vmeInterface_ = (Vme::type_t)value;
        //if(d) cout << "Vme Interface code <= " << value << "\n";
      } else if (iValueSet<81){//Spy Mode
        //TODO validity check on value
        //      spyMode_[iCh] = value & 0x3;
        //      if(d) cout << "Spy mode <= " << value << "\n";
      } else{//should never be reached!
        assert(false);
      }
      ++iCh;
    }
    if(iCh!=nChs[iValueSet]){//error
      sErr << "Syntax error in imported SRP system configuration file "
        /*<< filename <<*/ " line " << iLine << ".";
    }
  }
  if(sErr.str().empty() && iValueSet!=(nValueSets-1)){//error
    sErr << "Syntax Error in imported SRP system configuration file "
      /*<< filename <<*/ " line " << iLine << ".";
  }
  if(sErr.str().size()!=0) throw cms::Exception("SyntaxError") << sErr.str();
}
double EcalSRCondTools::normalizeWeights ( int  hwWeight) [static]

convert hardware weights (interger weights) into normalized weights. The former reprensentation is used in DCC firmware and in online databaser, while the later is used in offline software.

Definition at line 404 of file EcalSRCondTools.cc.

                                                    {
  //Fix sign bit in case only the 12 least significant bits of hwWeight were set
  //(hardware reprensentation uses only 12 bits)
  if(hwWeight & (1<<11)) hwWeight |= ~0xEFF;
  return hwWeight/1024.;
}
string EcalSRCondTools::tokenize ( const std::string &  s,
const std::string &  delim,
int &  pos 
) [static, private]

Help function to tokenize a string

Parameters:
sstring to parse token delimiters internal string position pointer. Must be set to zero before the first call

Definition at line 56 of file PasswordReader.cc.

References spr::find(), and pos.

Referenced by importSrpConfigFile().

                                                       {
  size_t pos0 = pos;
  size_t len = s.size();
  //eats delimeters at beginning of the string
  while(pos0<s.size() && find(delim.begin(), delim.end(), s[pos0])!=delim.end()){
    ++pos0;
  }
  if(pos0>=len || pos0==string::npos) return "";
  pos = s.find_first_of(delim, pos0);
  return s.substr(pos0, (pos>0?pos:s.size())-pos0);
}
std::string EcalSRCondTools::trim ( std::string  s) [static, private]

Help function to trim spaces at beginning and end of a string

Parameters:
sstring to trim

Definition at line 424 of file EcalSRCondTools.cc.

Referenced by importSrpConfigFile().

                                          {
  std::string::size_type pos0 = s.find_first_not_of(" \t");
  if(pos0==string::npos){
    pos0=0;
  }
  string::size_type pos1 = s.find_last_not_of(" \t") + 1;
  if(pos1==string::npos){
    pos1 = pos0;
  }
  return s.substr(pos0, pos1-pos0);
}

Member Data Documentation

Definition at line 73 of file EcalSRCondTools.h.

Referenced by analyze().