Merge branch 'master' into TPCdev
[u/mrichter/AliRoot.git] / STEER / STEER / AliCTPTimeParams.cxx
CommitLineData
d4b2dc5f 1/*************************************************************************
2* Copyright(c) 1998-2008, 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
fabd1b29 17#include <Riostream.h>
18
19#include <TObjArray.h>
20#include <TObjString.h>
21#include <TObject.h>
22#include <TString.h>
23#include <TSystem.h>
24#include <TFile.h>
fabd1b29 25
26#include "AliLog.h"
27#include "AliCTPTimeParams.h"
28#include "AliCTPInputTimeParams.h"
29
66b0310c 30using std::endl;
31using std::cout;
32using std::ifstream;
fabd1b29 33ClassImp(AliCTPTimeParams)
34
fabd1b29 35//______________________________________________________________________________
36AliCTPTimeParams::AliCTPTimeParams():
37TNamed(),
c7ff1a33 38fDelayL1L0(0),
39fDelayL2L0(0),
fabd1b29 40fCTPInputTimeParams()
41{
42//Default constructor
43}
44
45//______________________________________________________________________________
46AliCTPTimeParams::AliCTPTimeParams(const AliCTPTimeParams &timeparams):
47 TNamed(),
48 fDelayL1L0(timeparams.fDelayL1L0),
d4b2dc5f 49 fDelayL2L0(timeparams.fDelayL2L0),
50 fCTPInputTimeParams()
fabd1b29 51{
52 for (Int_t i = 0; i < timeparams.fCTPInputTimeParams.GetSize(); i++) {
53 if ( timeparams.fCTPInputTimeParams[i] ) fCTPInputTimeParams.Add(timeparams.fCTPInputTimeParams[i]->Clone());
54 }
55 // copy constructor
56}
57
58
59//______________________________________________________________________________
60AliCTPTimeParams& AliCTPTimeParams::operator=(const AliCTPTimeParams &timeparams)
61{
62 // assignment operator
63 if(this==&timeparams) return *this;
64 ((TNamed *)this)->operator=(timeparams);
65 fDelayL1L0=timeparams.fDelayL1L0;
66 fDelayL2L0=timeparams.fDelayL2L0;
67
68 for (Int_t i = 0; i < timeparams.fCTPInputTimeParams.GetSize(); i++) {
69 if ( timeparams.fCTPInputTimeParams[i] ) fCTPInputTimeParams.Add(timeparams.fCTPInputTimeParams[i]->Clone());
70 }
71
72 return *this;
73}
74
75//______________________________________________________________________________
76AliCTPTimeParams::~AliCTPTimeParams()
77{
78 //Destructor
79
80 fCTPInputTimeParams.SetOwner();
81 fCTPInputTimeParams.Delete();
82}
83
84//______________________________________________________________________________
125fd567 85void AliCTPTimeParams::AddInput( TString& inputName, UInt_t& inputLevel, UInt_t inputDelay, TString inputEdge, UInt_t deltamin, UInt_t deltamax )
fabd1b29 86{
125fd567 87 fCTPInputTimeParams.AddLast( new AliCTPInputTimeParams(inputName, inputLevel, inputDelay, inputEdge, deltamin, deltamax ));
fabd1b29 88}
89
90//______________________________________________________________________________
c7ff1a33 91void AliCTPTimeParams::AddDelayL0L1L2(Int_t delayL1L0, UInt_t delayL2L0)
fabd1b29 92{
93 fDelayL1L0 = delayL1L0;
94 fDelayL2L0 = delayL2L0;
95}
96//______________________________________________________________________________
125fd567 97AliCTPInputTimeParams* AliCTPTimeParams::GetTimeParamsForInput( TString inputname)
98{
926cebe1 99 // Get AliCTPInputTimeParams for input name
125fd567 100Int_t ninputs = fCTPInputTimeParams.GetEntriesFast();
101for ( Int_t i=0; i < ninputs; i++ )
102 {
103 AliCTPInputTimeParams* ctpinputtime = (AliCTPInputTimeParams*)fCTPInputTimeParams.At(i);
104 if (inputname == ctpinputtime->GetInputName() ) return ctpinputtime;
105 }
926cebe1 106cout << "Input: " << inputname << " not found." << endl;
125fd567 107return NULL;
108}
109//______________________________________________________________________________
926cebe1 110Int_t AliCTPTimeParams::GetDeltasforClass(TString classname,Int_t& deltamin,Int_t& deltamax)
111{
112 // Get deltamin and deltamax for given class
113 // Assumes that descriptor = DINPU
114 // ret: 0=OK, 1= input doea not exist
115 TString input(classname(1,4));
116 AliCTPInputTimeParams* tprm = GetTimeParamsForInput(input);
117 if(tprm){
118 deltamin=tprm->GetDeltaMin();
119 deltamax=tprm->GetDeltaMax();
120 return 0;
121 }
122 return 1;
123}
124//______________________________________________________________________________
fabd1b29 125AliCTPTimeParams* AliCTPTimeParams::LoadCTPTimeParams(TString filename)
126{
127 // Load pre-created CTP time parameters from database/file
128 // By default files are stored in GRP/CTP folder
129 // The filename is constructed as GRP/CTP/<file>.cfg
130 if( gSystem->AccessPathName( filename.Data() )) {
d4b2dc5f 131 // AliError( Form( "File (%s) not found!", filename.Data()));
fabd1b29 132 return NULL;
133 }
134
135 ifstream *file = new ifstream( filename.Data() );
136 if(!*file) {
137 //AliErrorClass( Form( "Error opening file (%s) !", filename.Data()));
138 file->close();
139 delete file;
140 return NULL;
141 }
142
143 AliCTPTimeParams *ctptime = new AliCTPTimeParams();
144
145 TString strline;
146
147 while (strline.ReadLine(*file)) {
148 if (ctptime->ProcessCTPTimeParamsLine(strline) == kFALSE) {
149 delete ctptime;
150 break;
151 }
152 }
153
154 file->close();
155 delete file;
156
157 return ctptime;
158}
159
160//______________________________________________________________________________
161AliCTPTimeParams* AliCTPTimeParams::LoadCTPTimeParamsFromString(const char* timeparams)
162{
163
164 // Loads configuration from string
165
166 if (!timeparams)
167 return 0;
168
169 AliCTPTimeParams *ctptime = new AliCTPTimeParams();
170
171 TObjArray* tokens = TString(timeparams).Tokenize("\n");
172 for (Int_t i=0; i<tokens->GetEntries(); i++)
173 {
174 TObjString* string = dynamic_cast<TObjString*>(tokens->At(i));
175 if (!string)
176 continue;
177
178 if (ctptime->ProcessCTPTimeParamsLine(string->String()) == kFALSE)
179 {
44d4be66 180 delete ctptime;
d4b2dc5f 181 ctptime = 0x0;
fabd1b29 182 break;
183 }
184 }
185
186 delete tokens;
d4b2dc5f 187 if (ctptime) return ctptime;
188 else return NULL;
fabd1b29 189}
190
191//______________________________________________________________________________
192Bool_t AliCTPTimeParams::ProcessCTPTimeParamsLine(const char* line)
193{
194 UInt_t level = 0;
195 TString strline(line);
196 if (strline.BeginsWith("L012")) {
197 strline.ReplaceAll("L012", "");
198 TObjArray *tokens = strline.Tokenize(" \t");
199
200
201 AddDelayL0L1L2(((TObjString*)tokens->At(0))->String().Atoi(),((TObjString*)tokens->At(1))->String().Atoi());
202 delete tokens;
203 }
204 else {
125fd567 205 if (strline.BeginsWith("0")) { level = 0; } // determine the input level (0, 1 or 2)
206 else if (strline.BeginsWith("1")) { level = 1; }
207 else if (strline.BeginsWith("2")) { level = 2; }
208 else return kFALSE; // file not in the right format!
fabd1b29 209
125fd567 210 TObjArray *tokens = strline.Tokenize(" \t");
211 Int_t ntokens = tokens->GetEntriesFast();
212 if (ntokens == 5) AddInput(((TObjString*)tokens->At(0))->String(), level, ((TObjString*)tokens->At(2))->String().Atoi(), ((TObjString*)tokens->At(1))->String(), ((TObjString*)tokens->At(3))->String().Atoi(), ((TObjString*)tokens->At(4))->String().Atoi());
213 else if (ntokens == 3) AddInput(((TObjString*)tokens->At(0))->String(), level, ((TObjString*)tokens->At(2))->String().Atoi(), ((TObjString*)tokens->At(1))->String(), 0, 0); //the old format is used - no DeltaMin & DeltaMax!
214 else return kFALSE; // file not in the right format!
44d4be66 215 delete tokens;
fabd1b29 216 }
fabd1b29 217return kTRUE;
218}
219
220//______________________________________________________________________________
fabd1b29 221void AliCTPTimeParams::Print(const Option_t*) const
222{
223 //Print
224 cout << "Delay L0 - L1 = " << fDelayL1L0 << endl;
225 cout << "Delay L0 - L2 = " << fDelayL2L0 << endl;
226 fCTPInputTimeParams.Print();
227 cout << ""<<endl;
228}
229//______________________________________________________________________________