Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:37

0001 
0002 #include "GctDigiToPsbText.h"
0003 
0004 #include <iomanip>
0005 using std::setfill;
0006 using std::setw;
0007 
0008 GctDigiToPsbText::GctDigiToPsbText(const edm::ParameterSet &iConfig)
0009     : m_gctInputLabel(iConfig.getParameter<edm::InputTag>("GctInputLabel")),
0010       m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
0011       m_hexUpperCase(iConfig.getUntrackedParameter<bool>("HexUpperCase", false)) {
0012   /// open output text files
0013   for (unsigned i = 0; i < 4; i++) {
0014     std::stringstream fileStream;
0015     int ii = (i < 2) ? i : i + 4;
0016     fileStream << m_textFileName << ii << ".txt";
0017     std::string fileName(fileStream.str());
0018     m_file[i].open(fileName.c_str(), std::ios::out);
0019     if (!m_file[i].good()) {
0020       throw cms::Exception("GctDigiToPsbTextTextFileOpenError")
0021           << "GctDigiToPsbText::GctDigiToPsbText : "
0022           << " couldn't create the file " << fileName << std::endl;
0023     }
0024   }
0025 }
0026 
0027 GctDigiToPsbText::~GctDigiToPsbText() {
0028   /// close  files
0029   for (unsigned i = 0; i < 4; i++)
0030     m_file[i].close();
0031 }
0032 
0033 void GctDigiToPsbText::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0034   // static int nevt = -1; nevt++;
0035 
0036   // get digis
0037   edm::Handle<L1GctEmCandCollection> gctIsolaEm;
0038   edm::Handle<L1GctEmCandCollection> gctNoIsoEm;
0039   iEvent.getByLabel(m_gctInputLabel.label(), "isoEm", gctIsolaEm);
0040   iEvent.getByLabel(m_gctInputLabel.label(), "nonIsoEm", gctNoIsoEm);
0041 
0042   /// buffer
0043   uint16_t data[4][2] = {{0}};
0044   for (int i = 0; i < 4; i++)
0045     for (int j = 0; j < 2; j++)
0046       data[i][j] = 0;
0047 
0048   std::stringstream sstrm;
0049   if (m_hexUpperCase)
0050     sstrm << std::uppercase;
0051   else
0052     sstrm.unsetf(std::ios::uppercase);
0053 
0054   // specify cycle bit sequence 1 0 1 0 ... or 0 1 0 1 ...
0055   unsigned short cbs[2] = {1, 0};
0056 
0057   unsigned int ifile;
0058   unsigned int cycle;
0059   unsigned iIsola, iNoIso;
0060 
0061   for (int i = 0; i < 4; i++) {
0062     cycle = i / 2;
0063     ifile = i % 2;
0064     iIsola = ifile + 2;
0065     iNoIso = ifile;
0066 
0067     // get the data
0068     data[iIsola][cycle] = gctIsolaEm->at(i).raw();
0069     data[iNoIso][cycle] = gctNoIsoEm->at(i).raw();
0070 
0071     // print electrons
0072     sstrm.str("");
0073     sstrm << setw(4) << setfill('0') << std::hex << (data[iIsola][cycle] & 0x7fff) + ((cbs[cycle] & 0x1) << 15);
0074     m_file[iIsola] << sstrm.str() << std::endl;
0075     sstrm.str("");
0076     sstrm << setw(4) << setfill('0') << std::hex << (data[iNoIso][cycle] & 0x7fff) + ((cbs[cycle] & 0x1) << 15);
0077     m_file[iNoIso] << sstrm.str() << std::endl;
0078   }
0079 
0080   /// flush data to files
0081   for (unsigned i = 0; i < 4; i++)
0082     m_file[i] << std::flush;
0083 }