added placement new after reinterpret_cast in order to get vtable; added empty contru...
authorsgweber <steffen.georg.weber@cern.ch>
Tue, 1 Jul 2014 11:52:20 +0000 (13:52 +0200)
committersgweber <steffen.georg.weber@cern.ch>
Tue, 1 Jul 2014 11:52:20 +0000 (13:52 +0200)
HLT/BASE/AliHLTComponentBenchmark.cxx
HLT/global/AliFlatESDEvent.cxx
HLT/global/AliFlatESDEvent.h
HLT/global/AliFlatESDTrack.h
HLT/global/AliFlatESDV0.h
HLT/global/AliFlatESDVertex.h
HLT/global/AliHLTGlobalEsdConverterComponent.cxx
HLT/global/AliHLTGlobalFlatEsdConverterComponent.cxx
HLT/global/CompareFlatESDs.C

index 311e5c3..a2da3dd 100644 (file)
@@ -128,8 +128,8 @@ void AliHLTComponentBenchmark::GetStatisticsData( Double_t* statistics, TString*
   if( fNEvents<=0 ) return ;
 
   statistics[0] = fNEvents;
-  statistics[1] = fTotalInput/fNEvents/1024;
-  statistics[2] = fTotalOutput/fNEvents/1024;
+  statistics[1] = fTotalInput/fNEvents;
+  statistics[2] = fTotalOutput/fNEvents;
   
   if( fNTimers<=0 ) return ;
   
index fae6620..ad29493 100644 (file)
@@ -72,6 +72,19 @@ AliFlatESDEvent::AliFlatESDEvent() :
 {
 }
 
+/*
+AliFlatESDEvent::AliFlatESDEvent(const AliFlatESDEvent& ev) :
+  // Default constructor
+  fPrimaryVertexMask(ev.fPrimaryVertexMask),
+  fNTracks(ev.fNTracks),
+  fTracksPointer(ev.fTracksPointer),
+  fNV0s(ev.fNV0s),
+  fV0Pointer(ev.fV0Pointer),
+  fSize(ev.fSize),
+  fContent() 
+{
+}
+*/
 // _______________________________________________________________________________________________________
 AliFlatESDEvent::AliFlatESDEvent(AliESDEvent *esd) :
   // Constructor
@@ -145,6 +158,7 @@ void AliFlatESDEvent::FillPrimaryVertex(const AliESDVertex *v, Byte_t flag)
   if (!v) return;
 
   AliFlatESDVertex *vtx = reinterpret_cast<AliFlatESDVertex*> (fContent + fSize);
+  new(vtx) AliFlatESDVertex;
   vtx->Set( *v );    
   fPrimaryVertexMask |= flag;
   fSize += sizeof(AliFlatESDVertex);
@@ -155,8 +169,8 @@ Int_t AliFlatESDEvent::FillNextTrack( const AliESDtrack* esdTrack, AliESDfriendT
 {
   // fill next track
 
-  AliFlatESDTrack *flatTrack = reinterpret_cast<AliFlatESDTrack*>(fContent+fSize);
-  //new (flatTrack) AliFlatESDTrack;
+  AliFlatESDTrack * flatTrack = reinterpret_cast<AliFlatESDTrack*>(fContent+fSize);
+  new(flatTrack) AliFlatESDTrack;
   flatTrack->Fill(esdTrack, friendTrack);
   fSize += flatTrack->GetSize();
   ++fNTracks;
index 166af5f..c2aa298 100644 (file)
@@ -26,6 +26,12 @@ class AliFlatESDEvent: public AliVVevent {
   // --------------------------------------------------------------------------------
   // -- Constructor / Destructors
   AliFlatESDEvent();   
+
+// empty constructor, to be called by placement new,
+// when accessing information after reinterpret_cast
+// so that vtable is generated, but values are not overwritten
+       AliFlatESDEvent(Bool_t){}
+
   AliFlatESDEvent(AliESDEvent *esd);   
   AliFlatESDEvent(AliESDEvent *esd, Bool_t useESDFriends);   
   ~AliFlatESDEvent();  
@@ -40,7 +46,11 @@ class AliFlatESDEvent: public AliVVevent {
                            const AliESDVertex *vertexTracks );
 
  
-  AliFlatESDTrack *GetNextTrackPointer(){ return reinterpret_cast<AliFlatESDTrack*>(fContent + fSize); }
+  AliFlatESDTrack *GetNextTrackPointer(){ 
+       AliFlatESDTrack * t = reinterpret_cast<AliFlatESDTrack*> (fContent + fSize);
+       new(t)  AliFlatESDTrack(kTRUE);
+       return t;
+  }
 
   void StoreLastTrack(){ 
     fNTracks++;
@@ -48,7 +58,11 @@ class AliFlatESDEvent: public AliVVevent {
     fV0Pointer = fSize;
   }
 
-  AliFlatESDV0 *GetNextV0Pointer(){ return reinterpret_cast<AliFlatESDV0*>(fContent + fSize); }
+  AliFlatESDV0 *GetNextV0Pointer(){
+       AliFlatESDV0 * t = reinterpret_cast<AliFlatESDV0*> (fContent + fSize);
+       new(t)  AliFlatESDV0(kTRUE);
+       return t;
+}
 
   void StoreLastV0(){ 
     fNV0s++;
@@ -58,19 +72,33 @@ class AliFlatESDEvent: public AliVVevent {
   // --------------------------------------------------------------------------------
   // -- Getter methods
 
-  const AliFlatESDVertex* GetPrimaryVertexSPD() const {
-    return (fPrimaryVertexMask & 0x1) ? reinterpret_cast<const AliFlatESDVertex*>(fContent) : NULL;
+   const AliFlatESDVertex* GetPrimaryVertexSPD() const {
+    if (fPrimaryVertexMask & 0x1){
+                AliFlatESDVertex * t = reinterpret_cast< AliFlatESDVertex*> (const_cast<Byte_t*>(fContent));
+               new(t)  AliFlatESDVertex(kTRUE);
+               return t;
+       }
+       else return NULL;
   } 
 
-  const AliFlatESDVertex* GetPrimaryVertexTracks() const { 
-    return (fPrimaryVertexMask & 0x2) ? reinterpret_cast<const AliFlatESDVertex*>(fContent) + CountBits(fPrimaryVertexMask, 0x1) : NULL;
-  } 
+  const  AliFlatESDVertex* GetPrimaryVertexTracks() const { 
+    if (fPrimaryVertexMask & 0x2){
+                AliFlatESDVertex * t = reinterpret_cast< AliFlatESDVertex*> (const_cast<Byte_t*>(fContent)) + CountBits(fPrimaryVertexMask, 0x1);
+               new(t)  AliFlatESDVertex(kTRUE);
+               return t;
+       }
+       else return NULL;
+   } 
 
   Int_t GetNumberOfV0s() const {return fNV0s;}
 
   Int_t GetNumberOfTracks() const {return fNTracks;}
   
-  AliFlatESDTrack *GetTracks() {return reinterpret_cast<AliFlatESDTrack*>(fContent + fTracksPointer);}
+  AliFlatESDTrack *GetTracks() {
+       AliFlatESDTrack * t = reinterpret_cast<AliFlatESDTrack*> (fContent + fTracksPointer);
+       new(t)  AliFlatESDTrack(kTRUE);
+       return t;
+}
 
   const AliVVvertex* GetPrimaryVertex() const {return NULL;}
   const AliVVvertex* GetPrimaryVertexTPC() const {return NULL;}
@@ -93,7 +121,10 @@ class AliFlatESDEvent: public AliVVevent {
   // -- Size methods
   static ULong64_t EstimateSize(AliESDEvent*esd, Bool_t useESDFriends = kTRUE, Bool_t fillV0s=kTRUE);
          ULong64_t GetSize()    {return fContent - reinterpret_cast<Byte_t*>(this) + fSize;}
-  
+
+
+
+
  private:
   AliFlatESDEvent(const AliFlatESDEvent&);
   AliFlatESDEvent& operator=(const AliFlatESDEvent&);
index 1ec1045..45e5c0d 100644 (file)
@@ -31,6 +31,7 @@ class AliFlatESDTrack: public AliVVtrack {
   // --------------------------------------------------------------------------------
   // -- Constructor / Destructors
   AliFlatESDTrack();   
+  AliFlatESDTrack(Bool_t){}   
   AliFlatESDTrack(const AliESDtrack* track, AliESDfriendTrack* friendTrack); 
   ~AliFlatESDTrack();  
 
@@ -91,9 +92,11 @@ class AliFlatESDTrack: public AliVVtrack {
   AliFlatTPCCluster *GetTPCClusters() {
     return reinterpret_cast< AliFlatTPCCluster*>(fContent + sizeof(AliFlatExternalTrackParam)*CountBits(fTrackParamMask));
   } 
+
+
   
   AliFlatTPCCluster *GetTPCCluster(Int_t ind) {
-    return GetTPCClusters() + ind*sizeof(AliFlatTPCCluster);
+    return  reinterpret_cast< AliFlatTPCCluster*>( GetTPCClusters() ) + ind ;
   }
 
   Int_t GetNumberOfITSClusters() {
@@ -103,13 +106,20 @@ class AliFlatESDTrack: public AliVVtrack {
   
   // --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  
   
-  AliFlatESDTrack *GetNextTrack() {return reinterpret_cast<AliFlatESDTrack*>(fContent+fSize);}
+  AliFlatESDTrack *GetNextTrack() 
+{      
+       
+       AliFlatESDTrack * t = reinterpret_cast<AliFlatESDTrack*> (fContent + fSize);
+       new(t)  AliFlatESDTrack(kTRUE);
+       return t;
+}
   
   // --------------------------------------------------------------------------------
   // -- Size methods
   static ULong64_t EstimateSize(Bool_t useESDFriends = kTRUE, Int_t nTPCClusters = 160 );
          ULong64_t GetSize()  {return fContent -  reinterpret_cast<Byte_t*>(this) + fSize;}
     
+
  private:
   AliFlatESDTrack(const AliFlatESDTrack&);
   AliFlatESDTrack& operator=(const AliFlatESDTrack&);
index 0846e68..524f03d 100644 (file)
@@ -14,6 +14,7 @@
 
 struct AliFlatESDV0: public AliVVv0
 {
+  AliFlatESDV0(Bool_t){}
   Int_t fNegTrackID;
   Int_t fPosTrackID;
 };
index 8cb7726..ca98f8f 100644 (file)
@@ -26,6 +26,8 @@ class AliFlatESDVertex: public AliVVvertex
     Char_t fBCID;     // BC ID assigned to vertex
   */
 
+       AliFlatESDVertex(Bool_t){}
+
   AliFlatESDVertex() :fNContributors(0), fChi2(0){
     for( int i=0; i<3; i++) fPosition[i] = -9999;
     for( int i=0; i<6; i++) fCov[i] = -9999;
index 79a3bfb..1771c5f 100644 (file)
@@ -390,7 +390,7 @@ AliSysInfo::AddStamp("DoEvent.Start", evtData.fStructSize);
        //  FillBenchmarkHistos( statistics, names);
          fBenchmark.Reset();
   
-       AliSysInfo::AddStamp("DoEvent.Stop", (int)(1000*statistics[1]), (int)(1000*statistics[2]) );
+       AliSysInfo::AddStamp("DoEvent.Stop", (int)(statistics[1]), (int)(statistics[2]),pESD->GetNumberOfV0s(),pESD->GetNumberOfTracks() );
   }
   
   
index 0a1775f..3c07998 100644 (file)
@@ -63,6 +63,8 @@
 #include "AliHLTTPCClusterMCData.h"
 #include "AliHLTTPCTransform.h"
 
+#include "AliSysInfo.h"
+
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTGlobalFlatEsdConverterComponent)
 
@@ -263,7 +265,13 @@ int AliHLTGlobalFlatEsdConverterComponent::DoEvent( const AliHLTComponentEventDa
                                                    AliHLTUInt32_t& size,
                                                    AliHLTComponentBlockDataList& outputBlocks)
 {
+
   // see header file for class documentation
+
+
+AliSysInfo::AddStamp("DoEvent.Start");
+
+
   int iResult=0;
   bool benchmark = true;
 
@@ -430,7 +438,7 @@ int AliHLTGlobalFlatEsdConverterComponent::DoEvent( const AliHLTComponentEventDa
 
     for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(AliHLTTPCDefinitions::fgkClustersDataType| kAliHLTDataOriginTPC);
         pBlock!=NULL; pBlock=GetNextInputBlock()) {
-      //fBenchmark.AddInput(pBlock->fSize);
+      fBenchmark.AddInput(pBlock->fSize);
       UInt_t slice     = AliHLTTPCDefinitions::GetMinSliceNr(*pBlock); 
       UInt_t patch  = AliHLTTPCDefinitions::GetMinPatchNr(*pBlock);
       if( slice >= kNSlices || patch>= kNPatches ){
@@ -442,7 +450,7 @@ int AliHLTGlobalFlatEsdConverterComponent::DoEvent( const AliHLTComponentEventDa
     
     for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo| kAliHLTDataOriginTPC);
         pBlock!=NULL; pBlock=GetNextInputBlock()) {
-      //fBenchmark.AddInput(pBlock->fSize);
+      fBenchmark.AddInput(pBlock->fSize);
       UInt_t slice     = AliHLTTPCDefinitions::GetMinSliceNr(*pBlock); 
       UInt_t patch  = AliHLTTPCDefinitions::GetMinPatchNr(*pBlock);
       if( slice >= kNSlices || patch>= kNPatches ){
@@ -554,11 +562,17 @@ int AliHLTGlobalFlatEsdConverterComponent::DoEvent( const AliHLTComponentEventDa
        }
        
        AliFlatESDTrack *flatTrack = flatEsd->GetNextTrackPointer();
+       //cout<<"flatTrack: "<<flatTrack<<endl;
+
+       //cout<<"GetNumberOfTPCClusters before: "<<flatTrack->GetNumberOfTPCClusters()<<endl;
 
        UInt_t nClustersTPC = tpcTrack->GetNumberOfPoints();
        UInt_t nClustersITS = itsRefit ?itsRefit->GetNumberOfPoints() :0;
 
        flatTrack->SetNumberOfITSClusters( nClustersITS );
+       //flatTrack->SetNumberOfTPCClusters(0);
+
+       //cout<<"GetNumberOfTPCClusters: "<<flatTrack->GetNumberOfTPCClusters()<<endl;
 
        if( flatEsd->GetSize() + flatTrack->EstimateSize( kTRUE, nClustersTPC ) >= maxOutputSize ){
                cout<<endl<<endl<<"NOT ENOUGH MEMORY!!!!"<<endl<<endl;
@@ -589,7 +603,8 @@ int AliHLTGlobalFlatEsdConverterComponent::DoEvent( const AliHLTComponentEventDa
                 continue;
              } 
              const AliHLTTPCSpacePointData &cIn = clusterBlock->fSpacePoints[iCluster];
-             AliFlatTPCCluster *c= flatTrack->GetNextTPCClusterPointer();
+
+             AliFlatTPCCluster *c= flatTrack->GetTPCCluster( flatTrack->GetNumberOfTPCClusters() );;
              c->fX = cIn.GetX();
              c->fY = cIn.GetY();
              c->fZ = cIn.GetZ();
@@ -602,6 +617,8 @@ int AliHLTGlobalFlatEsdConverterComponent::DoEvent( const AliHLTComponentEventDa
           }
        }
 
+               //      cout<<"number of tpc clusters: "<<flatTrack->GetNumberOfTPCClusters()<<endl;
+                       //cout<<"number of its clusters: "<<flatTrack->GetNumberOfITSClusters()<<endl;
        
        flatEsd->StoreLastTrack();
        
@@ -615,6 +632,7 @@ int AliHLTGlobalFlatEsdConverterComponent::DoEvent( const AliHLTComponentEventDa
   {    
     const AliHLTComponentBlockData* pP = GetFirstInputBlock(kAliHLTDataTypeGlobalVertexer|kAliHLTDataOriginOut);
     if (pP && pP->fSize && pP->fPtr) {
+               fBenchmark.AddInput(pP->fSize);
       const AliHLTGlobalVertexerComponent::AliHLTGlobalVertexerData *data = reinterpret_cast<AliHLTGlobalVertexerComponent::AliHLTGlobalVertexerData*>(pP->fPtr);
       const int* v0s = data->fTrackIndices + data->fNPrimTracks;
       nV0s = data->fNV0s;
@@ -633,6 +651,12 @@ int AliHLTGlobalFlatEsdConverterComponent::DoEvent( const AliHLTComponentEventDa
   for( const AliHLTComponentBlockData *i= GetFirstInputBlock(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS); i!=NULL; i=GetNextInputBlock() ){
     fBenchmark.AddInput(i->fSize);
   }
+  // Get Track vertex
+  for( const AliHLTComponentBlockData *i= GetFirstInputBlock(kAliHLTDataTypeESDVertex|kAliHLTDataOriginOut); i!=NULL; i=GetNextInputBlock() ){
+    fBenchmark.AddInput(i->fSize);
+  }
+
+
 
   /*
   for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS); iter != NULL; iter = GetNextInputObject() ) {
@@ -732,9 +756,15 @@ int AliHLTGlobalFlatEsdConverterComponent::DoEvent( const AliHLTComponentEventDa
          
        //  FillBenchmarkHistos( statistics, names);
          fBenchmark.Reset();
+
+       AliSysInfo::AddStamp("DoEvent.Stop", (int)(statistics[1]), (int)(statistics[2]) );
   
   }
   return iResult;
+
+
+
+
 }
 
 
index 3761f2e..f436066 100644 (file)
 #include "Riostream.h"
 #endif   
 
-void CompareFlatESDs(const char* filename1="outFlatESD1.root",const char* filename2="outFlatESD2.root") {
+void CompareFlatESDs(const char* filename1="outFlatESD1.dat",const char* filename2="outFlatESD2.dat", Bool_t verbose=kFALSE) {
   
   
   // Create output histograms
   
-    TH2F* hNTracks;
   
   TString outputFilename = "$PWD/compare.root";
   
        cout<< "creating histograms"<<endl;
-       hNTracks = new TH2F("nTracks","number of tracks", 100,0,100, 100,0,100);
+       TH2F* hNTracks = new TH2F("nTracks","number of tracks", 100,0,100, 100,0,100);
+       TH2F* hNV0s = new TH2F("nV0s","number of V0s", 10,0,10, 10,0,10);
+       TH2F* hVtxTr = new TH2F("vtxTr","vtx Tracks", 2,0,2, 2,0,2);
+       TH2F* hVtxSPD = new TH2F("vtxSPD","vtx SPD", 2,0,2, 2,0,2);
+       TH1F * hStat = new TH1F("stat","statistics Differences",20,0,20);
+       hStat->GetXaxis()->SetBinLabel(1,"All events");
+       hStat->GetXaxis()->SetBinLabel(2,"no diffs");
+       hStat->GetXaxis()->SetBinLabel(3,"nTracks");
+       hStat->GetXaxis()->SetBinLabel(4,"nV0s");
+       hStat->GetXaxis()->SetBinLabel(5,"vtxTracks");
+       hStat->GetXaxis()->SetBinLabel(6,"vtxSPD");
+       hStat->GetXaxis()->SetBinLabel(7,"tracks->extParams");
+
   
   
 
@@ -79,11 +90,15 @@ void CompareFlatESDs(const char* filename1="outFlatESD1.root",const char* filena
     char *endBuff2 = buffer2+length2;
        
     int iEvent = 0;
+       static const int nExt = 4;
     
        while( curr1 < endBuff1  && curr2 < endBuff2 ){
+//cout<<" curr1 endBuff1 curr2 endBuff2 "<< static_cast<void*> (curr1)<<" "<<static_cast<void*> (endBuff1)<<" "<<static_cast<void*> (curr2)<<" "<<static_cast<void*> (endBuff2)<<endl;
+
+       Int_t diff[6]={0};
       AliFlatESDEvent *flatEsd1 = reinterpret_cast<AliFlatESDEvent *>(curr1);
       AliFlatESDEvent *flatEsd2 = reinterpret_cast<AliFlatESDEvent *>(curr2);
-         
+         /*
          if(flatEsd1->GetNumberOfTracks()==0  ||  flatEsd2->GetNumberOfTracks() ==0){
                if(flatEsd1->GetNumberOfTracks()==0){
                  curr1=curr1+ flatEsd1->GetSize();
@@ -93,116 +108,179 @@ void CompareFlatESDs(const char* filename1="outFlatESD1.root",const char* filena
                }
                continue;
          }
-         
+         */
          
       cout<<endl<<"Reading event "<<iEvent<<":"<<endl;
+         /*
+       if(  flatEsd1->GetNumberOfTracks() != flatEsd2->GetNumberOfTracks() ) {
+               cout<<"\t\tDIFFERENCE!: ";
+               diff[0] =1;
+       }
+       cout<<"\t\tntracks: "<<flatEsd1->GetNumberOfTracks()<< " | " <<flatEsd2->GetNumberOfTracks();
+       hNTracks->Fill(flatEsd1->GetNumberOfTracks(),flatEsd2->GetNumberOfTracks());
          
-         
-         if( (Bool_t) flatEsd1->GetPrimaryVertexSPD() != (Bool_t) flatEsd2->GetPrimaryVertexSPD()  ) cout<<"DIFFERENCE!: ";
-      cout<<"vtx SPD: "<<(Bool_t) flatEsd1->GetPrimaryVertexSPD() << " | " << (Bool_t) flatEsd2->GetPrimaryVertexSPD() << endl;
+         if(  flatEsd1->GetNumberOfV0s() != flatEsd2->GetNumberOfV0s() ){
+               cout<<"\t\tDIFFERENCE!: ";
+               diff[1] =1;
+       }
+         cout<<"\t\tnV0's: "<<flatEsd1->GetNumberOfV0s()<< " | " <<flatEsd2->GetNumberOfV0s()<<endl;
+         hNV0s->Fill(flatEsd1->GetNumberOfV0s(),flatEsd2->GetNumberOfV0s());
+        
+         if( (Bool_t) flatEsd1->GetPrimaryVertexTracks() != (Bool_t) flatEsd2->GetPrimaryVertexTracks()  ){
+               cout<<"\t\tDIFFERENCE!: ";
+               diff[2] =1;
+       }
+
+
+         cout<<"\t\tvtx tracks: "<<(Bool_t) flatEsd1->GetPrimaryVertexTracks()<< " | " <<      (Bool_t) flatEsd2->GetPrimaryVertexTracks();      
+         hVtxTr->Fill( (Bool_t) flatEsd1->GetPrimaryVertexTracks(), (Bool_t) flatEsd2->GetPrimaryVertexTracks());
+
         
-         if( (Bool_t) flatEsd1->GetPrimaryVertexTracks() != (Bool_t) flatEsd2->GetPrimaryVertexTracks()  ) cout<<"DIFFERENCE!: ";
-         cout<<" vtx tracks: "<<(Bool_t) flatEsd1->GetPrimaryVertexTracks()<< " | " << (Bool_t) flatEsd2->GetPrimaryVertexTracks()<< endl;
-         
-         if(  flatEsd1->GetNumberOfTracks() != flatEsd2->GetNumberOfTracks() ) cout<<"DIFFERENCE!: ";
-         cout<<" ntracks: "<<flatEsd1->GetNumberOfTracks()<< " | " <<flatEsd2->GetNumberOfTracks()<< endl;
-         
-         if(  flatEsd1->GetNumberOfV0s() != flatEsd2->GetNumberOfV0s() ) cout<<"DIFFERENCE!: ";
-         cout<<" nV0's: "<<flatEsd1->GetNumberOfV0s()<< " | " <<flatEsd2->GetNumberOfV0s()<< endl;
-         
          
+         if( (Bool_t) flatEsd1->GetPrimaryVertexSPD() != (Bool_t) flatEsd2->GetPrimaryVertexSPD()  ){
+               cout<<"\t\tDIFFERENCE!: ";
+               diff[3] =1;
+       }
+      cout<<"\t\tvtx SPD: "<<(Bool_t) flatEsd1->GetPrimaryVertexSPD() << " | " << (Bool_t) flatEsd2->GetPrimaryVertexSPD()<<endl;
+         hVtxSPD->Fill( (Bool_t) flatEsd1->GetPrimaryVertexSPD(), (Bool_t) flatEsd2->GetPrimaryVertexSPD());
+
+  if(true|| (Bool_t)flatEsd1->GetPrimaryVertexSPD() && (Bool_t)flatEsd2->GetPrimaryVertexSPD()  ){
+               cout<<endl<<"\t\tvtx tracksX: "<< flatEsd1->GetPrimaryVertexSPD()<<" | " <<     flatEsd2->GetPrimaryVertexSPD();          
+               }
+         */
          
          // compare tracks
-         
-         
+         #if 1
          AliFlatESDTrack *track1 = flatEsd1->GetTracks();
          AliFlatESDTrack *track2 = flatEsd2->GetTracks();
-    for (Int_t idxTrack = 0; idxTrack < flatEsd1->GetNumberOfTracks(); ++idxTrack) { 
+    for (Int_t idxTrack = 0; idxTrack < flatEsd1->GetNumberOfTracks() && track1 && track2; ++idxTrack) { 
 
-      if (track1 && track2) {
-       AliFlatExternalTrackParam* exp11 = track1->GetTrackParamCp();
-       AliFlatExternalTrackParam* exp21 = track1->GetTrackParamIp();
-       AliFlatExternalTrackParam* exp31 = track1->GetTrackParamTPCInner();
-       AliFlatExternalTrackParam* exp41 = track1->GetTrackParamOp();
-       
-       AliFlatExternalTrackParam* exp12 = track2->GetTrackParamCp();
-       AliFlatExternalTrackParam* exp22 = track2->GetTrackParamIp();
-       AliFlatExternalTrackParam* exp32 = track2->GetTrackParamTPCInner();
-       AliFlatExternalTrackParam* exp42 = track2->GetTrackParamOp();
-
-       Float_t alphaFLAT1[4] = {-99., -99., -99., -99.};
-       if (exp11) alphaFLAT1[0] = exp11->GetAlpha();
-       if (exp21) alphaFLAT1[1] = exp21->GetAlpha();
-       if (exp31) alphaFLAT1[2] = exp31->GetAlpha();
-       if (exp41) alphaFLAT1[3] = exp41->GetAlpha();
-       
-       Float_t alphaFLAT2[4] = {-99.,-99., -99., -99.};
-       if (exp12) alphaFLAT2[0] = exp12->GetAlpha();
-       if (exp22) alphaFLAT2[1] = exp22->GetAlpha();
-       if (exp32) alphaFLAT2[2] = exp32->GetAlpha();
-       if (exp42) alphaFLAT2[3] = exp42->GetAlpha();
-       
-       
-       Float_t pFLAT1[4] = {-99., -99., -99., -99.};
-       if (exp11) pFLAT1[0] = exp11->GetSigned1Pt();
-       if (exp21) pFLAT1[1] = exp21->GetSigned1Pt();
-       if (exp31) pFLAT1[2] = exp31->GetSigned1Pt();
-       if (exp41) pFLAT1[3] = exp41->GetSigned1Pt();
-       
-       Float_t pFLAT2[4] = {-99., -99., -99., -99.};
-       if (exp12) pFLAT2[0] = exp12->GetSigned1Pt();
-       if (exp22) pFLAT2[1] = exp22->GetSigned1Pt();
-       if (exp32) pFLAT2[2] = exp32->GetSigned1Pt();
-       if (exp42) pFLAT2[3] = exp42->GetSigned1Pt();
-       
-       
-       
-         if( alphaFLAT1[0] != alphaFLAT2[0] ) cout<<"DIFFERENCE!: ";
-         cout<<" alpha0: "<<alphaFLAT1[0]<< " | " <<alphaFLAT2[0]<< endl;
-         if( alphaFLAT1[1] != alphaFLAT2[1] ) cout<<"DIFFERENCE!: ";
-         cout<<" alpha1: "<<alphaFLAT1[1]<< " | " <<alphaFLAT2[1]<< endl;
-         if( alphaFLAT1[2] != alphaFLAT2[2] ) cout<<"DIFFERENCE!: ";
-         cout<<" alpha2: "<<alphaFLAT1[2]<< " | " <<alphaFLAT2[2]<< endl;
-         if( alphaFLAT1[3] != alphaFLAT2[3] ) cout<<"DIFFERENCE!: ";
-         cout<<" alpha3: "<<alphaFLAT1[3]<< " | " <<alphaFLAT2[3]<< endl;
-       
+               AliFlatExternalTrackParam* ext[2][nExt] ={
+                       {
+                               track1->GetTrackParamRefitted(),
+                               track1->GetTrackParamIp(),
+                               track1->GetTrackParamTPCInner(),
+                               track1->GetTrackParamOp(),
+               //              track1->GetTrackParamCp(),
+               //              track1->GetTrackParamITSOut()
+                       },
+                       {
+                               track2->GetTrackParamRefitted(),
+                               track2->GetTrackParamIp(),
+                               track2->GetTrackParamTPCInner(),
+                               track2->GetTrackParamOp(),
+                       //      track2->GetTrackParamCp(),
+                       //      track2->GetTrackParamITSOut()
+                       }
+               };
        
+       //Printf("  TEST: FlatTrack1 %d > FlatExternalTrackParam1 > %p %p %p %p", idxTrack, exp11, exp21, exp31, exp41);
+       //Printf("  TEST: FlatTrack2 %d > FlatExternalTrackParam2 > %p %p %p %p", idxTrack, exp12, exp22, exp32, exp42);
+
+
+       for(int iExt=0; iExt<nExt; ++iExt){
+cout<<endl<<iExt<<endl;                
+if(!ext[0][iExt] && !ext[1][iExt]) continue;   
+               if(!ext[0][iExt] && ext[1][iExt]){
+               //      cout<<"DIFFERENCE!: ";
+                       cout<<" ext"<<iExt<<" not set in "<<filename1<<endl;
+               }       
+               if(ext[0][iExt] && !ext[1][iExt]){
+               //      cout<<"DIFFERENCE!: ";
+                       cout<<" ext"<<iExt<<" not set in "<<filename2<<endl;
+               }
+
+
+               if( (!ext[0][iExt] || !ext[1][iExt])|| ext[0][iExt]->GetAlpha() != ext[1][iExt]->GetAlpha() ) {
+       //              cout<<"DIFFERENCE!: ";
+                       //cout<<" alpha"<<iExt<<" :"  << (ext[0][iExt] ? ext[0][iExt]->GetAlpha() : -99.)  << "\t\t" << (ext[1][iExt] ?  ext[1][iExt]->GetAlpha(): -99.)<<endl;
+                       diff[4]=1;
+               }       cout<<" alpha"<<iExt<<" :"  << (ext[0][iExt] ? ext[0][iExt]->GetAlpha() : -99.)  << "\t\t" << (ext[1][iExt] ?  ext[1][iExt]->GetAlpha(): -99.)<<endl;
+                       
+
+               if( (!ext[0][iExt] || !ext[1][iExt])||ext[0][iExt]->GetX() != ext[1][iExt]->GetX() ) {
+                       //cout<<"DIFFERENCE!: ";
+                       //cout<<" GetX"<<iExt<<" :"  << (ext[0][iExt] ? ext[0][iExt]->GetX(): -99.)  << " | " << (ext[1][iExt] ?  ext[1][iExt]->GetX(): -99.)<<endl;
+                       diff[4]=1;
+               }       
+cout<<" GetX"<<iExt<<" :"  << (ext[0][iExt] ? ext[0][iExt]->GetX(): -99.)  << " | " << (ext[1][iExt] ?  ext[1][iExt]->GetX(): -99.)<<endl;
+
+
+               if( (!ext[0][iExt] || !ext[1][iExt])||ext[0][iExt]->GetSigned1Pt() !=  ext[0][iExt]->GetSigned1Pt() ) {
+                       //cout<<"DIFFERENCE!: ";
+                       //cout<<" 1/pt"<<iExt<<" :"  <<  (ext[0][iExt] ? ext[0][iExt]->GetSigned1Pt(): -99.)  << " | " << (ext[1][iExt] ?  ext[1][iExt]->GetSigned1Pt(): -99.)<<endl;
+                       diff[4]=1;
+               }       
+       cout<<" 1/pt"<<iExt<<" :"  <<  (ext[0][iExt] ? ext[0][iExt]->GetSigned1Pt(): -99.)  << " | " << (ext[1][iExt] ?  ext[1][iExt]->GetSigned1Pt(): -99.)<<endl;
+                       
+
+}
        
-         if( pFLAT1[0] != pFLAT2[0] ) cout<<"DIFFERENCE!: ";
-         cout<<" p0: "<<pFLAT1[0]<< " | " <<pFLAT2[0]<< endl;
-         if( pFLAT1[1] != pFLAT2[1] ) cout<<"DIFFERENCE!: ";
-         cout<<" p1: "<<pFLAT1[1]<< " | " <<pFLAT2[1]<< endl;
-         if( pFLAT1[2] != pFLAT2[2] ) cout<<"DIFFERENCE!: ";
-         cout<<" p2: "<<pFLAT1[2]<< " | " <<pFLAT2[2]<< endl;
-         if( pFLAT1[3] != pFLAT2[3] ) cout<<"DIFFERENCE!: ";
-         cout<<" p3: "<<pFLAT1[3]<< " | " <<pFLAT2[3]<< endl;
-         
-         
-         if( track1->GetNumberOfTPCClusters() != track2->GetNumberOfTPCClusters() ) cout<<"DIFFERENCE!: ";
-         cout<<" nTPCclusters: "<<track1->GetNumberOfTPCClusters()<< " | " <<track2->GetNumberOfTPCClusters()<< endl;
          
-         if( track1->GetNumberOfITSClusters() != track2->GetNumberOfITSClusters() ) cout<<"DIFFERENCE!: ";
-         cout<<" nITSclusters: "<<track1->GetNumberOfITSClusters()<< " | " <<track2->GetNumberOfITSClusters()<< endl;
-       
+         /*
+       if( track1->GetNumberOfTPCClusters() != track2->GetNumberOfTPCClusters() ){
+               cout<<"DIFFERENCE!: ";
+               cout<<" nTPCclusters: "<<track1->GetNumberOfTPCClusters()<< " | " <<track2->GetNumberOfTPCClusters()<< endl;
+               diff[4]=1;
+       }  
+       if( track1->GetNumberOfITSClusters() != track2->GetNumberOfITSClusters() ){
+               cout<<"DIFFERENCE!: ";
+               cout<<" nITSclusters: "<<track1->GetNumberOfITSClusters()<< " | " <<track2->GetNumberOfITSClusters()<< endl;
+               diff[4]=1;
+       }
+*/
+
+// compare clusters
+       if( verbose &&  track1->GetNumberOfTPCClusters() == track2->GetNumberOfTPCClusters()){
+               for (Int_t idxCluster = 0; idxCluster < track1->GetNumberOfTPCClusters(); ++idxCluster){
+                       AliFlatTPCCluster * cl1 = track1->GetTPCCluster(idxCluster);
+                       AliFlatTPCCluster * cl2 = track2->GetTPCCluster(idxCluster);
 /*
+                       if( cl1->GetX()&& cl2->GetX() && cl1->GetX() != cl2->GetX() ){
+                               cout<<"DIFFERENCE!: ";
+                               cout<<" cluster: "<<idxCluster<<" GetX :"<<cl1->GetX()<< " | " <<cl2->GetX()<< endl;
+                               diff=kTRUE;
+                       }
+                               cout<<" cluster: "<<idxCluster<<" GetX :"<<cl1->GetX()<< " | " <<cl2->GetX()<< endl;
+                               cout<<" cluster: "<<idxCluster<<" GetY :"<<cl1->GetY()<< " | " <<cl2->GetY()<< endl;
 
-       for (Int_t idxCluster = 0; idxCluster < track1->GetNumberOfTPCClusters(); ++idxCluster){
-         Printf(" TEST: FlatTrack %d > FlatCluster %d has row %d", idxTrack, idxCluster, track1->GetTPCCluster(idxCluster).GetPadRow());
-      }
-  */    
+                       if( cl1 && cl2 && cl1->GetY() != cl2->GetY() ){
+                               cout<<"DIFFERENCE!: ";
+                               cout<<" cluster: "<<idxCluster<<" GetY :"<<cl1->GetY()<< " | " <<cl2->GetY()<< endl;
+                               diff=kTRUE;
+                       }
+                       if( cl1->GetZ()&& cl2->GetZ() && cl1->GetZ() != cl2->GetZ() ){
+                               cout<<"DIFFERENCE!: ";
+                               cout<<" cluster: "<<idxCluster<<" GetZ :"<<cl1->GetZ()<< " | " <<cl2->GetZ()<< endl;
+                               diff=kTRUE;
+                       }
+*/
+                       if( cl1->GetPadRow()&& cl2->GetPadRow() && cl1->GetPadRow() != cl2->GetPadRow() ){
+                               cout<<"DIFFERENCE!: ";
+                               cout<<" cluster: "<<idxCluster<<" GetPadRow :"<<cl1->GetPadRow()<< " | " <<cl2->GetPadRow()<< endl;
+                               diff[5]=1;
+                       }
+
+               }
          }
      
       track1 = track1->GetNextTrack();
       track2 = track2->GetNextTrack();
          
          
+         }
+#endif
+          hStat->Fill(0);        
+         Bool_t diffs=kFALSE;
+         for(int iDiff=0; iDiff<5;++iDiff){
+               if(diff[iDiff]){
+                       hStat->Fill(iDiff+2);
+                       diffs = kTRUE;
+               }
        }
-         
-         
-         
-         hNTracks->Fill(flatEsd1->GetNumberOfTracks(),flatEsd2->GetNumberOfTracks());
-         
-         
+       if(!diffs) hStat->Fill(1);        
+
+
       curr1=curr1+ flatEsd1->GetSize();
       curr2=curr2+ flatEsd2->GetSize();
       iEvent++;
@@ -214,9 +292,16 @@ void CompareFlatESDs(const char* filename1="outFlatESD1.root",const char* filena
   else {
     cout << "File could not be read" << endl;
   }
+
+
+
   
        TList histosList;
+       histosList.Add(hStat);
        histosList.Add(hNTracks);
+       histosList.Add(hNV0s);
+       histosList.Add(hVtxTr);
+       histosList.Add(hVtxSPD);
   histosList.SaveAs(outputFilename);
   
   return;