]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpCDB.cxx
Removing a comma that gcc 3.4 does not like ;-)
[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
183279c1 29#include "AliCDBEntry.h"
30#include "AliCDBManager.h"
31#include "AliLog.h"
3f862c88 32#include "AliMpDDLStore.h"
183279c1 33#include "AliMpDEStore.h"
34#include "AliMpDataMap.h"
228fd720 35#include "AliMpDataProcessor.h"
36#include "AliMpDataStreams.h"
183279c1 37#include "AliMpManuStore.h"
38#include "AliMpSegmentation.h"
ff5445c2 39#include <Riostream.h>
183279c1 40#include <TClass.h>
41#include <TSystem.h>
3f862c88 42
43/// \cond CLASSIMP
44ClassImp(AliMpCDB)
45/// \endcond
46
228fd720 47Bool_t AliMpCDB::fgLoadFromData = kTRUE;
48
3f862c88 49//
228fd720 50// private static methods
3f862c88 51//
707ad0dc 52
3f862c88 53//______________________________________________________________________________
228fd720 54TObject* AliMpCDB::GetCDBEntryObject(const char* dataPath)
3f862c88 55{
228fd720 56/// Load CDB entry object with checks
3f862c88 57
3f862c88 58 AliCDBManager* cdbManager = AliCDBManager::Instance();
3f862c88 59
60 Int_t run = cdbManager->GetRun();
61 if ( run < 0 ) {
0be76c28 62 AliErrorClassStream() << "Cannot get run number from CDB manager." << endl;
228fd720 63 return 0;
3f862c88 64 }
65
228fd720 66 AliCDBEntry* cdbEntry = cdbManager->Get(dataPath, run);
67 if ( ! cdbEntry ) {
68 AliErrorClassStream() << "Cannot get cdbEntry." << endl;
69 return 0;
5699c0e6 70 }
228fd720 71
72 TObject* object = cdbEntry->GetObject();
73 if ( ! object ) {
74 AliErrorClassStream() << "Cannot get object from cdbEntry." << endl;
75 return 0;
76 }
77
78 return object;
79}
80
81
82//______________________________________________________________________________
83TObject* AliMpCDB::GetCDBEntryObject(const char* dataPath,
84 const char* cdbpath,
85 Int_t runNumber )
86{
87/// Load CDB entry from CDB and run specified in arguments
88
89 AliCDBManager* cdbManager = AliCDBManager::Instance();
90 cdbManager->SetDefaultStorage(cdbpath);
91
92 AliCDBEntry* cdbEntry = cdbManager->Get(dataPath, runNumber);
93 if ( ! cdbEntry ) {
94 AliErrorClassStream() << "Cannot get cdbEntry." << endl;
95 return 0;
96 }
97
98 TObject* object = cdbEntry->GetObject();
99 if ( ! object ) {
100 AliErrorClassStream() << "Cannot get object from cdbEntry." << endl;
101 return 0;
102 }
103
104 return object;
105}
106
107//
108// public static methods
109//
110
111
112//______________________________________________________________________________
113Bool_t AliMpCDB::LoadMpSegmentation(Bool_t warn)
114{
115/// Load the sementation from the mapping data from OCDB,
116/// if it does not yet exist;
117/// return false only in case loading from CDB failed
118
119 if ( AliMpSegmentation::Instance(false) ) {
120 if ( warn )
121 AliWarningClass("Segmentation has been already loaded.");
122 return true;
123 }
124
125 if ( fgLoadFromData ) {
126 AliDebugClassStream(1)
127 << "Loading segmentation from MUON/Calib/MappingData" << endl;
128
129 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/MappingData");
130 if ( ! cdbEntryObject ) return kFALSE;
131
132 // Pass the map to the streams and then read segmentation
133 // from data map
134 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
ab167304 135 AliMpDataStreams dataStreams(dataMap);
136 AliMpSegmentation::ReadData(dataStreams);
228fd720 137 return kTRUE;
5699c0e6 138 }
228fd720 139 else {
140 AliDebugClassStream(1)
141 << "Loading segmentation from MUON/Calib/Mapping" << endl;
142
143 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/Mapping");
144 return cdbEntryObject != 0x0;
145 }
3f862c88 146}
147
148//______________________________________________________________________________
149Bool_t AliMpCDB::LoadDDLStore(Bool_t warn)
150{
228fd720 151/// Load the DDL store from the mapping data from OCDB,
152/// if it does not yet exist;
3f862c88 153/// return false only in case loading from CDB failed
154
3f862c88 155 if ( AliMpDDLStore::Instance(false) ) {
156 if ( warn )
157 AliWarningClass("DDL Store has been already loaded.");
158 return true;
159 }
160
228fd720 161 if ( fgLoadFromData ) {
162 AliDebugClassStream(1)
163 << "Loading DDL store from MUON/Calib/MappingData" << endl;
707ad0dc 164
228fd720 165 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/MappingData");
166 if ( ! cdbEntryObject ) return kFALSE;
3f862c88 167
228fd720 168 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
ab167304 169 AliMpDataStreams dataStreams(dataMap);
170 AliMpDDLStore::ReadData(dataStreams);
228fd720 171 return kTRUE;
5699c0e6 172 }
228fd720 173 else {
174 AliDebugClassStream(1)
175 << "Loading DDL store from MUON/Calib/DDLStore" << endl;
176
177 // Load segmentation
178 LoadMpSegmentation(warn);
179
180 // Load DDL store
181 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/DDLStore");
182 return cdbEntryObject != 0x0;
183 }
3f862c88 184}
185
ab167304 186//______________________________________________________________________________
187Bool_t AliMpCDB::LoadManuStore(Bool_t warn)
188{
189/// Load the DDL store from the mapping data from OCDB,
190/// if it does not yet exist;
191/// return false only in case loading from CDB failed
192
193 if ( AliMpManuStore::Instance(false) ) {
194 if ( warn )
195 AliWarningClass("Manu Store has been already loaded.");
196 return true;
197 }
198
199 if ( fgLoadFromData ) {
200 AliDebugClassStream(1)
201 << "Loading Manu store from MUON/Calib/MappingRunData" << endl;
202
203 // Load segmentation
204 LoadMpSegmentation(warn);
205
206 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/MappingRunData");
207 if ( ! cdbEntryObject ) return kFALSE;
208
209 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
210 AliMpDataStreams dataStreams(dataMap);
211 AliMpManuStore::ReadData(dataStreams);
212 return kTRUE;
213 }
214 else {
215 AliDebugClassStream(1)
216 << "Loading Manu store from MUON/Calib/ManuStore" << endl;
217
218 // Load Manu store
219 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/ManuStore");
220 return cdbEntryObject != 0x0;
221 }
222}
d3af4674 223//______________________________________________________________________________
224Bool_t AliMpCDB::LoadMpSegmentation2(const char* cdbpath, Int_t runNumber,
225 Bool_t warn)
226{
227/// Load the sementation from the CDB if it does not yet exist;
228/// return false only in case loading from CDB failed.
229/// In difference from LoadMpSegmentation(), in this method the CDB path
230/// and run is set directly via arguments.
231
232
d3af4674 233 if ( AliMpSegmentation::Instance(false) ) {
234 if ( warn )
235 AliWarningClass("Segmentation has been already loaded.");
236 return true;
237 }
238
228fd720 239 if ( fgLoadFromData ) {
240 AliDebugClassStream(1)
241 << "Loading segmentation from MUON/Calib/MappingData" << endl;
d3af4674 242
228fd720 243 TObject* cdbEntryObject
244 = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
245 if ( ! cdbEntryObject ) return kFALSE;
246
247 // Pass the map to the streams and then read segmentation
248 // from data map
249 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
ab167304 250 AliMpDataStreams dataStreams(dataMap);
251 AliMpSegmentation::ReadData(dataStreams);
228fd720 252 return kTRUE;
d3af4674 253 }
228fd720 254 else {
255 AliDebugClassStream(1)
256 << "Loading segmentation from MUON/Calib/Mapping" << endl;
257
258 TObject* cdbEntryObject
259 = GetCDBEntryObject("MUON/Calib/Mapping", cdbpath, runNumber);
260 return cdbEntryObject != 0x0;
261 }
d3af4674 262}
263
264//______________________________________________________________________________
265Bool_t AliMpCDB::LoadDDLStore2(const char* cdbpath, Int_t runNumber,
266 Bool_t warn)
267{
268/// Load the DDL store from the CDB if it does not yet exist
269/// return false only in case loading from CDB failed
270/// In difference from LoadDDLStore(), in this method the CDB path
271/// and run is set directly via arguments.
272
d3af4674 273 if ( AliMpDDLStore::Instance(false) ) {
274 if ( warn )
275 AliWarningClass("DDL Store has been already loaded.");
276 return true;
277 }
278
228fd720 279 if ( fgLoadFromData ) {
280 AliDebugClassStream(1)
281 << "Loading DDL store from MUON/Calib/MappingData" << endl;
d3af4674 282
228fd720 283 TObject* cdbEntryObject
284 = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
285 if ( ! cdbEntryObject ) return kFALSE;
d3af4674 286
228fd720 287 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
ab167304 288 AliMpDataStreams dataStreams(dataMap);
289 AliMpDDLStore::ReadData(dataStreams);
228fd720 290 return kTRUE;
d3af4674 291 }
228fd720 292 else {
293 AliDebugClassStream(1)
294 << "Loading DDL store from MUON/Calib/DDLStore" << endl;
295
296 // Load segmentation
297 LoadMpSegmentation2(cdbpath, runNumber, warn);
298
299 // Load DDL store
300 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/DDLStore");
301 return cdbEntryObject != 0x0;
302 }
d3af4674 303}
304
ab167304 305//______________________________________________________________________________
306Bool_t AliMpCDB::LoadManuStore2(const char* cdbpath, Int_t runNumber,
307 Bool_t warn)
308{
309/// Load the DDL store from the CDB if it does not yet exist
310/// return false only in case loading from CDB failed
311/// In difference from LoadDDLStore(), in this method the CDB path
312/// and run is set directly via arguments.
313
314 if ( AliMpManuStore::Instance(false) ) {
315 if ( warn )
316 AliWarningClass("Manu Store has been already loaded.");
317 return true;
318 }
319
320 if ( fgLoadFromData ) {
321 AliDebugClassStream(1)
322 << "Loading Manu store from MUON/Calib/MappingRunData" << endl;
323
324 // Load segmentation
325 LoadMpSegmentation2(cdbpath, runNumber, warn);
326
327 TObject* cdbEntryObject
328 = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
329 if ( ! cdbEntryObject ) return kFALSE;
330
331 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
332 AliMpDataStreams dataStreams(dataMap);
333 AliMpManuStore::ReadData(dataStreams);
334 return kTRUE;
335 }
336 else {
337 AliDebugClassStream(1)
338 << "Loading Manu store from MUON/Calib/ManuStore" << endl;
339
340 // Load Manu store
341 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/ManuStore");
342 return cdbEntryObject != 0x0;
343 }
344}
345
228fd720 346//______________________________________________________________________________
347Bool_t AliMpCDB::WriteMpData()
348{
349/// Write mapping data in OCDB
350
351 AliCDBManager* cdbManager = AliCDBManager::Instance();
352 if ( ! cdbManager->GetDefaultStorage() )
162637e4 353 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
228fd720 354
355 AliCDBMetaData* cdbData = new AliCDBMetaData();
356 cdbData->SetResponsible("Dimuon Offline project");
357 cdbData->SetComment("MUON mapping");
358 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
359 AliCDBId id("MUON/Calib/MappingData", 0, AliCDBRunRange::Infinity());
360
361 AliMpDataProcessor mp;
ab167304 362 AliMpDataMap* map = mp.CreateDataMap("data");
363 return cdbManager->Put(map, id, cdbData);
364}
365
366//______________________________________________________________________________
367Bool_t AliMpCDB::WriteMpRunData()
368{
369/// Write mapping data in OCDB
370
371 AliCDBManager* cdbManager = AliCDBManager::Instance();
372 if ( ! cdbManager->GetDefaultStorage() )
162637e4 373 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
ab167304 374
375 AliCDBMetaData* cdbData = new AliCDBMetaData();
376 cdbData->SetResponsible("Dimuon Offline project");
377 cdbData->SetComment("MUON run-dependent mapping");
378 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
379 AliCDBId id("MUON/Calib/MappingRunData", 0, AliCDBRunRange::Infinity());
380
381 AliMpDataProcessor mp;
382 AliMpDataMap* map = mp.CreateDataMap("data_run");
228fd720 383 return cdbManager->Put(map, id, cdbData);
384}
385
3f862c88 386//______________________________________________________________________________
90bcb4c9 387Bool_t AliMpCDB::WriteMpSegmentation(Bool_t readData)
3f862c88 388{
389/// Write mapping segmentation in OCDB
390
90bcb4c9 391 if ( ! readData && ! AliMpSegmentation::Instance() ) return false;
392
3f862c88 393 AliCDBManager* cdbManager = AliCDBManager::Instance();
394 if ( ! cdbManager->GetDefaultStorage() )
162637e4 395 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
3f862c88 396
397 AliCDBMetaData* cdbData = new AliCDBMetaData();
398 cdbData->SetResponsible("Dimuon Offline project");
399 cdbData->SetComment("MUON mapping");
400 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
ebbfcf5c 401 AliCDBId id("MUON/Calib/Mapping", 0, AliCDBRunRange::Infinity());
3f862c88 402
90bcb4c9 403 if ( readData ) {
ab167304 404 AliMpDataStreams dataStreams;
405 AliMpSegmentation::ReadData(dataStreams, false);
406 AliMpDDLStore::ReadData(dataStreams, false);
90bcb4c9 407 }
408
3f862c88 409 return cdbManager->Put(AliMpSegmentation::Instance(), id, cdbData);
410}
411
412//______________________________________________________________________________
90bcb4c9 413Bool_t AliMpCDB::WriteDDLStore(Bool_t readData)
3f862c88 414{
415/// Write mapping DDL store in OCDB
416
90bcb4c9 417 if ( ! readData && ! AliMpDDLStore::Instance() ) return false;
418
3f862c88 419 AliCDBManager* cdbManager = AliCDBManager::Instance();
420 if ( ! cdbManager->GetDefaultStorage() )
162637e4 421 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
3f862c88 422
423 AliCDBMetaData* cdbData = new AliCDBMetaData();
424 cdbData->SetResponsible("Dimuon Offline project");
425 cdbData->SetComment("MUON DDL store");
426 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
ebbfcf5c 427 AliCDBId id("MUON/Calib/DDLStore", 0, AliCDBRunRange::Infinity());
3f862c88 428
90bcb4c9 429 if ( readData ) {
ab167304 430 AliMpDataStreams dataStreams;
431 AliMpSegmentation::ReadData(dataStreams, false);
432 AliMpDDLStore::ReadData(dataStreams, false);
90bcb4c9 433 }
3f862c88 434 return cdbManager->Put(AliMpDDLStore::Instance(), id, cdbData);
435}
228fd720 436
ab167304 437//______________________________________________________________________________
438Bool_t AliMpCDB::WriteManuStore(Bool_t readData)
439{
440/// Write mapping Manu store in OCDB
441
442 if ( ! readData && ! AliMpManuStore::Instance() ) return false;
443
444 AliCDBManager* cdbManager = AliCDBManager::Instance();
445 if ( ! cdbManager->GetDefaultStorage() )
162637e4 446 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
ab167304 447
448 AliCDBMetaData* cdbData = new AliCDBMetaData();
449 cdbData->SetResponsible("Dimuon Offline project");
450 cdbData->SetComment("MUON Manu store");
451 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
452 AliCDBId id("MUON/Calib/ManuStore", 0, AliCDBRunRange::Infinity());
453
454 if ( readData ) {
455 AliMpDataStreams dataStreams;
456 AliMpSegmentation::ReadData(dataStreams, false);
457 AliMpManuStore::ReadData(dataStreams, false);
458 }
459 return cdbManager->Put(AliMpManuStore::Instance(), id, cdbData);
460}
461
228fd720 462//______________________________________________________________________________
463Bool_t AliMpCDB::GenerateMpData(const char* cdbpath, Int_t runNumber)
464{
465/// Generate mapping data ASCII files from OCDB
466
467 TObject* cdbEntryObject
468 = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
469 if ( ! cdbEntryObject ) return kFALSE;
470
471 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
472 AliMpDataProcessor mp;
473 return mp.GenerateData(dataMap);
474}
475
ab167304 476//______________________________________________________________________________
477Bool_t AliMpCDB::GenerateMpRunData(const char* cdbpath, Int_t runNumber)
478{
479/// Generate mapping data ASCII files from OCDB
480
481 TObject* cdbEntryObject
482 = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
483 if ( ! cdbEntryObject ) return kFALSE;
484
485 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
486 AliMpDataProcessor mp;
487 return mp.GenerateData(dataMap);
488}
489
183279c1 490//______________________________________________________________________________
491void AliMpCDB::UnloadAll()
492{
493 /// Unload all the mapping from the memory
494 delete AliMpDDLStore::Instance(false);
495 delete AliMpSegmentation::Instance(false);
496 delete AliMpDEStore::Instance(false);
497}
228fd720 498