]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/MUONmapping/AliMpCDB.cxx
Fixes for object target dependencies
[u/mrichter/AliRoot.git] / MUON / MUONmapping / 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
2b34965a 186//______________________________________________________________________________
187Bool_t AliMpCDB::LoadAll2(const char* cdbpath, Int_t runNumber, Bool_t warn)
188{
189 /// Load everything in one shot
190 return
191 LoadDDLStore2(cdbpath,runNumber,warn) &&
192 LoadManuStore2(cdbpath,runNumber,warn);
193}
194
195//______________________________________________________________________________
196Bool_t AliMpCDB::LoadAll(Bool_t warn)
197{
198 /// Load everything in one shot
199 return LoadDDLStore(warn) && LoadManuStore(warn);
200}
201
ab167304 202//______________________________________________________________________________
203Bool_t AliMpCDB::LoadManuStore(Bool_t warn)
204{
205/// Load the DDL store from the mapping data from OCDB,
206/// if it does not yet exist;
207/// return false only in case loading from CDB failed
208
209 if ( AliMpManuStore::Instance(false) ) {
210 if ( warn )
211 AliWarningClass("Manu Store has been already loaded.");
212 return true;
213 }
214
215 if ( fgLoadFromData ) {
216 AliDebugClassStream(1)
217 << "Loading Manu store from MUON/Calib/MappingRunData" << endl;
218
219 // Load segmentation
f05cce50 220 if ( ! AliMpSegmentation::Instance(false) )
221 LoadMpSegmentation(warn);
ab167304 222
223 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/MappingRunData");
224 if ( ! cdbEntryObject ) return kFALSE;
225
226 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
227 AliMpDataStreams dataStreams(dataMap);
228 AliMpManuStore::ReadData(dataStreams);
229 return kTRUE;
230 }
231 else {
232 AliDebugClassStream(1)
233 << "Loading Manu store from MUON/Calib/ManuStore" << endl;
234
235 // Load Manu store
236 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/ManuStore");
237 return cdbEntryObject != 0x0;
238 }
239}
d3af4674 240//______________________________________________________________________________
241Bool_t AliMpCDB::LoadMpSegmentation2(const char* cdbpath, Int_t runNumber,
242 Bool_t warn)
243{
244/// Load the sementation from the CDB if it does not yet exist;
245/// return false only in case loading from CDB failed.
246/// In difference from LoadMpSegmentation(), in this method the CDB path
247/// and run is set directly via arguments.
248
249
d3af4674 250 if ( AliMpSegmentation::Instance(false) ) {
251 if ( warn )
252 AliWarningClass("Segmentation has been already loaded.");
253 return true;
254 }
255
228fd720 256 if ( fgLoadFromData ) {
257 AliDebugClassStream(1)
258 << "Loading segmentation from MUON/Calib/MappingData" << endl;
d3af4674 259
228fd720 260 TObject* cdbEntryObject
261 = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
262 if ( ! cdbEntryObject ) return kFALSE;
263
264 // Pass the map to the streams and then read segmentation
265 // from data map
266 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
ab167304 267 AliMpDataStreams dataStreams(dataMap);
268 AliMpSegmentation::ReadData(dataStreams);
228fd720 269 return kTRUE;
d3af4674 270 }
228fd720 271 else {
272 AliDebugClassStream(1)
273 << "Loading segmentation from MUON/Calib/Mapping" << endl;
274
275 TObject* cdbEntryObject
276 = GetCDBEntryObject("MUON/Calib/Mapping", cdbpath, runNumber);
277 return cdbEntryObject != 0x0;
278 }
d3af4674 279}
280
281//______________________________________________________________________________
282Bool_t AliMpCDB::LoadDDLStore2(const char* cdbpath, Int_t runNumber,
283 Bool_t warn)
284{
285/// Load the DDL store from the CDB if it does not yet exist
286/// return false only in case loading from CDB failed
287/// In difference from LoadDDLStore(), in this method the CDB path
288/// and run is set directly via arguments.
289
d3af4674 290 if ( AliMpDDLStore::Instance(false) ) {
291 if ( warn )
292 AliWarningClass("DDL Store has been already loaded.");
293 return true;
294 }
295
228fd720 296 if ( fgLoadFromData ) {
297 AliDebugClassStream(1)
298 << "Loading DDL store from MUON/Calib/MappingData" << endl;
d3af4674 299
228fd720 300 TObject* cdbEntryObject
301 = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
302 if ( ! cdbEntryObject ) return kFALSE;
d3af4674 303
228fd720 304 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
ab167304 305 AliMpDataStreams dataStreams(dataMap);
306 AliMpDDLStore::ReadData(dataStreams);
228fd720 307 return kTRUE;
d3af4674 308 }
228fd720 309 else {
310 AliDebugClassStream(1)
311 << "Loading DDL store from MUON/Calib/DDLStore" << endl;
312
313 // Load segmentation
314 LoadMpSegmentation2(cdbpath, runNumber, warn);
315
316 // Load DDL store
317 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/DDLStore");
318 return cdbEntryObject != 0x0;
319 }
d3af4674 320}
321
ab167304 322//______________________________________________________________________________
323Bool_t AliMpCDB::LoadManuStore2(const char* cdbpath, Int_t runNumber,
324 Bool_t warn)
325{
326/// Load the DDL store from the CDB if it does not yet exist
327/// return false only in case loading from CDB failed
328/// In difference from LoadDDLStore(), in this method the CDB path
329/// and run is set directly via arguments.
330
331 if ( AliMpManuStore::Instance(false) ) {
332 if ( warn )
333 AliWarningClass("Manu Store has been already loaded.");
334 return true;
335 }
336
337 if ( fgLoadFromData ) {
338 AliDebugClassStream(1)
339 << "Loading Manu store from MUON/Calib/MappingRunData" << endl;
340
341 // Load segmentation
342 LoadMpSegmentation2(cdbpath, runNumber, warn);
343
344 TObject* cdbEntryObject
345 = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
346 if ( ! cdbEntryObject ) return kFALSE;
347
348 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
349 AliMpDataStreams dataStreams(dataMap);
350 AliMpManuStore::ReadData(dataStreams);
351 return kTRUE;
352 }
353 else {
354 AliDebugClassStream(1)
355 << "Loading Manu store from MUON/Calib/ManuStore" << endl;
356
357 // Load Manu store
358 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/ManuStore");
359 return cdbEntryObject != 0x0;
360 }
361}
362
228fd720 363//______________________________________________________________________________
364Bool_t AliMpCDB::WriteMpData()
365{
366/// Write mapping data in OCDB
367
368 AliCDBManager* cdbManager = AliCDBManager::Instance();
369 if ( ! cdbManager->GetDefaultStorage() )
162637e4 370 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
228fd720 371
372 AliCDBMetaData* cdbData = new AliCDBMetaData();
373 cdbData->SetResponsible("Dimuon Offline project");
374 cdbData->SetComment("MUON mapping");
375 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
376 AliCDBId id("MUON/Calib/MappingData", 0, AliCDBRunRange::Infinity());
377
378 AliMpDataProcessor mp;
ab167304 379 AliMpDataMap* map = mp.CreateDataMap("data");
380 return cdbManager->Put(map, id, cdbData);
381}
382
383//______________________________________________________________________________
384Bool_t AliMpCDB::WriteMpRunData()
385{
386/// Write mapping data in OCDB
387
388 AliCDBManager* cdbManager = AliCDBManager::Instance();
389 if ( ! cdbManager->GetDefaultStorage() )
162637e4 390 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
ab167304 391
392 AliCDBMetaData* cdbData = new AliCDBMetaData();
393 cdbData->SetResponsible("Dimuon Offline project");
394 cdbData->SetComment("MUON run-dependent mapping");
395 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
396 AliCDBId id("MUON/Calib/MappingRunData", 0, AliCDBRunRange::Infinity());
397
398 AliMpDataProcessor mp;
399 AliMpDataMap* map = mp.CreateDataMap("data_run");
228fd720 400 return cdbManager->Put(map, id, cdbData);
401}
402
3f862c88 403//______________________________________________________________________________
d2d10ee1 404Bool_t AliMpCDB::WriteMpSegmentation(Bool_t readData)
3f862c88 405{
d2d10ee1 406/// Write mapping segmentation in OCDB
3f862c88 407
90bcb4c9 408 if ( ! readData && ! AliMpSegmentation::Instance() ) return false;
409
3f862c88 410 AliCDBManager* cdbManager = AliCDBManager::Instance();
411 if ( ! cdbManager->GetDefaultStorage() )
162637e4 412 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
3f862c88 413
414 AliCDBMetaData* cdbData = new AliCDBMetaData();
415 cdbData->SetResponsible("Dimuon Offline project");
416 cdbData->SetComment("MUON mapping");
417 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
ebbfcf5c 418 AliCDBId id("MUON/Calib/Mapping", 0, AliCDBRunRange::Infinity());
3f862c88 419
90bcb4c9 420 if ( readData ) {
ab167304 421 AliMpDataStreams dataStreams;
d2d10ee1 422 AliMpSegmentation::ReadData(dataStreams, false);
423 AliMpDDLStore::ReadData(dataStreams, false);
90bcb4c9 424 }
425
3f862c88 426 return cdbManager->Put(AliMpSegmentation::Instance(), id, cdbData);
427}
428
429//______________________________________________________________________________
d2d10ee1 430Bool_t AliMpCDB::WriteDDLStore(Bool_t readData)
3f862c88 431{
432/// Write mapping DDL store in OCDB
433
90bcb4c9 434 if ( ! readData && ! AliMpDDLStore::Instance() ) return false;
435
3f862c88 436 AliCDBManager* cdbManager = AliCDBManager::Instance();
437 if ( ! cdbManager->GetDefaultStorage() )
162637e4 438 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
3f862c88 439
440 AliCDBMetaData* cdbData = new AliCDBMetaData();
441 cdbData->SetResponsible("Dimuon Offline project");
442 cdbData->SetComment("MUON DDL store");
443 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
ebbfcf5c 444 AliCDBId id("MUON/Calib/DDLStore", 0, AliCDBRunRange::Infinity());
3f862c88 445
90bcb4c9 446 if ( readData ) {
ab167304 447 AliMpDataStreams dataStreams;
d2d10ee1 448 AliMpSegmentation::ReadData(dataStreams, false);
449 AliMpDDLStore::ReadData(dataStreams, false);
90bcb4c9 450 }
3f862c88 451 return cdbManager->Put(AliMpDDLStore::Instance(), id, cdbData);
452}
228fd720 453
ab167304 454//______________________________________________________________________________
d2d10ee1 455Bool_t AliMpCDB::WriteManuStore(Bool_t readData)
ab167304 456{
457/// Write mapping Manu store in OCDB
458
459 if ( ! readData && ! AliMpManuStore::Instance() ) return false;
460
461 AliCDBManager* cdbManager = AliCDBManager::Instance();
462 if ( ! cdbManager->GetDefaultStorage() )
162637e4 463 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
ab167304 464
465 AliCDBMetaData* cdbData = new AliCDBMetaData();
466 cdbData->SetResponsible("Dimuon Offline project");
467 cdbData->SetComment("MUON Manu store");
468 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
469 AliCDBId id("MUON/Calib/ManuStore", 0, AliCDBRunRange::Infinity());
470
471 if ( readData ) {
472 AliMpDataStreams dataStreams;
d2d10ee1 473 AliMpSegmentation::ReadData(dataStreams, false);
474 AliMpManuStore::ReadData(dataStreams, false);
ab167304 475 }
476 return cdbManager->Put(AliMpManuStore::Instance(), id, cdbData);
477}
478
228fd720 479//______________________________________________________________________________
480Bool_t AliMpCDB::GenerateMpData(const char* cdbpath, Int_t runNumber)
481{
482/// Generate mapping data ASCII files from OCDB
483
484 TObject* cdbEntryObject
485 = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
486 if ( ! cdbEntryObject ) return kFALSE;
487
488 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
489 AliMpDataProcessor mp;
490 return mp.GenerateData(dataMap);
491}
492
ab167304 493//______________________________________________________________________________
494Bool_t AliMpCDB::GenerateMpRunData(const char* cdbpath, Int_t runNumber)
495{
496/// Generate mapping data ASCII files from OCDB
497
498 TObject* cdbEntryObject
499 = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
500 if ( ! cdbEntryObject ) return kFALSE;
501
502 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
503 AliMpDataProcessor mp;
504 return mp.GenerateData(dataMap);
505}
506
183279c1 507//______________________________________________________________________________
508void AliMpCDB::UnloadAll()
509{
510 /// Unload all the mapping from the memory
511 delete AliMpDDLStore::Instance(false);
512 delete AliMpSegmentation::Instance(false);
513 delete AliMpDEStore::Instance(false);
a99c3449 514 delete AliMpManuStore::Instance(false);
183279c1 515}
228fd720 516