DCMSimulator.cpp
Go to the documentation of this file.
1 #include <sys/types.h> // Standard System Types
2 #include <stdlib.h> // Standard Library Header
3 #include <stdio.h> //
4 #include <time.h> // Standard System Time Header
5 #include "DAQDataFormats/DCMSimulator.h"
6 
7 #define DEFAULT_HIT_PROBABILITY 0.1
8 #define randReal() (1.0*rand() )/RAND_MAX
9 
10 using namespace daqdataformats;
11 
13  this->init();
14 }
15 
16 DCMSimulator::DCMSimulator(uint32_t diblock_number, uint32_t dcm_number){
17  this->init();
18  this->dcmID = dcm_number;
19  this->diblockID = diblock_number;
20 }
21 
22 
24 
25 }
26 
27 DCMSimulator::DCMSimulator(uint32_t FEBMask){
28  this->setFEBMask(FEBMask);
29  this->setHitProbability(DEFAULT_HIT_PROBABILITY); // Default hit probability
30 }
31 
32 DCMSimulator::DCMSimulator(uint32_t FEBMask, float probability){
33  this->setFEBMask(FEBMask);
34  this->setHitProbability(probability); // Default hit probability
35 }
36 
38  this->dcmID=0; // Unassigned
39  this->diblockID=0; // Unassigned
40  this->clock=0; // Reset the clock to zero time
41  this->febMask=0x0; // All FEBs are off by default
42  this->setHitProbability(DEFAULT_HIT_PROBABILITY); // Default hit probability
43 
44  // Clear the databuffer
45  int i=0;
46  while(i < DCM_DATA_BUFFER_SIZE){
47  this->databuffer[i]=0x0;
48  ++i;
49  }
50 
51  this->nextWord = &(databuffer[0]);
52 
53  i=0;
54  while(i < 64){
55  ActiveFEBList[i]=NULL;
56  ++i;
57  }
58 
59  return true;
60 }
61 
62 
63 bool DCMSimulator::initFEB(int FEBNumber [[gnu::unused]]){
64  return true;
65 }
66 
68  // We look at the FEB Mask and make a list of the pointers to the
69  // active FEBs for subsequent readouts
70 
71  int j=0;
72  for(int i=0;i<64;++i){
73  if(febMask & (0x1 << i)){
75  ++j;
76  } // endif febMask
77  } // endfor i
78 
79  return true;
80 }
81 
82 void DCMSimulator::setFEBMask(uint32_t FEBMask){
83  febMask = FEBMask; // Set the front end board mask
84 }
85 
86 void DCMSimulator::setHitProbability(float probability){
87  hit_probability = probability; // Set the prob of generating a single hit
88 }
89 
90 
92  // We need to generate a microslice
93  // from scratch. We do this in stages
94 
95  // First generate the header
96  RawMicroSliceHeader microHeader;
97  //microHeader.setDataPresent(true);
98 
99  // Note: The header is generated with a zero byte count
100  // so we need to set that later when we know the size of the block
101 
102  // Now generate the time marker;
103  RawTimingMarker tMarker;
104  tMarker.generate();
105 
106 
107 
108  return &LastMicroSlice;
109 }
110 
111 #ifdef ASDF
112 
113 const RawNanoSlice& DCMSimulator::GenerateNanoSlice(int PixelID){
114  NanoSliceHeader FullHeader;
115  uint32_t EncodedHeader;
116  int TimeStamp;
117  // time_t TimeStamp;
118  uint32_t PulseHeight;
119 
120  // Fill the header information for the nano slice
121  FullHeader.FrameSequenceNumber = SEQ;
122  FullHeader.PixelAddress = PixelID & 0x001F; // Generate a random Pixel
123  FullHeader.FEBStatus = 0x1;
124  FullHeader.FEBLinkID = FEBLinkID;
125  FullHeader.DebugMode = false;
126  FullHeader.DataPresent = false;
127  FullHeader.LinkStatus = true;
128 
129  // Check to see if we should generate a hit for this block
130  if( randReal() < this->HitProbability){
131  // printf("%2.6f\n",randReal());
132 
133  FullHeader.DataPresent = true;
134 
135  // Generate the time stamp (just from the current time)
136  TimeStamp = time((time_t*)&TimeStamp);
137  // TimeStamp = 0xFFFFFFFF;
138 
139  // Generate a random pulse height (12bit)
140  PulseHeight = rand() & 0x00000FFF;
141  // Shift the pulse height over to give the right word alignment;
142  PulseHeight = PulseHeight << 16;
143 
144  // Now Advance the Sequence Number
145  this->AdvanceSEQ();
146 
147  }else{
148  TimeStamp = 0x0;
149  PulseHeight = 0x0;
150  }
151 
152  EncodedHeader = LastNanoSlice.PackNanoSliceHeader(FullHeader);
153 
154  LastNanoSlice.SetHeader(EncodedHeader);
155  LastNanoSlice.SetTimeStamp(TimeStamp);
156  LastNanoSlice.SetPulseHeight(PulseHeight);
157 }
158 
159 // This version forces hit generation of a hit on a given pixel
160 const RawNanoSlice& DCMSimulator::GenerateNanoSlice(int PixelID, bool ForceGeneration){
161  NanoSliceHeader FullHeader;
162  uint32_t EncodedHeader;
163  uint32_t PulseHeight;
164  int TimeStamp;
165 
166  // Fill the header information for the nano slice
167  FullHeader.FrameSequenceNumber = SEQ;
168  FullHeader.PixelAddress = PixelID & 0x001F; // Generate a random Pixel
169  FullHeader.FEBStatus = 0x1;
170  FullHeader.FEBLinkID = FEBLinkID;
171  FullHeader.DebugMode = false;
172  FullHeader.DataPresent = false;
173  FullHeader.LinkStatus = true;
174  FullHeader.DataPresent = true;
175 
176  // Generate the time stamp (just from the current time)
177  TimeStamp = time((time_t*)&TimeStamp);
178  // TimeStamp = 0xFFFFFFFF;
179 
180  // Generate a random pulse height (12bit)
181  PulseHeight = rand() & 0x00000FFF;
182  // Shift the pulse height over to give the right word alignment;
183  PulseHeight = PulseHeight << 16;
184 
185  // Now Advance the Sequence Number
186  this->AdvanceSEQ();
187 
188  // Encode the data into the block
189  EncodedHeader = LastNanoSlice.PackNanoSliceHeader(FullHeader);
190 
191  // Set the block data
192  LastNanoSlice.SetHeader(EncodedHeader);
193  LastNanoSlice.SetTimeStamp(TimeStamp);
194  LastNanoSlice.SetPulseHeight(PulseHeight);
195 }
196 
197 // This version forces hit generation of a hit on a given pixel
198 const RawNanoSlice& DCMSimulator::GenerateNanoSlice(int PixelID,int iTimeStamp, int iPulseHeight, bool ForceGeneration){
199  NanoSliceHeader FullHeader;
200  uint32_t EncodedHeader;
201  uint32_t PulseHeight;
202  int TimeStamp;
203 
204  // Fill the header information for the nano slice
205  FullHeader.FrameSequenceNumber = SEQ;
206  FullHeader.PixelAddress = PixelID & 0x001F; // Generate a random Pixel
207  FullHeader.FEBStatus = 0x1;
208  FullHeader.FEBLinkID = FEBLinkID;
209  FullHeader.DebugMode = false;
210  FullHeader.DataPresent = false;
211  FullHeader.LinkStatus = true;
212  FullHeader.DataPresent = true;
213 
214  // Set the timestamp
215  TimeStamp = iTimeStamp;
216 
217  // Set the PulseHeight (and limit it to 12 bits with an overflow
218  if(iPulseHeight & 0xFFFFF000){iPulseHeight= 0x00000FFF;}
219  PulseHeight = iPulseHeight & 0x00000FFF;
220  // Shift the pulse height over to give the right word alignment;
221  PulseHeight = PulseHeight << 16;
222 
223  // Now Advance the Sequence Number
224  this->AdvanceSEQ();
225 
226  // Encode the data into the block
227  EncodedHeader = LastNanoSlice.PackNanoSliceHeader(FullHeader);
228 
229  // Set the block data
230  LastNanoSlice.SetHeader(EncodedHeader);
231  LastNanoSlice.SetTimeStamp(TimeStamp);
232  LastNanoSlice.SetPulseHeight(PulseHeight);
233 }
234 
235 
236 bool DCMSimulator::nonEmptyNanoSlice(){
237  if(LastNanoSlice.getNanoSliceHeader() & 0x2){return true;}
238  return false;
239 }
240 
241 #endif
242 
244 
245 #ifdef ASDF
246  uint32_t rawheader;
248 
249  printf("Header: 0x%08x \t Time: 0x%08x\t PulseHeight: 0x%08x\t",LastNanoSlice.GetNanoSliceHeader(), LastNanoSlice.GetTimeStamp(), LastNanoSlice.GetPulseHeight());
250 
251  rawheader = LastNanoSlice.GetNanoSliceHeader();
252 
253  LastNanoSlice.UnPackNanoSliceHeader(rawheader, &header);
254 
255  printf("Frame: %d\tPixel: %d\tStatus: %d\tLink: %d\n",header.FrameSequenceNumber, header.PixelAddress, header.FEBStatus, header.FEBLinkID);
256 
257 #endif
258 }
void setHitProbability(float probability)
bool initFEB(int FEBnumber)
Float_t x1[n_points_granero]
Definition: compare.C:5
::xsd::cxx::tree::time< char, simple_type > time
Definition: Database.h:194
Data structure for holding all the nanoslice data of interest.
FEBSimulator FrontEndBoards[64]
Definition: DCMSimulator.h:40
printf("%d Experimental points found\n", nlines)
const double j
Definition: BetheBloch.cxx:29
#define randReal()
Definition: DCMSimulator.cpp:8
const float DEFAULT_HIT_PROBABILITY
Definition: FEBSimulator.h:10
Class to hold the MicroSlice data.
Definition: RawMicroSlice.h:48
Class to hold the timing markers used in the construction of Microslices in the DCMs.
#define DCM_DATA_BUFFER_SIZE
Definition: DCMSimulator.h:9
Class to hold the data from the FEBs in correct formats.
FEBSimulator * ActiveFEBList[64]
Definition: DCMSimulator.h:41
void generate()
! Set the time-stamp as a single 64-bit value
RawMicroSlice * generateMicroSlice()
void setFEBMask(uint32_t FEBMask)
uint32_t databuffer[DCM_DATA_BUFFER_SIZE]
Definition: DCMSimulator.h:45