LCOV - code coverage report
Current view: top level - FIT/FITbase - AliFITRawData.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 170 0.6 %
Date: 2016-06-14 17:26:59 Functions: 1 18 5.6 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : /* $Id$ */
      17             : 
      18             : ///////////////////////////////////////////////////////////////////////////////
      19             : //                                                                           //
      20             : //  FIT raw data conversion class                                            //
      21             : //                                                                           //
      22             : ///////////////////////////////////////////////////////////////////////////////
      23             : 
      24             : //#include <Riostream.h>
      25             : //#include <TTree.h>
      26             : #include <TMap.h>
      27             : #include "AliFIT.h"
      28             : #include "AliFITRawData.h"
      29             : #include "AliFITDigit.h"
      30             : #include "AliBitPacking.h"
      31             : #include "AliRawDataHeader.h"
      32             : #include "AliRawDataHeaderSim.h"
      33             : #include "AliBitPacking.h"
      34             : #include "AliFstream.h"
      35             : #include "AliRunLoader.h"
      36             : #include "AliDAQ.h"
      37             : #include "AliLog.h"
      38             : #include <iostream>
      39             : 
      40             : using std::cout;
      41             : using std::endl;
      42             : using std::ios_base;
      43             : 
      44           4 : ClassImp(AliFITRawData)
      45             : 
      46             : //_____________________________________________________________________________
      47           0 :   AliFITRawData::AliFITRawData():TObject(),
      48           0 :                                  fFITdigitArray(NULL),
      49           0 :                                  fVerbose(0),      
      50           0 :                                  fIndex(-1) ,     
      51           0 :                                  fEventNumber(0), 
      52           0 :                                  fDataHeaderPos(0),
      53           0 :                                  fFile(0x0)   
      54             :     
      55           0 : {
      56             :   /*
      57             :     -  160 channels (2 words each as in TOF DDL) for :
      58             :     word 1 :0-5bit number of PMT; word 2: 0-7 error sign, 8-31 TDC
      59             :     and the same but for amplified signal. Now I wrote the same time because
      60             :     CDF are not ready and differences didn't measured yet.
      61             :     
      62             :     -  160x2 channel for amplitude: very preliminary, QTC features are not
      63             :     known now, preliminary i put as T1 time signal for this PMT in first
      64             :     channel and T1+A in second, where A=Log(Amplitude);
      65             :     and the same for amplified but A=Log(10*Amplitude).
      66             :     
      67             :     - Or FIT-A and Or FIT-C 2 channels
      68             :     - FITA-FITC vertex information
      69             :     - Time Meaner (FITA+FITC)/2
      70             :     - 4 MPD  multiplicity signals sum amp both sides
      71             :   */
      72             :   //open the output file
      73             :   // char fileName[15];
      74           0 :   TString fileName = Form("%s",AliDAQ::DdlFileName("FIT",0));
      75           0 :   fFile = new AliFstream(fileName.Data());
      76           0 :   memset(fBuffer,0,512*sizeof(UInt_t));
      77             :   
      78             :   //get event number 
      79           0 :   AliRunLoader *runloader = AliRunLoader::Instance();
      80           0 :   if (runloader) {
      81           0 :     fEventNumber = runloader->GetEventNumber();
      82           0 :   }
      83           0 :    for ( Int_t k=0; k<1000; k++)   fAllData[k] = -1;
      84             : 
      85           0 : }
      86             : 
      87             : //_____________________________________________________________________________
      88             : 
      89           0 : AliFITRawData::AliFITRawData(const AliFITRawData &r):TObject(),
      90           0 :                                                      fFITdigitArray(NULL),
      91           0 :                                                      fVerbose(0),      
      92           0 :                                                      fIndex(-1) ,     
      93           0 :                                                      fEventNumber(0), 
      94           0 :                                                      fDataHeaderPos(0),
      95           0 :                                                      fFile(0x0)  
      96           0 : {
      97             :   //
      98             :   // AliFITrawData copy constructor
      99             :   //
     100             :   
     101           0 :   ((AliFITRawData &) r).Copy(*this);
     102           0 :   for ( Int_t k=0; k<1000; k++)   fAllData[k] = -1;
     103             : 
     104             :   
     105           0 : }
     106             : 
     107             : //_____________________________________________________________________________
     108             : AliFITRawData::~AliFITRawData()
     109           0 : {
     110             :   //
     111             :   // Destructor
     112             :   //
     113           0 : }
     114             : 
     115             : //_____________________________________________________________________________
     116             : AliFITRawData &AliFITRawData::operator=(const AliFITRawData &r)
     117             : {
     118             :   //
     119             :   // Assignment operator
     120             :   //
     121             :   
     122           0 :   if (this != &r) ((AliFITRawData &) r).Copy(*this);
     123           0 :   return *this;
     124             :   
     125             : }
     126             : 
     127             : //_____________________________________________________________________________
     128             : void AliFITRawData::GetDigits()
     129             : {
     130             :   
     131             :   //This method packs the FIT digits in a proper 32 bits structure
     132             : 
     133             :   //read FIT digits and fill TDC and ADC arrays
     134             :   
     135             :   Int_t digit = -1;
     136           0 :   Int_t ndigits = fFITdigitArray->GetEntries();
     137           0 :   AliDebug(2, Form(" Number of read digits = %d",ndigits));
     138             :   AliFITDigit *digs;
     139           0 :   for(Int_t i=0; i<1000; i++) fAllData[i]=-1;
     140             :   // loop on FIT digits
     141           0 :   for (digit=0; digit<ndigits; digit++) {
     142           0 :     digs = (AliFITDigit*)fFITdigitArray->UncheckedAt(digit);
     143           0 :     Int_t pmt = digs->NPMT();
     144           0 :     fAllData[pmt] = digs->TimeCFD();
     145           0 :     fAllData[pmt+240] = digs->TimeQT0();
     146           0 :     fAllData[pmt+480] = digs->TimeQT1();
     147             :   }
     148             :   //  Int_t error=0;
     149             :   
     150           0 : }
     151             : //---------------------------------------------------------------------------------------
     152             : 
     153             : Int_t AliFITRawData::RawDataFIT(TBranch* branch)
     154             : {
     155             :   //This method creates the Raw data files for FIT detector
     156             :   
     157             :   
     158             :   //max number of digits per DDL file times 2
     159             :   //  UInt_t fBuffer[kSize];
     160             :   //  UInt_t baseWord;
     161             :   // UInt_t word;
     162           0 :   cout.setf( ios_base::hex, ios_base::basefield );
     163             :   
     164           0 :   fIndex=-1;
     165           0 :   Int_t ch[4] = {0,2,4,6};
     166             :   
     167           0 :   fFITdigitArray = * (TClonesArray**) branch->GetAddress();
     168             : 
     169           0 :   AliRawDataHeaderSim header;
     170           0 :   WriteDataHeader(kTRUE, kFALSE);
     171             :   
     172           0 :   branch->GetEvent();
     173             :   
     174           0 :   GetDigits();
     175             :   
     176             :   Int_t time,  positionOfTRMHeader, iTDC, channel;
     177             :   //space for DRM header
     178           0 :   fIndex += 6;
     179             :   Int_t trm1words=0;
     180             :   
     181           0 :   for (Int_t itrm=0; itrm <4 ; itrm++) {
     182           0 :     Int_t startTRM=fIndex;
     183             :     //space for 1st TRM header
     184           0 :     fIndex ++;
     185             :     positionOfTRMHeader= fIndex;
     186             :     
     187           0 :     for (Int_t chain=0; chain <2 ; chain++) {
     188             :       // space for chain  header
     189           0 :       fIndex ++;
     190           0 :       WriteChainDataHeader(chain+1, 1); // 
     191             :       //data TRM 1 chain 1 
     192           0 :       for (Int_t det = 0; det < 60; det++) {
     193           0 :         time = fAllData[det + itrm*120 + chain*60];
     194           0 :         if (time >0 && time !=999999) {
     195           0 :           fIndex++;
     196           0 :           iTDC = det / 4;
     197           0 :           channel = ch[det - iTDC*4];
     198           0 :           AliDebug(2, Form("det %i  alldata %i trm %i chain %i tdc %i channel %i \n",det, det + itrm*120 + chain*60, itrm, chain, iTDC, det - iTDC*4) );
     199           0 :           FillTime(channel,iTDC, time);
     200           0 :         }
     201             :       } 
     202           0 :       fIndex++;
     203           0 :       WriteChainDataTrailer (chain+1);
     204             :     }
     205           0 :     fIndex++;
     206           0 :     WriteTrailer(15, 0,fEventNumber,5); // 1st TRM trailer
     207             :     
     208           0 :     trm1words = fIndex - startTRM;
     209           0 :     WriteTRMDataHeader(itrm, trm1words , positionOfTRMHeader);
     210             :   }
     211             :   
     212             :   //DRM trailer
     213           0 :   fIndex++;
     214           0 :   WriteTrailer(1,0,fEventNumber,5);
     215           0 :   WriteDRMDataHeader();
     216             :   
     217             :   //write packing digits    
     218           0 :   fFile->WriteBuffer((char*) fBuffer,((fIndex+1)*sizeof(UInt_t)));
     219             :   //write real data header on its place
     220           0 :   WriteDataHeader(kFALSE, kFALSE);
     221             :   
     222             :   
     223             :   //end for
     224             :   
     225           0 :   return 0;  
     226             :   
     227           0 : }
     228             : 
     229             : //_____________________________________________________________________________
     230             : 
     231             : void  AliFITRawData::WriteDRMDataHeader()
     232             : {
     233             :   //Write a (dummy or real) DDL DRM  data header, 
     234             :   //set the compression bit if compressed
     235             :   //  UInt_t drmheader[4];  
     236           0 :   cout.setf( ios_base::hex, ios_base::basefield );
     237             :   UInt_t word;
     238           0 :   UInt_t baseWord=0;
     239             :   //fill DRM headers
     240             :   //DRM Global Header
     241             :   word = 1;
     242           0 :   AliBitPacking::PackWord(word,baseWord,0, 3); // 0001 
     243           0 :   word = fIndex ;
     244           0 :   AliBitPacking::PackWord(word,baseWord,4, 20); // event words 
     245             :   word=124;
     246           0 :   AliBitPacking::PackWord(word,baseWord, 21, 27); // event words 
     247             :   word=4;
     248           0 :   AliBitPacking::PackWord(word,baseWord,28, 31);// 0100 marks header
     249           0 :   fBuffer[0]=  baseWord;
     250             :   //DRM status header 1
     251             :   word = 1;
     252           0 :   AliBitPacking::PackWord(word,baseWord,0, 3); // 0001 
     253             :   word = 1;
     254           0 :   AliBitPacking::PackWord(word,baseWord,4, 14); // slotID now 0000000001
     255             :   word = 1;
     256           0 :   AliBitPacking::PackWord(word,baseWord,15, 15); //if 1  LHC clock is coorectly recieved from CPDM 
     257             :   word=0;
     258           0 :   AliBitPacking::PackWord(word,baseWord,16,27); // reserve for future use
     259             :   word=4;
     260           0 :   AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
     261           0 :   fBuffer[1] = baseWord;
     262             :   
     263             :   word=0;
     264           0 :   baseWord=0;
     265             :   
     266             :   //DRM status header 2
     267             :   word = 1;
     268           0 :   AliBitPacking::PackWord(word,baseWord, 0, 3); // 0001 
     269             :   word = 3;
     270           0 :    AliBitPacking::PackWord(word,baseWord, 4, 14); //enable slotID now 00000000011
     271             :    word = 0;
     272           0 :    AliBitPacking::PackWord(word,baseWord, 15, 15); // something
     273             :    word=0;
     274           0 :    AliBitPacking::PackWord(word,baseWord, 16, 27); // fault ID for simulation 0
     275             :    word=4;
     276           0 :    AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
     277           0 :    fBuffer[2]=  baseWord;
     278             :    
     279             :    word=0;
     280           0 :    baseWord=0;
     281             :    //DRM status header 3
     282             :    word = 1;
     283           0 :    AliBitPacking::PackWord(word,baseWord,0, 3); // 0001 
     284             :    word = 0;
     285           0 :    AliBitPacking::PackWord(word,baseWord,4, 27); // TTC event counter
     286             :    word=4;
     287           0 :    AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
     288           0 :    fBuffer[3]=  baseWord;
     289             :     
     290             :    // new DRM format
     291           0 :    fBuffer[4]=  baseWord;
     292           0 :    fBuffer[5]=  baseWord;
     293             :    
     294             :    word=0;
     295           0 :    baseWord=0;
     296             :    
     297           0 : }
     298             :   
     299             : //_____________________________________________________________________________
     300             : 
     301             : void  AliFITRawData::WriteTRMDataHeader(UInt_t slotID, Int_t nWordsInTRM,
     302             :                                         Int_t  positionOfTRMHeader)
     303             : {
     304             :   //Write a (dummy or real) DDL TRM  data header, 
     305             :   //set the compression bit if compressed
     306             :   //  UInt_t trmheader;  
     307             :   UInt_t word;
     308           0 :   UInt_t baseWord=0;
     309             :   //fill TRM headers
     310             :   //TRM Global Header
     311             :   word = slotID;
     312           0 :   AliBitPacking::PackWord(word,baseWord,0, 3); // slotID
     313             :   word = nWordsInTRM;
     314             :  //+this word - DRM header 
     315             :   
     316           0 :   AliBitPacking::PackWord(word,baseWord,4, 16); // event words 
     317             :   word=0;
     318           0 :   AliBitPacking::PackWord(word,baseWord,17,18); // ACQ
     319             :   word=0;
     320           0 :   AliBitPacking::PackWord(word,baseWord,19,19); //  L SEY inside LUT
     321             :   word=0;
     322           0 :   AliBitPacking::PackWord(word,baseWord,20,27); //  MBZ
     323             :   word=4;
     324           0 :   AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
     325           0 :   fBuffer[positionOfTRMHeader] =  baseWord;
     326             :   word=0; 
     327           0 :   baseWord=0;
     328           0 : }
     329             : 
     330             : //_____________________________________________________________________________
     331             : 
     332             : void  AliFITRawData::WriteChainDataHeader(UInt_t chainNumber,UInt_t slotID)
     333             : {
     334             :   //Write a (dummy or real) DDL Chain  data header, 
     335             :   //set the compression bit if compressed
     336             :   //  chainNumber 00 or 10
     337             :   UInt_t word;
     338           0 :   UInt_t baseWord=0;
     339             :   //fill TRM headers
     340             :   //TRM Global Header
     341             :   word = slotID; // ask Tatiana 7 or 9 
     342           0 :   AliBitPacking::PackWord(word,baseWord,0, 3); // slotID
     343             :   word = 0;
     344           0 :   AliBitPacking::PackWord(word,baseWord,4, 15); // bunchID
     345             :   word=0;
     346           0 :   AliBitPacking::PackWord(word,baseWord,16,23); // PB24 temperature
     347             :   word=0;
     348           0 :   AliBitPacking::PackWord(word,baseWord,24,26); //  PB24 ID
     349             :   word=0;
     350           0 :   AliBitPacking::PackWord(word,baseWord,27,27); //  TS
     351             :   word=chainNumber;
     352           0 :   AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
     353           0 :   fBuffer[fIndex] =  baseWord;
     354             :   word=0;
     355           0 :   baseWord=0;     
     356           0 : }
     357             : //_____________________________________________________________________________
     358             : 
     359             : void  AliFITRawData::WriteChainDataTrailer(UInt_t chainNumber )
     360             : {
     361             :   //Write a (dummy or real) DDL Chain  data trailer 
     362             :   //set the compression bit if compressed
     363             :   //  chainNumber 00 or 10
     364             :   UInt_t word;
     365           0 :   UInt_t baseWord=0;
     366             :   word = 0; // ask Tatiana 7 or 9 
     367           0 :   AliBitPacking::PackWord(word,baseWord,0, 3); // status
     368             :   word = 0;
     369           0 :   AliBitPacking::PackWord(word,baseWord,4, 15); // MBZ
     370           0 :   word=fEventNumber;
     371           0 :   AliBitPacking::PackWord(word,baseWord,16,27); // event counter
     372             :   word=chainNumber;
     373           0 :   AliBitPacking::PackWord(word,baseWord,28,31); // chain number
     374             :  // fIndex++;
     375           0 :   fBuffer[fIndex] =  baseWord;
     376             : 
     377             :   word=0;
     378           0 :   baseWord=0;       
     379           0 : }
     380             : //_____________________________________________________________________________
     381             : 
     382             : void  AliFITRawData::WriteDataHeader(Bool_t dummy, Bool_t compressed)
     383             : {
     384             :   //Write a (dummy or real) DDL data header, 
     385             :   //set the compression bit if compressed
     386             :   
     387           0 :   AliRawDataHeaderSim header;
     388             :   
     389           0 :   if (dummy) {
     390             :     //if size=0 it means that this data header is a dummy data header
     391           0 :     fDataHeaderPos = fFile->Tellp();
     392           0 :     fFile->WriteBuffer((char*)(&header), sizeof(header));
     393           0 :   } else {
     394           0 :     UInt_t currentFilePos = fFile->Tellp();
     395           0 :     fFile->Seekp(fDataHeaderPos);
     396           0 :     header.fSize = currentFilePos-fDataHeaderPos;
     397           0 :     header.SetAttribute(0);  // valid data
     398           0 :     if (compressed) header.SetAttribute(1); 
     399           0 :     fFile->WriteBuffer((char*)(&header), sizeof(header));
     400           0 :     fFile->Seekp(currentFilePos);
     401             :   }
     402             :   
     403           0 : }
     404             : 
     405             : //___ __________________________________________________________________________
     406             : void  AliFITRawData::WriteTrailer(UInt_t slot, Int_t word1, UInt_t word2, UInt_t word3)
     407             : {
     408             :   //Write a (dummy or real) DDL Chain  data trailer 
     409             :   
     410             :   UInt_t word;
     411           0 :   UInt_t baseWord=0;
     412             :   word = slot;
     413           0 :   AliBitPacking::PackWord(word,baseWord,0, 3); // 0001 
     414             :   word=word1;
     415           0 :   AliBitPacking::PackWord(word,baseWord,4, 15); // CRC ?
     416             :   word = word2;
     417           0 :   AliBitPacking::PackWord(word,baseWord,16,27); // event counter
     418             :   word=word3;
     419           0 :   AliBitPacking::PackWord(word,baseWord,28,31); //  marks trailer
     420           0 :   fBuffer[fIndex] =  baseWord;
     421             :   word=0;
     422           0 :   baseWord=0;
     423             :   
     424           0 : }
     425             : 
     426             : //---------------------------------------------------------------------------------------
     427             : void  AliFITRawData::FillTime(Int_t ch, Int_t iTDC, Int_t time)
     428             : {
     429             :   //  put all time fields thother in 1 word
     430             :   
     431             :   UInt_t word;
     432           0 :   UInt_t baseWord=0;
     433             :   
     434             :   word=time;
     435           0 :   AliBitPacking::PackWord(word,baseWord, 0, 20); // Time 
     436             :   
     437             :   word=ch;
     438           0 :   AliBitPacking::PackWord(word,baseWord, 21, 23); // number of channel 
     439             :   word=iTDC;
     440           0 :   AliBitPacking::PackWord(word,baseWord, 24, 27); // TDC ID
     441             :   
     442             :   word=0;
     443           0 :   AliBitPacking::PackWord(word,baseWord, 28, 28); // E = 0 in simulation
     444             :   word=0;
     445           0 :   AliBitPacking::PackWord(word,baseWord, 29, 30); // PS bit data 00
     446             :   word=1;
     447           0 :   AliBitPacking::PackWord(word,baseWord, 31, 31); // 1
     448           0 :   fBuffer[fIndex]=baseWord;
     449             :   word=0;
     450           0 :   baseWord=0;
     451           0 : }

Generated by: LCOV version 1.11