StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFpsRawDaqReader.cxx
1 /*
2  *
3  * \class StFpsRawMaker
4  *
5  */
6 
7 #include "StFpsRawDaqReader.h"
8 #include "StRoot/StEvent/StEvent.h"
9 
10 #include "StRoot/St_base/StMessMgr.h"
11 #include "RTS/src/DAQ_FPS/daq_fps.h"
12 #include "RTS/src/DAQ_READER/daq_dta.h"
13 #include "StRoot/StEvent/StTriggerData.h"
14 #include "StRoot/StEvent/StTriggerData2017.h"
15 #include "StRoot/StEvent/StFmsCollection.h"
16 #include "StRoot/StEvent/StFmsHit.h"
17 #include "RTS/src/DAQ_READER/daqReader.h"
18 #include "StRoot/StFmsDbMaker/StFmsDbMaker.h"
19 
20 #include <string.h>
21 #include <time.h>
22 
23 StFpsRawDaqReader::StFpsRawDaqReader( const Char_t* name, const Char_t *daqFileName) :
24  StMaker(name),mEvent(0),mFmsCollectionPtr(0),mDaqFileName(daqFileName),mRdr(0),mFmsDbMkr(0){
25  std::string daqFileNameS( daqFileName );
26 };
27 
28 StFpsRawDaqReader::~StFpsRawDaqReader(){
29  if(mRdr) delete mRdr;
30 };
31 
32 Int_t StFpsRawDaqReader::prepareEnvironment(){
33  //mEvent = (StEvent*)GetInputDS("StEvent");
34  if(mEvent) {
35  mFmsCollectionPtr=mEvent->fmsCollection();
36  LOG_DEBUG <<"::prepareEnvironment() found StEvent"<<endm;
37  } else {
38  mEvent=new StEvent();
39  AddData(mEvent);
40  LOG_DEBUG <<"::prepareEnvironment() has added StEvent"<<endm;
41  }
42  if(!mFmsCollectionPtr) {
43  mFmsCollectionPtr=new StFmsCollection();
44  mEvent->setFmsCollection(mFmsCollectionPtr);
45  LOG_DEBUG <<"::prepareEnvironment() has added StFpsCollection"<<endm;
46  } else {
47  LOG_DEBUG <<"::prepareEnvironment() found FmsCollection"<<endm;
48  };
49  return kStOK;
50 };
51 
52 Int_t StFpsRawDaqReader::Init(){
53  GetEvtHddr()->SetEventNumber(1);
54  LOG_INFO << "Opening "<< mDaqFileName.data() <<endm;
55  mRdr = new daqReader( const_cast< Char_t* >( mDaqFileName.data() ) );
56  if(!mRdr) {
57  LOG_FATAL << "Error constructing daqReader" << endm;
58  return kStFatal;
59  }
60  mRdr->get(0,EVP_TYPE_ANY);
61  int unixtime=mRdr->evt_time;
62  struct tm* local = localtime((const time_t*)&unixtime);
63  int date=(local->tm_year+1900)*10000 + (local->tm_mon+1)*100 + local->tm_mday;
64  int time=local->tm_hour*10000 + local->tm_min*100 + local->tm_sec;
65  printf("Event Unix Time = %d %0d %06d\n",mRdr->evt_time,date,time);
66  mFmsDbMkr = static_cast< StFmsDbMaker*>(GetMaker("fmsDb"));
67  if(!mFmsDbMkr){
68  LOG_FATAL << "Error finding StFmsDbMaker"<< endm;
69  return kStFatal;
70  }
71  mFmsDbMkr->SetDateTime(date,time);
72  LOG_INFO << "Using date and time " << mFmsDbMkr->GetDateTime().GetDate() << ", "
73  << mFmsDbMkr->GetDateTime().GetTime() << endm;
74  return kStOK;
75 };
76 
78  enum {kFpsQtCrate=8, kFpostQtCrate=9};
79  mTrg=0;
80 
81  prepareEnvironment();
82 
83  mRdr->get(0,EVP_TYPE_ANY);
84  if(mRdr->status == EVP_STAT_EOR) {
85  LOG_DEBUG <<"End of File reached..."<<endm;
86  return kStEOF;
87  }
88 
89  mTrgMask = mRdr->daqbits64;
90  if(Debug()){
91  printf("daqbits64=");
92  for(int i=63; i>=0; i--){
93  if(i%10==9) printf(" ");
94  printf("%1x",(mTrgMask>>i)&0x1);
95  };
96  printf("\n");
97  }
98 
99  daq_dta *dd = 0;
100  dd = mRdr->det("trg")->get("raw");
101  if(!dd){
102  printf("trg/raw not found\n");
103  }else{
104  while(dd->iterate()) {
105  uint8_t *trg_raw = dd->Byte;
106  struct simple_desc {
107  short len ;
108  char evt_desc ;
109  char ver ;
110  } *desc ;
111  desc = (simple_desc *) trg_raw ;
112  //printf("Trigger: raw bank has %d bytes: ver 0x%02X, desc %d, len %d\n",dd->ncontent,desc->ver,desc->evt_desc,desc->len);
113  if(desc->ver==0x44){
114  int mDebug=0;
115  TriggerDataBlk2017* trgdata2017 = (TriggerDataBlk2017*)dd->Byte;
116  mTrg = (StTriggerData*) new StTriggerData2017(trgdata2017,mRun,1,mDebug);
117  if(Debug()) printf("Creating StTriggerData for ver=0x44 (2017) with run=%d\n",mRun);
118  //AddData(new TObjectSet("StTriggerData",new StTriggerData2017(trgdata2017,mRun,1,mDebug),kTRUE));
119  //printf("Adding dataset StTriggerData for ver=0x44 (2017) with run=%d\n",mRun);
120  }else{
121  printf("Unknown StTriggerData version = %x\n",desc->ver);
122  }
123  }
124  }
125 
126  int ndata=0;
127  mRccFps=0; mRccFpost=0;
128  for(int fpsfpost=1;fpsfpost<=2;fpsfpost++) {
129  dd = mRdr->det("fps")->get("adc",fpsfpost) ;
130  if(dd){
131  if(fpsfpost==1){
132  mRccFps=((fps_evt_hdr_t *)(dd->meta))->reserved[1];
133  }else{
134  mRccFpost=((fps_evt_hdr_t *)(dd->meta))->reserved[1];
135  }
136  }
137  while(dd && dd->iterate()) {
138 
139  // 2015
140  //int xing=(char)dd->sec;
141  //if(xing>=128) xing-=256;
142  //int qt=dd->rdo;
143  //int n=dd->ncontent;
144 
145  // 2017
146  //int fpsfpost=dd->sec;
147  int xing=(char)dd->pad;
148  if(xing>=128) xing-=256;
149  int qt=dd->row;
150  uint32_t n=dd->ncontent;
151 
152  if(Debug()) printf("FPS: fpsfpost %1d xing %2d, QT %d, chs %d\n",fpsfpost,xing,qt,n) ;
153  fps_adc_t *a = (fps_adc_t *) dd->Void ;
154  for(uint32_t i=0;i<n;i++) {
155  ndata++;
156  int ch=a[i].ch;
157  int adc=a[i].adc;
158  int tdc=a[i].tdc;
159  if(Debug()) {
160  if(fpsfpost==1) printf("FPS : xing %2d, QT %4d, ch %2d: ADC %4d, TDC %2d\n",xing,qt,ch,adc,tdc);
161  if(fpsfpost==2) printf("FPOST: xing %2d, QT %4d, ch %2d: ADC %4d, TDC %2d\n",xing,qt,ch,adc,tdc);
162  }
163  int slatid,q,l,s,flag=0,det,crate;
164  if(fpsfpost==1){
165  slatid = mFmsDbMkr->fpsSlatidFromQT(qt,ch);
166  mFmsDbMkr->fpsQLSfromSlatId(slatid,&q,&l,&s);
167  if(slatid<0) { /* LOG_WARN << "Invalid SlatId = "<<slatid<<endm;*/ flag=1; }
168  if(q<0 || l<1 || s<1) { /* LOG_WARN << Form("Invalid Q/L/S = %d/%d/%d",q,l,s);*/ flag=1; }
169  det=kFpsDetId;
170  crate=kFpsQtCrate;
171  }else if(fpsfpost==2){
172  slatid = mFmsDbMkr->fpostSlatidFromQT(qt,ch); //Get SlatId from QT address and channel
173  mFmsDbMkr->fpostQLSfromSlatId(slatid,&q,&l,&s); //Get Quad/Layer/Slat#s from SlatId
174  if(slatid<0) { /* LOG_WARN << "Invalid SlatId = "<<slatid<<endm;*/ flag=1; }
175  if(q<0 || l<1 || s<1) { /* LOG_WARN << Form("Invalid Q/L/S = %d/%d/%d",q,l,s);*/ flag=1; }
176  det=kFpostDetId;
177  crate=kFpostQtCrate;
178  }
179  if(flag==0){
180  StFmsHit* hit = new StFmsHit();
181  hit->setDetectorId(det);
182  hit->setChannel(slatid);
183  hit->setQtCrate(crate);
184  hit->setQtSlot(qt);
185  hit->setQtChannel(ch);
186  hit->setAdc(adc);
187  hit->setTdc((char)xing);
188  hit->setEnergy(0.0);
189  if(Debug()) {
190  printf("Nhit=%d : ",mFmsCollectionPtr->numberOfHits());
191  hit->print();
192  }
193  mFmsCollectionPtr->addHit(hit);
194  }
195  }
196  }
197  }
198  LOG_DEBUG <<Form("Found %d data lines",ndata)<<endm;
199  return kStOK;
200 };
201 
202 void StFpsRawDaqReader::Clear( Option_t *opts ){
204  if(d) delete d;
205  if(mFmsCollectionPtr) mFmsCollectionPtr->hits().clear();
206 };
207 
208 ClassImp(StFpsRawDaqReader);
209 
210 /*
211  * $Id: StFpsRawDaqReader.cxx,v 1.12 2019/03/14 15:29:15 akio Exp $
212  * $Log: StFpsRawDaqReader.cxx,v $
213  * Revision 1.12 2019/03/14 15:29:15 akio
214  * fixing wrong comit
215  *
216  * Revision 1.10 2017/03/20 21:05:12 akio
217  * Moving accessing RCC counters before hit loop
218  *
219  * Revision 1.9 2017/03/02 23:19:02 akio
220  * check before deleting mTrg
221  *
222  * Revision 1.8 2017/03/02 23:17:06 akio
223  * initialize mTrg=0
224  *
225  * Revision 1.7 2017/02/20 19:17:16 akio
226  * Explicit loop over sector to get meta for both FPS and FPOST
227  *
228  * Revision 1.6 2017/02/18 18:25:40 akio
229  * adding RCC counter reading from meta
230  *
231  * Revision 1.5 2017/02/16 20:54:27 akio
232  * fix typo
233  *
234  * Revision 1.4 2017/02/16 20:19:25 akio
235  * modified for run17
236  *
237  * Revision 1.3 2015/05/21 18:23:51 akio
238  * *** empty log message ***
239  *
240  * Revision 1.2 2015/02/28 02:58:56 akio
241  * Some bug fixes
242  *
243  * Revision 1.1 2015/02/26 20:26:38 akio
244  * Adding raw daq file (or EVP) reader for FPS (not for offline BFC, but for online use)
245  *
246  */
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
Definition: StMaker.cxx:332
Definition: Stypes.h:43
virtual void Clear(Option_t *opts="")
User defined functions.
Definition: Stypes.h:40
virtual Int_t Make()