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