test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 " << fileName
40  //<< "...skipping!"
41  << std::endl;
42  }
43  std::hex(m_file[ifile]);
44  }
45 
46  // Initialize bc0 position holder
47  for(int i=0; i<4; i++)
48  m_bc0[i]=-1;
49 }
50 
52  // Close the input files
53  for (unsigned i=0; i<4; i++){
54  m_file[i].close();
55  }
56 }
57 
60  std::auto_ptr<L1GctEmCandCollection> gctIsolaEm( new L1GctEmCandCollection () );
61  std::auto_ptr<L1GctEmCandCollection> gctNoIsoEm( new L1GctEmCandCollection () );
62  std::auto_ptr<L1GctJetCandCollection> gctCenJets( new L1GctJetCandCollection() );
63  std::auto_ptr<L1GctJetCandCollection> gctForJets( new L1GctJetCandCollection() );
64  std::auto_ptr<L1GctJetCandCollection> gctTauJets( new L1GctJetCandCollection() );
65  //std::auto_ptr<L1GctEtTotal> gctEtTotal( new L1GctEtTotal () );
66  for (int i=0; i<4; i++){
67  gctIsolaEm->push_back(L1GctEmCand (0,1));
68  gctNoIsoEm->push_back(L1GctEmCand (0,0));
69  gctCenJets->push_back(L1GctJetCand(0,0,0));
70  gctForJets->push_back(L1GctJetCand(0,0,1));
71  gctTauJets->push_back(L1GctJetCand(0,1,0));
72  //gctEtTotal->push_back(());
73  }
74  iEvent.put(gctIsolaEm, "isoEm");
75  iEvent.put(gctNoIsoEm, "nonIsoEm");
76  iEvent.put(gctCenJets, "cenJets");
77  iEvent.put(gctForJets, "forJets");
78  iEvent.put(gctTauJets, "tauJets");
79  //iEvent.put(gctEtTotal);
80 
81  LogDebug("GtPsbTextToDigi") << "putting empty digi (evt:" << m_nevt << ")\n";
82 }
83 
85 
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){
91  putEmptyDigi(iEvent);
92  LogDebug("GtPsbTextToDigi")
93  << "[GtPsbTextToDigi::produce()] skipping event " << m_nevt
94  << std::endl;
95  m_nevt++;
96  return;
97  } else if (m_nevt==0 && m_fileEventOffset<0) {
98  // skip first fileEventOffset input events
99  unsigned long int buff;
100  for (int ievt=0; ievt<abs(m_fileEventOffset); ievt++){
101  for (int ifile=0; ifile<4; ifile++){
102  for (int cycle=0; cycle<2; cycle++){
103  std::hex(m_file[ifile]);
104  m_file[ifile] >> buff;
105  unsigned tmp = (buff>>15)&0x1;
106  if(tmp!=cbs[cycle]) {
107  if(m_bc0[ifile]==-1 && cycle==1 && tmp==1)
108  m_bc0[ifile] = ievt;
109  else
110  throw cms::Exception("GtPsbTextToDigiTextFileFormatError")
111  //std::cout << "GtPsbTextToDigiTextFileFormatError"
112  << "GtPsbTextToDigi::produce : "
113  << " found format inconsistency in file #" << ifile
114  << "\n in skipped line:" << ievt*2+1
115  << " cycle:" << tmp << " is different from " << cbs[cycle]
116  << std::endl;
117  }
118  }
119  }
120  LogDebug("GtPsbTextToDigi")
121  << "[GtPsbTextToDigi::produce()] skipping input " << ievt
122  << std::endl;
123  }
124  }
125  m_nevt++;
126 
127  // New collections
128  std::auto_ptr<L1GctEmCandCollection> gctIsolaEm( new L1GctEmCandCollection () );
129  std::auto_ptr<L1GctEmCandCollection> gctNoIsoEm( new L1GctEmCandCollection () );
130  std::auto_ptr<L1GctJetCandCollection> gctCenJets( new L1GctJetCandCollection() );
131  std::auto_ptr<L1GctJetCandCollection> gctForJets( new L1GctJetCandCollection() );
132  std::auto_ptr<L1GctJetCandCollection> gctTauJets( new L1GctJetCandCollection() );
133  //std::auto_ptr<L1GctEtTotal> gctEtTotal( new L1GctEtTotal () );
134 
136  uint16_t data[4][2]= {{0}};
137  for (int i=0; i<4; i++)
138  for (int j=0; j<2; j++)
139  data[i][j]=0;
140 
141  // Loop over files
142  for (int ifile=0; ifile<4; ifile++){
143  int ii = (ifile<2)?ifile:ifile+4;
144 
145  // Check we're not at the end of the file
146  if(m_file[ifile].eof()) {
147  LogDebug("GtPsbTextToDigi")
148  << "GtPsbTextToDigi::produce : "
149  << " unexpected end of file " << m_textFileName << ii << ".txt"
150  << std::endl;
151  putEmptyDigi(iEvent);
152  continue;
153  }
154 
155  if(!m_file[ifile].good()) {
156  LogDebug("GtPsbTextToDigi")
157  << "GtPsbTextToDigi::produce : "
158  << " problem reading file " << m_textFileName << ii << ".txt"
159  << std::endl;
160  putEmptyDigi(iEvent);
161  continue;
162  }
163 
165  unsigned long int uLongBuffer;
166 
167  for(unsigned cycle=0; cycle<2; cycle++) {
168  m_file[ifile] >> uLongBuffer;
169  unsigned tmp = (uLongBuffer>>15)&0x1;
170 
172  if(false && tmp!=cbs[cycle])
173  std::cout << "[GtPsbTextToDigi::produce()] asserting "
174  << " evt:" << m_nevt
175  << " ifile:" << ifile
176  << " cycle:" << cbs[cycle]
177  << std::hex
178  << " buffer:"<< uLongBuffer
179  << " tmp: " << tmp
180  << std::dec
181  << "\n\n" << std::flush;
182 
183  if(tmp!=cbs[cycle]){
184  if(m_bc0[ifile]==-1 && cycle==1 && tmp==1){
186  }else{
187  throw cms::Exception("GtPsbTextToDigiTextFileFormatError")
188  //std::cout << "GtPsbTextToDigiTextFileFormatError "
189  << "GtPsbTextToDigi::produce : "
190  << " found format inconsistency in file #" << ifile
191  << "\n in line:" << (m_nevt-m_fileEventOffset)*2-1
192  << " cycle:" << tmp << " is different from " << cbs[cycle]
193  << std::endl;
194  }
195  }
196  data[ifile][cycle] = (uLongBuffer&0x7fff);
197  } //cycle loop
198  } //ifile loop
199 
201  unsigned iIsola, iNoIso;
202  for (unsigned cycle=0; cycle<2; cycle++){
203  for (unsigned i=0; i<2; i++){
204  iIsola = i+2;
205  iNoIso = i;
206  gctIsolaEm->push_back(L1GctEmCand(data[iIsola][cycle]&0x7fff,1));
207  gctNoIsoEm->push_back(L1GctEmCand(data[iNoIso][cycle]&0x7fff,0));
208  L1GctEmCand candI(data[iIsola][cycle],1);
209  L1GctEmCand candN(data[iNoIso][cycle],0);
210  }
211  }
212 
214  iEvent.put(gctIsolaEm, "isoEm");
215  iEvent.put(gctNoIsoEm, "nonIsoEm");
216  iEvent.put(gctCenJets, "cenJets");
217  iEvent.put(gctForJets, "forJets");
218  iEvent.put(gctTauJets, "tauJets");
219  //iEvent.put(gctEtTotal);
220 
221 }
222 
225  int nmem = 4;
226  bool match = true;
227  for(int i=0; i<nmem-1; i++)
228  match &= (m_bc0[i]==m_bc0[i+1]);
229  LogDebug("GtPsbTextToDigi") << "[GtPsbTextToDigi::endJob()] ";
230  if(!match)
231  LogDebug("GtPsbTextToDigi") << "did not find matching BC0 in all input files: ";
232  else
233  LogDebug("GtPsbTextToDigi") << "detected common BC0 in all input files: ";
234  for(int i=0; i<nmem; i++)
235  LogDebug("GtPsbTextToDigi") << " " << m_bc0[i];
236  LogDebug("GtPsbTextToDigi") << std::flush << std::endl;
237 
238 }
#define LogDebug(id)
virtual void produce(edm::Event &, const edm::EventSetup &)
int i
Definition: DBlmapReader.cc:9
Level-1 Trigger jet candidate.
Definition: L1GctJetCand.h:18
GtPsbTextToDigi(const edm::ParameterSet &)
int ii
Definition: cuy.py:588
std::string m_textFileName
Name out input file.
Level-1 Trigger EM candidate at output of GCT.
Definition: L1GctEmCand.h:22
virtual void endJob()
std::vector< L1GctJetCand > L1GctJetCandCollection
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
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
int j
Definition: DBlmapReader.cc:9
void putEmptyDigi(edm::Event &)
Create empty digi collection.
int m_nevt
Event counter.
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
int m_bc0[4]
Hold detected BC0 signal position per file.
tuple cout
Definition: gather_cfg.py:145
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
std::vector< L1GctEmCand > L1GctEmCandCollection