Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:23

0001 /*
0002  *  DTSpy.cc
0003  *  
0004  *
0005  *  Created by Sandro Ventura on 7/28/07.
0006  *  Copyright 2007 __MyCompanyName__. All rights reserved.
0007  *
0008  */
0009 
0010 #include "DTSpy.h"
0011 #include <cstdlib>
0012 #include <cstring>
0013 
0014 #define DTSPY_HEAD_SIZE 36
0015 #define DTSPY_MAX_MSG 512 * 1024
0016 
0017 DTSpy::DTSpy() : DTCtcp(0) {
0018   spybuf = (char *)malloc(DTSPY_MAX_MSG);
0019   givenonce = 0;
0020 }
0021 
0022 DTSpy::~DTSpy() { free(spybuf); }
0023 
0024 DTSpy::DTSpy(char *hostaddr, int port) : DTCtcp(0) {
0025   Connect(hostaddr, port);
0026   givenonce = 0;
0027 }
0028 
0029 int DTSpy::getNextBuffer() {
0030   if (!connected)
0031     return -1;
0032   if (givenonce)
0033     if ((lastpointer - spybuf) < getBuffSize())
0034       return (getBuffSize() - (lastpointer - spybuf));
0035   givenonce = 0;
0036 
0037   memset(spybuf, 0x0, DTSPY_MAX_MSG); /* init buffer */
0038 
0039   int howm = Receive(spybuf, DTSPY_HEAD_SIZE);
0040 
0041   unsigned short *i2ohea = (unsigned short *)(spybuf + 2);
0042   if (howm == DTSPY_HEAD_SIZE) {
0043     howm = Receive(spybuf + DTSPY_HEAD_SIZE, ((*i2ohea) * 4) - DTSPY_HEAD_SIZE);
0044 
0045     // for (int ii=0; ii<12; ii++)
0046     //       printf("%d: %x %x %x %x \n",ii*4,spybuf[ii*4],
0047     //             spybuf[ii*4+1],spybuf[ii*4+2],spybuf[ii*4+3]);
0048 
0049     return howm + DTSPY_HEAD_SIZE;
0050     ;
0051   } else
0052     return -1;
0053 }
0054 
0055 int DTSpy::getBuffSize() {
0056   unsigned short *i2ohea = (unsigned short *)(spybuf + 2);
0057   return *i2ohea;
0058 }
0059 
0060 int DTSpy::getRunNo() {
0061   unsigned short *i2ohea = (unsigned short *)(spybuf + 28);
0062   return *i2ohea;
0063 }
0064 
0065 const char *DTSpy::getEventPointer() {
0066   if (givenonce)
0067     return lastpointer;
0068   lastpointer = spybuf + DTSPY_HEAD_SIZE;
0069   givenonce = 1;
0070   return lastpointer;
0071 }
0072 
0073 void DTSpy::setlastPointer(char *thep) { lastpointer = thep; }