]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSDetTypeSim.cxx
Bug fix: adding SHLIB to SYSLIBS (C.Holm)
[u/mrichter/AliRoot.git] / ITS / AliITSDetTypeSim.cxx
CommitLineData
3b9df642 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/*
17 $Id$
18*/
19
fcf95fc7 20
7d62fb64 21/////////////////////////////////////////////////////////////////////
22// Base simulation functions for ITS //
23// //
24// //
25/////////////////////////////////////////////////////////////////////
26#include "TBranch.h"
27#include "TClonesArray.h"
28#include "TObjArray.h"
29#include "TTree.h"
30
31#include "AliRun.h"
8ba39da9 32
33#include "AliCDBManager.h"
34#include "AliCDBId.h"
35#include "AliCDBStorage.h"
36#include "AliCDBEntry.h"
37#include "AliCDBMetaData.h"
38
7d62fb64 39#include "AliITSdigit.h"
40#include "AliITSdigitSPD.h"
41#include "AliITSdigitSDD.h"
42#include "AliITSdigitSSD.h"
3b9df642 43#include "AliITSDetTypeSim.h"
7d62fb64 44#include "AliITSpListItem.h"
fcf95fc7 45#include "AliITSresponseSDD.h"
46#include "AliITSCalibrationSDD.h"
028a3709 47#include "AliITSMapSDD.h"
18da6e54 48#include "AliITSDriftSpeedArraySDD.h"
140e5249 49#include "AliITSDriftSpeedSDD.h"
fcf95fc7 50#include "AliITSCalibrationSSD.h"
fb4dfab9 51#include "AliITSNoiseSSD.h"
52#include "AliITSGainSSD.h"
53#include "AliITSBadChannelsSSD.h"
54#include "AliITSCalibrationSSD.h"
7d62fb64 55#include "AliITSsegmentationSPD.h"
56#include "AliITSsegmentationSDD.h"
57#include "AliITSsegmentationSSD.h"
58#include "AliITSsimulation.h"
59#include "AliITSsimulationSPD.h"
60#include "AliITSsimulationSDD.h"
61#include "AliITSsimulationSSD.h"
62
63
64const Int_t AliITSDetTypeSim::fgkNdettypes = 3;
8ba39da9 65const Int_t AliITSDetTypeSim::fgkDefaultNModulesSPD = 240;
66const Int_t AliITSDetTypeSim::fgkDefaultNModulesSDD = 260;
67const Int_t AliITSDetTypeSim::fgkDefaultNModulesSSD = 1698;
3b9df642 68
69ClassImp(AliITSDetTypeSim)
70
71//----------------------------------------------------------------------
72AliITSDetTypeSim::AliITSDetTypeSim():
73TObject(),
3b9df642 74fSimulation(), // [NDet]
75fSegmentation(), // [NDet]
fcf95fc7 76fCalibration(), // [NMod]
3b9df642 77fPreProcess(), // [] e.g. Fill fHitModule with hits
78fPostProcess(), // [] e.g. Wright Raw data
3b9df642 79fNSDigits(0), //! number of SDigits
e6b4e6b9 80fSDigits("AliITSpListItem",1000),
3b9df642 81fNDigits(0), //! number of Digits
023ae34b 82fRunNumber(0), //! Run number (to access DB)
3b9df642 83fDigits(), //! [NMod][NDigits]
979b5a5f 84fDDLMapSDD(0),
3b9df642 85fHitClassName(), // String with Hit class name.
86fSDigClassName(),// String with SDigit class name.
023ae34b 87fDigClassName(), // String with digit class name.
88fLoader(0), // local pointer to loader
89fFirstcall(kTRUE){ // flag
3b9df642 90 // Default Constructor
91 // Inputs:
92 // none.
93 // Outputs:
94 // none.
95 // Return:
96 // A properly zero-ed AliITSDetTypeSim class.
023ae34b 97
7d62fb64 98 fSimulation = new TObjArray(fgkNdettypes);
99 fSegmentation = new TObjArray(fgkNdettypes);
1964ae5f 100 fSegmentation->SetOwner(kTRUE);
7d62fb64 101 fDigits = new TObjArray(fgkNdettypes);
102 fNDigits = new Int_t[fgkNdettypes];
979b5a5f 103 fDDLMapSDD=new AliITSDDLModuleMapSDD();
8ba39da9 104 fNMod[0] = fgkDefaultNModulesSPD;
105 fNMod[1] = fgkDefaultNModulesSDD;
106 fNMod[2] = fgkDefaultNModulesSSD;
107 SetRunNumber();
3b9df642 108}
109//----------------------------------------------------------------------
110AliITSDetTypeSim::~AliITSDetTypeSim(){
111 // Destructor
112 // Inputs:
113 // none.
114 // Outputs:
115 // none.
116 // Return:
117 // Nothing.
023ae34b 118
7d62fb64 119 if(fSimulation){
023ae34b 120 fSimulation->Delete();
121 delete fSimulation;
7d62fb64 122 }
023ae34b 123 fSimulation = 0;
7d62fb64 124 if(fSegmentation){
023ae34b 125 fSegmentation->Delete();
126 delete fSegmentation;
7d62fb64 127 }
023ae34b 128 fSegmentation = 0;
b17dae48 129 if(fCalibration && fRunNumber<0){
023ae34b 130 AliITSresponse* rspd = ((AliITSCalibration*)fCalibration->At(
131 GetITSgeom()->GetStartSPD()))->GetResponse();
132 AliITSresponse* rsdd = ((AliITSCalibration*)fCalibration->At(
133 GetITSgeom()->GetStartSDD()))->GetResponse();
134 AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(
135 GetITSgeom()->GetStartSSD()))->GetResponse();
136 if(rspd) delete rspd;
137 if(rsdd) delete rsdd;
138 if(rssd) delete rssd;
139 fCalibration->Delete();
140 delete fCalibration;
7d62fb64 141 }
023ae34b 142 fCalibration = 0;
7d62fb64 143 if(fPreProcess){
023ae34b 144 fPreProcess->Delete();
145 delete fPreProcess;
7d62fb64 146 }
023ae34b 147 fPreProcess = 0;
7d62fb64 148 if(fPostProcess){
023ae34b 149 fPostProcess->Delete();
150 delete fPostProcess;
7d62fb64 151 }
023ae34b 152 fPostProcess = 0;
979b5a5f 153 if(fDDLMapSDD) delete fDDLMapSDD;
2a476797 154 if(fNDigits) delete [] fNDigits;
023ae34b 155 fNDigits = 0;
156 if (fLoader)fLoader->GetModulesFolder()->Remove(this);
157 fLoader = 0; // Not deleting it.
e6b4e6b9 158 fSDigits.Delete();
7d62fb64 159 if (fDigits) {
160 fDigits->Delete();
161 delete fDigits;
7d62fb64 162 }
023ae34b 163 fDigits=0;
3b9df642 164}
165//----------------------------------------------------------------------
7537d03c 166AliITSDetTypeSim::AliITSDetTypeSim(const AliITSDetTypeSim &source) : TObject(source),
167fSimulation(source.fSimulation), // [NDet]
168fSegmentation(source.fSegmentation), // [NDet]
169fCalibration(source.fCalibration), // [NMod]
170fPreProcess(source.fPreProcess), // [] e.g. Fill fHitModule with hits
171fPostProcess(source.fPostProcess), // [] e.g. Wright Raw data
172fNSDigits(source.fNSDigits), //! number of SDigits
e6b4e6b9 173fSDigits(*((TClonesArray*)source.fSDigits.Clone())),
7537d03c 174fNDigits(source.fNDigits), //! number of Digits
175fRunNumber(source.fRunNumber), //! Run number (to access DB)
176fDigits(source.fDigits), //! [NMod][NDigits]
979b5a5f 177fDDLMapSDD(source.fDDLMapSDD),
7537d03c 178fHitClassName(source.fHitClassName), // String with Hit class name.
179fSDigClassName(source.fSDigClassName),// String with SDigit class name.
180fDigClassName(), // String with digit class name.
181fLoader(source.fLoader), // local pointer to loader
182fFirstcall(source.fFirstcall)
183{
7d62fb64 184 // Copy Constructor for object AliITSDetTypeSim not allowed
7537d03c 185 for(Int_t i=0;i<fgkNdettypes;i++){
186 fDigClassName[i] = source.fDigClassName[i];
187 }
3b9df642 188}
189//----------------------------------------------------------------------
7d62fb64 190AliITSDetTypeSim& AliITSDetTypeSim::operator=(const AliITSDetTypeSim &source){
3b9df642 191 // The = operator for object AliITSDetTypeSim
7d62fb64 192
7537d03c 193 this->~AliITSDetTypeSim();
194 new(this) AliITSDetTypeSim(source);
195 return *this;
3b9df642 196}
7d62fb64 197
023ae34b 198//______________________________________________________________________
199void AliITSDetTypeSim::SetITSgeom(AliITSgeom *geom){
200 // Sets/replaces the existing AliITSgeom object kept in AliITSLoader
201 //
202 // Inputs:
203 // AliITSgoem *geom The AliITSgeom object to be used.
204 // Output:
205 // none.
206 // Return:
207 // none.
208 if(!fLoader){
209 Error("SetITSgeom","No pointer to loader - nothing done");
210 return;
211 }
212 else {
213 fLoader->SetITSgeom(geom); // protections in AliITSLoader::SetITSgeom
214 }
215
216}
217//______________________________________________________________________
218void AliITSDetTypeSim::SetLoader(AliITSLoader *loader){
219 // Sets the local copy of the AliITSLoader, and passes on the
220 // AliITSgeom object as needed.
221 // Inputs
222 // AliITSLoader *loader pointer to AliITSLoader for local use
223 // Outputs:
224 // none.
225 // Return:
226 // none.
227
228 if(fLoader==loader) return; // Same do nothing
229 if(fLoader){ // alread have an existing loader
230 Error("SetLoader",
231 "Already have an exisiting loader ptr=%p Nothing done",
232 fLoader);
233 } // end if
234 fLoader = loader;
235}
3b9df642 236//______________________________________________________________________
7d62fb64 237void AliITSDetTypeSim::SetSimulationModel(Int_t dettype,AliITSsimulation *sim){
238
239 //Set simulation model for detector type
240
241 if(fSimulation==0) fSimulation = new TObjArray(fgkNdettypes);
242 fSimulation->AddAt(sim,dettype);
243}
244//______________________________________________________________________
245AliITSsimulation* AliITSDetTypeSim::GetSimulationModel(Int_t dettype){
246
247 //Get simulation model for detector type
248 if(fSimulation==0) {
249 Warning("GetSimulationModel","fSimulation is 0!");
250 return 0;
251 }
252 return (AliITSsimulation*)(fSimulation->At(dettype));
253}
254//______________________________________________________________________
255AliITSsimulation* AliITSDetTypeSim::GetSimulationModelByModule(Int_t module){
256
257 //Get simulation model by module number
023ae34b 258 if(GetITSgeom()==0) {
259 Warning("GetSimulationModelByModule","GetITSgeom() is 0!");
7d62fb64 260 return 0;
261 }
262
023ae34b 263 return GetSimulationModel(GetITSgeom()->GetModuleType(module));
7d62fb64 264}
fcf95fc7 265//_______________________________________________________________________
1964ae5f 266void AliITSDetTypeSim::SetDefaultSegmentation(Int_t idet){
023ae34b 267 // Set default segmentation model objects
268 AliITSsegmentation *seg;
1964ae5f 269
023ae34b 270 if(fSegmentation==0x0){
271 fSegmentation = new TObjArray(fgkNdettypes);
272 fSegmentation->SetOwner(kTRUE);
273 }
274 if(GetSegmentationModel(idet))
275 delete (AliITSsegmentation*)fSegmentation->At(idet);
276 if(idet==0){
d24bc9d6 277 seg = new AliITSsegmentationSPD();
023ae34b 278 }else if(idet==1){
d24bc9d6 279 seg = new AliITSsegmentationSDD();
023ae34b 280 }else {
d24bc9d6 281 seg = new AliITSsegmentationSSD();
023ae34b 282 }
283 SetSegmentationModel(idet,seg);
284}
7d62fb64 285//______________________________________________________________________
023ae34b 286void AliITSDetTypeSim::SetSegmentationModel(Int_t dettype,
287 AliITSsegmentation *seg){
7d62fb64 288
289 //Set segmentation model for detector type
fcf95fc7 290 if(fSegmentation==0x0){
1964ae5f 291 fSegmentation = new TObjArray(fgkNdettypes);
292 fSegmentation->SetOwner(kTRUE);
293 }
7d62fb64 294 fSegmentation->AddAt(seg,dettype);
7d62fb64 295}
296//______________________________________________________________________
297AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModel(Int_t dettype){
7d62fb64 298 //Get segmentation model for detector type
299
300 if(fSegmentation==0) {
023ae34b 301 Warning("GetSegmentationModel","fSegmentation is 0!");
302 return 0;
7d62fb64 303 }
304 return (AliITSsegmentation*)(fSegmentation->At(dettype));
7d62fb64 305}
306//_______________________________________________________________________
307AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModelByModule(Int_t module){
023ae34b 308 //Get segmentation model by module number
309 if(GetITSgeom()==0){
310 Warning("GetSegmentationModelByModule","GetITSgeom() is 0!");
311 return 0;
312 }
313 return GetSegmentationModel(GetITSgeom()->GetModuleType(module));
7d62fb64 314}
315//_______________________________________________________________________
fcf95fc7 316void AliITSDetTypeSim::CreateCalibrationArray() {
023ae34b 317 //Create the container of calibration functions with correct size
318 if (fCalibration) {
319 Warning("CreateCalibration","pointer to calibration object exists\n");
320 fCalibration->Delete();
321 delete fCalibration;
322 }
8ba39da9 323
023ae34b 324 Int_t nModTot = GetITSgeom()->GetIndexMax();
325 fCalibration = new TObjArray(nModTot);
326 fCalibration->SetOwner(kTRUE);
327 fCalibration->Clear();
8ba39da9 328}
329//_______________________________________________________________________
fcf95fc7 330void AliITSDetTypeSim::SetCalibrationModel(Int_t iMod, AliITSCalibration *resp){
023ae34b 331 //Set response model for modules
8ba39da9 332
023ae34b 333 if (fCalibration==0) CreateCalibrationArray();
8ba39da9 334
023ae34b 335 if (fCalibration->At(iMod)!=0)
336 delete (AliITSCalibration*) fCalibration->At(iMod);
337 fCalibration->AddAt(resp, iMod);
8ba39da9 338}
7d62fb64 339//______________________________________________________________________
fcf95fc7 340void AliITSDetTypeSim::ResetCalibrationArray(){
023ae34b 341 //resets response array
342 if(fCalibration && fRunNumber<0){ // if fRunNumber<0 fCalibration is owner
343 AliITSresponse* rspd = ((AliITSCalibration*)fCalibration->At(
344 GetITSgeom()->GetStartSPD()))->GetResponse();
345 AliITSresponse* rsdd = ((AliITSCalibration*)fCalibration->At(
346 GetITSgeom()->GetStartSDD()))->GetResponse();
347 AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(
348 GetITSgeom()->GetStartSSD()))->GetResponse();
349 if(rspd) delete rspd;
350 if(rsdd) delete rsdd;
351 if(rssd) delete rssd;
352 fCalibration->Clear();
353 }else if (fCalibration && fRunNumber>=0){
354 fCalibration->Clear();
355 }
7d62fb64 356}
357//______________________________________________________________________
358void AliITSDetTypeSim::ResetSegmentation(){
023ae34b 359 //Resets segmentation array
360 if(fSegmentation) fSegmentation->Clear();
7d62fb64 361}
7d62fb64 362//_______________________________________________________________________
fcf95fc7 363AliITSCalibration* AliITSDetTypeSim::GetCalibrationModel(Int_t iMod){
023ae34b 364 //Get response model for module number iMod
8ba39da9 365
023ae34b 366 if(fCalibration==0) {
367 AliError("fCalibration is 0!");
368 return 0;
369 }
fcf95fc7 370 return (AliITSCalibration*)(fCalibration->At(iMod));
7d62fb64 371}
372//_______________________________________________________________________
373void AliITSDetTypeSim::SetDefaults(){
023ae34b 374 //Set defaults for segmentation and response
375
376 if(GetITSgeom()==0){
377 Warning("SetDefaults","GetITSgeom() is 0!");
378 return;
379 } // end if
380 if (fCalibration==0) {
381 CreateCalibrationArray();
382 } // end if
383
384 ResetSegmentation();
385 if(!GetCalibration()){AliFatal("Exit"); exit(0);}
386
fa4f0f62 387 SetDigitClassName(0,"AliITSdigitSPD");
388 SetDigitClassName(1,"AliITSdigitSDD");
389 SetDigitClassName(2,"AliITSdigitSSD");
390
023ae34b 391 for(Int_t idet=0;idet<fgkNdettypes;idet++){
fa4f0f62 392 if(!GetSegmentationModel(idet)) SetDefaultSegmentation(idet);
393 }
8ba39da9 394}
8ba39da9 395//______________________________________________________________________
396Bool_t AliITSDetTypeSim::GetCalibration() {
397 // Get Default calibration if a storage is not defined.
7d62fb64 398
b17dae48 399 if(!fFirstcall){
400 AliITSCalibration* cal = GetCalibrationModel(0);
401 if(cal)return kTRUE;
402 }
403 else {
404 fFirstcall = kFALSE;
405 }
406
407 SetRunNumber((Int_t)AliCDBManager::Instance()->GetRun());
408 Int_t run=GetRunNumber();
b17dae48 409
410 Bool_t origCacheStatus = AliCDBManager::Instance()->GetCacheFlag();
411 Bool_t isCacheActive = kTRUE;
412 if(GetRunNumber()<0){
413 isCacheActive=kFALSE;
414 fCalibration->SetOwner(kTRUE);
415 }
416 else{
417 fCalibration->SetOwner(kFALSE);
418 }
419
420 AliCDBManager::Instance()->SetCacheFlag(isCacheActive);
421
6727e2db 422 AliCDBEntry *entrySPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDDead", run);
b17dae48 423 AliCDBEntry *entrySDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD", run);
18da6e54 424 AliCDBEntry *drSpSDD = AliCDBManager::Instance()->Get("ITS/Calib/DriftSpeedSDD",run);
979b5a5f 425 AliCDBEntry *ddlMapSDD = AliCDBManager::Instance()->Get("ITS/Calib/DDLMapSDD",run);
028a3709 426 AliCDBEntry *mapASDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsAnodeSDD",run);
427 AliCDBEntry *mapTSDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsTimeSDD",run);
fb4dfab9 428 // AliCDBEntry *entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD", run);
028a3709 429 AliCDBEntry *entryNoiseSSD = AliCDBManager::Instance()->Get("ITS/Calib/NoiseSSD");
430 AliCDBEntry *entryGainSSD = AliCDBManager::Instance()->Get("ITS/Calib/GainSSD");
431 AliCDBEntry *entryBadChannelsSSD = AliCDBManager::Instance()->Get("ITS/Calib/BadChannelsSSD");
fb4dfab9 432
b17dae48 433 AliCDBEntry *entry2SPD = AliCDBManager::Instance()->Get("ITS/Calib/RespSPD", run);
434 AliCDBEntry *entry2SDD = AliCDBManager::Instance()->Get("ITS/Calib/RespSDD", run);
435 AliCDBEntry *entry2SSD = AliCDBManager::Instance()->Get("ITS/Calib/RespSSD", run);
06232459 436
fb4dfab9 437 if(!entrySPD || !entrySDD || !entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD ||
979b5a5f 438 !entry2SPD || !entry2SDD || !entry2SSD || !drSpSDD || !ddlMapSDD || !mapASDD ||!mapTSDD){
fb4dfab9 439 AliFatal("Calibration object retrieval failed! ");
440 return kFALSE;
441 }
8ba39da9 442
028a3709 443// if(!entrySPD || !entrySDD || !entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD ||
444// !entry2SPD || !entry2SDD || !entry2SSD){
445// AliFatal("Calibration object retrieval failed! ");
446// return kFALSE;
447// }
06232459 448
b17dae48 449 TObjArray *calSPD = (TObjArray *)entrySPD->GetObject();
450 if(!isCacheActive)entrySPD->SetObject(NULL);
8ba39da9 451 entrySPD->SetOwner(kTRUE);
06232459 452
fcf95fc7 453 AliITSresponseSPD *pSPD = (AliITSresponseSPD*)entry2SPD->GetObject();
b17dae48 454 if(!isCacheActive)entry2SPD->SetObject(NULL);
fcf95fc7 455 entry2SPD->SetOwner(kTRUE);
456
b17dae48 457 TObjArray *calSDD = (TObjArray *)entrySDD->GetObject();
458 if(!isCacheActive)entrySDD->SetObject(NULL);
8ba39da9 459 entrySDD->SetOwner(kTRUE);
06232459 460
fcf95fc7 461 AliITSresponseSDD *pSDD = (AliITSresponseSDD*)entry2SDD->GetObject();
b17dae48 462 if(!isCacheActive)entry2SDD->SetObject(NULL);
fcf95fc7 463 entry2SDD->SetOwner(kTRUE);
464
18da6e54 465 TObjArray *drSp = (TObjArray *)drSpSDD->GetObject();
466 if(!isCacheActive)drSpSDD->SetObject(NULL);
467 drSpSDD->SetOwner(kTRUE);
468
979b5a5f 469 AliITSDDLModuleMapSDD *ddlsdd=(AliITSDDLModuleMapSDD*)ddlMapSDD->GetObject();
470 if(!isCacheActive)ddlMapSDD->SetObject(NULL);
471 ddlMapSDD->SetOwner(kTRUE);
472
028a3709 473 TObjArray *mapAn = (TObjArray *)mapASDD->GetObject();
474 if(!isCacheActive)mapASDD->SetObject(NULL);
475 mapASDD->SetOwner(kTRUE);
476
477 TObjArray *mapT = (TObjArray *)mapTSDD->GetObject();
478 if(!isCacheActive)mapTSDD->SetObject(NULL);
479 mapTSDD->SetOwner(kTRUE);
480
fb4dfab9 481 /*
b17dae48 482 TObjArray *calSSD = (TObjArray *)entrySSD->GetObject();
483 if(!isCacheActive)entrySSD->SetObject(NULL);
8ba39da9 484 entrySSD->SetOwner(kTRUE);
fb4dfab9 485 */
486
487 TObjArray *noiseSSD = (TObjArray *)entryNoiseSSD->GetObject();
488 if(!isCacheActive)entryNoiseSSD->SetObject(NULL);
489 entryNoiseSSD->SetOwner(kTRUE);
490
491 TObjArray *gainSSD = (TObjArray *)entryGainSSD->GetObject();
492 if(!isCacheActive)entryGainSSD->SetObject(NULL);
493 entryGainSSD->SetOwner(kTRUE);
494
495 TObjArray *badchannelsSSD = (TObjArray *)entryBadChannelsSSD->GetObject();
496 if(!isCacheActive)entryBadChannelsSSD->SetObject(NULL);
497 entryBadChannelsSSD->SetOwner(kTRUE);
06232459 498
fcf95fc7 499 AliITSresponseSSD *pSSD = (AliITSresponseSSD*)entry2SSD->GetObject();
b17dae48 500 if(!isCacheActive)entry2SSD->SetObject(NULL);
fcf95fc7 501 entry2SSD->SetOwner(kTRUE);
502
b17dae48 503 // DB entries are deleted. In this way metadeta objects are deleted as well
504 if(!isCacheActive){
505 delete entrySPD;
506 delete entrySDD;
fb4dfab9 507 delete entryNoiseSSD;
508 delete entryGainSSD;
509 delete entryBadChannelsSSD;
b17dae48 510 delete entry2SPD;
511 delete entry2SDD;
512 delete entry2SSD;
028a3709 513 delete mapASDD;
514 delete mapTSDD;
18da6e54 515 delete drSpSDD;
979b5a5f 516 delete ddlMapSDD;
b17dae48 517 }
fcf95fc7 518
b17dae48 519 AliCDBManager::Instance()->SetCacheFlag(origCacheStatus);
520
979b5a5f 521 if ((!pSPD)||(!pSDD)||(!pSSD) || (!calSPD) || (!calSDD) || (!drSp) || (!ddlsdd)
028a3709 522 || (!mapAn) || (!mapT) || (!noiseSSD)|| (!gainSSD)|| (!badchannelsSSD)) {
8ba39da9 523 AliWarning("Can not get calibration from calibration database !");
524 return kFALSE;
525 }
fb4dfab9 526
b17dae48 527 fNMod[0] = calSPD->GetEntries();
528 fNMod[1] = calSDD->GetEntries();
fb4dfab9 529 fNMod[2] = noiseSSD->GetEntries();
8ba39da9 530 AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
531 fNMod[0], fNMod[1], fNMod[2]));
b17dae48 532 AliITSCalibration* cal;
8ba39da9 533 for (Int_t i=0; i<fNMod[0]; i++) {
b17dae48 534 cal = (AliITSCalibration*) calSPD->At(i);
535 cal->SetResponse(pSPD);
536 SetCalibrationModel(i, cal);
18da6e54 537 }
140e5249 538
539 fDDLMapSDD->SetDDLMap(ddlsdd);
946db678 540
541 for (Int_t i=0; i<fgkDefaultNModulesSDD; i++) {
542 Int_t iddl,icarlos;
543 Int_t iMod = i + fgkDefaultNModulesSPD;
544 fDDLMapSDD->FindInDDLMap(iMod,iddl,icarlos);
545 if(iddl<0){
546 AliITSCalibrationSDD* calsdddead=new AliITSCalibrationSDD();
547 calsdddead->SetResponse(pSDD);
548 calsdddead->SetBad();
549 AliITSDriftSpeedSDD* driftspdef = new AliITSDriftSpeedSDD();
550 AliITSDriftSpeedArraySDD* arrdrsp=new AliITSDriftSpeedArraySDD(1);
551 arrdrsp->AddDriftSpeed(driftspdef);
552 calsdddead->SetDriftSpeed(0,arrdrsp);
553 calsdddead->SetDriftSpeed(1,arrdrsp);
554 SetCalibrationModel(iMod, calsdddead);
555 AliWarning(Form("SDD module %d not present in DDL map: set it as dead",iMod));
556 }else{
140e5249 557 cal = (AliITSCalibration*) calSDD->At(i);
946db678 558 cal->SetResponse(pSDD);
140e5249 559 Int_t i0=2*i;
560 Int_t i1=1+2*i;
561 AliITSDriftSpeedArraySDD* arr0 = (AliITSDriftSpeedArraySDD*) drSp->At(i0);
562 AliITSMapSDD* ma0 = (AliITSMapSDD*)mapAn->At(i0);
563 AliITSMapSDD* mt0 = (AliITSMapSDD*)mapT->At(i0);
564 AliITSDriftSpeedArraySDD* arr1 = (AliITSDriftSpeedArraySDD*) drSp->At(i1);
565 AliITSMapSDD* ma1 = (AliITSMapSDD*)mapAn->At(i1);
566 AliITSMapSDD* mt1 = (AliITSMapSDD*)mapT->At(i1);
567 cal->SetDriftSpeed(0,arr0);
568 cal->SetDriftSpeed(1,arr1);
569 cal->SetMapA(0,ma0);
570 cal->SetMapA(1,ma1);
571 cal->SetMapT(0,mt0);
572 cal->SetMapT(1,mt1);
573 SetCalibrationModel(iMod, cal);
574 }
575 }
946db678 576
8ba39da9 577 for (Int_t i=0; i<fNMod[2]; i++) {
fb4dfab9 578 AliITSCalibrationSSD *calibSSD = new AliITSCalibrationSSD();
579 calibSSD->SetResponse((AliITSresponse*)pSSD);
580
581 AliITSNoiseSSD *noise = (AliITSNoiseSSD*) (noiseSSD->At(i));
582 calibSSD->SetNoise(noise);
583 AliITSGainSSD *gain = (AliITSGainSSD*) (gainSSD->At(i));
584 calibSSD->SetGain(gain);
585 AliITSBadChannelsSSD *bad = (AliITSBadChannelsSSD*) (badchannelsSSD->At(i));
586 calibSSD->SetBadChannels(bad);
587
6cc25d49 588 Int_t iMod = i + fgkDefaultNModulesSPD + fgkDefaultNModulesSDD;
fb4dfab9 589 SetCalibrationModel(iMod, calibSSD);
590
8ba39da9 591 }
8ba39da9 592 return kTRUE;
7d62fb64 593}
7d62fb64 594//_______________________________________________________________________
595void AliITSDetTypeSim::SetDefaultSimulation(){
7d62fb64 596 //Set default simulation for detector type
597
023ae34b 598 if(GetITSgeom()==0){
599 Warning("SetDefaultSimulation","GetITSgeom() is 0!");
8ba39da9 600 return;
601 }
fcf95fc7 602 if(fCalibration==0){
603 Warning("SetDefaultSimulation","fCalibration is 0!");
7d62fb64 604 return;
605 }
fcf95fc7 606 if(fSegmentation==0){
607 Warning("SetDefaultSimulation","fSegmentation is 0!");
608 for(Int_t i=0;i<fgkNdettypes;i++) SetDefaultSegmentation(i);
023ae34b 609 }else for(Int_t i=0;i<fgkNdettypes;i++) if(!GetSegmentationModel(i)){
610 Warning("SetDefaultSimulation",
611 "Segmentation not defined for det %d - Default taken\n!",i);
612 SetDefaultSegmentation(i);
1964ae5f 613 }
7d62fb64 614 AliITSsimulation* sim;
615
616 for(Int_t idet=0;idet<fgkNdettypes;idet++){
617 //SPD
618 if(idet==0){
023ae34b 619 sim = GetSimulationModel(idet);
7d62fb64 620 if(!sim){
8ba39da9 621 sim = new AliITSsimulationSPD(this);
7d62fb64 622 SetSimulationModel(idet,sim);
7d62fb64 623 }
624 }
625 //SDD
626 if(idet==1){
627 sim = GetSimulationModel(idet);
628 if(!sim){
8ba39da9 629 sim = new AliITSsimulationSDD(this);
7d62fb64 630 SetSimulationModel(idet,sim);
023ae34b 631 }
7d62fb64 632 }
633 //SSD
634 if(idet==2){
635 sim = GetSimulationModel(idet);
636 if(!sim){
8ba39da9 637 sim = new AliITSsimulationSSD(this);
7d62fb64 638 SetSimulationModel(idet,sim);
7d62fb64 639 }
7d62fb64 640 }
641
642 }
643}
7d62fb64 644//___________________________________________________________________
645void AliITSDetTypeSim::SetTreeAddressS(TTree* treeS, Char_t* name){
023ae34b 646 // Set branch address for the ITS summable digits Trees.
7d62fb64 647 char branchname[30];
648
649 if(!treeS){
650 return;
651 }
7d62fb64 652 TBranch *branch;
653 sprintf(branchname,"%s",name);
654 branch = treeS->GetBranch(branchname);
e6b4e6b9 655 TClonesArray *sdigi = &fSDigits;
656 if (branch) branch->SetAddress(&sdigi);
7d62fb64 657
658}
659//___________________________________________________________________
660void AliITSDetTypeSim::SetTreeAddressD(TTree* treeD, Char_t* name){
661 // Set branch address for the digit Trees.
662
663 const char *det[3] = {"SPD","SDD","SSD"};
664 TBranch *branch;
665
666 char branchname[30];
667
668 if(!treeD){
669 return;
670 }
671 if(!fDigits){
672 fDigits = new TObjArray(fgkNdettypes);
673 }
674 for(Int_t i=0;i<fgkNdettypes;i++){
675 Char_t* digclass = GetDigitClassName(i);
676 if(digclass==0x0){
677 if(i==0) SetDigitClassName(i,"AliITSdigitSPD");
678 if(i==1) SetDigitClassName(i,"AliITSdigitSDD");
679 if(i==2) SetDigitClassName(i,"AliITSdigitSSD");
680 digclass = GetDigitClassName(i);
681 }
682 TString classn = digclass;
683 if(!(fDigits->At(i))){
684 fDigits->AddAt(new TClonesArray(classn.Data(),1000),i);
3b9df642 685 }else{
7d62fb64 686 ResetDigits(i);
687 }
688
689 if(fgkNdettypes==3) sprintf(branchname,"%sDigits%s",name,det[i]);
690 else sprintf(branchname,"%sDigits%d",name,i+1);
691 if(fDigits){
692 branch = treeD->GetBranch(branchname);
693 if(branch) branch->SetAddress(&((*fDigits)[i]));
694 }
695 }
3b9df642 696
3b9df642 697}
7d62fb64 698//___________________________________________________________________
699void AliITSDetTypeSim::ResetDigits(){
023ae34b 700 // Reset number of digits and the digits array for the ITS detector.
7d62fb64 701
702 if(!fDigits){
703 Error("ResetDigits","fDigits is null!");
704 return;
705 }
706 for(Int_t i=0;i<fgkNdettypes;i++){
707 ResetDigits(i);
708 }
709}
710//___________________________________________________________________
711void AliITSDetTypeSim::ResetDigits(Int_t branch){
712 // Reset number of digits and the digits array for this branch.
713
714 if(fDigits->At(branch)){
715 ((TClonesArray*)fDigits->At(branch))->Clear();
716 }
717 if(fNDigits) fNDigits[branch]=0;
718
719}
720
721
722
723//_______________________________________________________________________
724void AliITSDetTypeSim::SDigitsToDigits(Option_t* opt, Char_t* name){
725 // Standard Summable digits to Digits function.
023ae34b 726 if(!GetITSgeom()){
727 Warning("SDigitsToDigits","GetITSgeom() is null!!");
7d62fb64 728 return;
729 }
730
731 const char *all = strstr(opt,"All");
732 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
733 strstr(opt,"SSD")};
734 if( !det[0] && !det[1] && !det[2] ) all = "All";
735 else all = 0;
736 static Bool_t setDef = kTRUE;
737 if(setDef) SetDefaultSimulation();
738 setDef = kFALSE;
739
740 AliITSsimulation *sim =0;
741 TTree* trees = fLoader->TreeS();
742 if( !(trees && GetSDigits()) ){
743 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
744 return;
745 }
746 sprintf(name,"%s",name);
747 TBranch* brchSDigits = trees->GetBranch(name);
748
749 Int_t id;
023ae34b 750 for(Int_t module=0;module<GetITSgeom()->GetIndexMax();module++){
751 id = GetITSgeom()->GetModuleType(module);
7d62fb64 752 if (!all && !det[id]) continue;
753 sim = (AliITSsimulation*)GetSimulationModel(id);
754 if(!sim){
755 Error("SDigit2Digits","The simulation class was not "
756 "instanciated for module %d type %s!",module,
023ae34b 757 GetITSgeom()->GetModuleTypeName(module));
7d62fb64 758 exit(1);
759 }
760 sim->InitSimulationModule(module,gAlice->GetEvNumber());
761
e6b4e6b9 762 fSDigits.Clear();
7d62fb64 763 brchSDigits->GetEvent(module);
e6b4e6b9 764 sim->AddSDigitsToModule(&fSDigits,0);
7d62fb64 765 sim->FinishSDigitiseModule();
766 fLoader->TreeD()->Fill();
767 ResetDigits();
768 }
769 fLoader->TreeD()->GetEntries();
770 fLoader->TreeD()->AutoSave();
771 fLoader->TreeD()->Reset();
772}
7d62fb64 773//_________________________________________________________
023ae34b 774void AliITSDetTypeSim::AddSumDigit(AliITSpListItem &sdig){
7d62fb64 775 //Adds the module full of summable digits to the summable digits tree.
023ae34b 776
e6b4e6b9 777 new(fSDigits[fNSDigits++]) AliITSpListItem(sdig);
7d62fb64 778}
779//__________________________________________________________
023ae34b 780void AliITSDetTypeSim::AddSimDigit(Int_t branch, AliITSdigit* d){
7d62fb64 781 // Add a simulated digit.
023ae34b 782
7d62fb64 783 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
784 switch(branch){
785 case 0:
786 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
787 break;
788 case 1:
789 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
790 break;
791 case 2:
792 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
793 break;
023ae34b 794 }
7d62fb64 795}
3b9df642 796//______________________________________________________________________
7d62fb64 797void AliITSDetTypeSim::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,
83ec5e27 798 Int_t *tracks,Int_t *hits,Float_t *charges,
799 Int_t sigexpanded){
7d62fb64 800 // Add a simulated digit to the list.
801
802 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
7d62fb64 803 switch(branch){
804 case 0:
805 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(digits,tracks,hits);
806 break;
807 case 1:
7d62fb64 808 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(phys,digits,tracks,
83ec5e27 809 hits,charges,sigexpanded);
7d62fb64 810 break;
811 case 2:
812 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(digits,tracks,hits);
813 break;
814 }
3b9df642 815}
8ba39da9 816//______________________________________________________________________
023ae34b 817void AliITSDetTypeSim::StoreCalibration(Int_t firstRun, Int_t lastRun,
818 AliCDBMetaData &md) {
8ba39da9 819 // Store calibration in the calibration database
8ba39da9 820 // The database must be created in an external piece of code (i.e.
821 // a configuration macro )
822
823 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
06232459 824 AliWarning("No storage set! Will use dummy one");
8ba39da9 825 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
8ba39da9 826 }
827
fcf95fc7 828 if (!fCalibration) {
829 AliError("AliITSCalibration classes are not defined - nothing done");
8ba39da9 830 return;
831 }
6727e2db 832 AliCDBId idRespSPD("ITS/Calib/SPDDead",firstRun, lastRun);
fcf95fc7 833 AliCDBId idRespSDD("ITS/Calib/CalibSDD",firstRun, lastRun);
834 AliCDBId idRespSSD("ITS/Calib/CalibSSD",firstRun, lastRun);
8ba39da9 835
836 TObjArray respSPD(fNMod[0]);
837 TObjArray respSDD(fNMod[1]-fNMod[0]);
838 TObjArray respSSD(fNMod[2]-fNMod[1]);
839 respSPD.SetOwner(kFALSE);
840 respSSD.SetOwner(kFALSE);
841 respSSD.SetOwner(kFALSE);
842
843 Int_t index[fgkNdettypes];
844 for (Int_t i = 0; i<fgkNdettypes; i++ ) {
845 index[i] = 0;
846 for (Int_t j = 0; j<=i; j++ )
847 index[i]+=fNMod[j];
848 }
849
850 for (Int_t i = 0; i<index[0]; i++ )
fcf95fc7 851 respSPD.Add(fCalibration->At(i));
8ba39da9 852
853 for (Int_t i = index[0]; i<index[1]; i++ )
fcf95fc7 854 respSDD.Add(fCalibration->At(i));
8ba39da9 855
856 for (Int_t i = index[1]; i<index[2]; i++ )
fcf95fc7 857 respSSD.Add(fCalibration->At(i));
8ba39da9 858
06232459 859 AliCDBManager::Instance()->Put(&respSPD, idRespSPD, &md);
860 AliCDBManager::Instance()->Put(&respSDD, idRespSDD, &md);
861 AliCDBManager::Instance()->Put(&respSSD, idRespSSD, &md);
8ba39da9 862}
863
864