]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliFlatESDFriend.cxx
Merge branch 'master_patch'
[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 using std::cout;
45 using std::endl;
46
47
48
49 void AliFlatESDFriend::Ls() const
50 {
51   cout<<"Flat ESD friend: "<<endl;
52   cout<<"  N tracks: "<<fNTracks<<endl;
53   cout<<"  N track entries: "<<fNTrackEntries<<endl;
54 }
55
56
57
58 // _______________________________________________________________________________________________________
59   ULong64_t AliFlatESDFriend::EstimateSize(AliESDfriend* esdFriend) 
60 {
61   // Estimate upper limit of the object size
62   // -> Added objects have to be added here as well
63   if(esdFriend == NULL) return 0;
64   ULong64_t size = sizeof(AliFlatESDFriend);
65         // one Long64_t per track for tracks table
66   size += esdFriend->GetNumberOfTracks() *  (AliFlatESDFriendTrack::EstimateSize() + sizeof(Long64_t) );
67   return size;
68 }
69
70
71
72 // _______________________________________________________________________________________________________
73
74 Int_t AliFlatESDFriend::SetFromESDfriend( const size_t allocatedMemorySize, const AliESDfriend *esdFriend )
75 {
76   // Fill flat ESD friend from ALiESDfriend
77  
78   if( allocatedMemorySize < sizeof(AliFlatESDFriend ) ) return -1;
79
80   Reset();
81   
82   if( !esdFriend ) return 0;
83   
84   Int_t err = 0;
85   size_t freeSpace = allocatedMemorySize - GetSize();
86
87   // fill event info
88   {
89     SetSkipBit( esdFriend->TestSkipBit() );
90     for( int iSector=0; iSector<72; iSector++ ){
91       SetNclustersTPC( iSector, esdFriend->GetNclustersTPC(iSector) );
92       SetNclustersTPCused( iSector, esdFriend->GetNclustersTPCused(iSector) );
93     }
94   }
95  
96   // fill track friends
97   {
98    size_t trackSize = 0;
99    int nTracks = 0;
100    int nTrackEntries = 0;
101    Long64_t *table = NULL;
102    AliFlatESDFriendTrack *flatTrack = NULL;
103    err = SetTracksStart( flatTrack, table, esdFriend->GetNumberOfTracks(), freeSpace );
104    if( err!=0 ) return err;
105    freeSpace = allocatedMemorySize - GetSize();
106    
107    for (Int_t idxTrack = 0; idxTrack < esdFriend->GetNumberOfTracks(); ++idxTrack) {
108      const AliESDfriendTrack *esdTrack = esdFriend->GetTrack(idxTrack);
109      table[idxTrack] = -1;
110      if (esdTrack) {
111        table[idxTrack] = trackSize;
112        if( freeSpace<flatTrack->EstimateSize() ) return -1;
113        new (flatTrack) AliFlatESDFriendTrack;       
114        if( flatTrack->SetFromESDfriendTrack( esdTrack, freeSpace ) ) return -1;
115
116        trackSize += flatTrack->GetSize();
117        freeSpace -= flatTrack->GetSize();
118        nTrackEntries++;
119        flatTrack = flatTrack->GetNextTrackNonConst();
120      }
121      nTracks++;
122     }
123    
124    SetTracksEnd( nTracks, nTrackEntries, trackSize );
125   }
126
127   return 0;
128 }
129