Correct sign for calculated b_y (outside measured region).
[u/mrichter/AliRoot.git] / TPC / AliTPCDBPressure.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
17 ///////////////////////////////////////////////////////////////////////////////
18 //                                                                           //
19 //  Class to generate TPC atmospheric pressure data base entries             //
20 //  Author: Haavard Helstrup                                                 //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24
25
26 /**
27 TTimeStamp startTime(2006,10,18,0,0,0,0,kFALSE)
28 TTimeStamp endTime(2006,10,19,0,0,0,0,kFALSE)
29 Int_t run=2546
30 AliTPCDBPressure db
31 db->Init(run)
32 db->MakeCalib("PressureSensor.txt","DCSMap.root",startTime,endTime,firstRun,lastRun)
33
34
35 **/
36 #include "AliTPCDBPressure.h"
37
38 ClassImp(AliTPCDBPressure)
39
40 //______________________________________________________________________________________________
41
42 AliTPCDBPressure::AliTPCDBPressure(): 
43    fFirstRun(0),
44    fLastRun(0),
45    fPressure(0),
46    fStorLoc(0),
47    fCalib(0),
48    fMetaData(0),
49    fConfTree(0)
50 //
51 //  standard constructor
52 //
53 {}
54
55 //______________________________________________________________________________________________
56
57 AliTPCDBPressure::AliTPCDBPressure(const AliTPCDBPressure& org):
58   TObject(org),
59   fFirstRun(org.fFirstRun),
60   fLastRun(org.fLastRun),
61   fPressure(0),
62   fStorLoc(0),
63   fCalib(0),
64   fMetaData(0),
65   fConfTree(0)
66 {
67 //
68 //  Copy constructor
69 //
70
71  ((AliTPCDBPressure &) org).Copy(*this);
72 }
73
74 //______________________________________________________________________________________________
75 AliTPCDBPressure::~AliTPCDBPressure(){
76 //
77 // destructor
78 //
79    fCalib->Terminate();
80    delete fPressure;
81    delete fMetaData;
82    delete fConfTree;
83 }
84
85 //______________________________________________________________________________________________
86 AliTPCDBPressure& AliTPCDBPressure::operator= (const AliTPCDBPressure& org )
87 {
88  //
89  // assignment operator
90  //
91  if (&org == this) return *this;
92
93  new (this) AliTPCDBPressure(org);
94  return *this;
95
96
97 //______________________________________________________________________________________________
98 void AliTPCDBPressure::Copy(TObject &c) const
99 {
100   //
101   // Copy function
102   //
103
104   TObject::Copy(c);
105 }
106
107 //______________________________________________________________________________________________
108 void AliTPCDBPressure::MakeCalib(const char *list, const char *mapDCS,
109                              const TTimeStamp& startTime, 
110                              const TTimeStamp& endTime,
111                              Int_t firstRun, Int_t lastRun )
112 {
113    // The Terminate() function is the last function to be called during
114    // a query. It always runs on the client, it can be used to present
115    // the results graphically or save the results to file.
116
117    TClonesArray *arr = ReadList(list);
118    AliDCSSensorArray *fPressure = new AliDCSSensorArray(arr);
119    fPressure->SetStartTime(startTime);
120    fPressure->SetEndTime(endTime);
121    TMap* map = SetGraphFile(mapDCS);
122    if (map) {
123      fPressure->MakeSplineFit(map);
124    }
125    delete map;
126    map=0;
127    mapDCS=0;
128
129    SetFirstRun(firstRun);
130    SetLastRun(lastRun);                     
131
132    StoreObject("TPC/Calib/Pressure",fPressure, fMetaData);
133 }
134
135 //______________________________________________________________________________________________
136 void AliTPCDBPressure::MakeConfig(const char *file, Int_t firstRun, Int_t lastRun )
137 {
138    //
139    // Store Configuration file to OCDB
140    //
141
142    TTree *tree = ReadListTree(file);
143    SetConfTree(tree);
144    SetFirstRun(firstRun);
145    SetLastRun(lastRun);                     
146
147    StoreObject("TPC/Config/Pressure",fConfTree, fMetaData);
148 }
149
150
151
152 //______________________________________________________________________________________________
153 AliCDBMetaData* AliTPCDBPressure::CreateMetaObject(const char* objectClassName)
154 {
155   AliCDBMetaData *md1= new AliCDBMetaData(); 
156   md1->SetObjectClassName(objectClassName);
157   md1->SetResponsible("Haavard Helstrup");
158   md1->SetBeamPeriod(2);
159   md1->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
160   md1->SetComment("Pressure");
161   
162   return md1;
163 }
164
165 //______________________________________________________________________________________________
166 void AliTPCDBPressure::StoreObject(const char* cdbPath, TObject* object, AliCDBMetaData* metaData)
167 {
168
169   AliCDBId id1(cdbPath, fFirstRun, fLastRun); 
170   if (fStorLoc) fStorLoc->Put(object, id1, metaData); 
171 }
172
173 //______________________________________________________________________________________________
174 void AliTPCDBPressure::Init(Int_t run){
175
176    Long64_t longRun;
177    
178    SetFirstRun(run);
179    SetLastRun(run); 
180        
181    InitDB(run);
182    fCalib = AliTPCcalibDB::Instance();    
183    longRun=run;
184    fCalib->SetRun(longRun);
185    fPressure = fCalib->GetPressure();
186      
187 }
188
189 //______________________________________________________________________________________________
190 void AliTPCDBPressure::InitDB(Int_t run)
191
192    //   Data base generation
193    
194    char   *CDBpath="local:///afs/cern.ch/alice/tpctest/Calib/";
195
196    fMetaData = CreateMetaObject("AliDCSSensorArray");
197    AliCDBManager *man = AliCDBManager::Instance();
198    man->SetDefaultStorage("local:///afs/cern.ch/alice/tpctest/AliRoot/HEAD"); 
199    man->SetRun(run);
200    man->SetSpecificStorage("TPC/*/*","local:///afs/cern.ch/alice/tpctest/Calib");
201    AliCDBEntry *config = man->Get("TPC/Config/Pressure");
202    if (config) fConfTree = (TTree*)config->GetObject();
203    fStorLoc = man->GetStorage(CDBpath);
204    if (!fStorLoc)    return;
205 }
206
207
208 //_____________________________________________________________________________
209 TMap* AliTPCDBPressure::SetGraphFile(const char *fname)
210 {
211   // 
212   // Read DCS maps from file given by fname 
213   //
214   TFile file(fname);
215   TMap * map = (TMap*)file.Get("DCSMap");
216   return map;
217 }
218
219 //______________________________________________________________________________________________
220
221 TClonesArray * AliTPCDBPressure::ReadList(const char *fname) {
222   //
223   // read values from ascii file
224   //
225   TTree* tree = new TTree("pressureConf","pressureConf");
226   tree->ReadFile(fname,"");
227   TClonesArray *arr = AliDCSSensor::ReadTree(tree);
228   return arr;
229 }
230
231 //______________________________________________________________________________________________
232
233 TTree * AliTPCDBPressure::ReadListTree(const char *fname) {
234   //
235   // read values from ascii file
236   //
237   TTree* tree = new TTree("pressureConf","pressureConf");
238   tree->ReadFile(fname,"");
239   TClonesArray *arr = AliDCSSensor::ReadTree(tree);
240   arr->Delete();
241   delete arr;
242   return tree;
243 }
244
245