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