HGCal Test Beam  03a93d6239a951948e06fb3ef8dae4cbdebfad30
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
HGCalTBTextSource.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include "HGCal/RawToDigi/plugins/HGCalTBTextSource.h"
3 #include "HGCal/Geometry/interface/HGCalTBGeometryParameters.h"
4 #include "HGCal/Geometry/interface/HGCalTBSpillParameters.h"
5 using namespace std;
6 unsigned int runcounter = 0;
7 int runflag = 0;
9 unsigned int Events_Per_Spill = 0;
10 unsigned int spillcounter = 0;
11 //unsigned int Number_Of_Events_Per_Spill = 150;
12 //unsigned int Number_Of_Spills = 8;
15 
16 string buffer1 = "0 0 0x00000000 0x00000000";
17 bool HGCalTBTextSource::readLines()
18 {
19  m_lines.clear();
20  char buffer[1024];
21  int counter = 0;
22  if(runcounter == 0 && runflag == 0){
23  buffer[0] = 0;
24  fgets(buffer, 1000, m_file);
25  if(sscanf(buffer, "STARTING SPILL READ AT TIME (1us): %x RUN: %u",&m_time_tmp,&m_run_tmp) !=2 ) return false;
26  m_run = m_run_tmp;
27  runflag = 1;
28  }
30  runcounter=0;
32  }
33 
35  spillcounter++;
37  }
38 
39 /*
40  if(runcounter == 0 && trigcountperspillflag == 0){
41  buffer[0] = 0;
42  fgets(buffer, 1000, m_file);
43  if(sscanf(buffer,"Board header: on FMC-IO 2, trig_count in mem= %u, sk_status = 1",&Events_Per_Spill) !=1 ) return false;
44  trigcountperspillflag = 1;
45  if(Events_Per_Spill < 140) return false;
46  }
47 */
48 
49 // if( sscanf(buffer, " RUN: %u", &m_run) != 1) return false;
50 // sscanf(buffer, " RUN:%u", &m_run);
51 // cout<<endl<<m_run<<endl;
52  while (!feof(m_file) && spillcounter< SPILLS) {
53 // while (!feof(m_file) && runcounter < 1001) {
54  buffer[0] = 0;
55  fgets(buffer, 1000, m_file);
56  if (strstr(buffer, "STARTING")) continue;
57  if (strstr(buffer, "Board")) continue;
58 // if(strstr(buffer, "Event")) continue;
59 
60 
61 /*
62  if(strstr(buffer,"CKOV= 1")){
63  for(int iii=1; iii<=64;iii++){
64  m_lines.push_back(buffer1);
65  if(iii==64) counter=67;
66  }
67  }
68 
69  if(strstr(buffer,"CKOV= 1")) cout<<endl<<"CKOV= 1"<<endl;
70  else cout<<endl<<"CKOV= 0"<<endl;
71 */
72 
73  if(strstr(buffer, "Event")) continue;
74  counter++;
75  if(runcounter < EVENTSPERSPILL && counter <= Number_Of_SKIROC_Data_Words) m_lines.push_back(buffer);
77  runcounter++;
78 // cout<<endl<<" Reached Here 1"<<endl;
79  break;
80  }
81 
82  }
83 
84  return !m_lines.empty();
85 }
86 
87 void HGCalTBTextSource::produce(edm::Event & e)
88 {
89  std::auto_ptr<FEDRawDataCollection> bare_product(new FEDRawDataCollection());
90 
91 // cout<<endl<<"Size= "<<m_lines.size()<<endl;
92  // here we parse the data
93  std::vector<uint16_t> skiwords;
94  // make sure there are an even number of 32-bit-words (a round number of 64 bit words...
95  if (m_lines.size() % 2) {
96  skiwords.push_back(0);
97  skiwords.push_back(0);
98  }
99  for (std::vector<std::string>::const_iterator i = m_lines.begin(); i != m_lines.end(); i++) {
100  uint32_t a, b, c, d;
101  sscanf(i->c_str(), "%x %x %x %x", &a, &b, &c, &d);
102 // cout<<endl<<" Here "<<dec<<a<<dec<<" "<<b<<hex<<" "<<c<<hex<<" "<<d<<endl;
103  skiwords.push_back(uint16_t(c >> 16));
104  skiwords.push_back(uint16_t(d >> 16));
105  skiwords.push_back(uint16_t(c));
106  skiwords.push_back(uint16_t(d));
107  }
108 
109  FEDRawData& fed = bare_product->FEDData(m_sourceId);
110  size_t len = sizeof(uint16_t) * skiwords.size();
111 // cout<<endl<<" Len= "<<len<<endl;
112  fed.resize(len);
113  memcpy(fed.data(), &(skiwords[0]), len);
114 
115  e.put(bare_product);
116 }
117 
118 
119 
120 void HGCalTBTextSource::fillDescriptions(edm::ConfigurationDescriptions& descriptions)
121 {
122  edm::ParameterSetDescription desc;
123  desc.setComment("TEST");
124  desc.addUntracked<int>("run", 101);
125  desc.addUntracked<std::vector<std::string> >("fileNames");
126  descriptions.add("source", desc);
127 }
128 
129 
130 #include "FWCore/Framework/interface/InputSourceMacros.h"
131 
int runflag
unsigned int Events_Per_Spill
string buffer1
unsigned int spillcounter
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define MAXLAYERS
int trigcountperspillflag
convert data from txt file to FEDRawData
int Number_Of_SKIROC_Data_Words
#define EVENTSPERSPILL
int counter
DEFINE_FWK_INPUT_SOURCE(HGCalTBTextSource)
#define SPILLS
int Number_Of_SKIROC_Words
unsigned int runcounter