]>
Commit | Line | Data |
---|---|---|
d16062ac | 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 | ||
5f25234b | 16 | // $Id: AliEvent.cxx,v 1.16 2003/12/03 14:30:26 nick Exp $ |
d16062ac | 17 | |
18 | /////////////////////////////////////////////////////////////////////////// | |
19 | // Class AliEvent | |
20 | // Creation and investigation of an Alice physics event. | |
7849a8ab | 21 | // An AliEvent can be constructed by adding AliTracks, Alivertices, AliJets |
1c01b4f8 | 22 | // and/or devices like AliCalorimeters. |
23 | // All objects which are derived from TObject can be regarded as a device. | |
d16062ac | 24 | // |
25 | // The basic functionality of AliEvent is identical to the one of AliVertex. | |
35044448 | 26 | // So, an AliEvent may be used as the primary vertex with some additional |
27 | // functionality compared to AliVertex. | |
d16062ac | 28 | // |
7849a8ab | 29 | // To provide maximal flexibility to the user, the two modes of track/jet/vertex |
30 | // storage as described in AliJet and AliVertex can be used. | |
1c01b4f8 | 31 | // In addition an identical structure is provided for the storage of devices like |
32 | // AliCalorimeter objects, which can be selected by means of the memberfunction | |
33 | // SetDevCopy(). | |
34 | // | |
35 | // a) SetDevCopy(0) (which is the default). | |
36 | // Only the pointers of the 'added' devices are stored. | |
37 | // This mode is typically used by making studies based on a fixed set | |
38 | // of devices which stays under user control or is kept on an external | |
7849a8ab | 39 | // file/tree. |
40 | // In this way the AliEvent just represents a 'logical structure' for the | |
41 | // physics analysis. | |
35044448 | 42 | // |
43 | // Note : | |
1c01b4f8 | 44 | // Modifications made to the original devices also affect the device |
7849a8ab | 45 | // objects which are stored in the AliEvent. |
35044448 | 46 | // |
1c01b4f8 | 47 | // b) SetDevCopy(1). |
48 | // Of every 'added' device a private copy will be made of which the pointer | |
7849a8ab | 49 | // will be stored. |
50 | // In this way the AliEvent represents an entity on its own and modifications | |
51 | // made to the original calorimeters do not affect the AliCalorimeter objects | |
52 | // which are stored in the AliEvent. | |
1c01b4f8 | 53 | // This mode will allow 'adding' many different devices into an AliEvent by |
54 | // creating only one device instance in the main programme and using the | |
55 | // Reset() and parameter setting memberfunctions of the object representing the device. | |
56 | // | |
57 | // Note : | |
58 | // The copy is made using the Clone() memberfunction. | |
59 | // All devices (i.e. classes derived from TObject) have the default TObject::Clone() | |
60 | // memberfunction. | |
61 | // However, devices generally contain an internal (signal) data structure | |
62 | // which may include pointers to other objects. Therefore it is recommended to provide | |
63 | // for all devices a specific copy constructor and override the default Clone() | |
64 | // memberfunction using this copy constructor. | |
65 | // An example for this may be seen from AliCalorimeter. | |
7849a8ab | 66 | // |
8e8e6c7f | 67 | // See also the documentation provided for the memberfunction SetOwner(). |
68 | // | |
7849a8ab | 69 | // Coding example to make an event consisting of a primary vertex, |
70 | // 2 secondary vertices and a calorimeter. | |
d16062ac | 71 | // -------------------------------------------------------------- |
7849a8ab | 72 | // vp contains the tracks 1,2,3 and 4 (primary vertex) |
73 | // v1 contains the tracks 5,6 and 7 (sec. vertex) | |
74 | // v2 contains the jets 1 and 2 (sec. vertex) | |
75 | // | |
7849a8ab | 76 | // AliEvent evt; |
77 | // | |
78 | // Specify the event object as the repository of all objects | |
79 | // for the event building and physics analysis. | |
80 | // | |
1c01b4f8 | 81 | // evt.SetDevCopy(1); |
7849a8ab | 82 | // evt.SetTrackCopy(1); |
83 | // | |
84 | // Fill the event structure with the basic objects | |
85 | // | |
35044448 | 86 | // AliCalorimeter emcal; |
87 | // ... | |
88 | // ... // code to fill the calorimeter data | |
89 | // ... | |
90 | // | |
1c01b4f8 | 91 | // evt.AddDevice(emcal); |
7849a8ab | 92 | // |
35044448 | 93 | // AliTrack* tx=new AliTrack(); |
7849a8ab | 94 | // for (Int_t i=0; i<10; i++) |
95 | // { | |
d16062ac | 96 | // ... |
97 | // ... // code to fill the track data | |
98 | // ... | |
7849a8ab | 99 | // evt.AddTrack(tx); |
100 | // tx->Reset(); | |
101 | // } | |
102 | // | |
35044448 | 103 | // if (tx) |
104 | // { | |
105 | // delete tx; | |
106 | // tx=0; | |
107 | // } | |
108 | // | |
7849a8ab | 109 | // Build the event structure (vertices, jets, ...) for physics analysis |
110 | // based on the basic objects from the event repository. | |
d16062ac | 111 | // |
112 | // AliJet j1,j2; | |
7849a8ab | 113 | // for (Int_t i=0; i<evt.GetNtracks(); i++) |
114 | // { | |
115 | // tx=evt.GetTrack(i); | |
d16062ac | 116 | // ... |
117 | // ... // code to fill the jet data | |
118 | // ... | |
7849a8ab | 119 | // } |
d16062ac | 120 | // |
7849a8ab | 121 | // AliVertex vp; |
35044448 | 122 | // tx=evt.GetTrack(1); |
7849a8ab | 123 | // vp.AddTrack(tx); |
35044448 | 124 | // tx=evt.GetTrack(2); |
7849a8ab | 125 | // vp.AddTrack(tx); |
35044448 | 126 | // tx=evt.GetTrack(3); |
7849a8ab | 127 | // vp.AddTrack(tx); |
35044448 | 128 | // tx=evt.GetTrack(4); |
7849a8ab | 129 | // vp.AddTrack(tx); |
d16062ac | 130 | // |
7849a8ab | 131 | // Float_t rp[3]={2.4,0.1,-8.5}; |
132 | // vp.SetPosition(rp,"car"); | |
d16062ac | 133 | // |
7849a8ab | 134 | // AliVertex v1; |
35044448 | 135 | // tx=evt.GetTrack(5); |
7849a8ab | 136 | // v1.AddTrack(tx); |
35044448 | 137 | // tx=evt.GetTrack(6); |
7849a8ab | 138 | // v1.AddTrack(tx); |
35044448 | 139 | // tx=evt.GetTrack(7); |
7849a8ab | 140 | // v1.AddTrack(tx); |
d16062ac | 141 | // |
142 | // Float_t r1[3]={1.6,-3.2,5.7}; | |
143 | // v1.SetPosition(r1,"car"); | |
144 | // | |
d16062ac | 145 | // |
7849a8ab | 146 | // AliVertex v2; |
147 | // v2.SetJetCopy(1); | |
d16062ac | 148 | // v2.AddJet(j1); |
149 | // v2.AddJet(j2); | |
150 | // | |
151 | // Float_t r2[3]={6.2,4.8,1.3}; | |
152 | // v2.SetPosition(r2,"car"); | |
153 | // | |
7849a8ab | 154 | // Specify the vertices v1 and v2 as secondary vertices of the primary |
155 | // | |
156 | // vp.SetVertexCopy(1); | |
157 | // vp.AddVertex(v1); | |
158 | // vp.AddVertex(v2); | |
159 | // | |
160 | // Enter the physics structures into the event | |
161 | // evt.SetVertexCopy(1); | |
162 | // evt.AddVertex(vp,0); | |
163 | // | |
164 | // The jets j1 and j2 are already available via sec. vertex v2, | |
165 | // but can be made available also from the event itself if desired. | |
166 | // AliJet* jx; | |
167 | // jx=v2.GetJet(1); | |
168 | // evt.AddJet(jx,0); | |
169 | // jx=v2.GetJet(2); | |
170 | // evt.AddJet(jx,0); | |
171 | // | |
84bb7c66 | 172 | // evt.Data("sph"); |
d16062ac | 173 | // v1.ListAll(); |
174 | // v2.List("cyl"); | |
175 | // | |
176 | // Float_t etot=evt.GetEnergy(); | |
177 | // Ali3Vector ptot=evt.Get3Momentum(); | |
178 | // Float_t loc[3]; | |
179 | // evt.GetPosition(loc,"sph"); | |
180 | // AliPosition r=v1.GetPosition(); | |
84bb7c66 | 181 | // r.Data(); |
d16062ac | 182 | // Int_t nt=v2.GetNtracks(); |
183 | // AliTrack* tv=v2.GetTrack(1); // Access track number 1 of Vertex v2 | |
184 | // | |
d16062ac | 185 | // evt.List(); |
186 | // | |
187 | // Int_t nv=evt.GetNvtx(); | |
7849a8ab | 188 | // AliVertex* vx=evt.GetVertex(1); // Access primary vertex |
d16062ac | 189 | // Float_t e=vx->GetEnergy(); |
190 | // | |
191 | // Float_t M=evt.GetInvmass(); | |
192 | // | |
193 | // Reconstruct the event from scratch | |
194 | // | |
195 | // evt.Reset(); | |
196 | // evt.SetNvmax(25); // Increase initial no. of sec. vertices | |
7849a8ab | 197 | // ... |
198 | // ... // code to create tracks etc... | |
199 | // ... | |
d16062ac | 200 | // |
201 | // Note : All quantities are in GeV, GeV/c or GeV/c**2 | |
202 | // | |
203 | //--- Author: Nick van Eijndhoven 27-may-2001 UU-SAP Utrecht | |
5f25234b | 204 | //- Modified: NvE $Date: 2003/12/03 14:30:26 $ UU-SAP Utrecht |
d16062ac | 205 | /////////////////////////////////////////////////////////////////////////// |
206 | ||
207 | #include "AliEvent.h" | |
c72198f1 | 208 | #include "Riostream.h" |
d16062ac | 209 | |
210 | ClassImp(AliEvent) // Class implementation to enable ROOT I/O | |
211 | ||
c72198f1 | 212 | AliEvent::AliEvent() : AliVertex() |
d16062ac | 213 | { |
214 | // Default constructor. | |
215 | // All variables initialised to default values. | |
387a745b | 216 | TTimeStamp tx; |
217 | fDaytime=tx; | |
d16062ac | 218 | fRun=0; |
219 | fEvent=0; | |
4575fcea | 220 | fAproj=0; |
221 | fZproj=0; | |
222 | fPnucProj=0; | |
da17f667 | 223 | fIdProj=0; |
4575fcea | 224 | fAtarg=0; |
225 | fZtarg=0; | |
226 | fPnucTarg=0; | |
da17f667 | 227 | fIdTarg=0; |
1c01b4f8 | 228 | fDevices=0; |
229 | fDevCopy=0; | |
d16062ac | 230 | } |
231 | /////////////////////////////////////////////////////////////////////////// | |
c72198f1 | 232 | AliEvent::AliEvent(Int_t n) : AliVertex(n) |
d16062ac | 233 | { |
234 | // Create an event to hold initially a maximum of n tracks | |
235 | // All variables initialised to default values | |
c72198f1 | 236 | if (n<=0) |
237 | { | |
238 | cout << " *** This AliVertex initialisation was invoked via the AliEvent ctor." << endl; | |
239 | } | |
387a745b | 240 | TTimeStamp tx; |
241 | fDaytime=tx; | |
d16062ac | 242 | fRun=0; |
243 | fEvent=0; | |
4575fcea | 244 | fAproj=0; |
245 | fZproj=0; | |
246 | fPnucProj=0; | |
da17f667 | 247 | fIdProj=0; |
4575fcea | 248 | fAtarg=0; |
249 | fZtarg=0; | |
250 | fPnucTarg=0; | |
da17f667 | 251 | fIdTarg=0; |
1c01b4f8 | 252 | fDevices=0; |
253 | fDevCopy=0; | |
d16062ac | 254 | } |
255 | /////////////////////////////////////////////////////////////////////////// | |
256 | AliEvent::~AliEvent() | |
257 | { | |
258 | // Default destructor | |
1c01b4f8 | 259 | if (fDevices) |
7849a8ab | 260 | { |
1c01b4f8 | 261 | delete fDevices; |
262 | fDevices=0; | |
7849a8ab | 263 | } |
d16062ac | 264 | } |
265 | /////////////////////////////////////////////////////////////////////////// | |
c72198f1 | 266 | AliEvent::AliEvent(AliEvent& evt) : AliVertex(evt) |
267 | { | |
268 | // Copy constructor. | |
269 | fDaytime=evt.fDaytime; | |
270 | fRun=evt.fRun; | |
271 | fEvent=evt.fEvent; | |
272 | fAproj=evt.fAproj; | |
273 | fZproj=evt.fZproj; | |
274 | fPnucProj=evt.fPnucProj; | |
275 | fIdProj=evt.fIdProj; | |
276 | fAtarg=evt.fAtarg; | |
277 | fZtarg=evt.fZtarg; | |
278 | fPnucTarg=evt.fPnucTarg; | |
279 | fIdTarg=evt.fIdTarg; | |
1c01b4f8 | 280 | fDevCopy=evt.fDevCopy; |
c72198f1 | 281 | |
1c01b4f8 | 282 | fDevices=0; |
283 | Int_t ndevs=evt.GetNdevices(); | |
284 | if (ndevs) | |
c72198f1 | 285 | { |
1c01b4f8 | 286 | fDevices=new TObjArray(ndevs); |
287 | if (fDevCopy) fDevices->SetOwner(); | |
288 | for (Int_t i=1; i<=ndevs; i++) | |
c72198f1 | 289 | { |
1c01b4f8 | 290 | TObject* dev=evt.GetDevice(i); |
291 | if (dev) | |
c72198f1 | 292 | { |
1c01b4f8 | 293 | if (fDevCopy) |
c72198f1 | 294 | { |
1c01b4f8 | 295 | fDevices->Add(dev->Clone()); |
c72198f1 | 296 | } |
297 | else | |
298 | { | |
1c01b4f8 | 299 | fDevices->Add(dev); |
c72198f1 | 300 | } |
301 | } | |
302 | } | |
303 | } | |
304 | } | |
305 | /////////////////////////////////////////////////////////////////////////// | |
d16062ac | 306 | void AliEvent::Reset() |
307 | { | |
308 | // Reset all variables to default values | |
309 | // The max. number of tracks is set to the initial value again | |
310 | // The max. number of vertices is set to the default value again | |
8e8e6c7f | 311 | // Note : The CalCopy mode is maintained as it was set by the user before. |
c72198f1 | 312 | |
313 | AliVertex::Reset(); | |
314 | ||
387a745b | 315 | TTimeStamp tx; |
316 | fDaytime=tx; | |
d16062ac | 317 | fRun=0; |
318 | fEvent=0; | |
4575fcea | 319 | fAproj=0; |
320 | fZproj=0; | |
321 | fPnucProj=0; | |
da17f667 | 322 | fIdProj=0; |
4575fcea | 323 | fAtarg=0; |
324 | fZtarg=0; | |
325 | fPnucTarg=0; | |
da17f667 | 326 | fIdTarg=0; |
d16062ac | 327 | |
1c01b4f8 | 328 | if (fDevices) |
7849a8ab | 329 | { |
1c01b4f8 | 330 | delete fDevices; |
331 | fDevices=0; | |
7849a8ab | 332 | } |
d16062ac | 333 | } |
334 | /////////////////////////////////////////////////////////////////////////// | |
8e8e6c7f | 335 | void AliEvent::SetOwner(Bool_t own) |
336 | { | |
337 | // Set ownership of all added objects. | |
338 | // The default parameter is own=kTRUE. | |
339 | // | |
340 | // Invokation of this memberfunction also sets all the copy modes | |
341 | // (e.g. TrackCopy & co.) according to the value of own. | |
342 | // | |
343 | // This function (with own=kTRUE) is particularly useful when reading data | |
344 | // from a tree/file, since Reset() will then actually remove all the | |
345 | // added objects from memory irrespective of the copy mode settings | |
346 | // during the tree/file creation process. In this way it provides a nice way | |
347 | // of preventing possible memory leaks in the reading/analysis process. | |
348 | // | |
349 | // In addition this memberfunction can also be used as a shortcut to set all | |
350 | // copy modes in one go during a tree/file creation process. | |
351 | // However, in this case the user has to take care to only set/change the | |
352 | // ownership (and copy mode) for empty objects (e.g. newly created objects | |
353 | // or after invokation of the Reset() memberfunction) otherwise it will | |
354 | // very likely result in inconsistent destructor behaviour. | |
355 | ||
356 | Int_t mode=1; | |
357 | if (!own) mode=0; | |
1c01b4f8 | 358 | if (fDevices) fDevices->SetOwner(own); |
359 | fDevCopy=mode; | |
8e8e6c7f | 360 | |
361 | AliVertex::SetOwner(own); | |
362 | } | |
363 | /////////////////////////////////////////////////////////////////////////// | |
387a745b | 364 | void AliEvent::SetDayTime(TTimeStamp& stamp) |
d16062ac | 365 | { |
387a745b | 366 | // Set the date and time stamp for this event. |
367 | // An exact copy of the entered date/time stamp will be saved with an | |
368 | // accuracy of 1 second. | |
d16062ac | 369 | fDaytime=stamp; |
370 | } | |
371 | /////////////////////////////////////////////////////////////////////////// | |
387a745b | 372 | void AliEvent::SetDayTime(TDatime& stamp) |
373 | { | |
374 | // Set the date and time stamp for this event. | |
375 | // The entered date/time will be interpreted as being the local date/time | |
376 | // and the accuracy is 1 second. | |
377 | // This function with the TDatime argument is mainly kept for backward | |
378 | // compatibility reasons. It is recommended to use the corresponding | |
379 | // function with the TTimeStamp argument. | |
380 | ||
381 | TTimeStamp ts(stamp.GetDate(),stamp.GetTime(),0,kFALSE); | |
382 | fDaytime=ts; | |
383 | } | |
384 | /////////////////////////////////////////////////////////////////////////// | |
d16062ac | 385 | void AliEvent::SetRunNumber(Int_t run) |
386 | { | |
387 | // Set the run number for this event | |
388 | fRun=run; | |
389 | } | |
390 | /////////////////////////////////////////////////////////////////////////// | |
391 | void AliEvent::SetEventNumber(Int_t evt) | |
392 | { | |
393 | // Set the event number for this event | |
394 | fEvent=evt; | |
395 | } | |
396 | /////////////////////////////////////////////////////////////////////////// | |
387a745b | 397 | TTimeStamp AliEvent::GetDayTime() |
d16062ac | 398 | { |
399 | // Provide the date and time stamp for this event | |
400 | return fDaytime; | |
401 | } | |
402 | /////////////////////////////////////////////////////////////////////////// | |
403 | Int_t AliEvent::GetRunNumber() | |
404 | { | |
405 | // Provide the run number for this event | |
406 | return fRun; | |
407 | } | |
408 | /////////////////////////////////////////////////////////////////////////// | |
409 | Int_t AliEvent::GetEventNumber() | |
410 | { | |
411 | // Provide the event number for this event | |
412 | return fEvent; | |
413 | } | |
414 | /////////////////////////////////////////////////////////////////////////// | |
da17f667 | 415 | void AliEvent::SetProjectile(Int_t a,Int_t z,Double_t pnuc,Int_t id) |
4575fcea | 416 | { |
da17f667 | 417 | // Set the projectile A, Z, momentum per nucleon and user defined particle ID. |
418 | // By default the particle ID is set to zero. | |
4575fcea | 419 | fAproj=a; |
420 | fZproj=z; | |
421 | fPnucProj=pnuc; | |
da17f667 | 422 | fIdProj=id; |
4575fcea | 423 | } |
424 | /////////////////////////////////////////////////////////////////////////// | |
425 | Int_t AliEvent::GetProjectileA() | |
426 | { | |
427 | // Provide the projectile A value. | |
428 | return fAproj; | |
429 | } | |
430 | /////////////////////////////////////////////////////////////////////////// | |
431 | Int_t AliEvent::GetProjectileZ() | |
432 | { | |
433 | // Provide the projectile Z value. | |
434 | return fZproj; | |
435 | } | |
436 | /////////////////////////////////////////////////////////////////////////// | |
437 | Double_t AliEvent::GetProjectilePnuc() | |
438 | { | |
439 | // Provide the projectile momentum value per nucleon. | |
440 | return fPnucProj; | |
441 | } | |
442 | /////////////////////////////////////////////////////////////////////////// | |
da17f667 | 443 | Int_t AliEvent::GetProjectileId() |
4575fcea | 444 | { |
da17f667 | 445 | // Provide the user defined particle ID of the projectile. |
446 | return fIdProj; | |
447 | } | |
448 | /////////////////////////////////////////////////////////////////////////// | |
449 | void AliEvent::SetTarget(Int_t a,Int_t z,Double_t pnuc,Int_t id) | |
450 | { | |
451 | // Set the target A, Z, momentum per nucleon and user defined particle ID. | |
452 | // By default the particle ID is set to zero. | |
4575fcea | 453 | fAtarg=a; |
454 | fZtarg=z; | |
455 | fPnucTarg=pnuc; | |
da17f667 | 456 | fIdTarg=id; |
4575fcea | 457 | } |
458 | /////////////////////////////////////////////////////////////////////////// | |
459 | Int_t AliEvent::GetTargetA() | |
460 | { | |
461 | // Provide the target A value. | |
462 | return fAtarg; | |
463 | } | |
464 | /////////////////////////////////////////////////////////////////////////// | |
465 | Int_t AliEvent::GetTargetZ() | |
466 | { | |
467 | // Provide the target Z value. | |
468 | return fZtarg; | |
469 | } | |
470 | /////////////////////////////////////////////////////////////////////////// | |
471 | Double_t AliEvent::GetTargetPnuc() | |
472 | { | |
473 | // Provide the target momentum value per nucleon. | |
474 | return fPnucTarg; | |
475 | } | |
476 | /////////////////////////////////////////////////////////////////////////// | |
da17f667 | 477 | Int_t AliEvent::GetTargetId() |
478 | { | |
479 | // Provide the user defined particle ID of the target. | |
480 | return fIdTarg; | |
481 | } | |
482 | /////////////////////////////////////////////////////////////////////////// | |
84bb7c66 | 483 | void AliEvent::HeaderData() |
d16062ac | 484 | { |
485 | // Provide event header information | |
387a745b | 486 | cout << " *" << ClassName() << "::Data* Name : " << GetName() |
487 | << " Title : " << GetTitle() << endl; | |
488 | cout << " " << fDaytime.AsString() << endl; | |
489 | cout << " Run : " << fRun << " Event : " << fEvent << endl; | |
d16062ac | 490 | |
1c01b4f8 | 491 | ShowDevices(); |
d16062ac | 492 | } |
493 | /////////////////////////////////////////////////////////////////////////// | |
84bb7c66 | 494 | void AliEvent::Data(TString f) |
d16062ac | 495 | { |
496 | // Provide event information within the coordinate frame f | |
84bb7c66 | 497 | HeaderData(); |
498 | AliVertex::Data(f); | |
d16062ac | 499 | } |
500 | /////////////////////////////////////////////////////////////////////////// | |
1c01b4f8 | 501 | Int_t AliEvent::GetNdevices() |
7849a8ab | 502 | { |
1c01b4f8 | 503 | // Provide the number of stored devices |
504 | Int_t ndevs=0; | |
505 | if (fDevices) ndevs=fDevices->GetEntries(); | |
506 | return ndevs; | |
7849a8ab | 507 | } |
508 | /////////////////////////////////////////////////////////////////////////// | |
1c01b4f8 | 509 | void AliEvent::AddDevice(TObject& d) |
7849a8ab | 510 | { |
1c01b4f8 | 511 | // Add a device to the event. |
512 | // | |
513 | // Note : | |
514 | // In case a private copy is made, this is performed via the Clone() memberfunction. | |
515 | // All devices (i.e. classes derived from TObject) have the default TObject::Clone() | |
516 | // memberfunction. | |
517 | // However, devices generally contain an internal (signal) data structure | |
518 | // which may include pointers to other objects. Therefore it is recommended to provide | |
519 | // for all devices a specific copy constructor and override the default Clone() | |
520 | // memberfunction using this copy constructor. | |
521 | // An example for this may be seen from AliCalorimeter. | |
522 | ||
523 | if (!fDevices) | |
6516b62d | 524 | { |
1c01b4f8 | 525 | fDevices=new TObjArray(); |
526 | if (fDevCopy) fDevices->SetOwner(); | |
6516b62d | 527 | } |
7849a8ab | 528 | |
1c01b4f8 | 529 | // Add the device to this event |
530 | if (fDevCopy) | |
7849a8ab | 531 | { |
1c01b4f8 | 532 | fDevices->Add(d.Clone()); |
7849a8ab | 533 | } |
534 | else | |
535 | { | |
1c01b4f8 | 536 | fDevices->Add(&d); |
7849a8ab | 537 | } |
538 | } | |
539 | /////////////////////////////////////////////////////////////////////////// | |
1c01b4f8 | 540 | void AliEvent::SetDevCopy(Int_t j) |
7849a8ab | 541 | { |
1c01b4f8 | 542 | // (De)activate the creation of private copies of the added devices. |
543 | // j=0 ==> No private copies are made; pointers of original devices are stored. | |
544 | // j=1 ==> Private copies of the devices are made and these pointers are stored. | |
545 | // | |
546 | // | |
547 | // Notes : | |
548 | // In case a private copy is made, this is performed via the Clone() memberfunction. | |
549 | // All devices (i.e. classes derived from TObject) have the default TObject::Clone() | |
550 | // memberfunction. | |
551 | // However, devices generally contain an internal (signal) data structure | |
552 | // which may include pointers to other objects. Therefore it is recommended to provide | |
553 | // for all devices a specific copy constructor and override the default Clone() | |
554 | // memberfunction using this copy constructor. | |
555 | // An example for this may be seen from AliCalorimeter. | |
556 | // | |
557 | // Once the storage contains pointer(s) to device(s) one cannot | |
558 | // change the DevCopy mode anymore. | |
559 | // To change the DevCopy mode for an existing AliEvent containing | |
560 | // devices one first has to invoke Reset(). | |
561 | ||
562 | if (!fDevices) | |
7849a8ab | 563 | { |
564 | if (j==0 || j==1) | |
565 | { | |
1c01b4f8 | 566 | fDevCopy=j; |
7849a8ab | 567 | } |
568 | else | |
569 | { | |
1c01b4f8 | 570 | cout << " *" << ClassName() << "::SetDevCopy* Invalid argument : " << j << endl; |
7849a8ab | 571 | } |
572 | } | |
573 | else | |
574 | { | |
1c01b4f8 | 575 | cout << " *" << ClassName() << "::SetDevCopy* Storage already contained devices." |
576 | << " ==> DevCopy mode not changed." << endl; | |
7849a8ab | 577 | } |
578 | } | |
579 | /////////////////////////////////////////////////////////////////////////// | |
1c01b4f8 | 580 | Int_t AliEvent::GetDevCopy() |
7849a8ab | 581 | { |
1c01b4f8 | 582 | // Provide value of the DevCopy mode. |
583 | // 0 ==> No private copies are made; pointers of original devices are stored. | |
584 | // 1 ==> Private copies of the devices are made and these pointers are stored. | |
585 | // | |
586 | // Note : | |
587 | // In case a private copy is made, this is performed via the Clone() memberfunction. | |
588 | // All devices (i.e. classes derived from TObject) have the default TObject::Clone() | |
589 | // memberfunction. | |
590 | // However, devices generally contain an internal (signal) data structure | |
591 | // which may include pointers to other objects. Therefore it is recommended to provide | |
592 | // for all devices a specific copy constructor and override the default Clone() | |
593 | // memberfunction using this copy constructor. | |
594 | // An example for this may be seen from AliCalorimeter. | |
595 | ||
596 | return fDevCopy; | |
7849a8ab | 597 | } |
598 | /////////////////////////////////////////////////////////////////////////// | |
1c01b4f8 | 599 | TObject* AliEvent::GetDevice(Int_t i) |
7849a8ab | 600 | { |
1c01b4f8 | 601 | // Return the i-th device of this event. |
602 | // The first device corresponds to i=1. | |
603 | ||
604 | if (!fDevices) | |
7849a8ab | 605 | { |
7849a8ab | 606 | return 0; |
607 | } | |
608 | else | |
609 | { | |
1c01b4f8 | 610 | Int_t ndevs=GetNdevices(); |
611 | if (i<=0 || i>ndevs) | |
7849a8ab | 612 | { |
1c01b4f8 | 613 | cout << " *" << ClassName() << "::GetDevice* Invalid argument i : " << i |
614 | << " ndevs = " << ndevs << endl; | |
7849a8ab | 615 | return 0; |
616 | } | |
617 | else | |
618 | { | |
1c01b4f8 | 619 | return fDevices->At(i-1); |
7849a8ab | 620 | } |
621 | } | |
622 | } | |
623 | /////////////////////////////////////////////////////////////////////////// | |
1c01b4f8 | 624 | TObject* AliEvent::GetDevice(TString name) |
7849a8ab | 625 | { |
1c01b4f8 | 626 | // Return the device with name tag "name" |
627 | if (!fDevices) | |
7849a8ab | 628 | { |
7849a8ab | 629 | return 0; |
630 | } | |
631 | else | |
632 | { | |
7849a8ab | 633 | TString s; |
1c01b4f8 | 634 | Int_t ndevs=GetNdevices(); |
635 | for (Int_t i=0; i<ndevs; i++) | |
7849a8ab | 636 | { |
1c01b4f8 | 637 | TObject* dev=fDevices->At(i); |
638 | if (dev) | |
35044448 | 639 | { |
1c01b4f8 | 640 | s=dev->GetName(); |
641 | if (s == name) return dev; | |
35044448 | 642 | } |
7849a8ab | 643 | } |
644 | ||
645 | return 0; // No matching name found | |
646 | } | |
647 | } | |
648 | /////////////////////////////////////////////////////////////////////////// | |
1c01b4f8 | 649 | void AliEvent::ShowDevices() |
1ce8a857 | 650 | { |
1c01b4f8 | 651 | // Provide an overview of the available devices. |
652 | Int_t ndevs=GetNdevices(); | |
653 | if (ndevs) | |
1ce8a857 | 654 | { |
1c01b4f8 | 655 | cout << " The following " << ndevs << " devices are available :" << endl; |
656 | for (Int_t i=1; i<=ndevs; i++) | |
1ce8a857 | 657 | { |
1c01b4f8 | 658 | TObject* dev=GetDevice(i); |
659 | if (dev) | |
660 | { | |
661 | cout << " Device number : " << i | |
662 | << " Class : " << dev->ClassName() | |
663 | << " Name : " << dev->GetName() << endl; | |
664 | } | |
1ce8a857 | 665 | } |
666 | } | |
667 | else | |
668 | { | |
1c01b4f8 | 669 | cout << " No devices present for this event." << endl; |
1ce8a857 | 670 | } |
671 | } | |
672 | /////////////////////////////////////////////////////////////////////////// | |
5f25234b | 673 | TObject* AliEvent::Clone(char* name) |
674 | { | |
675 | // Make a deep copy of the current object and provide the pointer to the copy. | |
676 | // This memberfunction enables automatic creation of new objects of the | |
677 | // correct type depending on the object type, a feature which may be very useful | |
678 | // for containers when adding objects in case the container owns the objects. | |
679 | // This feature allows to store either AliEvent objects or objects derived from | |
680 | // AliEvent via some generic AddEvent memberfunction, provided these derived | |
681 | // classes also have a proper Clone memberfunction. | |
682 | ||
683 | AliEvent* evt=new AliEvent(*this); | |
684 | if (name) | |
685 | { | |
686 | if (strlen(name)) evt->SetName(name); | |
687 | } | |
688 | return evt; | |
689 | } | |
690 | /////////////////////////////////////////////////////////////////////////// | |
d16062ac | 691 |