CMS 3D CMS Logo

Public Member Functions | Private Attributes

L1MuGMTHWFileReader Class Reference

#include <L1MuGMTHWFileReader.h>

Inheritance diagram for L1MuGMTHWFileReader:
edm::ExternalInputSource edm::ConfigurableInputSource edm::InputSource edm::ProductRegistryHelper

List of all members.

Public Member Functions

 L1MuGMTHWFileReader (edm::ParameterSet const &, edm::InputSourceDescription const &)
virtual bool produce (edm::Event &)
void readNextEvent ()
virtual void setRunAndEventInfo ()
 ~L1MuGMTHWFileReader ()

Private Attributes

L1MuGMTInputEvent m_evt
std::ifstream m_in

Detailed Description

Definition at line 41 of file L1MuGMTHWFileReader.h.


Constructor & Destructor Documentation

L1MuGMTHWFileReader::L1MuGMTHWFileReader ( edm::ParameterSet const &  ps,
edm::InputSourceDescription const &  desc 
) [explicit]

Definition at line 39 of file L1MuGMTHWFileReader.cc.

References edm::ExternalInputSource::fileNames(), spr::find(), and m_in.

                                                                                :
                                         ExternalInputSource(ps, desc) {

  produces<std::vector<L1MuRegionalCand> >("DT");
  produces<std::vector<L1MuRegionalCand> >("CSC");
  produces<std::vector<L1MuRegionalCand> >("RPCb");
  produces<std::vector<L1MuRegionalCand> >("RPCf");

  produces<L1CaloRegionCollection>();

  if(!fileNames().size()) {
    throw std::runtime_error("L1MuGMTHWFileReader: no input file");
  }
  edm::LogInfo("GMT_HWFileReader_info") << "opening file " << fileNames()[0];
  m_in.open((fileNames()[0].substr(fileNames()[0].find(":")+1)).c_str());
  if(!m_in) {
    throw std::runtime_error("L1MuGMTHWFileReader: file " + fileNames()[0]
                        + " could not be openned");
  }

}
L1MuGMTHWFileReader::~L1MuGMTHWFileReader ( )

Definition at line 65 of file L1MuGMTHWFileReader.cc.

References m_in.

                                          {
  m_in.close();
}

Member Function Documentation

bool L1MuGMTHWFileReader::produce ( edm::Event e) [virtual]

Implements edm::ConfigurableInputSource.

Definition at line 81 of file L1MuGMTHWFileReader.cc.

References L1MuGMTInputEvent::getEventNumber(), L1MuGMTInputEvent::getInputMuon(), L1MuGMTInputEvent::getIsoBit(), L1MuGMTInputEvent::getMipBit(), L1MuGMTInputEvent::getRunNumber(), i, m_evt, and edm::Event::put().

                                             {
  L1MuRegionalCand empty_mu;

  if(!m_evt.getRunNumber() && !m_evt.getEventNumber()) return false;

  std::auto_ptr<std::vector<L1MuRegionalCand> > DTCands(new std::vector<L1MuRegionalCand>);
  for (unsigned i = 0; i < 4; i++) {
    const L1MuRegionalCand *mu = m_evt.getInputMuon("IND", i);
    if (!mu) mu = &empty_mu;
    DTCands->push_back(*mu);
  }
  e.put(DTCands,"DT");

  std::auto_ptr<std::vector<L1MuRegionalCand> > CSCCands(new std::vector<L1MuRegionalCand>);
  for (unsigned i = 0; i < 4; i++) {
    const L1MuRegionalCand *mu = m_evt.getInputMuon("INC", i);
    if (!mu) mu = &empty_mu;
    CSCCands->push_back(*mu);
  }
  e.put(CSCCands,"CSC");

  std::auto_ptr<std::vector<L1MuRegionalCand> > RPCbCands(new std::vector<L1MuRegionalCand>);
  for (unsigned i = 0; i < 4; i++) {
    const L1MuRegionalCand *mu = m_evt.getInputMuon("INB", i);
    if (!mu) mu = &empty_mu;
    RPCbCands->push_back(*mu);
  }
  e.put(RPCbCands,"RPCb");

  std::auto_ptr<std::vector<L1MuRegionalCand> > RPCfCands(new std::vector<L1MuRegionalCand>);
  for (unsigned i = 0; i < 4; i++) {
    const L1MuRegionalCand *mu = m_evt.getInputMuon("INF", i);
    if (!mu) mu = &empty_mu;
    RPCfCands->push_back(*mu);
  }
  e.put(RPCfCands,"RPCf");

  std::auto_ptr<L1CaloRegionCollection> rctRegions (new L1CaloRegionCollection);
  for(int ieta = 4; ieta < 18; ieta++) {
    for(int iphi = 0; iphi < 18; iphi++) {
      rctRegions->push_back(L1CaloRegion(0,false,true,m_evt.getMipBit(ieta-4,iphi),m_evt.getIsoBit(ieta-4,iphi),ieta,iphi));
    }
  }

  e.put(rctRegions);

  return true;
}
void L1MuGMTHWFileReader::readNextEvent ( )

Definition at line 130 of file L1MuGMTHWFileReader.cc.

References L1MuGMTInputEvent::addInputMuon(), eta(), i, m_evt, m_in, phi, L1MuGMTInputEvent::reset(), L1MuRegionalCand::setBx(), L1MuGMTInputEvent::setEventNumber(), L1MuGMTInputEvent::setIsoBit(), L1MuGMTInputEvent::setMipBit(), L1MuGMTInputEvent::setRunNumber(), and L1MuRegionalCand::setType().

Referenced by setRunAndEventInfo().

                                        {
  m_evt.reset();

  std::string line_id;
  do {
    int bx = 0;

    m_in >> line_id;
    if (line_id == "--") continue;

    if (line_id == "RUN") {
      unsigned long runnr;
      m_in >> runnr;
      m_evt.setRunNumber(runnr);
    }

    if (line_id == "EVT") {
      unsigned long evtnr;
      m_in >> evtnr;
      m_evt.setEventNumber(evtnr);
    }


    if (line_id == "DT" || line_id == "CSC" || line_id == "BRPC" || line_id == "FRPC")
    {

      // decode input muon

      unsigned inpmu = 0;
      unsigned val;
      m_in >> val; inpmu |= (val & 0x01) << 24; // valid charge
      m_in >> val; inpmu |= (val & 0x01) << 23; // charge
      m_in >> val; inpmu |= (val & 0x01) << 22; // halo / fine
      m_in >> val; inpmu |= (val & 0x3f) << 16; // eta
      m_in >> val; inpmu |= (val & 0x07) << 13; // quality
      m_in >> val; inpmu |= (val & 0x1f) <<  8; // pt
      m_in >> val; inpmu |= (val & 0xff)      ; // phi

      std::string chipid("IN");
      chipid += line_id[0];

      int type=0;
      if (line_id == "DT") type = 0;
      if (line_id == "CSC") type = 2;
      if (line_id == "BRPC") type = 1;
      if (line_id == "FRPC") type = 3;


      L1MuRegionalCand cand(inpmu);
      cand.setType(type);
      cand.setBx(bx);
      m_evt.addInputMuon(chipid, cand);
    }

    if (line_id == "MIP") {
      int nPairs;
      m_in >> nPairs;
      for (int i=0; i<nPairs; i++) {
        unsigned eta;
        unsigned phi;
        m_in >> eta;
        m_in >> phi;
        if (phi >= 9) phi-=9;
        else phi+=9;
        m_evt.setMipBit(eta, phi, true);
      }
    }

    if (line_id == "NQ") {
      int nPairs;
      m_in >> nPairs;
      for (int i=0; i<nPairs; i++) {
        unsigned eta;
        unsigned phi;
        m_in >> eta;
        m_in >> phi;
        if (phi >= 9) phi-=9;
        else phi+=9;
        m_evt.setIsoBit(eta, phi, false);
      }
    }

    //read the rest of the line
    const int sz=4000; char buf[sz];
    m_in.getline(buf, sz);

  } while (line_id != "NQ" && !m_in.eof());

}
void L1MuGMTHWFileReader::setRunAndEventInfo ( ) [virtual]

Member Data Documentation

Definition at line 58 of file L1MuGMTHWFileReader.h.

Referenced by produce(), readNextEvent(), and setRunAndEventInfo().

std::ifstream L1MuGMTHWFileReader::m_in [private]

Definition at line 57 of file L1MuGMTHWFileReader.h.

Referenced by L1MuGMTHWFileReader(), readNextEvent(), and ~L1MuGMTHWFileReader().