LCOV - code coverage report
Current view: top level - TRD/TRDbase - AliTRDSignalIndex.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 73 224 32.6 %
Date: 2016-06-14 17:26:59 Functions: 12 23 52.2 %

          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             : //  General container for data from TRD detector segments                    //
      21             : //  Adapted from AliDigits, origin M.Ivanov                                  //
      22             : //                                                                           //
      23             : //  Author:                                                                  //
      24             : //    Mateusz Ploskon (ploskon@ikf.uni-frankfurt.de)                         //
      25             : //                                                                           //
      26             : ///////////////////////////////////////////////////////////////////////////////
      27             : 
      28             : #include <algorithm>
      29             : #include "TObject.h"
      30             : #include "AliLog.h"
      31             : #include "AliTRDSignalIndex.h"
      32             : 
      33          48 : ClassImp(AliTRDSignalIndex)
      34             : 
      35             : //_____________________________________________________________________________
      36             : AliTRDSignalIndex::AliTRDSignalIndex()
      37       14581 :   :TObject()
      38       14581 :   ,fDet(-1)
      39       14581 :   ,fLayer(-1)
      40       14581 :   ,fStack(-1)
      41       14581 :   ,fSM(-1)
      42       14581 :   ,fBoolIndex(NULL)
      43       14581 :   ,fSortedIndex(NULL)
      44       14581 :   ,fMaxLimit(0)
      45       14581 :   ,fPositionRC(0)
      46       14581 :   ,fCountRC(1)
      47       14581 :   ,fSortedWasInit(kFALSE)
      48       14581 :   ,fCurrRow(0)
      49       14581 :   ,fCurrCol(0)
      50       14581 :   ,fCurrTbin(0)
      51       14581 :   ,fNrows(0)
      52       14581 :   ,fNcols(0)
      53       14581 :   ,fNtbins(0)
      54       72905 : {
      55             :   //
      56             :   // Default contructor
      57             :   //
      58             : 
      59       14581 :   ResetCounters();
      60             : 
      61       29162 : }
      62             : 
      63             : //_____________________________________________________________________________
      64             : AliTRDSignalIndex::AliTRDSignalIndex(Int_t nrow, Int_t ncol,Int_t ntime)
      65           0 :   :TObject()
      66           0 :   ,fDet(-1)
      67           0 :   ,fLayer(-1)
      68           0 :   ,fStack(-1)
      69           0 :   ,fSM(-1)
      70           0 :   ,fBoolIndex(NULL)
      71           0 :   ,fSortedIndex(NULL)
      72           0 :   ,fMaxLimit(0)
      73           0 :   ,fPositionRC(0)
      74           0 :   ,fCountRC(1)
      75           0 :   ,fSortedWasInit(kFALSE)
      76           0 :   ,fCurrRow(0)
      77           0 :   ,fCurrCol(0)
      78           0 :   ,fCurrTbin(0)
      79           0 :   ,fNrows(0)
      80           0 :   ,fNcols(0)
      81           0 :   ,fNtbins(0)
      82           0 : {
      83             :   //
      84             :   // Not the default contructor... hmmm...
      85             :   //
      86             : 
      87           0 :   Allocate(nrow, ncol, ntime);  
      88             : 
      89           0 : }
      90             : 
      91             : //_____________________________________________________________________________
      92             : AliTRDSignalIndex::AliTRDSignalIndex(const AliTRDSignalIndex &a)
      93           0 :   :TObject(a)
      94           0 :   ,fDet(a.fDet)
      95           0 :   ,fLayer(a.fLayer)
      96           0 :   ,fStack(a.fStack)
      97           0 :   ,fSM(a.fSM)
      98           0 :   ,fBoolIndex(NULL)
      99           0 :   ,fSortedIndex(NULL)
     100           0 :   ,fMaxLimit(a.fMaxLimit)
     101           0 :   ,fPositionRC(a.fPositionRC)
     102           0 :   ,fCountRC(a.fCountRC)
     103           0 :   ,fSortedWasInit(a.fSortedWasInit)
     104           0 :   ,fCurrRow(a.fCurrRow)
     105           0 :   ,fCurrCol(a.fCurrCol)
     106           0 :   ,fCurrTbin(a.fCurrTbin)
     107           0 :   ,fNrows(a.fNrows)
     108           0 :   ,fNcols(a.fNcols)
     109           0 :   ,fNtbins(a.fNtbins)
     110           0 : {
     111             :   //
     112             :   // Copy constructor
     113             :   //
     114             : 
     115           0 :   fBoolIndex = new Bool_t[fMaxLimit];
     116           0 :   memcpy(fBoolIndex, a.fBoolIndex, fMaxLimit*sizeof(Bool_t));
     117             : 
     118           0 :   fSortedIndex = new RowCol[fMaxLimit+1];
     119           0 :   memcpy(fSortedIndex, a.fSortedIndex, (fMaxLimit+1)*sizeof(RowCol));
     120           0 : }
     121             : 
     122             : //_____________________________________________________________________________
     123             : AliTRDSignalIndex::~AliTRDSignalIndex()
     124       87486 : {
     125             :   //
     126             :   // Destructor
     127             :   //
     128             : 
     129       14581 :   if (fBoolIndex) {
     130        1240 :     delete [] fBoolIndex;
     131         620 :     fBoolIndex = NULL;
     132         620 :   }
     133             : 
     134       14581 : if (fSortedIndex) {
     135        1240 :     delete [] fSortedIndex;
     136         620 :     fSortedIndex = NULL;
     137         620 :   }
     138             : 
     139       43743 : }
     140             : 
     141             : //_____________________________________________________________________________
     142             : void AliTRDSignalIndex::Copy(TObject &a) const
     143             : {
     144             :   //
     145             :   // Copy function
     146             :   //
     147             : 
     148           0 :   ((AliTRDSignalIndex &)a).fDet           = fDet;
     149           0 :   ((AliTRDSignalIndex &)a).fLayer         = fLayer;
     150           0 :   ((AliTRDSignalIndex &)a).fStack         = fStack;
     151           0 :   ((AliTRDSignalIndex &)a).fSM            = fSM;
     152           0 :   ((AliTRDSignalIndex &)a).fMaxLimit      = fMaxLimit;
     153           0 :   ((AliTRDSignalIndex &)a).fPositionRC    = fPositionRC;
     154           0 :   ((AliTRDSignalIndex &)a).fCountRC       = fCountRC;
     155           0 :   ((AliTRDSignalIndex &)a).fSortedWasInit = fSortedWasInit;
     156           0 :   ((AliTRDSignalIndex &)a).fCurrRow       = fCurrRow;
     157           0 :   ((AliTRDSignalIndex &)a).fCurrCol       = fCurrCol;
     158           0 :   ((AliTRDSignalIndex &)a).fCurrTbin      = fCurrTbin;
     159           0 :   ((AliTRDSignalIndex &)a).fNrows         = fNrows;
     160           0 :   ((AliTRDSignalIndex &)a).fNcols         = fNcols;
     161           0 :   ((AliTRDSignalIndex &)a).fNtbins        = fNtbins;
     162             : 
     163           0 :   if(((AliTRDSignalIndex &)a).fBoolIndex)
     164             :     {
     165           0 :       delete [] ((AliTRDSignalIndex &)a).fBoolIndex;
     166             :     }
     167           0 :   ((AliTRDSignalIndex &)a).fBoolIndex = new Bool_t[fMaxLimit];
     168           0 :   memcpy(((AliTRDSignalIndex &)a).fBoolIndex, fBoolIndex, fMaxLimit*sizeof(Bool_t));
     169             : 
     170           0 :   if(((AliTRDSignalIndex &)a).fSortedIndex)
     171             :     {
     172           0 :       delete [] ((AliTRDSignalIndex &)a).fSortedIndex;
     173             :     }
     174           0 :   ((AliTRDSignalIndex &)a).fSortedIndex = new RowCol[fMaxLimit+1];
     175           0 :   memcpy(((AliTRDSignalIndex &)a).fSortedIndex, fSortedIndex, (fMaxLimit+1)*sizeof(RowCol));
     176             : 
     177           0 : }
     178             : 
     179             : //_____________________________________________________________________________
     180             : AliTRDSignalIndex& AliTRDSignalIndex::operator = (const AliTRDSignalIndex& a)
     181             : {
     182             :   //
     183             :   // Assignment operator
     184             :   //
     185             : 
     186           0 :   if (this == &a) {
     187           0 :     return *this;
     188             :   }
     189             : 
     190           0 :   fDet           = a.fDet;
     191           0 :   fLayer         = a.fLayer;
     192           0 :   fStack         = a.fStack;
     193           0 :   fSM            = a.fSM;
     194           0 :   fMaxLimit      = a.fMaxLimit;
     195           0 :   fPositionRC    = a.fPositionRC;
     196           0 :   fCountRC       = a.fCountRC;
     197           0 :   fSortedWasInit = a.fSortedWasInit;
     198           0 :   fCurrRow       = a.fCurrRow;
     199           0 :   fCurrCol       = a.fCurrCol;
     200           0 :   fCurrTbin      = a.fCurrTbin;
     201           0 :   fNrows         = a.fNrows;
     202           0 :   fNcols         = a.fNcols;
     203           0 :   fNtbins        = a.fNtbins;
     204             : 
     205           0 :   if (fBoolIndex) {
     206           0 :     delete [] fBoolIndex;
     207             :   }
     208           0 :   fBoolIndex = new Bool_t[fMaxLimit];
     209           0 :   memcpy(fBoolIndex, fBoolIndex, fMaxLimit*sizeof(Bool_t));
     210             : 
     211           0 :   if (fSortedIndex) {
     212           0 :     delete [] fSortedIndex;
     213             :   }
     214           0 :   fSortedIndex = new RowCol[fMaxLimit+1];
     215           0 :   memcpy(fSortedIndex, fSortedIndex, (fMaxLimit+1)*sizeof(RowCol));
     216             : 
     217           0 :   ResetCounters();
     218             : 
     219           0 :   return *this;
     220             : 
     221           0 : }
     222             : 
     223             : //_____________________________________________________________________________
     224             : void AliTRDSignalIndex::Allocate(const Int_t nrow, const Int_t ncol, const Int_t ntime)
     225             : {
     226             :   //
     227             :   // Create the arrays
     228             :   //
     229             : 
     230        1240 :   fNrows = nrow;
     231         620 :   fNcols = ncol;
     232         620 :   fNtbins = ntime;
     233             : 
     234         620 :   fMaxLimit = nrow * ncol + 1;
     235             : 
     236         620 :   if (fBoolIndex) {
     237           0 :     delete [] fBoolIndex;
     238           0 :     fBoolIndex = NULL;
     239           0 :   }
     240         620 :   if (fSortedIndex) {
     241           0 :     delete [] fSortedIndex;
     242           0 :     fSortedIndex = NULL;
     243           0 :   }
     244             : 
     245         620 :   fBoolIndex = new Bool_t[fMaxLimit];
     246         620 :   fSortedIndex = new RowCol[fMaxLimit+1];
     247             : 
     248         620 :   fCountRC = fMaxLimit+1;
     249             : 
     250         620 :   ResetArrays();
     251         620 :   ResetCounters();
     252             : 
     253         620 :   fCountRC = 1;
     254             : 
     255         620 : }
     256             : 
     257             : //_____________________________________________________________________________
     258             : void AliTRDSignalIndex::ResetArrays()
     259             : {
     260        1992 :   if (!IsAllocated())
     261             :     return;
     262         996 :   memset(fBoolIndex,0x00,sizeof(Bool_t)*fMaxLimit);
     263         996 :   memset(fSortedIndex,0xFF,sizeof(RowCol)*fCountRC); 
     264         996 :   fSortedWasInit = kFALSE;
     265        1992 : }
     266             : 
     267             : //_____________________________________________________________________________
     268             : void AliTRDSignalIndex::Reset()
     269             : {
     270             :   //
     271             :   // Reset the array but keep the size - realloc
     272             :   //
     273             : 
     274           0 :   fDet   = -1;
     275           0 :   fLayer = -1;
     276           0 :   fStack = -1;
     277           0 :   fSM    = -1;
     278             : 
     279             :   // All will be lost 
     280           0 :   Allocate(fNrows, fNcols, fNtbins);
     281             : 
     282           0 : }
     283             : 
     284             : //_____________________________________________________________________________
     285             : void AliTRDSignalIndex::ResetContent()
     286             : {
     287             :   //
     288             :   // Reset the array but keep the size - no realloc
     289             :   //
     290             : 
     291         752 :   fDet   = -1;
     292         376 :   fLayer = -1;
     293         376 :   fStack = -1;
     294         376 :   fSM    = -1;
     295             : 
     296         376 :   ResetArrays();
     297         376 :   ResetCounters();
     298             : 
     299         376 :   fCountRC = 1;
     300             : 
     301         376 : }
     302             : 
     303             : //_____________________________________________________________________________
     304             : void AliTRDSignalIndex::ResetContentConditional(const Int_t nrow, const Int_t ncol, const Int_t ntime)
     305             : {
     306             :   //
     307             :   // Reset the array but keep the size if no need to enlarge - no realloc
     308             :   //
     309             : 
     310           0 :   fDet   = -1;
     311           0 :   fLayer = -1;
     312           0 :   fStack = -1;
     313           0 :   fSM    = -1;
     314             : 
     315           0 :   if ((nrow  > fNrows) || 
     316           0 :       (ncol  > fNcols) || 
     317           0 :       (ntime > fNtbins)) {
     318           0 :     Allocate(nrow, ncol, ntime);
     319           0 :   }
     320             :   else {
     321           0 :     ResetArrays();
     322           0 :     ResetCounters();
     323           0 :     fCountRC = 1;
     324             :   }
     325             : 
     326           0 : }
     327             : 
     328             : //_____________________________________________________________________________
     329             : void AliTRDSignalIndex::ClearAll()
     330             : {
     331             :   //
     332             :   // Reset the values - clear all!
     333             :   //
     334             : 
     335           0 :   fDet    = -1;
     336           0 :   fLayer  = -1;
     337           0 :   fStack  = -1;
     338           0 :   fSM     = -1;
     339             : 
     340           0 :   fNrows  = -1;
     341           0 :   fNcols  = -1;
     342           0 :   fNtbins = -1;
     343             : 
     344           0 :   if (fBoolIndex) {
     345           0 :     delete [] fBoolIndex;
     346           0 :     fBoolIndex = NULL;
     347           0 :   }
     348             : 
     349           0 :   if (fSortedIndex) {
     350           0 :     delete [] fSortedIndex;
     351           0 :     fSortedIndex = NULL;
     352           0 :   }
     353             :   
     354           0 :   ResetCounters();
     355             : 
     356           0 :   fCountRC = 1;
     357           0 :   fSortedWasInit = kFALSE;
     358           0 :   fMaxLimit = 0;
     359             : 
     360           0 : }
     361             : 
     362             : //_____________________________________________________________________________
     363             : Bool_t  AliTRDSignalIndex::CheckSorting(Int_t &row, Int_t &col)
     364             : {
     365             :   //
     366             :   // Check whether array was read to end or it was not sorted until now
     367             :   //
     368             : 
     369       22828 :   if(fSortedWasInit || fCountRC==1)
     370             :     { //we already reached the end of the array
     371       10850 :       ResetCounters();
     372       10850 :       row = fCurrRow;
     373       10850 :       col = fCurrCol;
     374       10850 :       return kFALSE;
     375             :     }
     376             :   else
     377             :     { //we have not sorted the array up to now, let's do so
     378         376 :       InitSortedIndex();
     379         376 :       return NextRCIndex(row, col);
     380             :     }
     381       11226 : }
     382             : 
     383             : //_____________________________________________________________________________
     384             : Bool_t AliTRDSignalIndex::NextRCTbinIndex(Int_t &row, Int_t &col, Int_t &tbin)
     385             : {
     386             :   //
     387             :   // Returns the next tbin, or if there is no next time bin, it returns the
     388             :   // next used RC combination.
     389             :   //  
     390             : 
     391           0 :   if (NextTbinIndex(tbin)) {
     392           0 :     row = fCurrRow;
     393           0 :     col = fCurrCol;
     394           0 :     return kTRUE;
     395             :   }
     396             :   else {
     397           0 :     if (NextRCIndex(row, col)) {
     398           0 :       return NextRCTbinIndex(row, col, tbin);
     399             :     }
     400             :   }
     401             : 
     402           0 :   return kFALSE;
     403             : 
     404           0 : }
     405             : 
     406             : //_____________________________________________________________________________
     407             : Bool_t AliTRDSignalIndex::NextTbinIndex(Int_t &tbin)
     408             : {
     409             :   //
     410             :   // Returns the next tbin of the current RC combination
     411             :   //
     412             :   
     413           0 :   if(fCurrTbin<fNtbins)
     414             :     {
     415           0 :       tbin = fCurrTbin++;
     416           0 :       return kTRUE;
     417             :     }
     418             : 
     419           0 :   return kFALSE;
     420             : 
     421           0 : }
     422             : 
     423             : //_____________________________________________________________________________
     424             : void AliTRDSignalIndex::InitSortedIndex()
     425             : {
     426             :   //
     427             :   // Creates the SortedIndex
     428             :   //
     429             : 
     430         752 :   fSortedWasInit = kTRUE;
     431         376 :   std::sort((UShort_t*)fSortedIndex, ((UShort_t*)fSortedIndex) + fCountRC);
     432             : 
     433         376 : }
     434             : 
     435             : //_____________________________________________________________________________
     436             : void AliTRDSignalIndex::ResetCounters()    
     437             : { 
     438             :   //
     439             :   // Reset the counters/iterators
     440             :   //
     441             : 
     442       52854 :   fCurrRow    = -1;
     443       26427 :   fCurrCol    = -1;
     444       26427 :   fCurrTbin   = -1;
     445       26427 :   fPositionRC =  0;
     446       26427 : }

Generated by: LCOV version 1.11