CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
GtPsbTextToDigi Class Reference

#include <GtPsbTextToDigi.h>

Inheritance diagram for GtPsbTextToDigi:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 GtPsbTextToDigi (const edm::ParameterSet &)
 
 ~GtPsbTextToDigi ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndex indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

virtual void endJob ()
 
virtual void produce (edm::Event &, const edm::EventSetup &)
 
void putEmptyDigi (edm::Event &)
 Create empty digi collection. More...
 

Private Attributes

int m_bc0 [4]
 Hold detected BC0 signal position per file. More...
 
std::ifstream m_file [4]
 File handle. More...
 
int m_fileEventOffset
 Number of events to be offset wrt input. More...
 
int m_nevt
 Event counter. More...
 
std::string m_textFileName
 Name out input file. More...
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 34 of file GtPsbTextToDigi.h.

Constructor & Destructor Documentation

GtPsbTextToDigi::GtPsbTextToDigi ( const edm::ParameterSet iConfig)
explicit

Definition at line 15 of file GtPsbTextToDigi.cc.

References edm::hlt::Exception, convertXMLtoSQLite_cfg::fileName, i, compare_using_db::ifile, cuy::ii, recoMuon::in, m_bc0, m_file, m_textFileName, and AlCaHLTBitMon_QueryRunRegistry::string.

15  :
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 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
int ii
Definition: cuy.py:588
std::string m_textFileName
Name out input file.
int m_fileEventOffset
Number of events to be offset wrt input.
std::ifstream m_file[4]
File handle.
int m_nevt
Event counter.
int m_bc0[4]
Hold detected BC0 signal position per file.
GtPsbTextToDigi::~GtPsbTextToDigi ( )

Definition at line 51 of file GtPsbTextToDigi.cc.

References i, and m_file.

51  {
52  // Close the input files
53  for (unsigned i=0; i<4; i++){
54  m_file[i].close();
55  }
56 }
int i
Definition: DBlmapReader.cc:9
std::ifstream m_file[4]
File handle.

Member Function Documentation

void GtPsbTextToDigi::endJob ( void  )
privatevirtual

Check BC0 signals consistency

Reimplemented from edm::EDProducer.

Definition at line 223 of file GtPsbTextToDigi.cc.

References i, LogDebug, m_bc0, and match().

223  {
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)
int i
Definition: DBlmapReader.cc:9
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:6
void GtPsbTextToDigi::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual

buffer

Read in file

cycle debuging (temporary)

Fill in digi collections

Put collections

Implements edm::EDProducer.

Definition at line 84 of file GtPsbTextToDigi.cc.

References abs, gather_cfg::cout, cycle, data, edm::hlt::Exception, i, compare_using_db::ifile, cuy::ii, j, LogDebug, m_bc0, m_file, m_fileEventOffset, m_nevt, m_textFileName, edm::Event::put(), putEmptyDigi(), and tmp.

84  {
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 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
#define abs(x)
Definition: mlp_lapack.h:159
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
std::vector< L1GctJetCand > L1GctJetCandCollection
int cycle
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
int m_fileEventOffset
Number of events to be offset wrt input.
std::ifstream m_file[4]
File handle.
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:121
std::vector< L1GctEmCand > L1GctEmCandCollection
void GtPsbTextToDigi::putEmptyDigi ( edm::Event iEvent)
private

Create empty digi collection.

Append empty digi collection.

Definition at line 59 of file GtPsbTextToDigi.cc.

References i, LogDebug, m_nevt, and edm::Event::put().

Referenced by produce().

59  {
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 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
Level-1 Trigger jet candidate.
Definition: L1GctJetCand.h:18
Level-1 Trigger EM candidate at output of GCT.
Definition: L1GctEmCand.h:22
std::vector< L1GctJetCand > L1GctJetCandCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
int m_nevt
Event counter.
std::vector< L1GctEmCand > L1GctEmCandCollection

Member Data Documentation

int GtPsbTextToDigi::m_bc0[4]
private

Hold detected BC0 signal position per file.

Definition at line 60 of file GtPsbTextToDigi.h.

Referenced by endJob(), GtPsbTextToDigi(), and produce().

std::ifstream GtPsbTextToDigi::m_file[4]
private

File handle.

Definition at line 57 of file GtPsbTextToDigi.h.

Referenced by GtPsbTextToDigi(), produce(), and ~GtPsbTextToDigi().

int GtPsbTextToDigi::m_fileEventOffset
private

Number of events to be offset wrt input.

Definition at line 48 of file GtPsbTextToDigi.h.

Referenced by produce().

int GtPsbTextToDigi::m_nevt
private

Event counter.

Definition at line 54 of file GtPsbTextToDigi.h.

Referenced by produce(), and putEmptyDigi().

std::string GtPsbTextToDigi::m_textFileName
private

Name out input file.

Definition at line 51 of file GtPsbTextToDigi.h.

Referenced by GtPsbTextToDigi(), and produce().