CMS 3D CMS Logo

GtPsbTextToDigi.cc
Go to the documentation of this file.
1 
2 #include "GtPsbTextToDigi.h"
3 // general
6 #include <iomanip>
7 #include <iostream>
8 // gct
13 //#include "DataFormats/L1GlobalCaloTrigger/interface/L1GctJetCounts.h"
14 
16  : m_fileEventOffset(iConfig.getUntrackedParameter<int>("FileEventOffset", 0)),
17  m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
18  m_nevt(0) {
19  // Produces collections
20  produces<L1GctEmCandCollection>("isoEm");
21  produces<L1GctEmCandCollection>("nonIsoEm");
22  produces<L1GctJetCandCollection>("cenJets");
23  produces<L1GctJetCandCollection>("forJets");
24  produces<L1GctJetCandCollection>("tauJets");
25  // produces<L1GctEtTotal>();
26 
27  // Open the input files
28  for (int ifile = 0; ifile < 4; ifile++) {
29  // gct em cand coll: (noiso) 0<->0, 1<->1, (iso) 6<->2, 7<->3
30  int ii = (ifile < 2) ? ifile : ifile + 4;
31  std::stringstream fileStream;
32  fileStream << m_textFileName << ii << ".txt";
33  std::string fileName(fileStream.str());
34  m_file[ifile].open(fileName.c_str(), std::ios::in);
35  if (!m_file[ifile].good()) {
36  throw cms::Exception("GtPsbTextToDigiTextFileOpenError")
37  // LogDebug("GtPsbTextToDigi")
38  << "GtPsbTextToDigi::GtPsbTextToDigi : "
39  << " couldn't open the file "
40  << fileName
41  //<< "...skipping!"
42  << std::endl;
43  }
44  std::hex(m_file[ifile]);
45  }
46 
47  // Initialize bc0 position holder
48  for (int i = 0; i < 4; i++)
49  m_bc0[i] = -1;
50 }
51 
53  // Close the input files
54  for (unsigned i = 0; i < 4; i++) {
55  m_file[i].close();
56  }
57 }
58 
61  std::unique_ptr<L1GctEmCandCollection> gctIsolaEm(new L1GctEmCandCollection());
62  std::unique_ptr<L1GctEmCandCollection> gctNoIsoEm(new L1GctEmCandCollection());
63  std::unique_ptr<L1GctJetCandCollection> gctCenJets(new L1GctJetCandCollection());
64  std::unique_ptr<L1GctJetCandCollection> gctForJets(new L1GctJetCandCollection());
65  std::unique_ptr<L1GctJetCandCollection> gctTauJets(new L1GctJetCandCollection());
66  // std::unique_ptr<L1GctEtTotal> gctEtTotal( new L1GctEtTotal () );
67  for (int i = 0; i < 4; i++) {
68  gctIsolaEm->push_back(L1GctEmCand(0, true));
69  gctNoIsoEm->push_back(L1GctEmCand(0, false));
70  gctCenJets->push_back(L1GctJetCand(0, false, false));
71  gctForJets->push_back(L1GctJetCand(0, false, true));
72  gctTauJets->push_back(L1GctJetCand(0, true, false));
73  // gctEtTotal->push_back(());
74  }
75  iEvent.put(std::move(gctIsolaEm), "isoEm");
76  iEvent.put(std::move(gctNoIsoEm), "nonIsoEm");
77  iEvent.put(std::move(gctCenJets), "cenJets");
78  iEvent.put(std::move(gctForJets), "forJets");
79  iEvent.put(std::move(gctTauJets), "tauJets");
80  // iEvent.put(std::move(gctEtTotal));
81 
82  LogDebug("GtPsbTextToDigi") << "putting empty digi (evt:" << m_nevt << ")\n";
83 }
84 
86  // specify clock cycle bit sequence 1 0 1 0... or 0 1 0 1...
87  unsigned short cbs[2] = {1, 0};
88 
89  // Skip event if required
90  if (m_nevt < m_fileEventOffset) {
92  LogDebug("GtPsbTextToDigi") << "[GtPsbTextToDigi::produce()] skipping event " << m_nevt << std::endl;
93  m_nevt++;
94  return;
95  } else if (m_nevt == 0 && m_fileEventOffset < 0) {
96  // skip first fileEventOffset input events
97  unsigned long int buff;
98  for (int ievt = 0; ievt < abs(m_fileEventOffset); ievt++) {
99  for (int ifile = 0; ifile < 4; ifile++) {
100  for (int cycle = 0; cycle < 2; cycle++) {
101  std::hex(m_file[ifile]);
102  m_file[ifile] >> buff;
103  unsigned tmp = (buff >> 15) & 0x1;
104  if (tmp != cbs[cycle]) {
105  if (m_bc0[ifile] == -1 && cycle == 1 && tmp == 1)
106  m_bc0[ifile] = ievt;
107  else
108  throw cms::Exception("GtPsbTextToDigiTextFileFormatError")
109  // std::cout << "GtPsbTextToDigiTextFileFormatError"
110  << "GtPsbTextToDigi::produce : "
111  << " found format inconsistency in file #" << ifile << "\n in skipped line:" << ievt * 2 + 1
112  << " cycle:" << tmp << " is different from " << cbs[cycle] << std::endl;
113  }
114  }
115  }
116  LogDebug("GtPsbTextToDigi") << "[GtPsbTextToDigi::produce()] skipping input " << ievt << std::endl;
117  }
118  }
119  m_nevt++;
120 
121  // New collections
122  std::unique_ptr<L1GctEmCandCollection> gctIsolaEm(new L1GctEmCandCollection());
123  std::unique_ptr<L1GctEmCandCollection> gctNoIsoEm(new L1GctEmCandCollection());
124  std::unique_ptr<L1GctJetCandCollection> gctCenJets(new L1GctJetCandCollection());
125  std::unique_ptr<L1GctJetCandCollection> gctForJets(new L1GctJetCandCollection());
126  std::unique_ptr<L1GctJetCandCollection> gctTauJets(new L1GctJetCandCollection());
127  // std::unique_ptr<L1GctEtTotal> gctEtTotal( new L1GctEtTotal () );
128 
130  uint16_t data[4][2] = {{0}};
131  for (int i = 0; i < 4; i++)
132  for (int j = 0; j < 2; j++)
133  data[i][j] = 0;
134 
135  // Loop over files
136  for (int ifile = 0; ifile < 4; ifile++) {
137  int ii = (ifile < 2) ? ifile : ifile + 4;
138 
139  // Check we're not at the end of the file
140  if (m_file[ifile].eof()) {
141  LogDebug("GtPsbTextToDigi") << "GtPsbTextToDigi::produce : "
142  << " unexpected end of file " << m_textFileName << ii << ".txt" << std::endl;
144  continue;
145  }
146 
147  if (!m_file[ifile].good()) {
148  LogDebug("GtPsbTextToDigi") << "GtPsbTextToDigi::produce : "
149  << " problem reading file " << m_textFileName << ii << ".txt" << std::endl;
151  continue;
152  }
153 
155  unsigned long int uLongBuffer;
156 
157  for (unsigned cycle = 0; cycle < 2; cycle++) {
158  m_file[ifile] >> uLongBuffer;
159  unsigned tmp = (uLongBuffer >> 15) & 0x1;
160 
162  if (false && tmp != cbs[cycle])
163  std::cout << "[GtPsbTextToDigi::produce()] asserting "
164  << " evt:" << m_nevt << " ifile:" << ifile << " cycle:" << cbs[cycle] << std::hex
165  << " buffer:" << uLongBuffer << " tmp: " << tmp << std::dec << "\n\n"
166  << std::flush;
167 
168  if (tmp != cbs[cycle]) {
169  if (m_bc0[ifile] == -1 && cycle == 1 && tmp == 1) {
171  } else {
172  throw cms::Exception("GtPsbTextToDigiTextFileFormatError")
173  // std::cout << "GtPsbTextToDigiTextFileFormatError "
174  << "GtPsbTextToDigi::produce : "
175  << " found format inconsistency in file #" << ifile
176  << "\n in line:" << (m_nevt - m_fileEventOffset) * 2 - 1 << " cycle:" << tmp << " is different from "
177  << cbs[cycle] << std::endl;
178  }
179  }
180  data[ifile][cycle] = (uLongBuffer & 0x7fff);
181  } // cycle loop
182  } // ifile loop
183 
185  unsigned iIsola, iNoIso;
186  for (unsigned cycle = 0; cycle < 2; cycle++) {
187  for (unsigned i = 0; i < 2; i++) {
188  iIsola = i + 2;
189  iNoIso = i;
190  gctIsolaEm->push_back(L1GctEmCand(data[iIsola][cycle] & 0x7fff, true));
191  gctNoIsoEm->push_back(L1GctEmCand(data[iNoIso][cycle] & 0x7fff, false));
192  L1GctEmCand candI(data[iIsola][cycle], true);
193  L1GctEmCand candN(data[iNoIso][cycle], false);
194  }
195  }
196 
198  iEvent.put(std::move(gctIsolaEm), "isoEm");
199  iEvent.put(std::move(gctNoIsoEm), "nonIsoEm");
200  iEvent.put(std::move(gctCenJets), "cenJets");
201  iEvent.put(std::move(gctForJets), "forJets");
202  iEvent.put(std::move(gctTauJets), "tauJets");
203  // iEvent.put(std::move(gctEtTotal));
204 }
205 
208  int nmem = 4;
209  bool match = true;
210  for (int i = 0; i < nmem - 1; i++)
211  match &= (m_bc0[i] == m_bc0[i + 1]);
212  LogDebug("GtPsbTextToDigi") << "[GtPsbTextToDigi::endJob()] ";
213  if (!match)
214  LogDebug("GtPsbTextToDigi") << "did not find matching BC0 in all input files: ";
215  else
216  LogDebug("GtPsbTextToDigi") << "detected common BC0 in all input files: ";
217  for (int i = 0; i < nmem; i++)
218  LogDebug("GtPsbTextToDigi") << " " << m_bc0[i];
219  LogDebug("GtPsbTextToDigi") << std::flush << std::endl;
220 }
~GtPsbTextToDigi() override
void endJob() override
Level-1 Trigger jet candidate.
Definition: L1GctJetCand.h:17
void produce(edm::Event &, const edm::EventSetup &) override
GtPsbTextToDigi(const edm::ParameterSet &)
std::string m_textFileName
Name out input file.
Level-1 Trigger EM candidate at output of GCT.
Definition: L1GctEmCand.h:21
std::vector< L1GctJetCand > L1GctJetCandCollection
int iEvent
Definition: GenABIO.cc:224
int m_fileEventOffset
Number of events to be offset wrt input.
std::ifstream m_file[4]
File handle.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void putEmptyDigi(edm::Event &)
Create empty digi collection.
int m_nevt
Event counter.
ii
Definition: cuy.py:589
auto const good
min quality of good
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
int m_bc0[4]
Hold detected BC0 signal position per file.
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
tmp
align.sh
Definition: createJobs.py:716
def move(src, dest)
Definition: eostools.py:511
std::vector< L1GctEmCand > L1GctEmCandCollection
#define LogDebug(id)