CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/L1Trigger/TextToDigi/plugins/GctDigiToPsbText.cc

Go to the documentation of this file.
00001 
00002 #include "GctDigiToPsbText.h"
00003 
00004 #include <iomanip>
00005 using std::setw;
00006 using std::setfill;
00007 
00008 GctDigiToPsbText::GctDigiToPsbText(const edm::ParameterSet& iConfig) : 
00009   m_gctInputLabel(iConfig.getParameter<edm::InputTag>("GctInputLabel")),
00010   m_textFileName(iConfig.getParameter<std::string>("TextFileName")), 
00011   m_hexUpperCase(iConfig.getUntrackedParameter<bool>("HexUpperCase",false)) {
00013   for (unsigned i=0; i<4; i++){
00014     std::stringstream fileStream;
00015     int ii = (i<2)?i:i+4;
00016     fileStream << m_textFileName << ii << ".txt";
00017     std::string fileName(fileStream.str());
00018     m_file[i].open(fileName.c_str(),std::ios::out);
00019     if(!m_file[i].good()) {
00020       throw cms::Exception("GctDigiToPsbTextTextFileOpenError")
00021         << "GctDigiToPsbText::GctDigiToPsbText : "
00022         << " couldn't create the file " << fileName 
00023         << std::endl;
00024     }
00025   }
00026 }
00027 
00028 GctDigiToPsbText::~GctDigiToPsbText() {
00030   for (unsigned i=0; i<4; i++) 
00031     m_file[i].close();
00032 }
00033 
00034 
00035 void
00036 GctDigiToPsbText::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00037   
00038   //static int nevt = -1; nevt++;
00039 
00040   // get digis
00041   edm::Handle<L1GctEmCandCollection> gctIsolaEm;
00042   edm::Handle<L1GctEmCandCollection> gctNoIsoEm;
00043   iEvent.getByLabel(m_gctInputLabel.label(), "isoEm",    gctIsolaEm);
00044   iEvent.getByLabel(m_gctInputLabel.label(), "nonIsoEm", gctNoIsoEm);
00045 
00047   uint16_t data[4][2]= {{0}};
00048   for (int i=0; i<4; i++)
00049     for (int j=0; j<2; j++)
00050       data[i][j]=0;
00051   
00052   std::stringstream sstrm;
00053   if(m_hexUpperCase)
00054     sstrm << std::uppercase;
00055   else  
00056     sstrm.unsetf(std::ios::uppercase);
00057 
00058   // specify cycle bit sequence 1 0 1 0 ... or 0 1 0 1 ...
00059   unsigned short cbs[2] = {1,0};
00060 
00061   unsigned int ifile;
00062   unsigned int cycle;
00063   unsigned iIsola, iNoIso;
00064 
00065   for(int i=0; i<4; i++) {
00066     cycle = i/2;
00067     ifile = i%2;
00068     iIsola = ifile+2;
00069     iNoIso = ifile;
00070     
00071     //get the data
00072     data[iIsola][cycle] = gctIsolaEm->at(i).raw();
00073     data[iNoIso][cycle] = gctNoIsoEm->at(i).raw();
00074     
00075     //print electrons
00076     sstrm.str("");
00077     sstrm << setw(4) << setfill('0') << std::hex 
00078           << (data[iIsola][cycle] & 0x7fff) + ((cbs[cycle]&0x1)<<15);
00079     m_file[iIsola] << sstrm.str() << std::endl;
00080     sstrm.str("");
00081     sstrm << setw(4) << setfill('0') << std::hex 
00082           << (data[iNoIso][cycle] & 0x7fff) + ((cbs[cycle]&0x1)<<15);
00083     m_file[iNoIso] << sstrm.str() << std::endl;
00084   }
00085   
00087   for (unsigned i=0; i<4; i++)
00088     m_file[i] << std::flush;
00089   
00090 }