+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * *
+ * Author: The ALICE Off-line Project. *
+ * Contributors are mentioned in the code where appropriate. *
+ * *
+ * Permission to use, copy, modify and distribute this software and its *
+ * documentation strictly for non-commercial purposes is hereby granted *
+ * without fee, provided that the above copyright notice appears in all *
+ * copies and that both the copyright notice and this permission notice *
+ * appear in the supporting documentation. The authors make no claims *
+ * about the suitability of this software for any purpose. It is *
+ * provided "as is" without express or implied warranty. *
+ **************************************************************************/
+
+/* $Id: */
+
+//____________________________________________________________________
+//
+// T0
+// Class for reading T0 RAW data in TOF data format
+//
#include "AliT0RawReader.h"
-#include "AliT0RawData.h"
-#include "AliT0digit.h"
+#include "AliT0Parameters.h"
#include "AliBitPacking.h"
#include "TBits.h"
ClassImp(AliT0RawReader)
- AliT0RawReader::AliT0RawReader (AliRawReader *rawReader, TTree* tree)
+ AliT0RawReader::AliT0RawReader (AliRawReader *rawReader, Bool_t isOnline)
: TTask("T0RawReader","read raw T0 data"),
- fDigits(NULL),
- fTree(tree),
fRawReader(rawReader),
fData(NULL),
- fPosition(0)
+ fPosition(0),
+ fParam(NULL),
+ fIsOnline(isOnline),
+ fBunchID(0),
+ fPrintout(kFALSE)
+
{
//
// create an object to read T0raw digits
AliDebug(1,"Start ");
- if (fDigits == 0x0) fDigits = new AliT0digit();
- fTree->Branch("T0","AliT0digit",&fDigits,405,1);
fRawReader->Reset();
fRawReader->Select("T0");
-
+ fParam = AliT0Parameters::Instance();
+ if (fIsOnline)
+ fParam->InitIfOnline();
+ else
+ fParam->Init();
}
AliT0RawReader::~AliT0RawReader ()
{
//
}
+/*
+AliT0RawReader::AliT0RawReader(const AliT0RawReader& o): TTask(o),
+ fRawReader(rawReader),
+ fData(NULL),
+ fPosition(0)
+{
+ //
+}
+*/
+
Bool_t AliT0RawReader::Next()
{
// allData[49] time difference (vertex)
UInt_t word;
- Int_t time=0, itdc=0, ichannel=0;
+ Int_t time=0, itdc=0, ichannel=0, uu;
Int_t numberOfWordsInTRM=0, iTRM=0;
- Int_t tdcTime, koef, meanTime, timeDiff ;
- Int_t allData[107];
-
- TArrayI *timeTDC1 = new TArrayI(24);
- TArrayI * chargeTDC1 = new TArrayI(24);
- TArrayI *timeTDC2 = new TArrayI(24);
- TArrayI *chargeTDC2 = new TArrayI(24);
-
- for ( Int_t k=0; k<107; k++) allData[k]=0;
+ Int_t tdcTime, koef,hit=0;
+ Int_t koefhits[110];
+ Int_t trm_chain_header = 0x00000000;
+ Int_t trm_chain_trailer = 0x10000000;
+
+ UInt_t filler = 0x70000000;
+ Bool_t correct=kTRUE;
+ Int_t header;
+
+ Int_t fNTRM = fParam->GetNumberOfTRMs();
+ for ( Int_t k=0; k<110; k++) {
+ koefhits[k]=0;
+ for ( Int_t jj=0; jj<5; jj++) {
+ fAllData[k][jj]=0;
+ }
+ }
do {
if (!fRawReader->ReadNextData(fData)) return kFALSE;
} while (fRawReader->GetDataSize() == 0);
- // fPosition = GetPosition();
fPosition = 0;
-
+ // cout.setf( ios_base::hex, ios_base::basefield );
+ if(fPrintout)
+ cout<<" CDH :: BC ID "<< (fRawReader->GetBCID())<<
+ " Event size"<<fRawReader->GetDataSize()<<
+ " orbit ID "<<fRawReader->GetOrbitID()<<
+ " event index "<<fRawReader->GetEventIndex()<<
+ " event type " <<fRawReader->GetType()<<endl;
//DRM header
- for (Int_t i=0; i<4; i++) {
- word = GetNextWord();
- }
- //TRMheader
- word = GetNextWord();
- numberOfWordsInTRM=AliBitPacking::UnpackWord(word,4,16);
- iTRM=AliBitPacking::UnpackWord(word,0,3);
-
- //chain header
- word = GetNextWord();
-
- for (Int_t i=0; i<numberOfWordsInTRM; i++) {
- word = GetNextWord();
- tdcTime = AliBitPacking::UnpackWord(word,31,31);
+ for (Int_t i=0; i<6; i++) {
+ word = GetNextWord();
+ if(fPrintout && i==0) cout<<" DRM header:: event words "<<AliBitPacking::UnpackWord(word,4, 20);
+ // cout<<i<<" DRM header "<<word<<endl;
+ if (fPrintout && i==4 ) cout<<" L0BC ID "<< AliBitPacking::UnpackWord(word,4, 15)<<endl;
+ header = AliBitPacking::UnpackWord(word,28,31);
+ if( header !=4 )
+ {
+ AliWarning(Form(" !!!! wrong DRM header %x!!!!", word));
+ fRawReader->AddFatalErrorLog(kWrongDRMHeader,Form("w=%x",word));
+ break;
+ }
+ }
+ for (Int_t ntrm=0; ntrm< fNTRM; ntrm++)
+ {
+ //TRMheader
+ word = GetNextWord();
+ // cout<<" TRM "<<word<<endl;
+ header = AliBitPacking::UnpackWord(word,28,31);
+ if ( header != 4 )
+ {
+ AliWarning(Form(" !!!! wrong TRM header %x!!!!", word));
+ fRawReader->AddMajorErrorLog(kWrongTRMHeader,Form("w=%x",word));
+ break;
+ }
+ numberOfWordsInTRM=AliBitPacking::UnpackWord(word,4,16);
+ if(fPrintout) {
+ cout<<" TRM header :: event words "<<numberOfWordsInTRM;
+ cout<<" ACQ bits "<<AliBitPacking::UnpackWord(word,17,18);
+ cout<<" L bit "<<AliBitPacking::UnpackWord(word,19,19)<<endl;
+ }
+ iTRM=AliBitPacking::UnpackWord(word,0,3);
+ for( Int_t ichain=0; ichain<2; ichain++)
+ {
+ //chain header
+ word = GetNextWord();
+ // cout<<" chain header "<<word<<endl;
+ uu = word & trm_chain_header;
+ if(uu != trm_chain_header)
+ {
+ AliWarning(Form(" !!!! wrong CHAIN 0 header %x!!!!", word));
+ fRawReader->AddMajorErrorLog(kWrongChain0Header,Form("w=%x",word));
+ break;
+ }
+ fBunchID=AliBitPacking::UnpackWord(word,4,15);
+ if(fPrintout)
+ cout<<" chain "<< ichain<<" header:: BunchID "<<fBunchID;
+ word = GetNextWord();
+ // cout<<" next word "<<word<<endl;
+ tdcTime = AliBitPacking::UnpackWord(word,31,31);
+ // for (; tdcTime==1; tdcTime)
+ while(tdcTime==1)
+ {
+ correct = kTRUE;
+ itdc=AliBitPacking::UnpackWord(word,24,27);
+ ichannel=AliBitPacking::UnpackWord(word,21,23);
+ time=AliBitPacking::UnpackWord(word,0,20);
+
+ koef = fParam->GetChannel(iTRM,itdc,ichain,ichannel);
+ if (koef != 0 )
+ // cout<<"RawReader>> "<<"koef "<<koef<<" trm "<<iTRM<<
+ // " tdc "<<itdc<<" chain "<<ichain<<
+ // " channel "<<ichannel<<" time "<<time<<endl;
+ if (koef ==-1 ){
+ AliWarning(Form("Incorrect lookup table ! "));
+ fRawReader->AddMajorErrorLog(kIncorrectLUT);
+ correct=kFALSE;
+ }
+ if(correct){
+ hit=koefhits[koef];
+ if(hit>4) {
+ AliDebug(10,Form("Too many hits for %i channel - %i ! ",koef,koefhits[koef] ));
+ hit=4;
+ }
+ fAllData[koef][hit]=time;
+ koefhits[koef]++;
+ }
+ word = GetNextWord();
- if ( tdcTime == 1)
+ tdcTime = AliBitPacking::UnpackWord(word,31,31);
+
+ }
+
+ // cout<<" trailer :: "<<word<<endl;
+ uu = word&trm_chain_trailer;
+ if(uu != trm_chain_trailer )
+ {
+ AliWarning(Form(" !!!! wrong CHAIN 0 trailer %x !!!!", word));
+ fRawReader->AddMajorErrorLog(kWrongChain0Trailer,Form("w=%x",word));
+ break;
+ }
+ if(fPrintout)
+ cout<<" trailer:: event counter "<< AliBitPacking::UnpackWord(word,16,27)<<endl;
+ }
+
+ word = GetNextWord(); //TRM trailer
+ // cout<<" TRM trailer "<<word<<endl;
+ header = AliBitPacking::UnpackWord(word,28,31);
+ if( header !=5 )
+ {
+ AliWarning(Form(" !!!! wrong TRM GLOBAL trailer %x!!!!", word));
+ fRawReader->AddMajorErrorLog(kWrongTRMTrailer,Form("w=%x",word));
+ break;
+ }
+ if(fPrintout)
+ cout<<" TRM trailer :: event counter "<< AliBitPacking::UnpackWord(word,16,27)<<endl;
+ } //TRM loop
+ word = GetNextWord(); //
+ // cout<<" after TRM trailer "<<word<<endl;
+ if (word == filler ) word = GetNextWord();
+ header = AliBitPacking::UnpackWord(word,28,31);
+ if( header !=5 )
{
- itdc=AliBitPacking::UnpackWord(word,24,27);
- ichannel=AliBitPacking::UnpackWord(word,21,23);
- time=AliBitPacking::UnpackWord(word,0,20);
- koef = itdc*4 + ichannel/2;
- allData[koef]=time;
- }
- }
- word = GetNextWord(); //chain trailer
- word = GetNextWord(); //TRM trailer
-
- //TRMheader
- word = GetNextWord();
- numberOfWordsInTRM=AliBitPacking::UnpackWord(word,4,16);
- iTRM=AliBitPacking::UnpackWord(word,0,3);
- //chain header
- word = GetNextWord();
-
- for (Int_t iword=0; iword<numberOfWordsInTRM; iword++) {
- word = GetNextWord();
- tdcTime = AliBitPacking::UnpackWord(word,31,31);
-
- if ( tdcTime == 1)
- {
- itdc=AliBitPacking::UnpackWord(word,24,27);
- ichannel=AliBitPacking::UnpackWord(word,21,23);
- time=AliBitPacking::UnpackWord(word,0,20);
- koef = itdc*4 + ichannel/2;
- allData[koef+54]=time;
- }
- }
-
- for (Int_t in=0; in<24; in++)
- {
- timeTDC1->AddAt(allData[in],in);
- timeTDC2->AddAt(allData[in+24],in);
- chargeTDC1->AddAt(allData[in+54],in);
- chargeTDC2->AddAt(allData[in+78],in);
- }
-
- meanTime = allData[48]; // T0 !!!!!!
- timeDiff = allData[49];
-
- word = GetNextWord();
- word = GetNextWord();
-
- fDigits->SetTime(*timeTDC2);
- fDigits->SetADC(*chargeTDC1);
-
- fDigits->SetTimeAmp(*timeTDC1);
- fDigits->SetADCAmp(*chargeTDC2);
-
- fDigits->SetMeanTime(meanTime);
- fDigits->SetDiffTime(timeDiff);
- fTree->Fill();
-
- delete timeTDC1 ;
- delete chargeTDC1;
- delete timeTDC2 ;
- delete chargeTDC2;
-
- return kTRUE;
-}
-//_____________________________________________________________________________
-/*
-void AliT0RawReader::UnpackTime(Int_t outTime, Int_t outCh)
-{
- UInt_t word=0;
- UInt_t unpackword=0;
+ AliWarning(Form(" !!!! wrong DRM GLOBAL trailer %x!!!!", word));
+ fRawReader->AddFatalErrorLog(kWrongDRMTrailer,Form("w=%x",word));
+ }
+ if(fPrintout)
+ cout<<" DRM trailer ::event counter "<< AliBitPacking::UnpackWord(word,4,15)<<endl;
+ cout.setf( ios_base::dec, ios_base::basefield );
- word = GetNextWord();
- unpackword=AliBitPacking::UnpackWord(word,0,12);
- outTime=unpackword;
- unpackword= AliBitPacking::UnpackWord(word,21,27);
- outCh=unpackword;
- }
- */
+ return kTRUE;
+}
//_____________________________________________________________________________
Int_t AliT0RawReader::GetPosition()
{