CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

GtPsbTextToDigi Class Reference

#include <GtPsbTextToDigi.h>

Inheritance diagram for GtPsbTextToDigi:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 GtPsbTextToDigi (const edm::ParameterSet &)
 ~GtPsbTextToDigi ()

Private Member Functions

virtual void endJob ()
virtual void produce (edm::Event &, const edm::EventSetup &)
void putEmptyDigi (edm::Event &)
 Create empty digi collection.

Private Attributes

int m_bc0 [4]
 Hold detected BC0 signal position per file.
std::ifstream m_file [4]
 File handle.
int m_fileEventOffset
 Number of events to be offset wrt input.
int m_nevt
 Event counter.
std::string m_textFileName
 Name out input file.

Detailed Description

Definition at line 34 of file GtPsbTextToDigi.h.


Constructor & Destructor Documentation

GtPsbTextToDigi::GtPsbTextToDigi ( const edm::ParameterSet iConfig) [explicit]

Definition at line 15 of file GtPsbTextToDigi.cc.

References Exception, convertXMLtoSQLite_cfg::fileName, i, indexGen::ifile, recoMuon::in, m_bc0, m_file, and m_textFileName.

                                                              :
  m_fileEventOffset(iConfig.getUntrackedParameter<int>("FileEventOffset",0)),
  m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
  m_nevt(0) {
  // Produces collections
  produces<L1GctEmCandCollection>("isoEm");
  produces<L1GctEmCandCollection>("nonIsoEm");
  produces<L1GctJetCandCollection>("cenJets");
  produces<L1GctJetCandCollection>("forJets");
  produces<L1GctJetCandCollection>("tauJets");
  //produces<L1GctEtTotal>();

  // Open the input files
  for (int ifile=0; ifile<4; ifile++){
    // gct em cand coll: (noiso) 0<->0, 1<->1, (iso) 6<->2, 7<->3
    int ii = (ifile<2)?ifile:ifile+4;
    std::stringstream fileStream;
    fileStream << m_textFileName << ii << ".txt";
    std::string fileName(fileStream.str());
    m_file[ifile].open(fileName.c_str(),std::ios::in);
    if(!m_file[ifile].good()) {
      throw cms::Exception("GtPsbTextToDigiTextFileOpenError")
        //LogDebug("GtPsbTextToDigi")
        << "GtPsbTextToDigi::GtPsbTextToDigi : "
        << " couldn't open the file " << fileName 
        //<< "...skipping!" 
        << std::endl;
    }
    std::hex(m_file[ifile]); 
  }

  // Initialize bc0 position holder
  for(int i=0; i<4; i++)
    m_bc0[i]=-1;  
}
GtPsbTextToDigi::~GtPsbTextToDigi ( )

Definition at line 51 of file GtPsbTextToDigi.cc.

References i, and m_file.

                                  {
  // Close the input files
  for (unsigned i=0; i<4; i++){  
    m_file[i].close();
  }
}

Member Function Documentation

void GtPsbTextToDigi::endJob ( void  ) [private, virtual]

Check BC0 signals consistency

Reimplemented from edm::EDProducer.

Definition at line 223 of file GtPsbTextToDigi.cc.

References i, LogDebug, m_bc0, and match().

                             {
  int nmem = 4;
  bool match = true;
  for(int i=0; i<nmem-1; i++)
    match &= (m_bc0[i]==m_bc0[i+1]);  
  LogDebug("GtPsbTextToDigi") << "[GtPsbTextToDigi::endJob()] ";
  if(!match) 
    LogDebug("GtPsbTextToDigi") << "did not find matching BC0 in all input files: ";
  else
    LogDebug("GtPsbTextToDigi") << "detected common BC0 in all input files: ";
  for(int i=0; i<nmem; i++)
    LogDebug("GtPsbTextToDigi") << " " << m_bc0[i];  
  LogDebug("GtPsbTextToDigi") << std::flush << std::endl;

}
void GtPsbTextToDigi::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [private, virtual]

buffer

Read in file

cycle debuging (temporary)

Fill in digi collections

Put collections

Implements edm::EDProducer.

Definition at line 84 of file GtPsbTextToDigi.cc.

References abs, gather_cfg::cout, cycle, AlCaHLTBitMon_QueryRunRegistry::data, Exception, i, indexGen::ifile, j, LogDebug, m_bc0, m_file, m_fileEventOffset, m_nevt, m_textFileName, edm::Event::put(), putEmptyDigi(), and tmp.

                                                                           {

  // specify clock cycle bit sequence 1 0 1 0... or 0 1 0 1...
  unsigned short cbs[2] = {1,0};

  // Skip event if required
  if (m_nevt < m_fileEventOffset){ 
    putEmptyDigi(iEvent);
    LogDebug("GtPsbTextToDigi")
      << "[GtPsbTextToDigi::produce()] skipping event " << m_nevt 
      << std::endl;
    m_nevt++;
    return;
  } else if (m_nevt==0 && m_fileEventOffset<0) {
    // skip first fileEventOffset input events
    unsigned long int buff;
    for (int ievt=0; ievt<abs(m_fileEventOffset); ievt++){  
      for (int ifile=0; ifile<4; ifile++){  
        for (int cycle=0; cycle<2; cycle++){  
          std::hex(m_file[ifile]);
          m_file[ifile] >> buff;
          unsigned tmp = (buff>>15)&0x1;
          if(tmp!=cbs[cycle]) {
            if(m_bc0[ifile]==-1 && cycle==1 && tmp==1)
              m_bc0[ifile] = ievt;
            else 
              throw cms::Exception("GtPsbTextToDigiTextFileFormatError") 
                //std::cout << "GtPsbTextToDigiTextFileFormatError" 
                << "GtPsbTextToDigi::produce : "
                << " found format inconsistency in file #" << ifile 
                << "\n in skipped line:" << ievt*2+1
                << " cycle:" << tmp << " is different from " << cbs[cycle]
                << std::endl;
          }
        } 
      }
      LogDebug("GtPsbTextToDigi")
        << "[GtPsbTextToDigi::produce()] skipping input " << ievt 
        << std::endl;
    }
  }
  m_nevt++;
  
  // New collections
  std::auto_ptr<L1GctEmCandCollection>  gctIsolaEm( new L1GctEmCandCollection () );
  std::auto_ptr<L1GctEmCandCollection>  gctNoIsoEm( new L1GctEmCandCollection () );
  std::auto_ptr<L1GctJetCandCollection> gctCenJets( new L1GctJetCandCollection() ); 
  std::auto_ptr<L1GctJetCandCollection> gctForJets( new L1GctJetCandCollection() ); 
  std::auto_ptr<L1GctJetCandCollection> gctTauJets( new L1GctJetCandCollection() );
  //std::auto_ptr<L1GctEtTotal>           gctEtTotal( new L1GctEtTotal          () );

  uint16_t data[4][2]= {{0}};
  for (int i=0; i<4; i++)
    for (int j=0; j<2; j++)
      data[i][j]=0;

  // Loop over files
  for (int ifile=0; ifile<4; ifile++){  
    int ii = (ifile<2)?ifile:ifile+4;
    
    // Check we're not at the end of the file
    if(m_file[ifile].eof()) {
      LogDebug("GtPsbTextToDigi")
        << "GtPsbTextToDigi::produce : "
        << " unexpected end of file " << m_textFileName << ii << ".txt"
        << std::endl;
      putEmptyDigi(iEvent);
      continue;
    }      
    
    if(!m_file[ifile].good()) {
      LogDebug("GtPsbTextToDigi")
        << "GtPsbTextToDigi::produce : "
        << " problem reading file " << m_textFileName << ii << ".txt"
        << std::endl;
      putEmptyDigi(iEvent);
      continue;
    }
    
    unsigned long int uLongBuffer;
    
    for(unsigned cycle=0; cycle<2; cycle++) {
      m_file[ifile] >> uLongBuffer;
      unsigned tmp = (uLongBuffer>>15)&0x1;
      
      if(false && tmp!=cbs[cycle]) 
        std::cout << "[GtPsbTextToDigi::produce()] asserting " 
                  << " evt:"   << m_nevt
                  << " ifile:" << ifile
                  << " cycle:" << cbs[cycle]
                  << std::hex
                  << " buffer:"<< uLongBuffer
                  << " tmp: "  << tmp
                  << std::dec 
                  << "\n\n" << std::flush;

      if(tmp!=cbs[cycle]){
        if(m_bc0[ifile]==-1 && cycle==1 && tmp==1){
          m_bc0[ifile] = (m_nevt-m_fileEventOffset);
        }else{
          throw cms::Exception("GtPsbTextToDigiTextFileFormatError") 
            //std::cout << "GtPsbTextToDigiTextFileFormatError " 
            << "GtPsbTextToDigi::produce : "
            << " found format inconsistency in file #" << ifile 
            << "\n in line:" << (m_nevt-m_fileEventOffset)*2-1  
            << " cycle:" << tmp << " is different from " << cbs[cycle]
            << std::endl;
        }
      }
      data[ifile][cycle] = (uLongBuffer&0x7fff);
    } //cycle loop
  } //ifile loop
  
  unsigned iIsola, iNoIso;
  for (unsigned cycle=0; cycle<2; cycle++){  
    for (unsigned i=0; i<2; i++){  
      iIsola = i+2;
      iNoIso = i;
      gctIsolaEm->push_back(L1GctEmCand(data[iIsola][cycle]&0x7fff,1));
      gctNoIsoEm->push_back(L1GctEmCand(data[iNoIso][cycle]&0x7fff,0));
      L1GctEmCand candI(data[iIsola][cycle],1);
      L1GctEmCand candN(data[iNoIso][cycle],0);
    }
  }

  iEvent.put(gctIsolaEm, "isoEm");
  iEvent.put(gctNoIsoEm, "nonIsoEm");
  iEvent.put(gctCenJets, "cenJets");
  iEvent.put(gctForJets, "forJets");
  iEvent.put(gctTauJets, "tauJets");
  //iEvent.put(gctEtTotal);

}
void GtPsbTextToDigi::putEmptyDigi ( edm::Event iEvent) [private]

Create empty digi collection.

Append empty digi collection.

Definition at line 59 of file GtPsbTextToDigi.cc.

References i, LogDebug, m_nevt, and edm::Event::put().

Referenced by produce().

                                                   {
  std::auto_ptr<L1GctEmCandCollection>  gctIsolaEm( new L1GctEmCandCollection () );
  std::auto_ptr<L1GctEmCandCollection>  gctNoIsoEm( new L1GctEmCandCollection () );
  std::auto_ptr<L1GctJetCandCollection> gctCenJets( new L1GctJetCandCollection() );
  std::auto_ptr<L1GctJetCandCollection> gctForJets( new L1GctJetCandCollection() );
  std::auto_ptr<L1GctJetCandCollection> gctTauJets( new L1GctJetCandCollection() );
  //std::auto_ptr<L1GctEtTotal>           gctEtTotal( new L1GctEtTotal          () );
  for (int i=0; i<4; i++){  
    gctIsolaEm->push_back(L1GctEmCand (0,1));
    gctNoIsoEm->push_back(L1GctEmCand (0,0));
    gctCenJets->push_back(L1GctJetCand(0,0,0));
    gctForJets->push_back(L1GctJetCand(0,0,1));
    gctTauJets->push_back(L1GctJetCand(0,1,0));
    //gctEtTotal->push_back(());
  }
  iEvent.put(gctIsolaEm, "isoEm");
  iEvent.put(gctNoIsoEm, "nonIsoEm");
  iEvent.put(gctCenJets, "cenJets");
  iEvent.put(gctForJets, "forJets");
  iEvent.put(gctTauJets, "tauJets");
  //iEvent.put(gctEtTotal);

  LogDebug("GtPsbTextToDigi") << "putting empty digi (evt:" << m_nevt << ")\n"; 
}

Member Data Documentation

int GtPsbTextToDigi::m_bc0[4] [private]

Hold detected BC0 signal position per file.

Definition at line 60 of file GtPsbTextToDigi.h.

Referenced by endJob(), GtPsbTextToDigi(), and produce().

std::ifstream GtPsbTextToDigi::m_file[4] [private]

File handle.

Definition at line 57 of file GtPsbTextToDigi.h.

Referenced by GtPsbTextToDigi(), produce(), and ~GtPsbTextToDigi().

Number of events to be offset wrt input.

Definition at line 48 of file GtPsbTextToDigi.h.

Referenced by produce().

int GtPsbTextToDigi::m_nevt [private]

Event counter.

Definition at line 54 of file GtPsbTextToDigi.h.

Referenced by produce(), and putEmptyDigi().

std::string GtPsbTextToDigi::m_textFileName [private]

Name out input file.

Definition at line 51 of file GtPsbTextToDigi.h.

Referenced by GtPsbTextToDigi(), and produce().