StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EztEmcRawData.cxx
1 /***********************************************************************
2  * $Id: EztEmcRawData.cxx,v 1.5 2005/03/10 16:59:54 mvl Exp $
3  * Author: Alex Suaide, Mar 2004, JB
4  ************************************************************************/
5 
6 #include "EztEmcRawData.h"
7 
8 ClassImp(EztEmcRawData)
9 
10 //----------------------------------------------------
12 {
13  for(int i=0;i<MAXEMCDATABANK;i++) {
14  mHeader[i].Set(0);
15  mData[i].Set(0);
16  setCorruption(i,0xffff); // all bad is default
17  }
18 }
19 
20 //----------------------------------------------------
21 EztEmcRawData::EztEmcRawData(const EztEmcRawData& h) : TObject(h)
22 {
23  for(int i=0;i<MAXEMCDATABANK;i++) {
24  if(h.header(i) && h.data(i)) {
25  createBank(i,h.sizeHeader(i),h.sizeData(i));
26  setHeader(i,(unsigned short*)h.header(i));
27  setData(i,(unsigned short*)h.data(i));
28  }
29  }
30 }
31 
32 //----------------------------------------------------
33 EztEmcRawData::~EztEmcRawData()
34 {
35  for(int i=0;i<MAXEMCDATABANK;i++) deleteBank(i);
36 }
37 
38 
39 //----------------------------------------------------
40 void
41 EztEmcRawData::createBank(int bank,int sizeHeader, int sizeData)
42 {
43  deleteBank(bank);
44  mHeader[bank].Set(sizeHeader);
45  mData[bank].Set(sizeData);
46  for(int i = 0;i<sizeHeader;i++) mHeader[bank][i] = 0;
47  for(int i = 0;i<sizeData;i++) mData[bank][i] = 0;
48  setCorruption(bank,0xffff); // all bad is default
49 
50 }
51 
52 //----------------------------------------------------
53 void
54 EztEmcRawData::deleteBank(int bank)
55 {
56  mHeader[bank].Set(0);
57  mData[bank].Set(0);
58  setCorruption(bank,0xffff); // all bad is default
59 }
60 
61 //----------------------------------------------------
62 void
63 EztEmcRawData::setHeader(int bank,unsigned short* data)
64 {
65  if(sizeHeader(bank)==0) return;
66  mHeader[bank].Set(sizeHeader(bank),(const Short_t*)data);
67 }
68 
69 //----------------------------------------------------
70 void
71 EztEmcRawData::setData(int bank,unsigned short* data)
72 {
73  if(sizeData(bank)==0) return;
74  mData[bank].Set(sizeData(bank),(const Short_t*)data);
75 }
76 
77 
78 //----------------------------------------------------
79 const UShort_t*
80 EztEmcRawData::header(int bank) const
81 {
82  return (UShort_t*)mHeader[bank].GetArray();
83 }
84 
85 //----------------------------------------------------
86 const UShort_t*
87 EztEmcRawData::data(int bank) const
88 {
89  return (UShort_t*)mData[bank].GetArray();
90 }
91 
92 //----------------------------------------------------
93 const int
94 EztEmcRawData::sizeHeader(int bank) const
95 {
96  return mHeader[bank].GetSize();
97 }
98 
99 //----------------------------------------------------
100 const int
101 EztEmcRawData::sizeData(int bank) const
102 {
103  return mData[bank].GetSize();
104 }
105 
106 //----------------------------------------------------
107 bool
108 EztEmcRawData::purgeCrateOFF(int ib){
109  bool isOFF=isCrateOFF(header(ib));
110  if(isOFF) { // crate was OFF based on the header
111  mData[ib].Set(0); // erase data block
112  }
113  return isOFF;
114 }
115 
116 //----------------------------------------------------
117 void
118 EztEmcRawData::tagHeadValid( int ib, int token, int crId, int len, int trigComm, int errFlag, int dbg) {
119  UShort_t ret= isHeadValid(header(ib), token, crId, len, trigComm, errFlag, dbg);
120  setCorruption(ib,ret);
121  // return ret;
122 }
123 
124 //----------------------------------------------------
125 bool
126 EztEmcRawData::doHeadCorruptionTest(int token, int lenCount, int firstCrId, int errFlag){
127  // general corruption test of all types
128  // RETURN : true =any corruption, false=no corruption
129  int trigComm=0x4; // physics, 9=laser/LED, 8=??
130 
131  int nCrIn=0;
132  int nCrOK=0;
133  int icr;
134  for(icr=0;icr<getNBlocks();icr++) {
135  if(isCrateVoid(icr)) continue;
136  if(purgeCrateOFF(icr)) continue;
137  nCrIn++;
138  int crID=icr+firstCrId;
139  //........... hader..........
140  tagHeadValid(icr,token, crID,lenCount,trigComm,errFlag);
141  if(getCorruption(icr)) continue;
142  nCrOK++; // count number of valid crates
143  }
144 
145  return nCrOK!=nCrIn;
146 }
147 
148 
149 //----------------------------------------------------
150 bool
151 EztEmcRawData::isCrateOFF( const UShort_t* hd) {
152  bool a=(hd[0]& 0xFFF)==0xFFF; // Gerard's prescription
153  bool b=(hd[1]& 0xFFF)==0xFFF;
154  return a && b;
155 }
156 
157 //----------------------------------------------------
158 UShort_t
159 EztEmcRawData::isHeadValid(const UShort_t* hd, int token, int crId, int len, int trigComm, int errFlag, int dbg) {// just test one header
160  // encode failure of all test as subsequent bits
161  UShort_t ret=0;
162  if (getCrateID(hd)!=crId) ret |=bitCrateID;
163  if (getToken(hd)!=token) ret |=bitToken;
164  if (getLenCount(hd)!=len) ret |=bitLenCount;
165  if (getTrigComm(hd)!=trigComm) ret |=bitTrigComm;
166  if (getErrFlag(hd)!=errFlag) ret |=bitErrFlag;
167  if (dbg) {
168  print(hd);
169  printf("getCrateID()/0x is=%x %x=required\n",getCrateID(hd),crId);
170  printf("getToken()/0x = %x %x\n",getToken(hd),token);
171  printf("getLenCount()/0x = %x %x\n",getLenCount(hd),len);
172  printf("getTrigComm()/0x = %x %x\n",getTrigComm(hd),trigComm);
173  printf("getErrFlag()/0x = %x %x\n",getErrFlag(hd),errFlag);
174  printf(" corruption=0x%02x\n",ret);
175  }
176  return ret;
177 }
178 
179 
180 //----------------------------------------------------
181 void
182 EztEmcRawData::print(int ib, int flag)
183 {
184  printf("EztEmcRawData block=%d corruption=0x%04x\n",ib,getCorruption(ib));
185 
186  if(flag<=0) { print(header(ib)); return; }
187 
188  print(header(ib),data(ib),sizeData(ib));
189 
190 }
191 
192 //----------------------------------------------------
193 void
194 EztEmcRawData::print(int flag)
195 {
196  int icr, nb=0;
197  for(icr=0;icr<getNBlocks();icr++) {
198  if(sizeHeader(icr)<=0) continue; // skip empty bloks
199  print(icr,flag);
200  nb++;
201  }
202  printf("EztEmcRawData total %d of non empty blocks\n\n",nb);
203 
204 }
205 
206 //----------------------------------------------------
207 void EztEmcRawData::print(const UShort_t* hd, const UShort_t* d, int nd) {
208  printf("EztEmcRawData Head: 0x%04hx 0x%04hx 0x%04hx 0x%04hx ",hd[0],hd[1],hd[2],hd[3]);
209  printf("\n --> token=0x%2x crateID=0x%x trigComm=0x%x lenCount=0x%x errFlag=0x%x\n",
210  getToken(hd),getCrateID(hd),getTrigComm(hd),getLenCount(hd),getErrFlag(hd));
211  if(d==0) return;
212  printf("Data[%3d]:",nd);
213  for(int i=0;i<nd;i++) {
214  if( i%8 == 0 ) printf("\n");
215  printf("0x%04hx ",d[i]);
216  }
217  printf("\n");
218 }
219 
220 /***************************************************************************
221  *
222  * $Log: EztEmcRawData.cxx,v $
223  * Revision 1.5 2005/03/10 16:59:54 mvl
224  * New routine for corruption checking by Jan Balewski
225  *
226  * Revision 1.4 2005/01/11 21:33:40 mvl
227  * Minor mod to hearder checking (do not delete data for certain error states ) By Jan Balewski.
228  *
229  * Revision 1.2 2004/11/29 18:36:59 mvl
230  * New code for header checks and some printing (by Jan Balewski)
231  *
232  * Revision 1.1 2004/10/28 00:10:19 mvl
233  * Initial revision of ezTree classes (for EEmc raw data)
234  *
235  *
236  **************************************************************************/
237