CMS 3D CMS Logo

GctDigiToPsbText.cc
Go to the documentation of this file.
1 
2 #include "GctDigiToPsbText.h"
3 
4 #include <iomanip>
5 using std::setfill;
6 using std::setw;
7 
9  : m_gctInputLabel(iConfig.getParameter<edm::InputTag>("GctInputLabel")),
10  m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
11  m_hexUpperCase(iConfig.getUntrackedParameter<bool>("HexUpperCase", false)) {
13  for (unsigned i = 0; i < 4; i++) {
14  std::stringstream fileStream;
15  int ii = (i < 2) ? i : i + 4;
16  fileStream << m_textFileName << ii << ".txt";
17  std::string fileName(fileStream.str());
18  m_file[i].open(fileName.c_str(), std::ios::out);
19  if (!m_file[i].good()) {
20  throw cms::Exception("GctDigiToPsbTextTextFileOpenError")
21  << "GctDigiToPsbText::GctDigiToPsbText : "
22  << " couldn't create the file " << fileName << std::endl;
23  }
24  }
25 }
26 
29  for (unsigned i = 0; i < 4; i++)
30  m_file[i].close();
31 }
32 
34  // static int nevt = -1; nevt++;
35 
36  // get digis
39  iEvent.getByLabel(m_gctInputLabel.label(), "isoEm", gctIsolaEm);
40  iEvent.getByLabel(m_gctInputLabel.label(), "nonIsoEm", gctNoIsoEm);
41 
43  uint16_t data[4][2] = {{0}};
44  for (int i = 0; i < 4; i++)
45  for (int j = 0; j < 2; j++)
46  data[i][j] = 0;
47 
48  std::stringstream sstrm;
49  if (m_hexUpperCase)
50  sstrm << std::uppercase;
51  else
52  sstrm.unsetf(std::ios::uppercase);
53 
54  // specify cycle bit sequence 1 0 1 0 ... or 0 1 0 1 ...
55  unsigned short cbs[2] = {1, 0};
56 
57  unsigned int ifile;
58  unsigned int cycle;
59  unsigned iIsola, iNoIso;
60 
61  for (int i = 0; i < 4; i++) {
62  cycle = i / 2;
63  ifile = i % 2;
64  iIsola = ifile + 2;
65  iNoIso = ifile;
66 
67  // get the data
68  data[iIsola][cycle] = gctIsolaEm->at(i).raw();
69  data[iNoIso][cycle] = gctNoIsoEm->at(i).raw();
70 
71  // print electrons
72  sstrm.str("");
73  sstrm << setw(4) << setfill('0') << std::hex << (data[iIsola][cycle] & 0x7fff) + ((cbs[cycle] & 0x1) << 15);
74  m_file[iIsola] << sstrm.str() << std::endl;
75  sstrm.str("");
76  sstrm << setw(4) << setfill('0') << std::hex << (data[iNoIso][cycle] & 0x7fff) + ((cbs[cycle] & 0x1) << 15);
77  m_file[iNoIso] << sstrm.str() << std::endl;
78  }
79 
81  for (unsigned i = 0; i < 4; i++)
82  m_file[i] << std::flush;
83 }
std::string const & label() const
Definition: InputTag.h:36
int iEvent
Definition: GenABIO.cc:224
std::ofstream m_file[4]
handles for output files
std::string m_textFileName
basename for output files
edm::InputTag m_gctInputLabel
label for input digis
ii
Definition: cuy.py:589
bool m_hexUpperCase
write upper case hex words
~GctDigiToPsbText() override
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
void analyze(const edm::Event &, const edm::EventSetup &) override
GctDigiToPsbText(const edm::ParameterSet &)