]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliFlatESDFriend.cxx
flat friend update
[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
43
44
45
46
47
48 void AliFlatESDFriend::Ls() const
49 {
50   cout<<"Flat ESD friend: "<<endl;
51   cout<<"  N tracks: "<<fNTracks<<endl;
52   cout<<"  N track entries: "<<fNTrackEntries<<endl;
53 }
54
55
56 // _______________________________________________________________________________________________________
57
58 Int_t AliFlatESDFriend::SetFromESDfriend( const size_t allocatedMemorySize, const AliESDfriend *esdFriend )
59 {
60   // Fill flat ESD friend from ALiESDfriend
61  
62   if( allocatedMemorySize < sizeof(AliFlatESDFriend ) ) return -1;
63
64   Reset();
65   
66   if( !esdFriend ) return 0;
67   
68   Int_t err = 0;
69   size_t freeSpace = allocatedMemorySize - GetSize();
70
71   // fill event info
72   {
73     SetSkipBit( esdFriend->TestSkipBit() );
74     for( int iSector=0; iSector<72; iSector++ ){
75       SetNclustersTPC( iSector, esdFriend->GetNclustersTPC(iSector) );
76       SetNclustersTPCused( iSector, esdFriend->GetNclustersTPCused(iSector) );
77     }
78   }
79  
80   // fill track friends
81   {
82    size_t trackSize = 0;
83    int nTracks = 0;
84    int nTrackEntries = 0;
85    Long64_t *table = NULL;
86    AliFlatESDFriendTrack *flatTrack = NULL;
87    err = SetTracksStart( flatTrack, table, esdFriend->GetNumberOfTracks(), freeSpace );
88    if( err!=0 ) return err;
89    freeSpace = allocatedMemorySize - GetSize();
90    
91    for (Int_t idxTrack = 0; idxTrack < esdFriend->GetNumberOfTracks(); ++idxTrack) {
92      const AliESDfriendTrack *esdTrack = esdFriend->GetTrack(idxTrack);
93      table[idxTrack] = -1;
94      if (esdTrack) {
95        table[idxTrack] = trackSize;
96        if( freeSpace<flatTrack->EstimateSize() ) return -1;
97        new (flatTrack) AliFlatESDFriendTrack;       
98        //flatTrack->SetFromESDTrack( esdTrack );
99        trackSize += flatTrack->GetSize();
100        freeSpace -= flatTrack->GetSize();
101        nTrackEntries++;
102        flatTrack = flatTrack->GetNextTrackNonConst();
103      }
104      nTracks++;
105     }
106    
107    SetTracksEnd( nTracks, nTrackEntries, trackSize );
108   }
109
110   return 0;
111 }
112