- }
- }
- }
-
- delete [] mcm;
-
- // Write end of raw data marker
- if (nw < maxSize) {
- buf[nw++] = kEndofrawdatamarker;
- } else {
- of++;
- }
-
- if (of != 0) {
- AliError("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
- }
-
- return nw;
-}
-
-
-//_____________________________________________________________________________
-Int_t AliTRDrawData::ProduceHcDataV1andV2(AliTRDarrayADC *digits, Int_t side
- , Int_t det, UInt_t *buf, Int_t maxSize)
-{
- //
- // This function simulates: 1) SM-I commissiong data Oct. 06 (Raw Version == 1).
- // 2) Full Raw Production Version (Raw Version == 2)
- //
- // Produce half chamber data (= an ORI data) for the given chamber (det) and side (side)
- // where
- //
- // side=0 means A side with ROB positions 0, 2, 4, 6.
- // side=1 means B side with ROB positions 1, 3, 5, 7.
- //
- // Chamber type (C0 orC1) is determined by "det" automatically.
- // Appropriate size of buffer (*buf) must be prepared prior to calling this function.
- // Pointer to the buffer and its size must be given to "buf" and "maxSize".
- // Return value is the number of valid data filled in the buffer in unit of 32 bits
- // UInt_t words.
- // If buffer size if too small, the data is truncated with the buffer size however
- // the function will finish without crash (this behaviour is similar to the MCM).
- //
-
- Int_t nw = 0; // Number of written words
- Int_t of = 0; // Number of overflowed words
- Int_t layer = fGeo->GetLayer( det ); // Layer
- Int_t stack = fGeo->GetStack( det ); // Stack
- Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
- Int_t nRow = fGeo->GetRowMax( layer, stack, sect );
- Int_t nCol = fGeo->GetColMax( layer );
- const Int_t kNTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
- Int_t kCtype = 0; // Chamber type (0:C0, 1:C1)
- Int_t iEv = 0xA; // Event ID. Now fixed to 10, how do I get event id?
- UInt_t x = 0; // General used number
- Int_t rv = fFee->GetRAWversion();
-
- // Check the nCol and nRow.
- if ((nCol == 144) &&
- (nRow == 16 || nRow == 12)) {
- kCtype = (nRow-12) / 4;
- }
- else {
- AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)."
- ,nRow,nCol));
- return 0;
- }
-
- AliDebug(1,Form("Producing raw data for sect=%d layer=%d stack=%d side=%d"
- ,sect,layer,stack,side));
-
- // Tracklet should be processed here but not implemented yet
-
- // Write end of tracklet marker
- if (nw < maxSize) {
- buf[nw++] = kEndoftrackletmarker;
- }
- else {
- of++;
- }
-
- // Half Chamber header
- if ( rv == 1 ) {
- // Now it is the same version as used in SM-I commissioning.
- Int_t dcs = det+100; // DCS Serial (in simulation, it is meaningless
- x = (dcs<<20) | (sect<<15) | (layer<<12) | (stack<<9) | (side<<8) | 1;
- if (nw < maxSize) {
- buf[nw++] = x;
- }
- else {
- of++;
- }
- }
- else if ( rv == 2 ) {
- // h[0] (there are 3 HC header)
- Int_t minorv = 0; // The minor version number
- Int_t add = 2; // The number of additional header words to follow
- x = (1<<31) | (rv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (layer<<6) | (stack<<3) | (side<<2) | 1;
- if (nw < maxSize) {
- buf[nw++] = x;
- }
- else {
- of++;
- }
- // h[1]
- Int_t bcCtr = 99; // bunch crossing counter. Here it is set to 99 always for no reason
- Int_t ptCtr = 15; // pretrigger counter. Here it is set to 15 always for no reason
- Int_t ptPhase = 11; // pretrigger phase. Here it is set to 11 always for no reason
- x = (bcCtr<<16) | (ptCtr<<12) | (ptPhase<<8) | ((kNTBin-1)<<2) | 1;
- if (nw < maxSize) {
- buf[nw++] = x;
- }
- else {
- of++;
- }
- // h[2]
- Int_t pedSetup = 1; // Pedestal filter setup (0:1). Here it is always 1 for no reason
- Int_t gainSetup = 1; // Gain filter setup (0:1). Here it is always 1 for no reason
- Int_t tailSetup = 1; // Tail filter setup (0:1). Here it is always 1 for no reason
- Int_t xtSetup = 0; // Cross talk filter setup (0:1). Here it is always 0 for no reason
- Int_t nonlinSetup = 0; // Nonlinearity filter setup (0:1). Here it is always 0 for no reason
- Int_t bypassSetup = 0; // Filter bypass (for raw data) setup (0:1). Here it is always 0 for no reason
- Int_t commonAdditive = 10; // Digital filter common additive (0:63). Here it is always 10 for no reason
- x = (pedSetup<<31) | (gainSetup<<30) | (tailSetup<<29) | (xtSetup<<28) | (nonlinSetup<<27)
- | (bypassSetup<<26) | (commonAdditive<<20) | 1;
- if (nw < maxSize) {
- buf[nw++] = x;
- }
- else {
- of++;
- }
- }
-
- // Scan for ROB and MCM
- for (Int_t iRobRow = 0; iRobRow < (kCtype + 3); iRobRow++ ) {
- Int_t iRob = iRobRow * 2 + side;
- for (Int_t iMcm = 0; iMcm < fGeo->MCMmax(); iMcm++ ) {
- Int_t padrow = iRobRow * 4 + iMcm / 4;
-
- // MCM header
- x = ((iRob * fGeo->MCMmax() + iMcm) << 24) | ((iEv % 0x100000) << 4) | 0xC;
- if (nw < maxSize) {
- buf[nw++] = x;
- }
- else {
- of++;
- }
-
- // ADC data
- for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) {
- Int_t padcol = fFee->GetPadColFromADC(iRob, iMcm, iAdc);
- UInt_t aa = !(iAdc & 1) + 2;
- UInt_t *a = new UInt_t[kNTBin+2];
- // 3 timebins are packed into one 32 bits word
- for (Int_t iT = 0; iT < kNTBin; iT+=3) {
- if ((padcol >= 0) && (padcol < nCol)) {
- a[iT ] = ((iT ) < kNTBin ) ? digits->GetData(padrow,padcol,iT ) : 0;
- a[iT+1] = ((iT + 1) < kNTBin ) ? digits->GetData(padrow,padcol,iT + 1) : 0;
- a[iT+2] = ((iT + 2) < kNTBin ) ? digits->GetData(padrow,padcol,iT + 2) : 0;
- }
- else {
- a[iT] = a[iT+1] = a[iT+2] = 0; // This happenes at the edge of chamber (should be pedestal! How?)
- }
- x = (a[iT+2] << 22) | (a[iT+1] << 12) | (a[iT] << 2) | aa;
- if (nw < maxSize) {
- buf[nw++] = x;
- }
- else {
- of++;
- }
- }
- // Diagnostics
- Float_t avg = 0;
- Float_t rms = 0;
- for (Int_t iT = 0; iT < kNTBin; iT++) {
- avg += (Float_t) (a[iT]);
- }
- avg /= (Float_t) kNTBin;
- for (Int_t iT = 0; iT < kNTBin; iT++) {
- rms += ((Float_t) (a[iT]) - avg) * ((Float_t) (a[iT]) - avg);
- }
- rms = TMath::Sqrt(rms / (Float_t) kNTBin);
- if (rms > 1.7) {
- AliDebug(2,Form("Large RMS (>1.7) (ROB,MCM,ADC)=(%02d,%02d,%02d), avg=%03.1f, rms=%03.1f"
- ,iRob,iMcm,iAdc,avg,rms));
- }
- delete [] a;
- }
- }
- }
-
- // Write end of raw data marker
- if (nw < maxSize) {
- buf[nw++] = kEndofrawdatamarker;
- }
- else {
- of++;
- }
- if (of != 0) {
- AliWarning("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
- }
-
- return nw;
-
-}
-
-//_____________________________________________________________________________
-
-//Int_t AliTRDrawData::ProduceHcDataV3(AliTRDarrayADC *digits, Int_t side , Int_t det, UInt_t *buf, Int_t maxSize)
-Int_t AliTRDrawData::ProduceHcDataV3(AliTRDarrayADC *digits, Int_t side , Int_t det, UInt_t *buf, Int_t maxSize, Bool_t newEvent = kFALSE)
-{
- //
- // This function simulates: Raw Version == 3 (Zero Suppression Prototype)
- //
-
- Int_t nw = 0; // Number of written words
- Int_t of = 0; // Number of overflowed words
- Int_t layer = fGeo->GetLayer( det ); // Layer
- Int_t stack = fGeo->GetStack( det ); // Stack
- Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
- Int_t nRow = fGeo->GetRowMax( layer, stack, sect );
- Int_t nCol = fGeo->GetColMax( layer );
- const Int_t kNTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
- Int_t kCtype = 0; // Chamber type (0:C0, 1:C1)
- //Int_t iEv = 0xA; // Event ID. Now fixed to 10, how do I get event id?
-
-
-
- Bool_t tracklet_on = fFee->GetTracklet(); // **new**
-
- // Check the nCol and nRow.
- if ((nCol == 144) &&
- (nRow == 16 || nRow == 12)) {
- kCtype = (nRow-12) / 4;
- }
- else {
- AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)."
- ,nRow,nCol));
- return 0;
- }
-
- AliDebug(1,Form("Producing raw data for sect=%d layer=%d stack=%d side=%d"
- ,sect,layer,stack,side));
-
- AliTRDmcmSim** mcm = new AliTRDmcmSim*[(kCtype + 3)*(fGeo->MCMmax())];
-
- // in case no tracklet-words are processed: write the tracklet-endmarker as well as all additional words immediately and write
- // raw-data in one go; if tracklet-processing is enabled, first all tracklet-words of a half-chamber have to be processed before the
- // additional words (tracklet-endmarker,headers,...)are written. Raw-data is written in a second loop;
-
- if (!tracklet_on) {
- WriteIntermediateWords(buf,nw,of,maxSize,det,side);
- }
-
- // Scan for ROB and MCM
- // scanning direction such, that tracklet-words are sorted in ascending z and then in ascending y order
- // ROB numbering on chamber and MCM numbering on ROB increase with decreasing z and increasing y
- for (Int_t iRobRow = (kCtype + 3)-1; iRobRow >= 0; iRobRow-- ) {
- Int_t iRob = iRobRow * 2 + side;
- // MCM on one ROB
- for (Int_t iMcmRB = 0; iMcmRB < fGeo->MCMmax(); iMcmRB++ ) {
- Int_t iMcm = 16 - 4*(iMcmRB/4 + 1) + (iMcmRB%4);
- Int_t entry = iRobRow*(fGeo->MCMmax()) + iMcm;
-
- mcm[entry] = new AliTRDmcmSim();
- mcm[entry]->Init( det, iRob, iMcm , newEvent);
- //mcm[entry]->Init( det, iRob, iMcm);
- if (newEvent == kTRUE) newEvent = kFALSE; // only one mcm is concerned with new event
- Int_t padrow = mcm[entry]->GetRow();
-
- // Copy ADC data to MCM simulator
- for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) {
- Int_t padcol = mcm[entry]->GetCol( iAdc );
- if ((padcol >= 0) && (padcol < nCol)) {
- for (Int_t iT = 0; iT < kNTBin; iT++) {
- mcm[entry]->SetData( iAdc, iT, digits->GetData( padrow, padcol, iT) );
- }
- }
- else { // this means it is out of chamber, and masked ADC
- mcm[entry]->SetDataPedestal( iAdc );
- }
- }
-
- // Simulate process in MCM
- // mcm[entry]->Filter(); // Apply filter
- // mcm[entry]->ZSMapping(); // Calculate zero suppression mapping
- mcm[entry]->CopyArrays();
- mcm[entry]->GeneratefZSM1Dim();
- mcm[entry]->RestoreZeros();
-
- if (tracklet_on) {
- mcm[entry]->Tracklet();
- Int_t tempNw = mcm[entry]->ProduceTrackletStream( &buf[nw], maxSize - nw );
- //Int_t tempNw = 0;
- if( tempNw < 0 ) {
- of += tempNw;
- nw += maxSize - nw;
- AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
- } else {
- nw += tempNw;
- }
- }
- // no tracklets: write raw-data already in this loop
- else {
- // Write MCM data to buffer
- Int_t tempNw = mcm[entry]->ProduceRawStream( &buf[nw], maxSize - nw );
- if( tempNw < 0 ) {
- of += tempNw;
- nw += maxSize - nw;
- AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
- } else {
- nw += tempNw;
- }
-
- delete mcm[entry];
- }
-
-
-
-
- //mcm->DumpData( "trdmcmdata.txt", "RFZS" ); // debugging purpose
- }
- }
-
- // if tracklets are switched on, raw-data can be written only after all tracklets
- if (tracklet_on) {
- WriteIntermediateWords(buf,nw,of,maxSize,det,side);
-
-
- // Scan for ROB and MCM
- for (Int_t iRobRow = (kCtype + 3)-1; iRobRow >= 0; iRobRow-- ) {
- //Int_t iRob = iRobRow * 2 + side;
- // MCM on one ROB
- for (Int_t iMcmRB = 0; iMcmRB < fGeo->MCMmax(); iMcmRB++ ) {