]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliFlatESDFriend.cxx
remove self-initializations from reinit ctors
[u/mrichter/AliRoot.git] / HLT / global / AliFlatESDFriend.cxx
1 /* $Id$ */
2
3 /**************************************************************************
4  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5  *                                                                        *
6  * Author: The ALICE Off-line Project.                                    *
7  * Contributors are mentioned in the code where appropriate.              *
8  *                                                                        *
9  * Permission to use, copy, modify and distribute this software and its   *
10  * documentation strictly for non-commercial purposes is hereby granted   *
11  * without fee, provided that the above copyright notice appears in all   *
12  * copies and that both the copyright notice and this permission notice   *
13  * appear in the supporting documentation. The authors make no claims     *
14  * about the suitability of this software for any purpose. It is          *
15  * provided "as is" without express or implied warranty.                  *
16  **************************************************************************/
17
18 /**
19  * >> Flat structure representing an ESD friend <<
20  *
21  * To be used in the online and offline calibration schema.
22  *
23  * Class provides interface methods for 
24  *   - Filling from AliESDfriend, but also from HLT 
25  *   - Getter methods
26  *
27  * In the online case, the structure can be directly written into a shared 
28  * memory, in the offline case, the size has to be estimated first.
29  *
30  * 
31  * Primary Authors : Sergey Gorbunov, Jochen Thaeder, Chiara Zampolli
32  *
33  * ************************************************************************
34  **/
35
36 #include "AliFlatESDFriend.h"
37 #include "AliFlatESDFriendTrack.h"
38 #include "Riostream.h"
39 #include "AliESDfriend.h"
40
41 // _______________________________________________________________________________________________________
42 AliFlatESDFriend::AliFlatESDFriend() :
43   fContentSize(0),
44   fBitFlags(0),
45   fNTracks(0),
46   fNTrackEntries(0),
47   fTrackTablePointer(0),
48   fTracksPointer(0)
49 {
50   // Default constructor
51   Reset();
52 }
53
54 void AliFlatESDFriend::Reset() 
55 {
56   fBitFlags = 0;
57   fNTracks = 0;
58   fNTrackEntries = 0; 
59   fTrackTablePointer = 0;
60   fTracksPointer = 0;
61   for( int i=0; i<72; i++ ){
62     fNclustersTPC[i]=0;
63     fNclustersTPCused[i]=0;
64   }
65   // We set size of the fContent array such, that it reaches the end of the AliFlatESDFriend structure. 
66   // To be sure that actual GetSize() is always >= size of the structure. 
67   // First, it makes the memory alignment better. Second, just for a case..
68   fContentSize = sizeof(AliFlatESDFriend) - (fContent - reinterpret_cast<const Byte_t*>(this));
69   for( UInt_t i=0; i<fContentSize; i++ ) fContent[i]=0;
70 }
71  
72 // _______________________________________________________________________________________________________
73 AliFlatESDFriend::AliFlatESDFriend(AliVConstructorReinitialisationFlag f)
74 :
75 AliVfriendEvent()
76 //  fContentSize(),
77 //  fBitFlags(),
78 //  fNTracks(),
79 //  fNTrackEntries(),
80 //  fTrackTablePointer(),
81 //  fTracksPointer()
82 {
83   //special constructor, used to restore the vtable pointer
84   //uses the special dummy constructors of contained objects
85
86   // the vtable pointer for this AliFlatESDFriend object is already reset when this constructor is called
87   // we should only initialise vtable pointers for all contained objects
88
89   if(f == AliVReinitialize){   
90     for( int i=0; i<fNTracks; i++ ){
91       AliFlatESDFriendTrack  *tr = GetFlatTrackNonConst(i);
92       if( tr ) tr->Reinitialize();
93     }
94   }
95   else{
96     AliFlatESDFriend();
97   }
98 }
99
100 void AliFlatESDFriend::Ls() const
101 {
102   cout<<"Flat ESD friend: "<<endl;
103   cout<<"  N tracks: "<<fNTracks<<endl;
104   cout<<"  N track entries: "<<fNTrackEntries<<endl;
105 }
106
107
108 // _______________________________________________________________________________________________________
109 Int_t AliFlatESDFriend::SetFromESDfriend( const size_t allocatedMemorySize, const AliESDfriend *esdFriend )
110 {
111   // Fill flat ESD friend from ALiESDfriend
112  
113   if( allocatedMemorySize < sizeof(AliFlatESDFriend ) ) return -1;
114
115   Reset();
116   
117   if( !esdFriend ) return 0;
118   
119   Int_t err = 0;
120   size_t freeSpace = allocatedMemorySize - GetSize();
121
122   // fill event info
123   {
124     SetSkipBit( esdFriend->TestSkipBit() );
125     for( int iSector=0; iSector<72; iSector++ ){
126       SetNclustersTPC( iSector, esdFriend->GetNclustersTPC(iSector) );
127       SetNclustersTPCused( iSector, esdFriend->GetNclustersTPCused(iSector) );
128     }
129   }
130  
131   // fill track friends
132   {
133    size_t trackSize = 0;
134    int nTracks = 0;
135    int nTrackEntries = 0;
136    Long64_t *table = NULL;
137    AliFlatESDFriendTrack *flatTrack = NULL;
138    err = SetTracksStart( flatTrack, table, esdFriend->GetNumberOfTracks(), freeSpace );
139    if( err!=0 ) return err;
140    freeSpace = allocatedMemorySize - GetSize();
141    
142    for (Int_t idxTrack = 0; idxTrack < esdFriend->GetNumberOfTracks(); ++idxTrack) {
143      const AliESDfriendTrack *esdTrack = esdFriend->GetTrack(idxTrack);
144      table[idxTrack] = -1;
145      if (esdTrack) {
146        table[idxTrack] = trackSize;
147        if( freeSpace<flatTrack->EstimateSize() ) return -1;
148        new (flatTrack) AliFlatESDFriendTrack;       
149        //flatTrack->SetFromESDTrack( esdTrack );
150        trackSize += flatTrack->GetSize();
151        freeSpace -= flatTrack->GetSize();
152        nTrackEntries++;
153        flatTrack = flatTrack->GetNextTrackNonConst();
154      }
155      nTracks++;
156     }
157    
158    SetTracksEnd( nTracks, nTrackEntries, trackSize );
159   }
160
161   return 0;
162 }
163