StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EMC_SmdReader.cxx
1 #include "EMC_SmdReader.hh"
2 #include "StMessMgr.h"
3 #include "TTimeStamp.h"
4 #include <assert.h>
5 #define MAX_ADC 0xFFF
6 #include <time.h>
7 #include <stdlib.h>
8 #include <Stiostream.h>
9 #include <stdio.h>
10 
11 using namespace OLDEVP;
12 
14 EMC_SmdReader::EMC_SmdReader(EventReader* er,Bank_EMCP *pEMCP): pBankEMCP(pEMCP),ercpy(er)
15 {
16  mNSMD = 8;
17 
18  EventInfo info=er->getEventInfo();
19  TTimeStamp ts(info.UnixTime);
20  UInt_t year,month,day,hour1,min,sec;
21  ts.GetDate(1,0,&year,&month,&day);
22  ts.GetTime(1,0,&hour1,&min,&sec);
23  UInt_t date= day + 100*(month+100*year );
24  UInt_t hour= sec + 100*(min +100*hour1);
25 
26  decoder = new StEmcDecoder(date,hour);
27 
28  if(date>20041201) mNSMD = 12;
29  LOG_INFO<<"EMC_SMDreader** Event time (Unix time) = "<<info.UnixTime<<" NSMD = "<<mNSMD<<endm;
30  Initialize();
31 }
34 {
35  if(decoder)
36  delete decoder;
37 }
39 
41 {
42  mTheSmdAdcR.NSmdHits = 0;
43  for(int RDO=0;RDO<12;RDO++)
44  mTheSmdAdcR.TimeBin[RDO]=999;
45  for(int RDO=0;RDO<12;RDO++)
46  mTheSmdAdcR.HasData[RDO]=0;
47 
48  // Initialize SMDDATA array to 0's
49  for(int i = 0 ; i <120 ; i++)
50  {
51  for(int j = 0 ; j < 150; j++)
52  mTheSmdAdcR.SmdE_ADCMatrix[i][j] = 0; //SMD_eta
53  for(int j = 0 ; j < 10; j++)
54  for(int k = 0;k < 15; k++)
55  mTheSmdAdcR.SmdP_ADCMatrix[i][j][k] = 0; //SMD_Phi
56  }
57 }
59 Bank_EMCSECP* EMC_SmdReader::getBarrelSmdSection(const Bank_EMCP* pBankEMCP,int section)
60 {
61  if((!pBankEMCP->EMCSecPointer[section].offset) || (!pBankEMCP->EMCSecPointer[section].length))
62  {
63  char str0[40];
64  sprintf(str0,"getBarrelsection(hs %d)",section);
65  ercpy->fprintError(INFO_MISSING_BANK,__FILE__,__LINE__,str0);
66  LOG_WARN<<" SmdReader::getBarrelSection** , no offset or length for section**"<<section<<endm;
67  return NULL;
68  }
69 
70  Bank_EMCSECP * ptr=(Bank_EMCSECP*)(((INT32 *)pBankEMCP)+pBankEMCP->EMCSecPointer[section].offset); // 2nd pointer is for SMD
71 
72  //put some checks
73  if(strncmp(ptr->header.BankType,"EMCSECP",7))
74  {
75  char str0[40];
76  LOG_WARN<<" error in header name**"<<endm;
77  sprintf(str0,"getBarrelSection(hs %d)",section);
78  ercpy->fprintError(ERR_BAD_HEADER,__FILE__,__LINE__, str0);
79  return NULL;
80  }
81  if(!ptr->test_CRC())
82  {
83  char str0[40];
84  LOG_WARN<<"error in CRC**"<<endm;
85  sprintf(str0,"getBarrelsection(hs %d)",section);
86  ercpy->fprintError(ERR_CRC,__FILE__,__LINE__,str0);
87  return NULL;
88  }
89  printf("Byte order of header for EMCSECP Before swap**: %x\n",ptr->header.ByteOrder);
90  if(ptr->swap() < 0)
91  {
92  char str0[40];
93  LOG_WARN<<"error in swap**"<<endm;
94  sprintf(str0,"getBarrelsection(hs %d)",section);
95  ercpy->fprintError(ERR_SWAP,__FILE__,__LINE__,str0);
96  return NULL;
97  }
98  ptr->header.CRC = 0;
99  return ptr;
100 }
102 Bank_EMCRBP* EMC_SmdReader::getBarrelSmdFiber(Bank_EMCSECP* secp,int section)
103 {
104  if((!secp->FiberPointer[section].offset) || (!secp->FiberPointer[section].length))
105  {
106  char str0[40];
107  sprintf(str0,"getBarrelSmdFiber(hs %d)",section);
108  ercpy->fprintError(INFO_MISSING_BANK,__FILE__,__LINE__,str0);
109  //cout<<" getBarrelSmdfiber** , no offset or length for section**"<<section<<endl;
110  return NULL;
111  }
112 
113 
114  Bank_EMCRBP* ptr =(Bank_EMCRBP*)(((INT32 *)secp)+secp->FiberPointer[section].offset);
115 
116  // some checks and swap
117 
118  if(strncmp(ptr->header.BankType,"EMCRBP",6))
119  {
120  char str0[40];
121  LOG_WARN<<" error in header name**"<<endm;
122  sprintf(str0,"getBarrelSmdfiber(hs %d)",section);
123  ercpy->fprintError(ERR_BAD_HEADER,__FILE__,__LINE__, str0);
124  return NULL;
125  }
126  if(!ptr->test_CRC())
127  {
128  char str0[40];
129  LOG_WARN<<"error in CRC**"<<endm;
130  sprintf(str0,"getBarrelSmdfiber(hs %d)",section);
131  ercpy->fprintError(ERR_CRC,__FILE__,__LINE__,str0);
132  return NULL;
133  }
134  if(ptr->swap() < 0)
135  {
136  char str0[40];
137  LOG_WARN<<"error in swap**"<<endm;
138  sprintf(str0,"getBarrelSmdFiber(hs %d)",section);
139  ercpy->fprintError(ERR_SWAP,__FILE__,__LINE__,str0);
140  return NULL;
141  }
142  ptr->header.CRC = 0;
143  return ptr;
144 }
146 Bank_SMDADCR* EMC_SmdReader::getSmdADC(Bank_EMCRBP* rbp)
147 {
148  if((!rbp->EMCADCR.offset) || (!rbp->EMCADCR.length))
149  {
150  char str0[40];
151  sprintf(str0,"getSmdADC(hs )");
152  ercpy->fprintError(INFO_MISSING_BANK,__FILE__,__LINE__,str0);
153  LOG_WARN<<" getBarrelADC** , no offset or length for ADCR**"<<endm;
154  return NULL;
155  }
156  Bank_SMDADCR* pADCR =(Bank_SMDADCR*)(((INT32 *)rbp)+rbp->EMCADCR.offset);
157 
158  // some checks and swap
159 
160  if(strncmp(pADCR->header.BankType,"EMCADCR",7))
161  {
162  char str0[40];
163  LOG_WARN<<" error in header name**"<<endm;
164  sprintf(str0,"getSmdADC(hs)");
165  ercpy->fprintError(ERR_BAD_HEADER,__FILE__,__LINE__, str0);
166  return NULL;
167  }
168  if(!pADCR->test_CRC())
169  {
170  char str0[40];
171  LOG_WARN<<"error in CRC**"<<endm;
172  sprintf(str0,"getSmdADC(hs)");
173  ercpy->fprintError(ERR_CRC,__FILE__,__LINE__,str0);
174  return NULL;
175  }
176  if(pADCR->swap() < 0)
177  {
178  char str0[40];
179  LOG_WARN<<"error in swap**"<<endm;
180  sprintf(str0,"getBankSVTSECP(hs)");
181  ercpy->fprintError(ERR_SWAP,__FILE__,__LINE__,str0);
182  return NULL;
183  }
184  pADCR->header.CRC = 0;
185  return pADCR;
186 }
188 int EMC_SmdReader::FillBarrelSmd(Bank_SMDADCR* pADCR,int RDO)
189 {
190  //fiber header
191  //for(int i=0;i<128;i+=2) cout <<"Fiber header "<<i/2<<" = "<< pADCR->fiberHeader[i]<<" "<<pADCR->fiberHeader[i+1]<<endl;
192 
193  //
194  // Fiber data and fill the struct
195 
196  mTheSmdAdcR.EventNumber=pADCR->header.Token; //Token number
197  mTheSmdAdcR.PedFlag=0; //Pedestal subtracted (1) or not (0)
198  mTheSmdAdcR.SMDErrorFlag=0; // Error from SMD (0=good)
199  mTheSmdAdcR.TimeBin[RDO]=pADCR->fiberHeader[32]; // To be taken from header
200  LOG_DEBUG <<"SMD Time bin for RDO "<<RDO<<" = "<<mTheSmdAdcR.TimeBin[RDO]<<endm;
201  for(int i=0;i<128;i++)
202  mTheSmdAdcR.SmdHeader[RDO][i]=pADCR->fiberHeader[i];
203  int sum =0;
204  //SMD_data
205  //fiberdata
206  for(int i=0;i<4800;i++)
207  {
208  int index=i;
209 
210  int det=0,mod=0,eta=0,sub=0;
211 
212  mTheSmdAdcR.SMDADCArray[RDO][i]=pADCR->fiberData[index];
213  sum+=mTheSmdAdcR.SMDADCArray[RDO][i];
214  mTheSmdAdcR.BankType="BSMDADCR\n";
215  if(RDO<8) // these are the SMD. PSD has header >=8
216  {
217  if(pADCR->fiberData[index]>0)
218  mTheSmdAdcR.NSmdHits++;
219  int binstat=decoder->GetSmdCoord(RDO,index,det,mod,eta,sub);
220 
221  if(binstat)
222  {
223  //cout <<"RDO = "<<RDO<<" index = "<<i<<" det = "<<det<<" m = "<<mod<<" e = "<<eta<<" s = "<<sub<<" adc = "<<pADCR->fiberData[index]<<endl;
224  mTheSmdAdcR.DetFlag=det; //Detector flag for BSMDE=3,BSMDP=4
225  //SMDE
226  if(det==3)
227  mTheSmdAdcR.SmdE_ADCMatrix[mod-1][eta-1]=pADCR->fiberData[index];
228  //SMDP
229  if(det==4)
230  mTheSmdAdcR.SmdP_ADCMatrix[mod-1][eta-1][sub-1]=pADCR->fiberData[index];
231  }
232  }
233  }
234  if(sum>0)
235  mTheSmdAdcR.HasData[RDO] = 1;
236  return 1;
237 }
239 int EMC_SmdReader::ProcessBarrelSmd(const Bank_EMCP* EmcPTR)
240 {
241  // First Barrel Tower
242  Bank_EMCSECP* barrelsmd=getBarrelSmdSection(EmcPTR,1); // 1 is for SMD
243 
244  if(barrelsmd)
245  {
246  for(int RDO=0;RDO<mNSMD;RDO++)
247  {
248  LOG_DEBUG<<" taking SMDfiber RDO *** "<<RDO<<endm;
249  Bank_EMCRBP* smdfiber=getBarrelSmdFiber(barrelsmd,RDO);
250  if(smdfiber)
251  {
252  //cout<<"Got SMD fiber "<<endl;
253  Bank_SMDADCR* smdadc=getSmdADC(smdfiber);
254 
255  if(smdadc)
256  {
257  int fillstat= FillBarrelSmd(smdadc,RDO);
258  if(!fillstat)
259  LOG_WARN<<" Error on SMD Filling "<<endm;
260  }
261  else
262  {
263  LOG_WARN<<" ADCR absent"<<endm;
264  }
265  if(smdadc)
266  smdadc=0;
267  if(smdfiber)
268  smdfiber=0;
269  }
270  }
271  }//barrelsmd
272  else
273  {
274  LOG_WARN<<" BANK_EMCSECP for SMD absent**"<<endm;
275  return 0;
276  }//barrelsmd
277  return 1;
278 }
280 Bank_BSMDADCR& EMC_SmdReader::getBSMDADCR()
281 {
282  return mTheSmdAdcR;
283 }
unsigned int EventNumber
Token number.
Definition: EMC_Reader.hh:111
const char * BankType
Will be filled with a 9 char array (8 letters + NULL)
Definition: EMC_Reader.hh:109
unsigned short SmdHeader[12][128]
SMDHeader for each fiber.
Definition: EMC_Reader.hh:120
unsigned int NSmdHits
Total number of channels.
Definition: EMC_Reader.hh:115
short fiberHeader[128]
256 bytes (64 words of 32 bits) of standard FEE header the same for event pool
Definition: EMC_Reader.hh:98
unsigned int DetFlag
Daq detector flag.
Definition: EMC_Reader.hh:110
unsigned int SMDErrorFlag
Error from TDC.
Definition: EMC_Reader.hh:113
int GetSmdCoord(int RDO, int posInFiber, int &det, int &m, int &e, int &s, bool print=false) const
Get SMD detector (3==SMDE, 4==SMDP), m, e, s from RDO and position for SMD.
EMC_SmdReader(EventReader *er, Bank_EMCP *pEMCP)
EMC_SmdReader constructor.
~EMC_SmdReader()
EMC_SmdReader destructor.
unsigned short HasData[12]
1 if there is data for that fiber
Definition: EMC_Reader.hh:121
unsigned short SMDADCArray[12][4800]
Matrix of ADC&#39;s as obtained from daq.
Definition: EMC_Reader.hh:117
void Initialize()
Initialization of arrays.
unsigned int PedFlag
Pedestal subtracted or not (??)
Definition: EMC_Reader.hh:112
short fiberData[4800]
stuff on the fiber - (Raw data)
Definition: EMC_Reader.hh:99
unsigned int TimeBin[12]
Time bin for each SMD fiber. Now it has 12 fibers for the PSD detector.
Definition: EMC_Reader.hh:116
unsigned short SmdE_ADCMatrix[120][150]
Matrix of ADC&#39;s in Physical Positions for SMD_Eta.
Definition: EMC_Reader.hh:118
unsigned short SmdP_ADCMatrix[120][10][15]
Matrix of ADC&#39;s in Physical Positions for SMD_Phi.
Definition: EMC_Reader.hh:119