StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EEfeeDataBlock.cxx
1 #include <cassert>
2 #include <string.h>
3 #include "EEdims.h"
4 
5 #include "EEfeeDataBlock.h"
6 
7 ClassImp(EEfeeDataBlock)
8 
9 const int EEfeeDataBlock::DefaultMaxHead=4;
10 const int EEfeeDataBlock::DefaultMaxData=192;
11 
12 
13 //--------------------------------------------------
14 //--------------------------------------------------
15 //--------------------------------------------------
16 
18  MaxHead = DefaultMaxHead;
19  MaxData = 0 ;
20  head = new UShort_t[MaxHead];
21  data = NULL;
22  sanity=0xff;
23 }
24 
25 
26 EEfeeDataBlock::EEfeeDataBlock(const EEfeeDataBlock *b) {
27  MaxData = b->getDataLen();
28  MaxHead = b->getHeadLen();
29  head=0;
30  if(MaxHead>0) head = new UShort_t[MaxHead];
31  data=0;
32  if(MaxData>0) data = new UShort_t[MaxData];
33  set(b);
34 }
35 
36 
37 
38 
39 //--------------------------------------------------
40 //--------------------------------------------------
41 //--------------------------------------------------
42 EEfeeDataBlock :: ~EEfeeDataBlock() {
43  if(head) delete [] head;
44  if(data) delete [] data;
45 }
46 
47 
48 //--------------------------------------------------
49 //--------------------------------------------------
50 //--------------------------------------------------
51 void EEfeeDataBlock :: print(int flag){
52  printf("feeDataBlock Head: 0x%04hx 0x%04hx 0x%04hx 0x%04hx ",head[0],head[1],head[2],head[3]);
53  printf("\n --> token=0x%2x crateID=0x%x trigComm=0x%x lenCount=0x%x errFlag=0x%x\n NpositiveData=%d sanity=0x%02x\n",
54  getToken(),getCrateID(),getTrigComm(),getLenCount(),getErrFlag(),getNData(0),sanity);
55 
56  if(flag<=0) return;
57 
58  int nd=getDataLen();
59  printf("Data[%3d]:",nd);
60  for(int i=0;i<nd;i++) {
61  if( i%8 == 0 ) printf("\n");
62  printf("0x%04hx ",data[i]);
63 
64  }
65  printf("\n");
66 
67 }
68 
69 
70 //--------------------------------------------------
71 //--------------------------------------------------
72 //--------------------------------------------------
73 
74 void
75 EEfeeDataBlock :: set(const EEfeeDataBlock *b) {
76  setHead(b->getHead());
77  setDataArray(b->getData(),b->getDataLen());
78 }
79 
80 
81 //--------------------------------------------------
82 //--------------------------------------------------
83 //--------------------------------------------------
84 void EEfeeDataBlock ::setHead(const UShort_t *h) {
85  if(h)
86  memcpy(head,h,sizeof(head[0])*MaxHead);
87  else // empty header==>clear
88  memset(head,0,sizeof(head[0])*MaxHead);
89 
90 }
91 
92 
93 //--------------------------------------------------
94 //--------------------------------------------------
95 //--------------------------------------------------
96 int EEfeeDataBlock ::getNData(int thres) const {
97  int n=0;
98  int i;
99  const int nd=getValidDataLen();
100  for(i=0;i<nd;i++) if(data[i]>thres) n++;
101  return n;
102 }
103 
104 //--------------------------------------------------
105 //--------------------------------------------------
106 //--------------------------------------------------
107 
108 void EEfeeDataBlock ::setDataArray(const UShort_t *dIn, int size) {
109  const UShort_t x=0,*d=&x;
110  if(dIn) {
111  d=dIn;
112  } else {
113  size =1;
114  }
115 
116  if(size!=MaxData) { // tmp, was '>'
117  if(data) delete [] data;
118  MaxData = size;
119  data = new UShort_t[MaxData];
120  } else {
121  memset(data,0x0,sizeof(data[0])*MaxData);
122  }
123  memcpy(data,d,size*sizeof(data[0]));
124 }
125 
126 
127 //--------------------------------------------------
128 //--------------------------------------------------
129 //--------------------------------------------------
130 
131 void EEfeeDataBlock ::setData(int chan, UShort_t d){
132  assert(chan>=0);
133  if(chan>=MaxData) {
134  Int_t newsize = MaxData + DefaultMaxData;
135  UShort_t *newdata = new UShort_t[newsize];
136  if(data) {
137  memcpy(newdata,data,MaxData);
138  delete [] data;
139  }
140  data = newdata;
141  MaxData = newsize;
142  }
143  data[chan]=d;
144 }
145 
146 
147 //--------------------------------------------------
148 //--------------------------------------------------
149 //--------------------------------------------------
150 
151 void EEfeeDataBlock :: clear(){
152  if(head) memset(head,0,sizeof(head[0])*MaxHead);
153  if(data) memset(data,0,sizeof(data[0])*MaxData);
154  sanity=0xff; // reset to full corruption
155 }
156 
157 
158 //--------------------------------------------------
159 //--------------------------------------------------
160 //--------------------------------------------------
161 UChar_t EEfeeDataBlock
162 ::isHeadValid(int token, int crId, int len, int trigComm, int errFlag){
163  // encode failure all test as subsequent bits
164  unsigned char ret=0;
165  ret|=(getCrateID()!=crId)<<0;
166  ret|=(getToken()!=token)<<1;
167  ret|=(getLenCount()!=len)<<2;
168  ret|=(getTrigComm()!=trigComm)<<3;
169  ret|=(getErrFlag()!=errFlag)<<4;
170  sanity=ret;
171 
172 #if 0
173  printf("\nask/0x: %x %x %x %x %x\n", token,crId,len,trigComm,errFlag);
174  print(0);
175  printf("getCrateID()/0x = %x %x\n",getCrateID(),crId);
176  printf("getToken()/0x = %x %x\n",getToken(),token);
177  printf("getLenCount()/0x = %x %x\n",getLenCount(),len);
178  printf("getTrigComm()/0x = %x %x\n",getTrigComm(),trigComm);
179  printf("getErrFlag()/0x = %x %x\n",getErrFlag(),errFlag);
180 #endif
181 
182 
183  return ret; // zero==good header
184 }
185 
186 
187 
188 /*
189  * $Log: EEfeeDataBlock.cxx,v $
190  * Revision 1.16 2007/07/12 19:30:13 fisyak
191  * Add includes for ROOT 5.16
192  *
193  * Revision 1.15 2004/06/21 19:50:21 balewski
194  * mre detailed monitoring of data corruption
195  *
196  * Revision 1.14 2004/06/01 16:05:18 balewski
197  * forgoten update of data block headers check
198  *
199  * Revision 1.13 2004/04/16 17:26:46 balewski
200  * more header checking, some mess introduced
201  *
202  * Revision 1.12 2004/04/02 06:38:52 balewski
203  * *** empty log message ***
204  *
205  * Revision 1.11 2004/03/25 16:54:58 balewski
206  * cleanup of arguments
207  *
208  * Revision 1.10 2004/03/20 20:25:55 balewski
209  * *** empty log message ***
210  *
211  * Revision 1.9 2004/01/27 07:09:37 balewski
212  * slower but simpler
213  *
214  * Revision 1.8 2003/12/03 18:55:41 zolnie
215  * fixed yet another bug
216  *
217  * Revision 1.7 2003/12/02 17:22:07 balewski
218  * fix after version mixup
219  *
220  * Revision 1.5 2003/11/24 05:40:55 balewski
221  * new stuff for miniDaq
222  *
223  * Revision 1.4 2003/11/20 16:01:46 balewski
224  * towars run 4
225  *
226  */
227