FACT++  1.0
void tcp_connection::SendData ( uint32_t  triggerid)
inline

Definition at line 132 of file fad.cc.

References buffer, data, fRegionOfInterest, i, kDelimiterEnd, kNumChannels, kNumTemp, and Time::utc.

133  {
134  if (fOutQueue.size()>3)
135  return;
136 
137  fHeader.fPackageLength = sizeof(EventHeader)/2+1;
138  fHeader.fEventCounter++;
139  fHeader.fTriggerCounter = triggerid;
140  fHeader.fTimeStamp = uint32_t((Time(Time::utc).UnixTime()-fStartTime)*10000);
141  fHeader.fFreqRefClock = 997+rand()/(RAND_MAX/7);
142 
143  /* Trigger ID
144 
145  * Byte[4]: Bit 0: ext1
146  * Byte[4]: Bit 1: ext2
147  * Byte[4]: Bit 2-7: n/40
148  * Byte[5]: Bit 0: LP_1
149  * Byte[5]: Bit 1: LP_2
150  * Byte[5]: Bit 2: Pedestal
151  * Byte[5]: Bit 3:
152  * Byte[5]: Bit 4:
153  * Byte[5]: Bit 5:
154  * Byte[5]: Bit 6:
155  * Byte[5]: Bit 7: TIM source
156 
157  */
158 
159  for (int i=0; i<FAD::kNumTemp; i++)
160  fHeader.fTempDrs[i] = (42.+fBoardId/40.+float(rand())/RAND_MAX*5)*16;
161 
162  // Header, channel header, end delimiter
163  size_t sz = sizeof(fHeader) + kNumChannels*sizeof(FAD::ChannelHeader) + 2;
164  // Data
165  for (int i=0; i<kNumChannels; i++)
166  sz += fChHeader[i].fRegionOfInterest*2;
167 
168  vector<uint16_t> evtbuf;
169  evtbuf.reserve(sz);
170 
171  for (int i=0; i<kNumChannels; i++)
172  {
173  fChHeader[i].fStartCell = int64_t(1023)*rand()/RAND_MAX;
174 
175  vector<int16_t> data(fChHeader[i].fRegionOfInterest, -1024+0x42+i/9+fHeader.fDac[1]/32);
176 
177  for (int ii=0; ii<fChHeader[i].fRegionOfInterest; ii++)
178  {
179  const int rel = ii;
180  const int abs = (ii+fChHeader[i].fStartCell)%fChHeader[i].fRegionOfInterest;
181 
182  data[rel] += 6.*rand()/RAND_MAX + 5*exp(-rel/10); // sigma=10
183  data[rel] += 15*sin(2*3.1415*abs/512); // sigma=10
184  }
185 
186  if (triggerid>0)
187  {
188  int p = 5.*rand()/RAND_MAX+ 20;
189  double rndm = 500.*rand()/RAND_MAX+500;
190  for (int ii=0; ii<fChHeader[i].fRegionOfInterest; ii++)
191  data[ii] += rndm*exp(-0.5*(ii-p)*(ii-p)/25); // sigma=10
192  }
193 
194  const vector<uint16_t> buf = fChHeader[i].HtoN();
195 
196  evtbuf.insert(evtbuf.end(), buf.begin(), buf.end());
197  evtbuf.insert(evtbuf.end(), data.begin(), data.end());
198 
199  fHeader.fPackageLength += sizeof(ChannelHeader)/2;
200  fHeader.fPackageLength += fChHeader[i].fRegionOfInterest;
201  }
202 
203  evtbuf.push_back(htons(FAD::kDelimiterEnd));
204 
205  const vector<uint16_t> h = fHeader.HtoN();
206 
207  evtbuf.insert(evtbuf.begin(), h.begin(), h.end());
208 
209  fOutQueue.push_back(evtbuf);
210 
211  if (fCommandSocket)
212  AsyncWrite(this, ba::buffer(ba::const_buffer(fOutQueue.back().data(), fOutQueue.back().size()*2)));
213  else
214  {
215  if (fSockets.size()==0)
216  return;
217 
218  fSocket++;
219  fSocket %= fSockets.size();
220 
221  AsyncWrite(fSockets[fSocket].get(), ba::buffer(ba::const_buffer(fOutQueue.back().data(), fOutQueue.back().size()*2)));
222  }
223  }
uint16_t fRegionOfInterest
Definition: HeadersFAD.h:95
int i
Definition: db_dim_client.c:21
Initialize with UTC.
Definition: Time.h:52
const int fBoardId
Definition: fad.cc:62
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
bool fCommandSocket
Definition: fad.cc:126
double fStartTime
Definition: fad.cc:64
FAD::ChannelHeader fChHeader[kNumChannels]
Definition: fad.cc:119
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
void AsyncWrite(ba::ip::tcp::socket *socket, const ba::const_buffers_1 &buffers)
Definition: fad.cc:73
vector< boost::shared_ptr< ba::ip::tcp::socket > > fSockets
Definition: fad.cc:478
float data[4 *1440]
FAD::EventHeader fHeader
Definition: fad.cc:117
deque< vector< uint16_t > > fOutQueue
Definition: fad.cc:130
int fSocket
Definition: fad.cc:128