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(
12  iConfig.getUntrackedParameter<bool>("HexUpperCase", false)) {
14  for (unsigned i = 0; i < 4; i++) {
15  std::stringstream fileStream;
16  int ii = (i < 2) ? i : i + 4;
17  fileStream << m_textFileName << ii << ".txt";
18  std::string fileName(fileStream.str());
19  m_file[i].open(fileName.c_str(), std::ios::out);
20  if (!m_file[i].good()) {
21  throw cms::Exception("GctDigiToPsbTextTextFileOpenError")
22  << "GctDigiToPsbText::GctDigiToPsbText : "
23  << " couldn't create the file " << fileName << std::endl;
24  }
25  }
26 }
27 
30  for (unsigned i = 0; i < 4; i++)
31  m_file[i].close();
32 }
33 
35  const edm::EventSetup &iSetup) {
36 
37  // static int nevt = -1; nevt++;
38 
39  // get digis
42  iEvent.getByLabel(m_gctInputLabel.label(), "isoEm", gctIsolaEm);
43  iEvent.getByLabel(m_gctInputLabel.label(), "nonIsoEm", gctNoIsoEm);
44 
46  uint16_t data[4][2] = {{0}};
47  for (int i = 0; i < 4; i++)
48  for (int j = 0; j < 2; j++)
49  data[i][j] = 0;
50 
51  std::stringstream sstrm;
52  if (m_hexUpperCase)
53  sstrm << std::uppercase;
54  else
55  sstrm.unsetf(std::ios::uppercase);
56 
57  // specify cycle bit sequence 1 0 1 0 ... or 0 1 0 1 ...
58  unsigned short cbs[2] = {1, 0};
59 
60  unsigned int ifile;
61  unsigned int cycle;
62  unsigned iIsola, iNoIso;
63 
64  for (int i = 0; i < 4; i++) {
65  cycle = i / 2;
66  ifile = i % 2;
67  iIsola = ifile + 2;
68  iNoIso = ifile;
69 
70  // get the data
71  data[iIsola][cycle] = gctIsolaEm->at(i).raw();
72  data[iNoIso][cycle] = gctNoIsoEm->at(i).raw();
73 
74  // print electrons
75  sstrm.str("");
76  sstrm << setw(4) << setfill('0') << std::hex
77  << (data[iIsola][cycle] & 0x7fff) + ((cbs[cycle] & 0x1) << 15);
78  m_file[iIsola] << sstrm.str() << std::endl;
79  sstrm.str("");
80  sstrm << setw(4) << setfill('0') << std::hex
81  << (data[iNoIso][cycle] & 0x7fff) + ((cbs[cycle] & 0x1) << 15);
82  m_file[iNoIso] << sstrm.str() << std::endl;
83  }
84 
86  for (unsigned i = 0; i < 4; i++)
87  m_file[i] << std::flush;
88 }
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
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
ii
Definition: cuy.py:590
bool m_hexUpperCase
write upper case hex words
~GctDigiToPsbText() override
std::string const & label() const
Definition: InputTag.h:36
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void analyze(const edm::Event &, const edm::EventSetup &) override
GctDigiToPsbText(const edm::ParameterSet &)