]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpCDB.cxx
bug in t0 in optimization fixed
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpCDB.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 // $Id$
17 // $MpId: $
18 // Category: management
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpCDB
22 // -----------------------
23 // Manager class for mapping CDB IO
24 // Author: Ivana Hrivnacova, IPN Orsay
25 //-----------------------------------------------------------------------------
26
27 #include "AliMpCDB.h"
28
29 #include "AliMpSegmentation.h"
30 #include "AliMpDDLStore.h"
31
32 #include "AliLog.h"
33 #include "AliCDBManager.h"
34 #include "AliCDBEntry.h"
35
36 #include <TSystem.h>
37 #include <TClass.h>
38 #include <Riostream.h>
39
40 /// \cond CLASSIMP
41 ClassImp(AliMpCDB)
42 /// \endcond
43
44 //
45 // static methods
46 //
47
48 //______________________________________________________________________________
49 Bool_t AliMpCDB::LoadMpSegmentation(Bool_t warn)
50 {
51 /// Load the sementation from the CDB if it does not yet exist;
52 /// return false only in case loading from CDB failed
53
54   AliDebugClass(1,"");
55
56   if ( AliMpSegmentation::Instance(false) ) {
57     if ( warn )  
58       AliWarningClass("Segmentation has been already loaded."); 
59     return true;
60   }  
61   
62   AliCDBManager* cdbManager = AliCDBManager::Instance();
63   if ( ! cdbManager->GetDefaultStorage() ) {
64     AliErrorClassStream() << "CDB default storage has not been set." << endl; 
65     return kFALSE;
66   }  
67
68   Int_t run = cdbManager->GetRun();
69   if ( run < 0 ) {
70     AliErrorClassStream() << "Cannot get run number from CDB manager." << endl; 
71     return kFALSE;
72   }  
73
74   AliCDBEntry* cdbEntry = cdbManager->Get("MUON/Calib/Mapping", run);
75   
76   if ( cdbEntry ) 
77   {
78     return (AliMpSegmentation*)cdbEntry->GetObject() != 0x0;
79   }
80   else
81   {
82     return kFALSE;
83   }
84 }    
85
86 //______________________________________________________________________________
87 Bool_t AliMpCDB::LoadDDLStore(Bool_t warn)
88 {
89 /// Load the DDL store from the CDB if it does not yet exist
90 /// return false only in case loading from CDB failed
91
92   AliDebugClass(1,"");
93
94   if ( AliMpDDLStore::Instance(false) ) {
95     if ( warn )  
96       AliWarningClass("DDL Store has been already loaded."); 
97     return true;
98   }  
99   
100   // Load segmentation
101   //
102   LoadMpSegmentation(warn); 
103   
104   // Load DDL store
105   //
106   AliCDBManager* cdbManager = AliCDBManager::Instance();
107   if ( ! cdbManager->GetDefaultStorage() ) {
108     AliErrorClassStream() << "CDB default storage has not been set." << endl; 
109     return kFALSE;
110   }  
111
112   Int_t run = cdbManager->GetRun();
113   if ( run < 0 ) {
114     AliErrorClassStream() << "Cannot get run number from CDB manager." << endl; 
115     return kFALSE;
116   }  
117
118   AliCDBEntry* cdbEntry =  cdbManager->Get("MUON/Calib/DDLStore", run);
119   
120   if ( cdbEntry ) 
121   {
122     return (AliMpDDLStore*)cdbEntry->GetObject() != 0x0;
123   }
124   else
125   {
126     return kFALSE;
127   }
128 }    
129
130 //______________________________________________________________________________
131 Bool_t AliMpCDB::LoadMpSegmentation2(const char* cdbpath, Int_t runNumber, 
132                                      Bool_t warn)
133 {
134 /// Load the sementation from the CDB if it does not yet exist;
135 /// return false only in case loading from CDB failed.
136 /// In difference from LoadMpSegmentation(), in this method the CDB path
137 /// and run is set directly via arguments.
138
139
140   AliDebugClass(1,"");
141
142   if ( AliMpSegmentation::Instance(false) ) {
143     if ( warn )  
144       AliWarningClass("Segmentation has been already loaded."); 
145     return true;
146   }  
147   
148   AliCDBManager* cdbManager = AliCDBManager::Instance();
149   cdbManager->SetDefaultStorage(cdbpath);
150
151   AliCDBEntry* cdbEntry = cdbManager->Get("MUON/Calib/Mapping", runNumber);
152   
153   if ( cdbEntry ) 
154   {
155     return (AliMpSegmentation*)cdbEntry->GetObject() != 0x0;
156   }
157   else
158   {
159     return kFALSE;
160   }
161 }    
162
163 //______________________________________________________________________________
164 Bool_t AliMpCDB::LoadDDLStore2(const char* cdbpath, Int_t runNumber, 
165                                Bool_t warn)
166 {
167 /// Load the DDL store from the CDB if it does not yet exist
168 /// return false only in case loading from CDB failed
169 /// In difference from LoadDDLStore(), in this method the CDB path
170 /// and run is set directly via arguments.
171
172   AliDebugClass(1,"");
173
174   if ( AliMpDDLStore::Instance(false) ) {
175     if ( warn )  
176       AliWarningClass("DDL Store has been already loaded."); 
177     return true;
178   }  
179   
180   // Load segmentation
181   //
182   LoadMpSegmentation2(cdbpath, runNumber, warn); 
183   
184   // Load DDL store
185   //
186   AliCDBManager* cdbManager = AliCDBManager::Instance();
187   cdbManager->SetDefaultStorage(cdbpath);
188
189   AliCDBEntry* cdbEntry =  cdbManager->Get("MUON/Calib/DDLStore", runNumber);
190   
191   if ( cdbEntry ) 
192   {
193     return (AliMpDDLStore*)cdbEntry->GetObject() != 0x0;
194   }
195   else
196   {
197     return kFALSE;
198   }
199 }    
200
201 //______________________________________________________________________________
202 Bool_t AliMpCDB::WriteMpSegmentation(Bool_t readData)
203 {
204 /// Write mapping segmentation in OCDB
205
206   if ( ! readData && ! AliMpSegmentation::Instance() ) return false;
207
208   AliCDBManager* cdbManager = AliCDBManager::Instance();
209   if ( ! cdbManager->GetDefaultStorage() )
210     cdbManager->SetDefaultStorage("local://$ALICE_ROOT");
211   
212   AliCDBMetaData* cdbData = new AliCDBMetaData();
213   cdbData->SetResponsible("Dimuon Offline project");
214   cdbData->SetComment("MUON mapping");
215   cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
216   AliCDBId id("MUON/Calib/Mapping", 0, AliCDBRunRange::Infinity()); 
217
218   if ( readData ) {
219     AliMpSegmentation::ReadData(false);
220     AliMpDDLStore::ReadData(false);
221   }
222   
223   return cdbManager->Put(AliMpSegmentation::Instance(), id, cdbData);
224 }
225
226 //______________________________________________________________________________
227 Bool_t AliMpCDB::WriteDDLStore(Bool_t readData)
228 {
229 /// Write mapping DDL store in OCDB
230
231   if ( ! readData && ! AliMpDDLStore::Instance() ) return false;
232
233   AliCDBManager* cdbManager = AliCDBManager::Instance();
234   if ( ! cdbManager->GetDefaultStorage() )
235     cdbManager->SetDefaultStorage("local://$ALICE_ROOT");
236   
237   AliCDBMetaData* cdbData = new AliCDBMetaData();
238   cdbData->SetResponsible("Dimuon Offline project");
239   cdbData->SetComment("MUON DDL store");
240   cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
241   AliCDBId id("MUON/Calib/DDLStore", 0, AliCDBRunRange::Infinity()); 
242
243   if ( readData ) {
244     AliMpSegmentation::ReadData(false);
245     AliMpDDLStore::ReadData(false);
246   }
247   return cdbManager->Put(AliMpDDLStore::Instance(), id, cdbData);
248 }