LCOV - code coverage report
Current view: top level - AD/ADsim - AliADBuffer.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 102 1.0 %
Date: 2016-06-14 17:26:59 Functions: 1 18 5.6 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-2003, 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             : /* $Id$ */
      16             : 
      17             : // Storing digits in a binary file
      18             : // according to the DDL mapping
      19             : // Author: B. Cheynis
      20             : 
      21             : #include <Riostream.h>
      22             : #include <TObjArray.h>
      23             : #include <TMath.h>
      24             : 
      25             : #include "AliLog.h"
      26             : #include "AliRawDataHeaderSim.h"
      27             : #include "AliADBuffer.h"
      28             : #include "AliADdigit.h"
      29             : #include "AliADConst.h"
      30             : #include "AliFstream.h"
      31             : 
      32          12 : ClassImp(AliADBuffer)
      33             : 
      34             : //_____________________________________________________________________________
      35           0 : AliADBuffer::AliADBuffer():TObject(),
      36           0 :     fRemainingWord(0),
      37           0 :     f()
      38           0 : {
      39             :   //
      40             :   // default constructor
      41             :   //
      42           0 : }
      43             : //_____________________________________________________________________________
      44           0 : AliADBuffer::AliADBuffer(const char* fileName):TObject(),
      45           0 :     fRemainingWord(0),
      46           0 :     f()
      47           0 : {
      48             :   // Constructor
      49           0 :   f = new AliFstream(fileName);
      50           0 :   AliRawDataHeaderSim header;
      51           0 :   f->WriteBuffer((char*)(&header), sizeof(header));
      52             : 
      53           0 : }
      54             : 
      55             : //_____________________________________________________________________________
      56           0 : AliADBuffer::~AliADBuffer(){
      57             :   // Destructor, it closes the IO stream
      58           0 :   AliRawDataHeaderSim header;
      59           0 :   header.fSize = f->Tellp();
      60           0 :   header.SetAttribute(0);  // valid data
      61           0 :   f->Seekp(0);
      62           0 :   f->WriteBuffer((char*)(&header), sizeof(header));
      63           0 :   delete f;
      64           0 : }
      65             : 
      66             : //_____________________________________________________________________________
      67             : void AliADBuffer::WriteTriggerInfo(UInt_t trigger) {
      68             :   // The method writes AD trigger information
      69             :   // This info is contained in the first two
      70             :   // raw-data words following the raw-data header (CDH).
      71             : 
      72           0 :   f->WriteBuffer((char*)(&trigger),sizeof(trigger));
      73             : 
      74             :   // By default all the inputs are unmasked... Hopefully
      75           0 :   UInt_t triggerMask = 0xffff;
      76           0 :   f->WriteBuffer((char*)(&triggerMask),sizeof(triggerMask));
      77           0 : }
      78             : 
      79             : //_____________________________________________________________________________
      80             : void AliADBuffer::WriteTriggerScalers() {
      81             :   // The method writes the AD trigger scalers
      82             :   // For the moment there is no way to simulate
      83             :   // this, so we fill the necessary 16 words with 0
      84             : 
      85             :   // First the general trigger scalers (16 of them)
      86           0 :   for(Int_t i = 0; i < 16; i++) {
      87           0 :       UInt_t data = 0;
      88           0 :       f->WriteBuffer((char*)&data,sizeof(data));
      89           0 :   }
      90           0 : }
      91             : 
      92             : //_____________________________________________________________________________
      93             : void AliADBuffer::WriteBunchNumbers() {
      94             :   // The method writes the Bunch Numbers corresponding 
      95             :   // to the 10 Minimum Bias events
      96             :   // For the moment there is no way to simulate
      97             :   // this, so we fill the necessary 10 words with 0
      98             : 
      99             :   // First the bunch crossing numbers
     100             :   // for these 10 events
     101             :   
     102           0 :   for(Int_t i = 0; i < 10; i++) {
     103           0 :       UInt_t data = 0;
     104           0 :       f->WriteBuffer((char*)&data,sizeof(data));
     105           0 :   }
     106             : 
     107           0 : }
     108             : 
     109             : //_____________________________________________________________________________
     110             : void AliADBuffer::WriteChannel(Int_t channel, Short_t *adc, Bool_t integrator){
     111             :   // It writes AD charge information into a raw data file. 
     112             :   // Being called by Digits2Raw
     113             :   
     114           0 :   UInt_t data = 0;
     115           0 :   for(Int_t i = 0; i < kADNClocks; ++i) {
     116           0 :     if (adc[i] > 1023) {
     117           0 :       AliWarning(Form("ADC (channel=%d) saturated: %d. Truncating to 1023",channel,adc[i]));
     118           0 :       adc[i] = 1023;
     119           0 :     }
     120             :   }
     121             :   
     122           0 :   if(channel%2 == 0) {
     123           0 :     for(Int_t i = 0; i < (kADNClocks/2); ++i) {
     124           0 :       data =   (adc[2*i] & 0x3ff);
     125           0 :       data |= ((integrator & 0x1) << 10);
     126             : 
     127           0 :       data |= ((adc[2*i+1] & 0x3ff) << 16);
     128           0 :       data |= ((!integrator & 0x1) << 26);
     129             : 
     130           0 :       f->WriteBuffer((char*)&data,sizeof(data));
     131             :     }
     132           0 :     fRemainingWord = (adc[kADNClocks-1] & 0x3ff);
     133           0 :     fRemainingWord |= ((integrator & 0x1) << 10);
     134           0 :   }
     135             :   else {
     136           0 :     data = fRemainingWord;
     137           0 :     data |= ((adc[0] & 0x3ff) << 16);
     138           0 :     data |= ((integrator & 0x1) << 26);
     139           0 :     f->WriteBuffer((char*)&data,sizeof(data));
     140             : 
     141           0 :     for(Int_t i = 1; i <= (kADNClocks/2); ++i) {
     142           0 :       data =   (adc[2*i-1] & 0x3ff);
     143           0 :       data |= ((!integrator & 0x1) << 10);
     144             : 
     145           0 :       data |= ((adc[2*i] & 0x3ff) << 16);
     146           0 :       data |= ((integrator & 0x1) << 26);
     147             : 
     148           0 :       f->WriteBuffer((char*)&data,sizeof(data));
     149             :     }
     150             :   }
     151             :     
     152           0 : }
     153             : 
     154             : //_____________________________________________________________________________
     155             : void AliADBuffer::WriteBeamFlags(Bool_t *bbFlag, Bool_t *bgFlag) {
     156             :   // The method writes information about
     157             :   // the Beam-Beam and Beam-Gas flags i.e. 
     158             :   // 6  words for the 4 channels 
     159             :   // of half a CIU card
     160             : 
     161             :   // Beam-beam and beam-gas flags are available
     162             :   // only for the triggered event-of-interest (sample index = 10)
     163             :   // As soon as trigger simulation would become more complex
     164             :   // and would allow to simulate neighbouring samples, this code
     165             :   // should be extended in order to fill all (or fraction) of the
     166             :   // flags
     167           0 :   for(Int_t i = 0; i < 2; i++) {
     168           0 :     UInt_t data = 0;
     169           0 :     f->WriteBuffer((char*)&data,sizeof(data));
     170           0 :   }
     171             :   {
     172           0 :     UInt_t data = 0;
     173           0 :     for(Int_t iChannel = 0; iChannel < 4; ++iChannel) {
     174           0 :       if (bbFlag[iChannel]) data |= (1 << (2*iChannel + 16));
     175           0 :       if (bgFlag[iChannel]) data |= (1 << (2*iChannel + 17));
     176             :     }
     177           0 :     f->WriteBuffer((char*)&data,sizeof(data));
     178           0 :   }  
     179           0 :   for(Int_t i = 0; i < 3; i++) {
     180           0 :     UInt_t data = 0;
     181           0 :     f->WriteBuffer((char*)&data,sizeof(data));
     182           0 :   }
     183             : 
     184           0 : }
     185             : 
     186             : //_____________________________________________________________________________
     187             : void AliADBuffer::WriteMBInfo() {
     188             :   // The method writes information about
     189             :   // the 10 previous minimum-bias events
     190             :   // i.e. channels charge for each of these
     191             :   // 10 events (4*10 shorts for the 4 channels 
     192             :   // of half a CIU card)
     193             :     
     194           0 :   for(Int_t i = 0; i < 20; i++) {
     195           0 :     UInt_t data = 0;
     196           0 :     f->WriteBuffer((char*)&data,sizeof(data));
     197           0 :   }
     198           0 : }
     199             : 
     200             : 
     201             : //_____________________________________________________________________________
     202             : void AliADBuffer::WriteMBFlags() {
     203             :   // The method writes information about
     204             :   // the Minimum Bias flags
     205             :   // 5 16-bits words for the 4 channels 
     206             :   // of half a CIU card + one empty 16-bit
     207             : 
     208             : 
     209           0 :   for(Int_t i = 0; i < 3; i++) {
     210           0 :     UInt_t data = 0;
     211           0 :     f->WriteBuffer((char*)&data,sizeof(data));  
     212           0 :     }
     213           0 : }
     214             : 
     215             : //_____________________________________________________________________________
     216             : void AliADBuffer::WriteBeamScalers() {
     217             :   // The method writes the AD beam scalers
     218             :   // For the moment there is no way to simulate
     219             :   // this, so we fill the necessary words with 0
     220             : 
     221             :   // Beam-beam and beam-gas scalers for
     222             :   // 4 individual channel (4x4 words)
     223             :   // (64-bit + 64-bit)*4 = 32bit * 16
     224             :   
     225           0 :   for(Int_t i = 0; i < 16; i++) {
     226           0 :     UInt_t data = 0;
     227           0 :     f->WriteBuffer((char*)&data,sizeof(data));
     228           0 :   }
     229           0 : }
     230             : 
     231             : //_____________________________________________________________________________
     232             : void AliADBuffer::WriteTiming(Short_t time, Short_t width) {
     233             :   // It writes the timing information into a raw data file. 
     234             :   // Being called by Digits2Raw
     235             : 
     236             :   // Writes the timing information
     237           0 :   UInt_t data = time & 0xfff;
     238           0 :   data |= (width & 0x7f) << 12;
     239           0 :   f->WriteBuffer((char*)&data,sizeof(data));
     240           0 : }
     241             : 
     242             : //_____________________________________________________________________________
     243             : void AliADBuffer::WriteEmptyCIU() {
     244             :   // The method writes holes in stream due to missing CIUs Ad has 2 vrt. to 8 VZERO 
     245             :   // There are 182 words per CIU
     246           0 :   for(Int_t i = 0; i < 182; i++) {
     247           0 :       UInt_t data = 0;
     248           0 :       f->WriteBuffer((char*)&data,sizeof(data));
     249           0 :   }
     250           0 : }

Generated by: LCOV version 1.11