Protection against not accessible input OCDB (Laurent)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpCDB.cxx
CommitLineData
3f862c88 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
3d1463c8 20//-----------------------------------------------------------------------------
3f862c88 21// Class AliMpCDB
22// -----------------------
23// Manager class for mapping CDB IO
24// Author: Ivana Hrivnacova, IPN Orsay
3d1463c8 25//-----------------------------------------------------------------------------
3f862c88 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
39/// \cond CLASSIMP
40ClassImp(AliMpCDB)
41/// \endcond
42
3f862c88 43//
44// static methods
45//
707ad0dc 46
3f862c88 47//______________________________________________________________________________
48Bool_t AliMpCDB::LoadMpSegmentation(Bool_t warn)
49{
50/// Load the sementation from the CDB if it does not yet exist;
51/// return false only in case loading from CDB failed
52
53 AliDebugClass(1,"");
54
55 if ( AliMpSegmentation::Instance(false) ) {
56 if ( warn )
57 AliWarningClass("Segmentation has been already loaded.");
58 return true;
59 }
60
61 AliCDBManager* cdbManager = AliCDBManager::Instance();
62 if ( ! cdbManager->GetDefaultStorage() )
63 cdbManager->SetDefaultStorage("local://$ALICE_ROOT");
64
65 Int_t run = cdbManager->GetRun();
66 if ( run < 0 ) {
67 run = 0;
68 cdbManager->SetRun(run);
69 }
70
5699c0e6 71 AliCDBEntry* cdbEntry = cdbManager->Get("MUON/Calib/Mapping", run);
3f862c88 72
5699c0e6 73 if ( cdbEntry )
74 {
75 return (AliMpSegmentation*)cdbEntry->GetObject() != 0x0;
76 }
77 else
78 {
79 return kFALSE;
80 }
3f862c88 81}
82
83//______________________________________________________________________________
84Bool_t AliMpCDB::LoadDDLStore(Bool_t warn)
85{
86/// Load the DDL store from the CDB if it does not yet exist
87/// return false only in case loading from CDB failed
88
89 AliDebugClass(1,"");
90
91 if ( AliMpDDLStore::Instance(false) ) {
92 if ( warn )
93 AliWarningClass("DDL Store has been already loaded.");
94 return true;
95 }
96
707ad0dc 97 // Load segmentation
98 //
99 LoadMpSegmentation(warn);
100
101 // Load DDL store
102 //
3f862c88 103 AliCDBManager* cdbManager = AliCDBManager::Instance();
104 if ( ! cdbManager->GetDefaultStorage() )
105 cdbManager->SetDefaultStorage("local://$ALICE_ROOT");
106
107 Int_t run = cdbManager->GetRun();
108 if ( run < 0 ) {
109 run = 0;
110 cdbManager->SetRun(run);
111 }
112
5699c0e6 113 AliCDBEntry* cdbEntry = cdbManager->Get("MUON/Calib/DDLStore", run);
3f862c88 114
5699c0e6 115 if ( cdbEntry )
116 {
117 return (AliMpDDLStore*)cdbEntry->GetObject() != 0x0;
118 }
119 else
120 {
121 return kFALSE;
122 }
3f862c88 123}
124
125//______________________________________________________________________________
126Bool_t AliMpCDB::WriteMpSegmentation()
127{
128/// Write mapping segmentation in OCDB
129
130 AliCDBManager* cdbManager = AliCDBManager::Instance();
131 if ( ! cdbManager->GetDefaultStorage() )
132 cdbManager->SetDefaultStorage("local://$ALICE_ROOT");
133
134 AliCDBMetaData* cdbData = new AliCDBMetaData();
135 cdbData->SetResponsible("Dimuon Offline project");
136 cdbData->SetComment("MUON mapping");
137 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
138 AliCDBId id("MUON/Calib/Mapping", 0, 9999999);
139
140 AliMpSegmentation::ReadData(false);
141 return cdbManager->Put(AliMpSegmentation::Instance(), id, cdbData);
142}
143
144//______________________________________________________________________________
145Bool_t AliMpCDB::WriteDDLStore()
146{
147/// Write mapping DDL store in OCDB
148
149 AliCDBManager* cdbManager = AliCDBManager::Instance();
150 if ( ! cdbManager->GetDefaultStorage() )
151 cdbManager->SetDefaultStorage("local://$ALICE_ROOT");
152
153 AliCDBMetaData* cdbData = new AliCDBMetaData();
154 cdbData->SetResponsible("Dimuon Offline project");
155 cdbData->SetComment("MUON DDL store");
156 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
157 AliCDBId id("MUON/Calib/DDLStore", 0, 9999999);
158
159 AliMpSegmentation::ReadData(false);
160 AliMpDDLStore::ReadData(false);
161 return cdbManager->Put(AliMpDDLStore::Instance(), id, cdbData);
162}