11 #include "StFgtRawDaqReader.h"
12 #include "StRoot/StEvent/StEvent.h"
14 #include "StRoot/StFgtPool/StFgtCosmicTestStandGeom/StFgtCosmicTestStandGeom.h"
15 #include "StRoot/St_base/StMessMgr.h"
16 #include "RTS/src/DAQ_FGT/daq_fgt.h"
17 #include "RTS/src/DAQ_READER/daq_dta.h"
18 #include "StRoot/StEvent/StFgtCollection.h"
19 #include "StRoot/StEvent/StFgtStripCollection.h"
20 #include "StRoot/StEvent/StFgtStrip.h"
21 #include "RTS/src/DAQ_READER/daqReader.h"
22 #include "StRoot/StFgtDbMaker/StFgtDbMaker.h"
23 #include "StRoot/StFgtUtil/StFgtConsts.h"
28 StFgtRawDaqReader::StFgtRawDaqReader(
const Char_t* name,
const Char_t *daqFileName,
const Char_t* dbMkrName ) :
29 StMaker( name ), mCutShortEvents(0), mIsCosmic(0), mFgtCollectionPtr(0), mDaqFileName( daqFileName ), mDbMkrName( dbMkrName ),
30 mRdr(0), mFgtDbMkr(0), mDataType(0), mStartTbin(0), mNumTbin(15) {
34 std::string daqFileNameS( daqFileName );
35 std::string::size_type pos = daqFileNameS.find_last_of(
".");
37 if( pos != std::string::npos && daqFileNameS.substr( pos ) ==
".sfs" )
41 StFgtRawDaqReader::~StFgtRawDaqReader(){
48 Int_t StFgtRawDaqReader::prepareEnvironment(){
50 eventPtr= (
StEvent*)GetInputDS(
"StEvent");
52 mFgtCollectionPtr=NULL;
54 mFgtCollectionPtr=eventPtr->fgtCollection();
58 mFgtCollectionPtr=eventPtr->fgtCollection();
60 if(!mFgtCollectionPtr) {
62 eventPtr->setFgtCollection(mFgtCollectionPtr);
63 LOG_DEBUG <<
"::prepareEnvironment() has added a non existing StFgtCollection()"<<endm;
66 mFgtCollectionPtr->Clear();
71 Int_t StFgtRawDaqReader::Init(){
74 GetEvtHddr()->SetEventNumber(1);
76 Int_t ierr = prepareEnvironment();
80 if( ierr || !mFgtCollectionPtr ) {
81 LOG_FATAL <<
"Error constructing FgtCollection" << endm;
90 mRdr =
new daqReader( const_cast< Char_t* >( mDaqFileName.data() ) );
92 mRdr->get(0,EVP_TYPE_ANY);
93 int unixtime=mRdr->evt_time;
94 struct tm* local = localtime((
const time_t*)&unixtime);
95 int date=(local->tm_year+1900)*10000 + (local->tm_mon+1)*100 + local->tm_mday;
96 int time=local->tm_hour*10000 + local->tm_min*100 + local->tm_sec;
97 printf(
"Event Unix Time = %d %08d %06d\n",mRdr->evt_time,date,time);
99 if( !ierr && !mIsCosmic ){
100 if( !mDbMkrName.empty() ){
102 mFgtDbMkr =
static_cast< StFgtDbMaker*
>( GetMaker( mDbMkrName.data() ) );
104 if( !ierr && !mFgtDbMkr ){
105 LOG_FATAL <<
"Error finding FgtDbMkr named '" << mDbMkrName <<
"'" << endm;
109 if( !mFgtDbMkr->InheritsFrom(
"StFgtDbMaker") ){
110 LOG_FATAL <<
"StFgtDbMkr does not inherit from StFgtDbMaker" << endm;
111 LOG_FATAL <<
"Name is '" << mFgtDbMkr->
GetName() <<
"', class is '" << mFgtDbMkr->ClassName() << endm;
117 mFgtDbMkr =
static_cast< StFgtDbMaker*
>( GetMakerInheritsFrom(
"StFgtDbMaker" ) );
119 LOG_FATAL <<
"StFgtDbMaker name not provided and error finding StFgtDbMaker" << endm;
124 if(date<21000000 && date>19990000) mFgtDbMkr->SetDateTime(date,time);
125 LOG_INFO <<
"Using date and time " << mFgtDbMkr->GetDateTime().GetDate() <<
", "
126 << mFgtDbMkr->GetDateTime().GetTime() << endm;
142 LOG_FATAL <<
"Pointer to Fgt DB Maker is null" << endm;
146 fgtTables = mFgtDbMkr->getDbTables();
149 LOG_FATAL <<
"Pointer to Fgt DB Tables is null" << endm;
157 if(mFgtCollectionPtr)
158 mFgtCollectionPtr->Clear();
173 mRdr->get(0,EVP_TYPE_ANY);
174 if(mRdr->status == EVP_STAT_EOR) {
175 LOG_DEBUG <<
"End of File reached..."<<endm;
181 dd = mRdr->det(
"fgt")->get(
"adc");
182 if(!dd) dd = mRdr->det(
"fgt")->get(
"zs");
183 }
else if(mDataType==1){
184 dd = mRdr->det(
"fgt")->get(
"adc");
185 }
else if(mDataType==2){
186 dd = mRdr->det(
"fgt")->get(
"zs");
187 }
else if(mDataType==3){
188 dd = mRdr->det(
"fgt")->get(
"zs");
189 if(!dd) dd = mRdr->det(
"fgt")->get(
"adc");
195 for(
int r=1;r<=FGT_RDO_COU;r++) {
196 if(meta->arc[r].present == 0) continue ;
197 for(
int arm=0;arm<FGT_ARM_COU;arm++) {
198 if(meta->arc[r].arm[arm].present == 0) continue ;
199 for(
int apv=0;apv<FGT_APV_COU;apv++) {
200 if(meta->arc[r].arm[arm].apv[apv].present == 0) continue ;
201 int nt=meta->arc[r].arm[arm].apv[apv].ntim;
203 if(ntimebin!=0 && nt!=0 && ntimebin!=nt) printf(
"Different number of timebins in different APV!!! Taking larger one!!!\n");
204 if(ntimebin<nt) ntimebin=nt;
209 mFgtCollectionPtr->setNumTimeBins(ntimebin);
210 if(mNumTbin < ntimebin) mFgtCollectionPtr->setNumTimeBins(mNumTbin);
213 while(dd && dd->iterate()) {
216 for(uint32_t i=0;i<dd->ncontent;i++) {
217 timebin=f[i].tb - mStartTbin;
218 if(timebin<0 || timebin>=mNumTbin)
continue;
228 if(rdo<1 || rdo > kFgtNumRdos) flag=1;
229 if(arm<0 || arm>=kFgtNumArms) flag=1;
230 if(apv>=22 || apv < 0 || apv ==10|| apv==11) flag=1;
231 if(channel<0 || channel>=kFgtNumChannels) flag=1;
232 if(timebin<0 || timebin>=kFgtNumTimeBins) flag=1;
235 LOG_INFO<<
"Corrupt data rdo: " << rdo <<
" arm: " << arm <<
" apv: " << apv <<
" channel: " << channel <<
" tbin: "<<timebin<<endm;
250 Int_t geoId = ( mIsCosmic
251 ? StFgtCosmicTestStandGeom::getNaiveGeoIdFromElecCoord(rdo,arm,apv,channel)
252 : fgtTables->getGeoIdFromElecCoord(rdo, arm, apv, channel)
254 StFgtGeom::decodeGeoId( geoId, discIdx, quad, layer, strip );
255 if(discIdx < 0 || discIdx >= kFgtNumDiscs) flag=1;
256 if(quad <0 || quad >= kFgtNumQuads) flag=1;
257 if(layer !=
'P' && layer !=
'R') flag=1;
258 if(strip < 0 || strip >= kFgtNumStrips) flag=1;
260 LOG_INFO<<
"Wrong geoId: " << geoId <<
" discIdx: " << discIdx <<
" quad: " << quad <<
" layer: " << layer <<
" strip: " << strip
261 <<
" is cosmic: " << mIsCosmic <<
" rdo: " << rdo <<
" arm: " << arm <<
" apv: " << apv <<
" channel: " << channel <<endm;
278 if( stripCollectionPtr ) {
279 Int_t elecId = StFgtGeom::getElectIdFromElecCoord( rdo, arm, apv, channel );
280 StFgtStrip* stripPtr = stripCollectionPtr->getStrip( elecId );
281 stripPtr->setAdc( adc, timebin );
282 stripPtr->setGeoId( geoId );
283 stripPtr->setElecCoords( rdo, arm, apv, channel );
285 LOG_WARN <<
"StFgtRawDaqReader::Make() -- Could not access stripCollection for disc " << discIdx << endm;
291 if( mCutShortEvents ){
294 UInt_t numDiscs = mFgtCollectionPtr->getNumDiscs();
296 for( UInt_t discIdx = 0; discIdx < numDiscs && eventOK; ++discIdx ){
298 if( stripCollectionPtr ){
299 Int_t chanPerQuad = kFgtApvsPerQuad*kFgtNumChannels;
300 Int_t remainder = stripCollectionPtr->getNumStrips() % chanPerQuad;
301 eventOK = (remainder == 0);
305 for( UInt_t discIdx = 0; discIdx < numDiscs && eventOK; ++discIdx ){
307 if( stripCollectionPtr )
308 stripCollectionPtr->Clear();
318 if( mFgtCollectionPtr )
323 mFgtCollectionPtr->Clear( opts );
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
virtual void Clear(Option_t *opts="")
User defined functions.
virtual const char * GetName() const
special overload