Setting of aliases to rawReader done only once. Base decision on cosmic or calib...
[u/mrichter/AliRoot.git] / STEER / 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 using std::endl;
31 using std::cout;
32 using std::ifstream;
33 ClassImp(AliCTPTimeParams)
34
35 //______________________________________________________________________________
36 AliCTPTimeParams::AliCTPTimeParams():
37 TNamed(),
38 fDelayL1L0(0),
39 fDelayL2L0(0),
40 fCTPInputTimeParams()
41 {
42 //Default constructor
43 }
44
45 //______________________________________________________________________________
46 AliCTPTimeParams::AliCTPTimeParams(const AliCTPTimeParams &timeparams):
47  TNamed(),
48  fDelayL1L0(timeparams.fDelayL1L0),
49  fDelayL2L0(timeparams.fDelayL2L0),
50  fCTPInputTimeParams()
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 //______________________________________________________________________________
60 AliCTPTimeParams& 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 //______________________________________________________________________________
76 AliCTPTimeParams::~AliCTPTimeParams()
77 {
78  //Destructor
79
80  fCTPInputTimeParams.SetOwner();
81  fCTPInputTimeParams.Delete();
82 }
83
84 //______________________________________________________________________________
85 void AliCTPTimeParams::AddInput( TString& inputName, UInt_t& inputLevel, UInt_t inputDelay, TString inputEdge, UInt_t deltamin, UInt_t deltamax )
86 {
87  fCTPInputTimeParams.AddLast( new AliCTPInputTimeParams(inputName, inputLevel, inputDelay, inputEdge, deltamin, deltamax ));
88 }
89
90 //______________________________________________________________________________
91 void AliCTPTimeParams::AddDelayL0L1L2(Int_t delayL1L0, UInt_t delayL2L0)
92 {
93  fDelayL1L0 = delayL1L0;
94  fDelayL2L0 = delayL2L0;
95 }
96 //______________________________________________________________________________
97 AliCTPInputTimeParams* AliCTPTimeParams::GetTimeParamsForInput( TString inputname)
98 {
99  // Get AliCTPInputTimeParams for input name
100 Int_t ninputs = fCTPInputTimeParams.GetEntriesFast();
101 for ( Int_t i=0; i < ninputs; i++ )
102  {
103   AliCTPInputTimeParams* ctpinputtime = (AliCTPInputTimeParams*)fCTPInputTimeParams.At(i);
104   if (inputname == ctpinputtime->GetInputName() ) return ctpinputtime;
105  }
106 cout << "Input: " << inputname << " not found." << endl;
107 return NULL;
108 }
109 //______________________________________________________________________________
110 Int_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 //______________________________________________________________________________
125 AliCTPTimeParams* 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() )) {
131  // AliError( Form( "File (%s) not found!", filename.Data()));
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 //______________________________________________________________________________
161 AliCTPTimeParams* 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      {
180         delete ctptime;
181         ctptime  = 0x0;
182         break;
183      }
184    }
185
186    delete tokens;
187    if (ctptime) return ctptime;
188    else return NULL;
189 }
190
191 //______________________________________________________________________________
192 Bool_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 {
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!
209    
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!
215     delete tokens;
216   }
217 return kTRUE;
218 }
219
220 //______________________________________________________________________________
221 void 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 //______________________________________________________________________________