StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFmsTriggerDetector.cxx
1 /***************************************************************************
2  *
3  * $Id: StFmsTriggerDetector.cxx,v 2.9 2010/01/25 17:25:00 ullrich Exp $
4  *
5  * Author: Akio Ogawa, Apr 2007
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: StFmsTriggerDetector.cxx,v $
13  * Revision 2.9 2010/01/25 17:25:00 ullrich
14  * Removed some redundant messages.
15  *
16  * Revision 2.8 2010/01/13 17:51:55 ullrich
17  * New clearFlag() for mudst reading, Data member mNumHeader gets //!
18  *
19  * Revision 2.6 2009/02/23 22:29:49 ullrich
20  * Fixed problem when running over 2009 data (solution by Pibero)
21  *
22  * Revision 2.5 2007/12/11 18:11:13 ullrich
23  * Fix bugs in QT decoding (Akio).
24  *
25  * Revision 2.4 2007/12/08 21:43:33 jeromel
26  * Wraped with LOG_ERROR, remove assert()
27  *
28  * Revision 2.3 2007/07/11 23:06:45 perev
29  * Cleanup+fix StXXXTriggerDetector
30  *
31  * Revision 2.2 2007/07/10 17:04:48 perev
32  * Check for zero pointer added
33  *
34  * Revision 2.1 2007/07/02 20:21:54 ullrich
35  * Initial Revision.
36  *
37  **************************************************************************/
38 #include "StFmsTriggerDetector.h"
39 #include "StTriggerData.h"
40 #include "Stiostream.h"
41 #include <stdio.h>
42 
43 static const char rcsid[] = "$Id: StFmsTriggerDetector.cxx,v 2.9 2010/01/25 17:25:00 ullrich Exp $";
44 
45 ClassImp(StFmsTriggerDetector)
46 
48 {
49  //cout << "StFmsTriggerDetector default constructor" << endl;
50  memset(mBeg,0,mEnd-mBeg);
51  mNumHeader=-1;
52  mNumQTdata=0;
53 }
54 
55 StFmsTriggerDetector::StFmsTriggerDetector(const StTriggerData& t)
56 {
57  //cout << "StFmsTriggerDetector constructor with StTriggerData" << endl;
58  const unsigned char *c=0;
59  const unsigned short *s=0;
60  const unsigned int *i=0;
61 
62  memset(mBeg,0,mEnd-mBeg);
63 
64  mNumHeader=-1;
65  mNumQTdata = (int)t.nQTdata();
66  if ( !(mMaxLine>=mNumQTdata)){
67  {LOG_ERROR << "StFmsTriggerDetector::StFmsTriggerDetector() mMaxLine < mNumQTdata" << endm;}
68  }
69  else {
70  i = t.QTdata(); if (i && mNumQTdata>0) memcpy(mQTdata,i, mNumQTdata*sizeof(int ));
71  }
72  c = t.getDsm_FMS() ; if (c) memcpy(mDSM ,c, sizeof(mDSM ));
73  c = t.getDsm01_FMS(); if (c) memcpy(mDSM01 ,c, sizeof(mDSM01));
74  c = t.getDsm02_FMS(); if (c) memcpy(mDSM02 ,c, sizeof(mDSM02));
75  s = t.getDsm1_FMS() ; if (s) memcpy(mDSM1 ,s, sizeof(mDSM1 ));
76  s = t.getDsm2_FMS() ; if (s) memcpy(mDSM2 ,s, sizeof(mDSM2 ));
77  // dump();
78 }
79 
80 StFmsTriggerDetector::~StFmsTriggerDetector() {/* noop */}
81 
82 void
83 StFmsTriggerDetector::clearFlag() {
84  //cout << "StFmsTriggerDetector::clearFlag" << endl;
85  mNumHeader=-1;
86 }
87 
88 void
89 StFmsTriggerDetector::decode()
90 {
91  //cout << "FMS data decode!!!" << endl;
92  mNumHeader=0;
93  if (mNumQTdata==0) return;
94  memset(mADC,0,sizeof(mADC));
95  memset(mTDC,0,sizeof(mTDC));
96  int header=1, nline=0, iline;
97  int crate=0, addr=0;
98  for (int i=0; i<static_cast<int>(mNumQTdata-1); i++){
99  unsigned int d = mQTdata[i];
100  if (header==1){
101  crate = getCRT(d);
102  addr = getADR(d);
103  nline = getNHT(d);
104  if (crate-mOffsetCrate<0 || crate-mOffsetCrate>mMaxCrate){
105  {LOG_ERROR << "StFmsTriggerDetector::decode() Wrong QT crate#=" <<crate<< endm;}
106  }
107  if (addr-mOffsetAddr<0 || addr-mOffsetAddr>mMaxAddr){
108  {LOG_ERROR << "StFmsTriggerDetector::decode() Wrong QT Addr#=" <<addr<< endm;}
109  }
110  if (nline<0 || nline>32){
111  {LOG_ERROR << "StFmsTriggerDetector::decode() Wrong QT # of lines=" <<nline<< endm;}
112  }
113  if (nline>0) {header=0; iline=0;}
114  mNumHeader++;
115  }
116  else {
117  iline++;
118  unsigned short dcard = getQT8(d);
119  unsigned short dch = getCHA(d);
120  if (dcard>mMaxDCard){
121  {LOG_ERROR << "StFmsTriggerDetector::decode() Wrong QT DCard=" <<dcard<< endm;}
122  }
123  if (dch>mMaxChan){
124  {LOG_ERROR << "StFmsTriggerDetector::decode() Wrong QT DChan=" <<dch<< endm;}
125  }
126  int tst=(char*)&mADC[crate-mOffsetCrate][addr-mOffsetAddr][dcard][dch]
127  -(char*)&mADC[0][0][0][0];
128  if ( ! (tst>=0 && tst<(int)sizeof(mADC)) ){
129  {LOG_ERROR << "StFmsTriggerDetector::decode() Sanity check failed in" << endm;}
130  }
131  else {
132  mADC[crate-mOffsetCrate][addr-mOffsetAddr][dcard][dch]=getADC(d);
133  mTDC[crate-mOffsetCrate][addr-mOffsetAddr][dcard][dch]=getTDC(d);
134  }
135  if (nline==iline) header=1;
136  }
137  }
138 }
139 
140 unsigned int
141 StFmsTriggerDetector::hit(int line) const
142 {
143  if (line>=0 && line<mMaxLine && line<(int)mNumQTdata) return mQTdata[line];
144  return 0;
145 }
146 
147 unsigned short
148 StFmsTriggerDetector::adc(int crate, int addr, int dcard, int dch)
149 {
150  if (mNumHeader==-1) decode();
151  crate -= mOffsetCrate;
152  addr -= mOffsetAddr;
153  if (crate >= 0 && crate < mMaxCrate &&
154  addr >= 0 && addr < mMaxAddr &&
155  dcard >= 0 && dcard < mMaxDCard &&
156  dch >= 0 && dch < mMaxChan ){
157  return mADC[crate][addr][dcard][dch];
158  }
159  else {
160  {LOG_WARN << "StFmsTriggerDetector::adc() arguments out of range" << endm;}
161  return 0;
162  }
163 }
164 
165 unsigned short
166 StFmsTriggerDetector::tdc(int crate, int addr, int dcard, int dch)
167 {
168  if (mNumHeader==-1) decode();
169  crate -= mOffsetCrate;
170  addr -= mOffsetAddr;
171  if (crate >= 0 && crate < mMaxCrate &&
172  addr >= 0 && addr < mMaxAddr &&
173  dcard >= 0 && dcard < mMaxDCard &&
174  dch >= 0 && dch < mMaxChan ){
175  return mTDC[crate][addr][dcard][dch];
176  }
177  else {
178  {LOG_WARN << "StFmsTriggerDetector::tdc() arguments out of range" << endm;}
179  return 0;
180  }
181 }
182 
183 void
184 StFmsTriggerDetector::dump()
185 {
186  cout << "FMS data dump" << endl;
187  cout << "mNumHeader = "<<mNumHeader<<endl;
188  if (mNumHeader==-1) decode();
189  cout << "Number of data lines = " << mNumQTdata << endl;
190  if (mNumQTdata>0){
191  printf("Number of header lines = %d\n", mNumHeader);
192  printf("Last check line (should be 0xAC10) = %x\n",mQTdata[mNumQTdata-1]);
193  printf("ADC\n");
194  for(int crate=0; crate<mMaxCrate; crate++){
195  for(int addr=0; addr<mMaxAddr; addr++){
196  for(int dcard=0; dcard<mMaxDCard; dcard++){
197  printf("Crate=%5d Addr=%5x DCard=%5d %4d %4d %4d %4d %4d %4d %4d %4d\n",
198  crate+mOffsetCrate, addr+mOffsetAddr, dcard,
199  mADC[crate][addr][dcard][0], mADC[crate][addr][dcard][1],
200  mADC[crate][addr][dcard][2], mADC[crate][addr][dcard][3],
201  mADC[crate][addr][dcard][4], mADC[crate][addr][dcard][5],
202  mADC[crate][addr][dcard][6], mADC[crate][addr][dcard][7]);
203  }
204  }
205  }
206  printf("TDC\n");
207  for(int crate=0; crate<mMaxCrate; crate++){
208  for(int addr=0; addr<mMaxAddr; addr++){
209  for(int dcard=0; dcard<mMaxDCard; dcard++){
210  printf("Crate=%5d Addr=%5x DCard=%5d %4d %4d %4d %4d %4d %4d %4d %4d\n",
211  crate+mOffsetCrate, addr+mOffsetAddr, dcard,
212  mTDC[crate][addr][dcard][0], mTDC[crate][addr][dcard][1],
213  mTDC[crate][addr][dcard][2], mTDC[crate][addr][dcard][3],
214  mTDC[crate][addr][dcard][4], mTDC[crate][addr][dcard][5],
215  mTDC[crate][addr][dcard][6], mTDC[crate][addr][dcard][7]);
216  }
217  }
218  }
219  }
220 }