]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/ESD/AliTriggerCluster.cxx
test
[u/mrichter/AliRoot.git] / STEER / ESD / AliTriggerCluster.cxx
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 //  Class to define a Trigger Cluster  
21 //
22 //  A Trigger Cluster is a group of detector to be trigger together
23 //
24 ///////////////////////////////////////////////////////////////////////////////
25
26 #include <Riostream.h>
27
28 #include <TObject.h>
29 #include <TClass.h>
30 #include <TString.h>
31 #include <TMath.h>
32
33 #include "AliLog.h"
34 #include "AliDAQ.h"
35 #include "AliTriggerCluster.h"
36 #include "AliTriggerInput.h"
37
38 using std::endl;
39 using std::cout;
40 ClassImp( AliTriggerCluster )
41
42 //_____________________________________________________________________________
43 AliTriggerCluster::AliTriggerCluster(): 
44   TNamed(),
45   fClusterMask(0)
46 {
47 }
48
49 //_____________________________________________________________________________
50 AliTriggerCluster::AliTriggerCluster( TString & name, UChar_t index, TString & detectors ) :
51   TNamed(name,detectors),
52   fClusterMask((index <=6) ? 1 << (index-1) : 0)
53 {
54   TString detClus;
55   for( Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++ ) {
56     if( IsSelected( AliTriggerInput::fgkCTPDetectorName[iDet], fTitle )) {
57       // Add the detector
58       detClus.Append( " " );
59       detClus.Append( AliDAQ::DetectorName(iDet) );
60     }
61   }
62   SetTitle(detClus.Data());
63 }
64
65 //_____________________________________________________________________________
66 AliTriggerCluster::AliTriggerCluster( const AliTriggerCluster &clus ):
67   TNamed(clus),
68   fClusterMask(clus.fClusterMask)
69 {
70   // Copy constructor
71 }
72
73 //_____________________________________________________________________________
74 Bool_t AliTriggerCluster::IsDetectorInCluster( TString & detName )
75 {
76    // search for the given detector
77    Bool_t result = kFALSE;
78    if( (fTitle.CompareTo( detName ) == 0) ||
79         fTitle.BeginsWith( detName+" " ) ||
80         fTitle.EndsWith( " "+detName ) ||
81         fTitle.Contains( " "+detName+" " ) ) {
82       result = kTRUE;
83    }
84    return result;
85 }
86
87
88 //_____________________________________________________________________________
89 void AliTriggerCluster::Print( const Option_t* ) const
90 {
91    // Print
92    cout << "Detector Cluster:" << endl;
93    cout << "  Name:           " << GetName() << endl;
94    cout << "  Cluster index:  " << (Int_t)TMath::Log2(fClusterMask) + 1 << endl;
95    cout << "  Detectors:      " << GetDetectorsInCluster() << endl;
96 }
97
98
99 //////////////////////////////////////////////////////////////////////////////
100 // Helper method
101
102 //_____________________________________________________________________________
103 Bool_t AliTriggerCluster::IsSelected( TString detName, TString& detectors ) const
104 {
105    // check whether detName is contained in detectors
106    // if yes, it is removed from detectors
107
108    // check if all detectors are selected
109    if( (detectors.CompareTo("ALL") == 0 ) ||
110         detectors.BeginsWith("ALL ") ||
111         detectors.EndsWith(" ALL") ||
112         detectors.Contains(" ALL ") ) {
113       detectors = "ALL";
114       return kTRUE;
115    }
116
117    // search for the given detector
118    Bool_t result = kFALSE;
119    if( (detectors.CompareTo( detName ) == 0) ||
120         detectors.BeginsWith( detName+" " ) ||
121         detectors.EndsWith( " "+detName ) ||
122         detectors.Contains( " "+detName+" " ) ) {
123       detectors.ReplaceAll( detName, "" );
124       result = kTRUE;
125    }
126
127    // clean up the detectors string
128    while( detectors.Contains("  ") )  detectors.ReplaceAll( "  ", " " );
129    while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 );
130    while( detectors.EndsWith(" ") )   detectors.Remove( detectors.Length()-1, 1 );
131
132    return result;
133 }