CMS 3D CMS Logo

DTSpy.cc
Go to the documentation of this file.
1 /*
2  * DTSpy.cc
3  *
4  *
5  * Created by Sandro Ventura on 7/28/07.
6  * Copyright 2007 __MyCompanyName__. All rights reserved.
7  *
8  */
9 
10 #include "DTSpy.h"
11 #include <cstdlib>
12 #include <cstring>
13 
14 #define DTSPY_HEAD_SIZE 36
15 #define DTSPY_MAX_MSG 512 * 1024
16 
18  spybuf = (char *)malloc(DTSPY_MAX_MSG);
19  givenonce = 0;
20 }
21 
23 
24 DTSpy::DTSpy(char *hostaddr, int port) : DTCtcp(0) {
25  Connect(hostaddr, port);
26  givenonce = 0;
27 }
28 
30  if (!connected)
31  return -1;
32  if (givenonce)
33  if ((lastpointer - spybuf) < getBuffSize())
34  return (getBuffSize() - (lastpointer - spybuf));
35  givenonce = 0;
36 
37  memset(spybuf, 0x0, DTSPY_MAX_MSG); /* init buffer */
38 
39  int howm = Receive(spybuf, DTSPY_HEAD_SIZE);
40 
41  unsigned short *i2ohea = (unsigned short *)(spybuf + 2);
42  if (howm == DTSPY_HEAD_SIZE) {
43  howm = Receive(spybuf + DTSPY_HEAD_SIZE, ((*i2ohea) * 4) - DTSPY_HEAD_SIZE);
44 
45  // for (int ii=0; ii<12; ii++)
46  // printf("%d: %x %x %x %x \n",ii*4,spybuf[ii*4],
47  // spybuf[ii*4+1],spybuf[ii*4+2],spybuf[ii*4+3]);
48 
49  return howm + DTSPY_HEAD_SIZE;
50  ;
51  } else
52  return -1;
53 }
54 
56  unsigned short *i2ohea = (unsigned short *)(spybuf + 2);
57  return *i2ohea;
58 }
59 
61  unsigned short *i2ohea = (unsigned short *)(spybuf + 28);
62  return *i2ohea;
63 }
64 
65 const char *DTSpy::getEventPointer() {
66  if (givenonce)
67  return lastpointer;
69  givenonce = 1;
70  return lastpointer;
71 }
72 
73 void DTSpy::setlastPointer(char *thep) { lastpointer = thep; }
DTSpy()
Definition: DTSpy.cc:17
#define DTSPY_MAX_MSG
Definition: DTSpy.cc:15
char * spybuf
Definition: DTSpy.h:17
int Receive(char *buffer, int size)
Definition: DTSpyHelper.cc:145
int port
Definition: query.py:116
void Connect(const char *hostaddr, int port)
Definition: DTSpyHelper.cc:133
const char * getEventPointer()
Definition: DTSpy.cc:65
void free(void *ptr) noexcept
~DTSpy()
Definition: DTSpy.cc:22
int connected
Definition: DTSpyHelper.h:23
int port
Definition: DTSpyHelper.h:20
char * lastpointer
Definition: DTSpy.h:21
void * malloc(size_t size) noexcept
void setlastPointer(char *data)
Definition: DTSpy.cc:73
short givenonce
Definition: DTSpy.h:18
int getNextBuffer()
Definition: DTSpy.cc:29
#define DTSPY_HEAD_SIZE
Definition: DTSpy.cc:14
int getBuffSize()
Definition: DTSpy.cc:55
int getRunNo()
Definition: DTSpy.cc:60