]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliTriggerDetector.cxx
Send the run number to dateStream, so that it appears in the raw data
[u/mrichter/AliRoot.git] / STEER / AliTriggerDetector.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 //  Base Class for Detector specific Trigger                                 //                                                                           //
21 //                                                                           //
22 //                                                                           //
23 //                                                                           //
24 //                                                                           //
25 //                                                                           //
26 ///////////////////////////////////////////////////////////////////////////////
27
28 #include <Riostream.h>
29 #include <TNamed.h>
30 #include <TString.h>
31 #include <TObjArray.h>
32 #include <TRandom.h>
33
34
35 #include "AliLog.h"
36 #include "AliRun.h"
37 #include "AliRunLoader.h"
38
39 #include "AliTriggerInput.h"
40 #include "AliTriggerDetector.h"
41
42
43
44 ClassImp( AliTriggerDetector )
45
46 //_____________________________________________________________________________
47 AliTriggerDetector::AliTriggerDetector() :
48   TNamed(),
49   fMask(0),
50   fInputs()
51 {
52    // Default constructor
53 }
54
55 //_____________________________________________________________________________
56 AliTriggerDetector::AliTriggerDetector(const AliTriggerDetector & de ):
57   TNamed(de),
58   fMask(de.fMask),
59   fInputs(de.fInputs)
60 {
61   // Copy constructor
62   
63 }
64
65 //_____________________________________________________________________________
66 AliTriggerDetector::~AliTriggerDetector()
67 {
68   // Destructor
69   // Delete only inputs that are not
70   // associated to the CTP
71   Int_t ninputs = fInputs.GetEntriesFast();
72   for(Int_t i = 0; i < ninputs; i++) {
73     AliTriggerInput *inp = (AliTriggerInput *)fInputs.At(i);
74     if (inp->GetSignature() == -1 &&
75         inp->GetMask() == 0)
76       delete fInputs.RemoveAt(i);
77   }
78 }
79
80 //_____________________________________________________________________________
81 void AliTriggerDetector::CreateInputs(const TObjArray &inputs)
82 {
83    // Define the inputs to the Central Trigger Processor
84    // This is a dummy version 
85    
86    // Check if we have to create the inputs first
87    if( fInputs.GetEntriesFast() == 0 ) {
88      // Create the inputs that the detector can provide
89      CreateInputs();
90    }
91
92    TString name = GetName();
93
94    // Pointer to the available inputs provided by the detector
95    TObjArray* availInputs = &fInputs;
96
97    Int_t ninputs = inputs.GetEntriesFast();
98    for( Int_t j=0; j<ninputs; j++ ) {
99      AliTriggerInput *inp = (AliTriggerInput*)inputs.At(j);
100      if ( name.CompareTo(inp->GetModule().Data()) ) continue;
101
102      TObject *tempObj = availInputs->FindObject(inp->GetInputName().Data());
103      if ( tempObj ) {
104        Int_t tempIndex = availInputs->IndexOf(tempObj);
105        delete availInputs->Remove(tempObj);
106        fInputs.AddAt( inp, tempIndex );
107        inp->Enable();
108        AliInfo(Form("Trigger input (%s) is found in the CTP configuration. Therefore it is enabled for trigger detector (%s)",
109                     inp->GetInputName().Data(),name.Data()));
110      }
111      else {
112        AliWarning(Form("Trigger Input (%s) is not implemented for the trigger detector (%s) ! It will be disabled !",
113                        inp->GetInputName().Data(),name.Data()));
114      }
115    }
116
117    for( Int_t j=0; j<fInputs.GetEntriesFast(); j++ ) {
118      AliTriggerInput *inp = (AliTriggerInput *)fInputs.At(j);
119      if (inp->GetSignature() == -1 &&
120          inp->GetMask() == 0)
121        inp->Enable();
122        AliInfo(Form("Trigger input (%s) was not found in the CTP configuration. Therefore it will be run in a stand-alone mode",
123                     inp->GetInputName().Data()));
124    }
125
126    fInputs.SetOwner(kFALSE);
127 }
128
129 //_____________________________________________________________________________
130 void AliTriggerDetector::CreateInputs()
131 {
132    // Define the inputs to the Central Trigger Processor
133    // This is a dummy version 
134    
135    // Do not create inputs again!!
136    if( fInputs.GetEntriesFast() > 0 ) return;
137    
138    fInputs.AddLast( new AliTriggerInput( "TEST1_L0", "TEST", 0 ) );
139    fInputs.AddLast( new AliTriggerInput( "TEST2_L0", "TEST", 0 ) );
140    fInputs.AddLast( new AliTriggerInput( "TEST3_L0", "TEST", 0 ) );
141 }
142
143 //_____________________________________________________________________________
144 void AliTriggerDetector::Trigger()
145 {
146    // This is a dummy version set all inputs in a random way
147
148    AliWarning( Form( "Triggering dummy detector %s", GetName() ) );
149
150    //  ********** Get Digits for the current event **********
151    AliRunLoader* runLoader = gAlice->GetRunLoader();
152    AliInfo( Form( "Event %d", runLoader->GetEventNumber() ) );
153    
154    TString loadername = GetName(); 
155    loadername.Append( "Loader" );
156    AliLoader * loader = runLoader->GetLoader( loadername.Data() );
157    if( loader ) {
158       loader->LoadDigits( "READ" );
159       TTree* digits = loader->TreeD();
160       // Do something with the digits !!!
161       if( digits ) { 
162 //         digits->Print();
163       }   
164       loader->UnloadDigits();
165    }
166    //  ******************************************************
167
168    // set all inputs in a random way
169    Int_t nInputs = fInputs.GetEntriesFast();
170    for( Int_t j=0; j<nInputs; j++ ) {
171       AliTriggerInput* in = (AliTriggerInput*)fInputs.At( j );
172       if( gRandom->Rndm() > 0.5 ) {
173          in->Set();
174          fMask |= in->GetValue();
175       }
176    }
177 }
178
179 //_____________________________________________________________________________
180 void AliTriggerDetector::SetInput( TString& name )
181 {
182    // Set Input by name
183    SetInput( name.Data() );
184 }
185
186 //_____________________________________________________________________________
187 void AliTriggerDetector::SetInput( const char * name )
188 {
189    // Set Input by name
190    AliTriggerInput* in = ((AliTriggerInput*)fInputs.FindObject( name ));
191    if( in ) {
192       in->Set();
193       fMask |= in->GetValue();
194    } else
195       AliError( Form( "There is not input named %s", name ) );
196 }
197
198 //_____________________________________________________________________________
199 void AliTriggerDetector::Print( const Option_t* opt ) const
200 {
201    // Print
202    cout << "Trigger Detector : " << GetName() << endl;
203    cout << "  Trigger Class Mask: 0x" << hex << GetMask() << dec << endl;
204    Int_t nInputs = fInputs.GetEntriesFast();
205    for( Int_t j=0; j<nInputs; j++ ) {
206       AliTriggerInput* in = (AliTriggerInput*)fInputs.At( j );
207       in->Print( opt );
208    }
209 }