GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BufferGANIL.C
Go to the documentation of this file.
1 // //
3 // BufferGANIL //
4 // //
6 
8 
9 #include <TObjString.h>
10 #include "BufferGANIL.h"
11 
12 #include <iostream>
13 #include <fstream>
14 using namespace std;
15 
16 const Int_t BufferGANIL::BYTE = 8;
17 const Int_t BufferGANIL::KBYTE = 1024;
18 const Int_t BufferGANIL::MBYTE = 1024*1024;
19 const Int_t BufferGANIL::GBYTE = 1024*1024*1024;
20 
21 const unsigned short BufferGANIL::fStartEventToken = 0xFF60;
22 const unsigned short BufferGANIL::fEndDataBlockToken = 0xFF00;
23 ::map<UShort_t, TString>* BufferGANIL::fgMap = 0x0;
24 
25 //__________________________________________________________
27 {
28  fBuffer = new Char_t[s];
29  fSubEvtIndex = 0;
30  fgMap = new ::map<UShort_t, TString>;
31 }
32 
33 //__________________________________________________________
35 {
36  if ( fBuffer ) delete fBuffer; fBuffer = NULL;
37  delete fgMap; // not secured
38 }
39 
40 //__________________________________________________________
41 bool BufferGANIL::IsType(const char *type)
42 {
43  if ( strncmp(fBuffer,type,8) == 0 )
44  return true;
45  return false;
46 }
47 
48 //__________________________________________________________
49 void BufferGANIL::InitTable(Char_t* buffer)
50 {
51  TString tmp;
52  // read the buffer and creat the list of parameters
53  tmp = ""; char c;
54 
55  ofstream out1("bufferGANIL.parameter",ios::out);
56  for( size_t i = 0; i < 16*KBYTE-12; i++ ) {
57  c = buffer[12+i]; tmp += c;
58  if ( c == 0x0D ) {
59  tmp.ReplaceAll(","," ");
60  out1 << tmp.Data() << endl ;
61  InitTable(tmp);
62  tmp = "";
63  } // c
64  } // i
65  out1.close();
66 }
67 
68 //__________________________________________________________
69 void BufferGANIL::InitTable(TString& data)
70 {
71  TString tmp(data);
72 
73  Int_t pos = tmp.First(' ');
74 
75  TString sIdx = tmp(pos+1, 2);
76 
77  TString type = tmp(0, pos);
78 
79  UShort_t idx = (UShort_t)sIdx.Atoi();
80  fgMap->insert(pair<UShort_t, TString>(idx, type.Data()));
81 }
82 
83 //__________________________________________________________
84 const Char_t* BufferGANIL::GetModuleName(UShort_t add)
85 {
86  ::map<UShort_t,TString>::iterator iter = fgMap->find(add);
87  return (iter->second).Data();
88 }
89 
90 //__________________________________________________________
92 {
93  int magic = 0; bool ok = false;
94 
95  if ( IsType(" FILEH ") ) {
96  printf("Header file block, set DAQ parameters to 0 \n"); //InitTable();
97  }
98 
99  if ( IsType(" SCALER ") ) {
100  printf("SCALER block\n"); //InitTable();
101  }
102 
103  if ( IsType(" COMMENT") ) {
104  // printf("Comment block \n ");
105  }
106  if ( IsType(" PARAM ") ) {
107  InitTable(fBuffer);
108  printf("Parameters block, re-initialisation of DAQ parameters \n");
109  }
110  if ( IsType(" EVENTH ") ) {
111  strncpy(fDate,&fBuffer[37],19); // new date
112  char tmp[6];
113  strncpy(tmp,&fBuffer[62],6); sscanf(tmp,"%d",&fRun); // new run
114  printf("Data block, NEW RUN # %d, written at %s \n",fRun,fDate);
115  }
116  if ( IsType(" EBYEDAT") ) {
117  // read some informations from the block header
118  fSubEvtIndex = 32;
119  ::memcpy(&fBlock, &fBuffer[8],sizeof(int));
120  //printf(" EbyE block %d \n",fBlock);
121 
122  ::memcpy(&magic,&fBuffer[12],sizeof(Int_t));
123  if ( magic != 0x22061999 ) printf("WARNING WRONG byte ordering for input buffer %x \n",magic);
124 
125  ::memcpy(&fNbEvents,&fBuffer[22],sizeof(Int_t));
126  //printf(" events %d \n",fNbEvents);
127 
128  ::memcpy(&fEventsSize,&fBuffer[28],sizeof(Int_t));
129  //printf(" events size %d \n",fEventsSize);
130 
131  fNbEventsR = 0; fEventsSizeR = 0; ok = true;
132  }
133  return ok;
134 }
135 
136 //_____________________________________________________________________
137 unsigned short* BufferGANIL::NextEvent(unsigned short &sub_event_size)
138 {
139  unsigned short start_token = 0;
140  unsigned short event_size = 0;
141 
142  // check if end event token
143  ::memcpy(&start_token,&fBuffer[fSubEvtIndex],sizeof(short));
144  //printf("token %x \n",start_token);
145 
146  if ( start_token != fStartEventToken ) {
147  if ( start_token == fEndDataBlockToken ) fEventsSizeR += 2;
148  return NULL;
149  }
150 
151  ::memcpy(&event_size,&fBuffer[fSubEvtIndex+2],sizeof(short));event_size -= 2;
152  //printf("event size %x \n",event_size);
153 
154  ::memcpy(&sub_event_size,&fBuffer[fSubEvtIndex+12],sizeof(short));sub_event_size -= 2;
155  //printf("event size %d \n",sub_event_size);
156 
157  for(unsigned short i = 0; i < sub_event_size; i++ ){::memcpy(&fEvent[i],&fBuffer[fSubEvtIndex+14+i*2],sizeof(short));}
158 
159  fNbEventsR++; fEventsSizeR += (event_size+2);
160  fSubEvtIndex += (event_size+2)*2;
161 
162  return fEvent;
163 }
164 
165 
printf("******************************************************************** \n")
static const Int_t MBYTE
Definition: BufferGANIL.h:27
static const Int_t BYTE
Definition: BufferGANIL.h:25
static std::map< UShort_t, TString > * fgMap
Definition: BufferGANIL.h:66
static void InitTable(Char_t *)
Definition: BufferGANIL.C:49
BufferGANIL(size_t s=16 *KBYTE)
Definition: BufferGANIL.C:26
bool InitReading()
Definition: BufferGANIL.C:91
static const Int_t GBYTE
Definition: BufferGANIL.h:28
static const unsigned short fEndDataBlockToken
Definition: BufferGANIL.h:30
static const Int_t KBYTE
Definition: BufferGANIL.h:26
static const unsigned short fStartEventToken
Definition: BufferGANIL.h:29
const Int_t KBYTE
Definition: Memory.h:37
unsigned short * NextEvent(unsigned short &)
Definition: BufferGANIL.C:137
bool IsType(const char *)
Definition: BufferGANIL.C:41
ADF::LogMessage & endl(ADF::LogMessage &log)
static const Char_t * GetModuleName(UShort_t add)
Definition: BufferGANIL.C:84