Belle II Software  release-05-02-19
HexDataPacker.cc
1 //+
2 // File : DummyDataPacker.cc
3 // Description : Module to store dummy data in RawSVD(and others) object
4 //
5 // Author : Satoru Yamada, IPNS, KEK
6 // Date : 14 - Jul - 2014
7 //-
8 
9 
10 // The format of readable hex dump
11 // ************************************************
12 // Program to read events by DMA
13 // Data mode
14 // SUCCESS: Device opened for ECS 0
15 // SUCCESS: Device opened for ECS 2
16 // SUCCESS: Device opened for DMA
17 // Header : eeee000c aaaaeeee 0180aaaa 00000000 00010000 00000000 00000000 00000000
18 // data 0 : eeee000c aaaaeeee 0180aaaa 00000000 00010000 00000000 00000000 00000000
19 // data 7 : 0000004e 7f7f0438 0343cd00 00000000 21ed8e47 5f7e6a02 00000000 00000001
20 // data 15 : 00000038 00000038 00000038 00000038 00000038 00000038 00000038 00000038
21 // data 23 : 00000038 00000038 00000038 00000038 0000004a 0000004a 0000004a 0000004a
22 // data 31 : 0000004a 0000004a 0000004a 0000004a 0000004a 0000004a 0000004a 0000004a
23 // data 39 : 0000004a 0000004a 0000004a 0000004a 0000004a 0000004a 0000004a 0000004a
24 // data 47 : 0000004a 0000004a 0000004a 0000004a 0000004a 0000004a 0000004a 0000004a
25 // data 55 : 0000004a 0000004a 0000004a 0000004a 0000004a 0000004a 0000004a 0000004a
26 // data 63 : ffaa0b00 21ed8e47 00000000 5f7e6a02 0343cd00 21ed9c30 4898121d 06a40000
27 // data 71 : 4cb01218 06840000 540110de 04980000 5401120f 060c0000 12ee0000 21ed8e47
28 // data 79 : 00006408 ff550000 7fff1775 7fff0006 7fff0007 7fff0008 7fff0009 7fff000a
29 // data 87 : Trailer : 0 0 0 0 0 0 0 C
30 // Bad event number prev 0 cur 0
31 // Header : eeee000c aaaaeeee 0180aaaa 00000000 00010000 00000001 00000000 00000000
32 // data 0 : eeee000c aaaaeeee 0180aaaa 00000000 00010000 00000001 00000000 00000000
33 // data 7 : 0000004c 7f7f0438 0343cd00 00000001 21fc9f57 5f7e6a02 00000000 00000001
34 // ************************************************
35 #include <iostream>
36 #include <rawdata/modules/HexDataPacker.h>
37 
38 using namespace std;
39 using namespace Belle2;
40 
41 #define USE_PCIE40
42 
43 //-----------------------------------------------------------------
44 // Register the Module
45 //-----------------------------------------------------------------
46 REG_MODULE(HexDataPacker)
47 
48 //-----------------------------------------------------------------
49 // Implementation
50 //-----------------------------------------------------------------
51 
53 {
55  setDescription("an Example to pack data to a RawCOPPER object");
56  addParam("inputFileName", m_fileName, "Output binary filename", string(""));
57  B2INFO("HexDataPacker: Constructor done.");
58  // initialize event #
59  n_basf2evt = 0;
60 }
61 
62 
63 
64 HexDataPackerModule::~HexDataPackerModule()
65 {
66 
67 }
68 
69 
70 void HexDataPackerModule::initialize()
71 {
72  B2INFO("HexDataPacker: initialize() started.");
73 
74  // Open message handler
75  // m_msghandler = new MsgHandler(m_compressionLevel);
76 
78  m_eventMetaDataPtr.registerInDataStore();
79 
80  m_raw_cprarray.registerInDataStore();
81  m_raw_svdarray.registerInDataStore();
82  m_raw_cdcarray.registerInDataStore();
83  m_raw_bpidarray.registerInDataStore();
84  m_raw_epidarray.registerInDataStore();
85  m_raw_eclarray.registerInDataStore();
86  m_raw_klmarray.registerInDataStore();
87 
88  B2INFO("HexDataPacker: initialize() done.");
89 
90  if (m_fileName == "") {
91  B2FATAL("HexDataPacker can't fine a filename: ");
92  }
93 
94  m_ifs.open(m_fileName.c_str());
95  if (!m_ifs) {
96  B2FATAL("HexDataPacker can't open a file " << m_fileName.c_str());
97  }
98 }
99 
100 
101 
102 
103 void HexDataPackerModule::event()
104 {
105  StoreArray<RawKLM> ary; // You need to change if you want to make a different Raw*** object.
106  const int MAX_CPRBUF_WORDS = 5000;
107  int* evtbuf = new int[MAX_CPRBUF_WORDS];
108  char char1[50], char2[50], char3[50], char4[50];
109 
110  unsigned int val[10];
111  int size = 0;
112  int runEnd = 0;
113  int word_count = 0;
114  int event_end = 0;
115  while (true) {
116 
117  if (m_ifs.eof()) {
118  runEnd = 1;
119  break;
120  }
121  string strin;
122  getline(m_ifs, strin);
123  sscanf(strin.c_str(), "%49s %49s %49s %49s",
124  char1, char2, char3, char4);
125  if (strcmp(char1, "data") == 0) {
126  if (strcmp(char4, "Trailer") == 0) {
127  continue;
128  }
129  if (strcmp(char2, "0") == 0) {
130  continue;
131  } else if (strcmp(char2, "7") == 0) {
132  sscanf(strin.c_str(), "%49s %u %49s %x %x %x %x %x %x %x %x",
133  char1, &(val[0]), char2, &(val[1]), &(val[2]), &(val[3]), &(val[4]), &(val[5]), &(val[6]), &(val[7]), &(val[8]));
134  size = val[1];
135  val[2] = val[2] | 0x00008000; // For data which was not reduced in FPGA
136  if (size < 0 || size > MAX_CPRBUF_WORDS) {
137  B2FATAL("The size of an event =(" << size << ") is too large. Exiting...");
138  }
139  } else {
140  sscanf(strin.c_str(), "%20s %u %20s %x %x %x %x %x %x %x %x",
141  char1, &(val[0]), char2, &(val[1]), &(val[2]), &(val[3]), &(val[4]), &(val[5]), &(val[6]), &(val[7]), &(val[8]));
142  }
143  if (size <= 0) {
144  B2FATAL("The size of an event (=" << size << ") is too large. Exiting...");
145  } else {
146  for (int i = 1; i <= 8 ; i++) {
147  if (word_count >= MAX_CPRBUF_WORDS) {
148  B2FATAL("The size of an event (=" << size << ") is too large. Exiting...");
149  }
150  evtbuf[word_count] = val[i];
151  word_count++;
152  if (word_count == size) {
153  event_end = 1;
154  break;
155  }
156  }
157  if (event_end == 1) {break;}
158  }
159  }
160  }
161 
162 #ifdef DEBUG
163  if (size > 0 && size < MAX_CPRBUF_WORDS) {
164  for (int i = 0; i < size; i++) {
165  printf("%.8x ", evtbuf[i]);
166  if (i % 8 == 7) printf("\n");
167  }
168  printf("\n");
169  }
170 #endif
171  StoreObjPtr<EventMetaData> evtmetadata;
172  if (runEnd == 0) {
173  (ary.appendNew())->SetBuffer(evtbuf, size, 1, 1, 1);
174 
175  //
176  // Update EventMetaData :
177  //
178  RawCOPPER tempcpr;
179  tempcpr.SetBuffer(evtbuf, size, false, 1, 1);
180 
181 
182  evtmetadata.create();
183  evtmetadata->setExperiment(tempcpr.GetExpNo(0));
184  evtmetadata->setRun(tempcpr.GetRunNo(0));
185  evtmetadata->setSubrun(tempcpr.GetSubRunNo(0));
186  evtmetadata->setEvent(tempcpr.GetEveNo(0));
187  // evtmetadata->setTime(mtime); //time(NULL));
188 
189  } else {
190  delete[] evtbuf;
191  evtmetadata.create();
192  evtmetadata->setEndOfData();
193  }
194 
195  printf("Event counter %8d\n", n_basf2evt); fflush(stdout);
196  n_basf2evt++;
197 
198 }
Belle2::RawCOPPER
The Raw COPPER class This class stores data received by COPPER via belle2linkt Data from all detector...
Definition: RawCOPPER.h:52
Belle2::StoreArray::appendNew
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:256
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::RawCOPPER::GetExpNo
int GetExpNo(int n)
get Experimental # from header
Definition: RawCOPPER.h:360
Belle2::RawCOPPER::GetRunNo
int GetRunNo(int n)
Exp# (10bit) run# (14bit) restart # (8bit)
Definition: RawCOPPER.h:372
Belle2::RawCOPPER::GetSubRunNo
int GetSubRunNo(int n)
get run # (14bit)
Definition: RawCOPPER.h:379
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::RawCOPPER::GetEveNo
unsigned int GetEveNo(int n)
get subrun #(8bit)
Definition: RawCOPPER.h:385
Belle2::RawCOPPER::SetBuffer
void SetBuffer(int *bufin, int nwords, int delete_flag, int num_events, int num_nodes) OVERRIDE_CPP17
set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
Definition: RawCOPPER.cc:141
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::HexDataPackerModule
Module to store dummy data in RawCOPPER object.
Definition: HexDataPacker.h:34