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 <stdlib.h>
12 #include <string.h>
13 
14 #define DTSPY_HEAD_SIZE 36
15 #define DTSPY_MAX_MSG 512*1024
16 
17 
19 {
20  spybuf=(char *)malloc(DTSPY_MAX_MSG);
21  givenonce=0;
22 }
23 
24 
26 {
27  free(spybuf);
28 }
29 
30 
31 DTSpy::DTSpy(char *hostaddr,int port):DTCtcp(0)
32 {
33  Connect(hostaddr,port);
34  givenonce=0;
35 }
36 
37 
38 int
40 {
41 
42  if (!connected) return -1;
43  if (givenonce)
44  if ((lastpointer - spybuf) < getBuffSize())
45  return (getBuffSize() - (lastpointer - spybuf));
46  givenonce=0;
47 
48  memset(spybuf,0x0,DTSPY_MAX_MSG); /* init buffer */
49 
50  int howm=Receive(spybuf,DTSPY_HEAD_SIZE);
51 
52  unsigned short *i2ohea = (unsigned short *) (spybuf+2);
53  if (howm == DTSPY_HEAD_SIZE )
54  {
55  howm = Receive(spybuf+DTSPY_HEAD_SIZE,((*i2ohea) * 4)-DTSPY_HEAD_SIZE);
56 
57  // for (int ii=0; ii<12; ii++)
58  // printf("%d: %x %x %x %x \n",ii*4,spybuf[ii*4],
59  // spybuf[ii*4+1],spybuf[ii*4+2],spybuf[ii*4+3]);
60 
61  return howm+DTSPY_HEAD_SIZE;;
62  }
63  else return -1;
64 }
65 
66 int
68 {
69  unsigned short *i2ohea = (unsigned short *) (spybuf+2);
70  return *i2ohea;
71 }
72 
73 
74 
75 int
77 {
78  unsigned short *i2ohea = (unsigned short *) (spybuf+28);
79  return *i2ohea;
80 }
81 
82 const char *
84 {
85  if (givenonce) return lastpointer;
87  givenonce = 1;
88  return lastpointer;
89 }
90 
91 void
93 {
94  lastpointer=thep;
95 }
DTSpy()
Definition: DTSpy.cc:18
#define DTSPY_MAX_MSG
Definition: DTSpy.cc:15
char * spybuf
Definition: DTSpy.h:20
int Receive(char *buffer, int size)
Definition: DTSpyHelper.cc:197
void Connect(const char *hostaddr, int port)
Definition: DTSpyHelper.cc:162
const char * getEventPointer()
Definition: DTSpy.cc:83
~DTSpy()
Definition: DTSpy.cc:25
int connected
Definition: DTSpyHelper.h:26
int port
Definition: DTSpyHelper.h:23
char * lastpointer
Definition: DTSpy.h:25
void setlastPointer(char *data)
Definition: DTSpy.cc:92
short givenonce
Definition: DTSpy.h:21
int getNextBuffer()
Definition: DTSpy.cc:39
#define DTSPY_HEAD_SIZE
Definition: DTSpy.cc:14
int getBuffSize()
Definition: DTSpy.cc:67
int getRunNo()
Definition: DTSpy.cc:76