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 
22 DTSpy::~DTSpy() { free(spybuf); }
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::getBuffSize
int getBuffSize()
Definition: DTSpy.cc:55
DTSPY_HEAD_SIZE
#define DTSPY_HEAD_SIZE
Definition: DTSpy.cc:14
DTSpy::spybuf
char * spybuf
Definition: DTSpy.h:17
DTCtcp::port
int port
Definition: DTSpyHelper.h:20
DTCtcp
Definition: DTSpyHelper.h:18
DTSpy.h
DTSpy::getEventPointer
const char * getEventPointer()
Definition: DTSpy.cc:65
DTSpy::~DTSpy
~DTSpy()
Definition: DTSpy.cc:22
DTSpy::lastpointer
char * lastpointer
Definition: DTSpy.h:21
DTSpy::getRunNo
int getRunNo()
Definition: DTSpy.cc:60
DTSpy::setlastPointer
void setlastPointer(char *data)
Definition: DTSpy.cc:73
DTSPY_MAX_MSG
#define DTSPY_MAX_MSG
Definition: DTSpy.cc:15
query.port
port
Definition: query.py:116
DTCtcp::connected
int connected
Definition: DTSpyHelper.h:23
DTSpy::givenonce
short givenonce
Definition: DTSpy.h:18
DTSpy::getNextBuffer
int getNextBuffer()
Definition: DTSpy.cc:29
DTCtcp::Connect
void Connect(const char *hostaddr, int port)
Definition: DTSpyHelper.cc:133
DTCtcp::Receive
int Receive(char *buffer, int size)
Definition: DTSpyHelper.cc:145
DTSpy::DTSpy
DTSpy()
Definition: DTSpy.cc:17