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