#include "CamacIO.h"
#include "camac.hh"
#include <iostream>
using namespace std;
ClassImp(CamacIO)
CamacIO::CamacIO(char* name,char* title):PelIO(name,title)
{
mIsCamac = false;
}
CamacIO::~CamacIO()
{
for(int i=0;i<MAXOUTPUT;i++) closeOutput(i);
closeInput();
}
int CamacIO::openInput(char *file)
{
if(mInput) { delete mInput; mInput = NULL;}
TString tmp = file;
if(tmp.BeginsWith("/dev/"))
{
mResidualSize = 0;
mIsCamac = true;
cc_handle = open (file, O_RDWR);
if (cc_handle == -1)
{
if(isDebug()) cout <<"Error opening CAMAC connection \n";
mIsCamac = false;
return kWarn;
}
}
else
{
if(isDebug()) cout <<"Opening file instead of CAMAC"<<endl;
return PelIO::openInput(file);
}
return kOk;
}
int CamacIO::closeInput()
{
if(!mIsCamac) return kWarn;
else
{
stopCamac();
close(cc_handle);
mIsCamac = false;
}
return kWarn;
}
int CamacIO::readBlock()
{
if(!mIsCamac)
{
PelIO::readBlock();
}
else
{
int arg = 0;
int ierr = ioctl(cc_handle, CCREADEVNT, (unsigned long) arg);
int nbytes = read (cc_handle, mBlock, 8192);
if(isDebug()) cout <<"ierr = "<<ierr<<" nbytes = "<<nbytes<<endl;
if(nbytes<1) return kEOF;
BLOCKSIZE = nbytes/sizeof(unsigned short int);
if(BLOCKSIZE<1) return kEOF;
if(mDebug)
{
for(int i=0;i<BLOCKSIZE/8;i++)
{
for (int j=0;j<8;j++) cout <<hex<<(unsigned int)mBlock[i*8+j]<<" ";
cout <<dec<<endl;
}
}
}
return decodeBlock();
}
int CamacIO::getNEventsLost()
{
if(!mIsCamac) return 0;
else
{
int arg = 0;
return ioctl(cc_handle, CCGETLOST, (unsigned long) arg);
}
}
int CamacIO::getNUsedBuffers()
{
if(!mIsCamac) return 0;
else
{
int arg = 0;
return ioctl(cc_handle, CCGETUSED, (unsigned long) arg);
}
}
int CamacIO::getNBuffers()
{
if(!mIsCamac) return 0;
else
{
int arg = 0;
return ioctl(cc_handle, CCGETBUF, (unsigned long) arg);
}
}
int CamacIO::loadEVO(char* file)
{
if(mIsCamac)
{
int arg,ierr;
arg=0xd03;
ierr = ioctl (cc_handle, CCRESET, (unsigned long) arg);
int EVOTYPE = CCLOADEH;
TString T = file;
if(!T.EndsWith(".evo") && !T.EndsWith(".evp"))
{
if(isDebug()) cout << "It is not an EVO/EVP file"<<endl;
return kWarn;
}
if(T.EndsWith(".evp")) EVOTYPE = CCLOADEHPLUS;
FILE *evo = fopen(file,"r");
if(evo==0)
{
if(isDebug()) cout << "Error opening EVO/EVP file"<<endl;
return kWarn;
}
int NH,NL,NKK,NAUX,KSYS,NSHD,KAUX,ADINIT;
char PROG_N[80], DATE[12],TIME[8];
unsigned char *ioff;
unsigned int instr[8192];
unsigned int D=1;
if(isDebug()) cout <<"EVO TYPE = "<<EVOTYPE<<endl;
if(EVOTYPE == CCLOADEH)
{
fscanf(evo,"%d %d %d %d %d %s %s ",&NKK,&NAUX,&KSYS,&NSHD,&KAUX,&DATE,&TIME);
fscanf(evo,"%76c \n",PROG_N);
if(isDebug()) cout <<"Loading "<<PROG_N<<endl<<"Date = "<<DATE<<" Time = "<<TIME<<endl;
for(int i=0;i<NKK;i++)
{
fscanf(evo,"%x ",&D);
instr[i]=D;
if(instr[i] == 0x2A0000) NH=i+1;
}
}
else
{
fgets(PROG_N,80,evo);
fscanf(evo,"%d %d %d %d %d %d",&NKK,&KSYS,&KAUX,&NAUX,&NSHD,&ADINIT);
if(isDebug()) cout <<"Loading "<<PROG_N<<endl;
for(int i=0;i<NKK;i++)
{
fscanf(evo,"%x ",&D);
instr[i]=D;
if(isDebug()) cout <<"i = "<<i<<(hex)<<" 0x"<<instr[i]<<(dec)<<endl;
if(instr[i] == 0x00100002) NH=i+1;
}
}
NL = NKK - NH;
if(isDebug()) cout<<" NH,NL = "<<NH<<" "<<NL<<endl;
ierr = ioctl(cc_handle, EVOTYPE, (unsigned long) arg);
ioff = (unsigned char *)instr;
ierr = write (cc_handle,ioff, NH*4);
ierr = ioctl(cc_handle, EVOTYPE, (unsigned long) arg);
ioff=ioff+NH*4;
ierr = write (cc_handle,ioff, NL*4);
arg=256;
ierr = ioctl(cc_handle, CCMAXSIZE, (unsigned long) arg);
return kOk;
}
return kOk;
}
int CamacIO::startCamac()
{
if(mIsCamac)
{
int arg=0x0c03;
int ierr = ioctl(cc_handle, CCRESET, (unsigned long) arg);
mResidualSize = 0;
if(isDebug()) cout <<"CAMAC has started\n";
}
else
{
cout <<"CAMAC Connection is not open \n";
if(isDebug()) return kWarn;
}
return kOk;
}
int CamacIO::setCamacBufferSize(int size)
{
if(mIsCamac)
{
int arg=size;
int size1 = ioctl(cc_handle, CCMAXSIZE, (unsigned long) arg);
if(isDebug()) cout <<"CAMAC buffer size set to "<<size1<<". Requested value was = "<<size<<"\n";
return size1;
}
else
{
if(isDebug()) cout <<"CAMAC Connection is not open \n";
return 0;
}
return 0;
}
int CamacIO::stopCamac()
{
if(mIsCamac)
{
int arg=0x0d03;
int ierr = ioctl(cc_handle, CCRESET, (unsigned long) arg);
if(isDebug()) cout <<"CAMAC has stopped\n";
}
else
{
if(isDebug()) cout <<"CAMAC Connection is not open \n";
return kWarn;
}
return kOk;
}
int CamacIO::readScalers(int slot,int* value,int crate)
{
if(mIsCamac)
{
int ierr = ioctl(cc_handle, CCSETCRATE, (unsigned long) crate);
int Q,X,D;
int N = slot;
int F = 0;
int A = 0;
for(int i=0;i<12;i++)
{
A = i;
cami24(N,A,F,&D,&Q,&X);
value[i] = D;
}
}
else
{
if(isDebug()) cout <<"CAMAC Connection is not open \n";
for(int i=0;i<12;i++) value[i] = 0;
return kWarn;
}
return kOk;
}
int CamacIO::clearScalers(int slot,int crate)
{
if(mIsCamac)
{
int ierr = ioctl(cc_handle, CCSETCRATE, (unsigned long) crate);
int Q,X,D;
int N = slot;
int F = 9;
int A = 0;
cami24(N,A,F,&D,&Q,&X);
}
else
{
if(isDebug()) cout <<"CAMAC Connection is not open \n";
return kWarn;
}
return kOk;
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.