]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliCTPTimeParams.cxx
AliACORDEQAChecker::Check fixed
[u/mrichter/AliRoot.git] / STEER / AliCTPTimeParams.cxx
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
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>
25
26 #include "AliLog.h"
27 #include "AliCTPTimeParams.h"
28 #include "AliCTPInputTimeParams.h"
29
30 ClassImp(AliCTPTimeParams)
31
32 //______________________________________________________________________________
33 AliCTPTimeParams::AliCTPTimeParams():
34 TNamed(),
35 fDelayL1L0(),
36 fDelayL2L0(),
37 fCTPInputTimeParams()
38 {
39 //Default constructor
40 }
41
42 //______________________________________________________________________________
43 AliCTPTimeParams::AliCTPTimeParams(const AliCTPTimeParams &timeparams):
44  TNamed(),
45  fDelayL1L0(timeparams.fDelayL1L0),
46  fDelayL2L0(timeparams.fDelayL2L0),
47  fCTPInputTimeParams()
48 {
49  for (Int_t i = 0; i < timeparams.fCTPInputTimeParams.GetSize(); i++) {
50  if ( timeparams.fCTPInputTimeParams[i] ) fCTPInputTimeParams.Add(timeparams.fCTPInputTimeParams[i]->Clone());
51  }
52  // copy constructor
53 }
54
55
56 //______________________________________________________________________________
57 AliCTPTimeParams& AliCTPTimeParams::operator=(const AliCTPTimeParams &timeparams)
58 {
59  // assignment operator
60  if(this==&timeparams) return *this;
61  ((TNamed *)this)->operator=(timeparams);
62  fDelayL1L0=timeparams.fDelayL1L0;
63  fDelayL2L0=timeparams.fDelayL2L0;
64  
65  for (Int_t i = 0; i < timeparams.fCTPInputTimeParams.GetSize(); i++) {
66  if ( timeparams.fCTPInputTimeParams[i] ) fCTPInputTimeParams.Add(timeparams.fCTPInputTimeParams[i]->Clone());
67  }
68
69  return *this;
70 }
71
72 //______________________________________________________________________________
73 AliCTPTimeParams::~AliCTPTimeParams()
74 {
75  //Destructor
76
77  fCTPInputTimeParams.SetOwner();
78  fCTPInputTimeParams.Delete();
79 }
80
81 //______________________________________________________________________________
82 void AliCTPTimeParams::AddInput( TString& inputName, UInt_t& inputLevel, UInt_t inputDelay, TString inputEdge )
83 {
84  fCTPInputTimeParams.AddLast( new AliCTPInputTimeParams(inputName, inputLevel, inputDelay, inputEdge ));
85 }
86
87 //______________________________________________________________________________
88 void AliCTPTimeParams::AddDelayL0L1L2(UInt_t delayL1L0, UInt_t delayL2L0)
89 {
90  fDelayL1L0 = delayL1L0;
91  fDelayL2L0 = delayL2L0;
92 }
93 //______________________________________________________________________________
94 AliCTPTimeParams* AliCTPTimeParams::LoadCTPTimeParams(TString filename)
95 {
96  // Load pre-created CTP time parameters from database/file
97  // By default files are stored in GRP/CTP folder
98  // The filename is constructed as GRP/CTP/<file>.cfg
99   if( gSystem->AccessPathName( filename.Data() )) {
100  // AliError( Form( "File (%s) not found!", filename.Data()));
101   return NULL;
102  }
103
104  ifstream *file = new ifstream( filename.Data() );
105  if(!*file) {
106   //AliErrorClass( Form( "Error opening file (%s) !", filename.Data()));
107   file->close();
108   delete file;
109   return NULL;
110  }
111
112  AliCTPTimeParams *ctptime = new AliCTPTimeParams();
113
114  TString strline;
115  
116  while (strline.ReadLine(*file)) {
117     if (ctptime->ProcessCTPTimeParamsLine(strline) == kFALSE) {
118      delete ctptime;
119      break;
120     }
121  }
122
123  file->close();
124  delete file;
125
126  return ctptime;
127 }
128
129 //______________________________________________________________________________
130 AliCTPTimeParams* AliCTPTimeParams::LoadCTPTimeParamsFromString(const char* timeparams)
131 {
132
133  // Loads configuration from string
134
135    if (!timeparams)
136      return 0;
137
138    AliCTPTimeParams *ctptime = new AliCTPTimeParams();
139
140    TObjArray* tokens = TString(timeparams).Tokenize("\n");
141    for (Int_t i=0; i<tokens->GetEntries(); i++)
142    {
143      TObjString* string = dynamic_cast<TObjString*>(tokens->At(i));
144      if (!string)
145        continue;
146
147      if (ctptime->ProcessCTPTimeParamsLine(string->String()) == kFALSE)
148      {
149         ctptime  = 0x0;
150         break;
151      }
152    }
153
154    delete tokens;
155    if (ctptime) return ctptime;
156    else return NULL;
157 }
158
159 //______________________________________________________________________________
160 Bool_t AliCTPTimeParams::ProcessCTPTimeParamsLine(const char* line)
161 {
162  UInt_t level = 0;
163  TString strline(line);
164   if (strline.BeginsWith("L012")) {
165    strline.ReplaceAll("L012", "");
166    TObjArray *tokens = strline.Tokenize(" \t");
167       
168
169    AddDelayL0L1L2(((TObjString*)tokens->At(0))->String().Atoi(),((TObjString*)tokens->At(1))->String().Atoi());
170    delete tokens;
171   }
172   else {
173    if (strline.BeginsWith("0")) { level = 0; }   // determine the input level (0, 1 or 2)
174    else if (strline.BeginsWith("1")) { level = 1; }
175    else if (strline.BeginsWith("2")) { level = 2; } 
176    else {
177            return 0; // file not in the right format!
178    }
179    
180    TObjArray *tokens = strline.Tokenize(" \t");
181    AddInput(((TObjString*)tokens->At(0))->String(), level, ((TObjString*)tokens->At(2))->String().Atoi(), ((TObjString*)tokens->At(1))->String() );
182   }
183
184 return kTRUE;
185 }
186
187 //______________________________________________________________________________
188 void AliCTPTimeParams::Print(const Option_t*) const
189 {
190   //Print
191  cout << "Delay L0 - L1 = " << fDelayL1L0 << endl;
192  cout << "Delay L0 - L2 = " << fDelayL2L0 << endl;
193  fCTPInputTimeParams.Print();
194  cout << ""<<endl;
195 }
196 //______________________________________________________________________________