28 #include "StFcsRawDaqReader.h"
29 #include "StRoot/StEvent/StEvent.h"
31 #include "StRoot/St_base/StMessMgr.h"
32 #include "RTS/src/DAQ_FCS/daq_fcs.h"
33 #include "RTS/src/DAQ_STGC/daq_stgc.h"
34 #include "RTS/src/DAQ_READER/daq_dta.h"
35 #include "StRoot/StEvent/StTriggerData.h"
36 #include "StRoot/StEvent/StTriggerData2022.h"
37 #include "StRoot/StEvent/StFcsCollection.h"
38 #include "StRoot/StEvent/StFcsHit.h"
39 #include "StRoot/StFcsDbMaker/StFcsDbMaker.h"
40 #include "StRoot/StFcsDbMaker/StFcsDb.h"
41 #include "RTS/src/DAQ_READER/daqReader.h"
46 StFcsRawDaqReader::StFcsRawDaqReader(
const Char_t* name,
const Char_t *daqFileName) :
47 StMaker(name),mDaqFileName(daqFileName){
48 std::string daqFileNameS( daqFileName );
51 StFcsRawDaqReader::~StFcsRawDaqReader(){
55 Int_t StFcsRawDaqReader::prepareEnvironment(){
56 mEvent = (
StEvent*)GetInputDS(
"StEvent");
58 LOG_DEBUG <<
"::prepareEnvironment() found StEvent"<<endm;
62 LOG_DEBUG <<
"StFcsRawDaqReader::prepareEnvironment() has added StEvent"<<endm;
64 mFcsCollectionPtr=mEvent->fcsCollection();
65 if(!mFcsCollectionPtr) {
67 mEvent->setFcsCollection(mFcsCollectionPtr);
68 LOG_DEBUG <<
"StFcsRawDaqReader::prepareEnvironment() has added StFcsCollection"<<endm;
70 mFcsCollectionPtr=mEvent->fcsCollection();
71 LOG_DEBUG <<
"StFcsRawDaqReader::prepareEnvironment() found StFcsCollection"<<endm;
76 Int_t StFcsRawDaqReader::Init(){
77 GetEvtHddr()->SetEventNumber(1);
78 LOG_INFO <<
"Opening "<< mDaqFileName.data() <<endm;
80 mRdr =
new daqReader( const_cast< Char_t* >( mDaqFileName.data() ) );
82 LOG_FATAL <<
"Error constructing daqReader" << endm;
85 mRdr->get(0,EVP_TYPE_ANY);
86 int unixtime=mRdr->evt_time;
87 struct tm* local = localtime((
const time_t*)&unixtime);
88 int date=(local->tm_year+1900)*10000 + (local->tm_mon+1)*100 + local->tm_mday;
89 int time=local->tm_hour*10000 + local->tm_min*100 + local->tm_sec;
90 LOG_INFO << Form(
"Event Unix Time = %d %0d %06d",mRdr->evt_time,date,time) << endm;
94 LOG_FATAL <<
"Error finding StFcsDbMaker"<< endm;
97 mFcsDbMkr->SetDateTime(date,time);
98 LOG_INFO <<
"Using date and time " << mFcsDbMkr->GetDateTime().GetDate() <<
", "
99 << mFcsDbMkr->GetDateTime().GetTime() << endm;
101 mFcsDb =
static_cast<StFcsDb*
>(GetDataSet(
"fcsDb"));
103 LOG_FATAL <<
"Error finding StFcsDb"<< endm;
110 LOG_DEBUG <<
"Starting StFcsRawDaqReader::Make()"<<endm;
113 static int nskiptot=0;
115 prepareEnvironment();
151 mRdr->get(0,EVP_TYPE_ANY);
152 if(mRdr->status != EVP_STAT_EOR){
153 int trgcmd = mRdr->trgcmd;
154 if(trgcmd != 4 && trgcmd !=10){
157 if(mDebug) LOG_INFO << Form(
"trgcmd=%d skipping nskip=%d nskiptot=%d",trgcmd,nskip,nskiptot)<<endm;
161 if(mRdr->status==EVP_STAT_EOR || (mMaxSector>0 && mEvtInSector>=mMaxEvtPerSector)) {
163 LOG_INFO <<
"End of File reached..."<<endm;
166 LOG_INFO <<
"EOF or max event for a sector file..."<<endm;
168 if(mSector>mMaxSector)
return kStEOF;
169 TString fn(mDaqFileName.data());
170 fn.ReplaceAll(
"_s01_",Form(
"_s%02d_",mSector));
171 LOG_INFO <<
"Opening "<< fn.Data() <<endm;
173 mRdr =
new daqReader( const_cast< Char_t* >( fn.Data() ) );
175 LOG_FATAL <<
"Error constructing daqReader" << endm;
187 int trgcmd = mRdr->trgcmd;
188 if(trgcmd != 4 && trgcmd !=10){
189 LOG_INFO << Form(
"This should not happen!!! trgcmd=%d skipping nskip=%d nskiptot=%d",trgcmd,nskip,nskiptot)<<endm;
193 printf(
"Skipped nskip=%d nskiptot=%d\n",nskip,nskiptot);
198 mTrgMask = mRdr->daqbits64;
200 printf(
"daqbits64=");
201 for(
int i=63; i>=0; i--){
202 if(i%8==7) printf(
" ");
203 printf(
"%1llx",(mTrgMask>>i)&0x1);
209 dd = mRdr->det(
"trg")->get(
"raw");
210 int startrg=0,fcstrg=0;
212 LOG_WARN <<
"trg/raw not found" << endm;
214 while(dd->iterate()) {
215 u_char *trg_raw = dd->Byte;
221 desc = (simple_desc *) trg_raw ;
225 LOG_INFO <<
"Creating StTriggerData for ver=0x47 (2022) with run="<<mRun<<endm;
227 LOG_DEBUG <<
"Added StTriggerData to StEvent"<<endm;
231 mTrg = mEvent->triggerData();
232 LOG_DEBUG <<
"Got back Dataset StTriggerData addr="<<mTrg<<endm;
234 mFcsTcuBit = mTrg->lastDSM(5);
247 LOG_DEBUG << Form(
"FCS TCU Bits = 0x%04x",mFcsTcuBit)<<endm;
249 unsigned long long l2sum=mTrg->l2sum();
255 printf(
"Unknown StTriggerData version = %x\n",desc->ver);
285 int ndata=0, nvaliddata=0;
287 string mode[2]={
"adc",
"zs"};
293 dd = mRdr->det(
"fcs")->get(mode[mReadMode].c_str());
295 mFcsCollectionPtr->setDataExist(0);
297 mFcsCollectionPtr->setDataExist(1);
298 while(dd->iterate()) {
299 int sec = ((dd->sec >> 11) & 0x1F) + 1;
300 int rdo = ((dd->sec >> 8) & 0x7) + 1;
301 int ehp = (dd->sec >> 6) & 0x3;
302 int ns = (dd->sec >> 5) & 1;
305 u_int n=dd->ncontent;
306 int detid,id,crt,sub;
310 u_short *d16 = (u_short *)dd->Void;
312 unsigned short tmp[1024];
314 hit =
new StFcsHit(0,detid,
id,ns,ehp,dep,ch,n,d16);
328 hit =
new StFcsHit(1,detid,
id,ns,ehp,dep,ch,2*n,d16);
331 mFcsCollectionPtr->addHit(detid,
hit);
333 if(detid<6) nvaliddata++;
336 printf(
"FCS %3s : S%2d:%2d [det%1d ns%1d dep%2d ch%2d] det=%d id=%3d size=%3d adc=",
337 mode[mReadMode].c_str(),sec,rdo,ehp,ns,dep,ch,detid,
id,n) ;
338 for(
unsigned int tb=0; tb<
hit->nTimeBin(); tb++) printf(
"%4d ",
hit->adc(tb));
344 LOG_DEBUG <<Form(
"FCS found %d data lines, and %d valid data lines",
345 ndata,nvaliddata)<<endm;
346 if(mDebug>3) mFcsCollectionPtr->print(3);
349 dd = mRdr->det(
"stgc")->get(
"raw");
351 while(dd->iterate()){
352 if(mDebug) printf(
"STGC RAW: stgc%02d(sec) RDO=%1d size=%d(bytes)\n",dd->sec,dd->rdo,dd->ncontent);
355 for(
int r=1; r<=6; r++) {
356 dd = mRdr->det(
"stgc")->get(
"altro",r) ;
357 while(dd && dd->iterate()) {
358 if(mDebug) printf(
"STGC ALTRO: stgc%02d(sec) RDO=%1d ALTRO=%03d(row) Ch=%02d(pad)\n",dd->sec,r,dd->row,dd->pad);
359 for(u_int i=0; i<dd->ncontent; i++) {
360 if(mDebug) printf(
" TB=%3d ADC=%4d",dd->adc[i].tb,dd->adc[i].adc) ;
363 if(mDebug) printf(
"\n");
366 LOG_DEBUG <<Form(
"STGC found %d data lines",ndata)<<endm;
virtual void Clear(Option_t *opts="")
User defined functions.
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
void getIdfromDep(int ehp, int ns, int dep, int ch, int &detectorId, int &id, int &crt, int &slt) const
Get DEP map.