]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDrawData.cxx
Fix Coverity
[u/mrichter/AliRoot.git] / TRD / AliTRDrawData.cxx
index cccb6f94364681a38ac4cb1b0c626ceff1b2e1c9..81fcf7f2f17c9f7c693705e314ab1468709f4154 100644 (file)
@@ -30,6 +30,7 @@
 #include "AliRawReader.h"
 #include "AliLog.h"
 #include "AliFstream.h"
+#include "AliLoader.h"
 #include "AliTreeLoader.h"
 
 #include "AliTRDrawData.h"
@@ -37,7 +38,7 @@
 #include "AliTRDgeometry.h"
 #include "AliTRDarrayDictionary.h"
 #include "AliTRDarrayADC.h"
-#include "AliTRDrawStreamBase.h"
+#include "AliTRDrawStream.h"
 #include "AliTRDcalibDB.h"
 #include "AliTRDSignalIndex.h"
 #include "AliTRDfeeParam.h"
@@ -57,10 +58,13 @@ AliTRDrawData::AliTRDrawData()
   ,fFee(NULL)
   ,fNumberOfDDLs(0)
   ,fTrackletTree(NULL)
-  ,fTrackletContainer(NULL)
+  ,fTracklets(NULL)
+  ,fTracks(NULL)
   ,fSMindexPos(0)
   ,fStackindexPos(0)
   ,fEventCounter(0)
+  ,fTrgFlags()
+  ,fMcmSim(new AliTRDmcmSim)
   ,fDigitsParam(NULL)
 {
   //
@@ -80,10 +84,13 @@ AliTRDrawData::AliTRDrawData(const AliTRDrawData &r)
   ,fFee(NULL)
   ,fNumberOfDDLs(0)
   ,fTrackletTree(NULL)
-  ,fTrackletContainer(NULL)
+  ,fTracklets(NULL)
+  ,fTracks(NULL)
   ,fSMindexPos(0)
   ,fStackindexPos(0)
   ,fEventCounter(0)
+  ,fTrgFlags()
+  ,fMcmSim(new AliTRDmcmSim)
   ,fDigitsParam(NULL)
 {
   //
@@ -102,11 +109,18 @@ AliTRDrawData::~AliTRDrawData()
   // Destructor
   //
 
-  if (fTrackletContainer){
-    delete fTrackletContainer;
-    fTrackletContainer = NULL;
+  if (fTracklets){
+    fTracklets->Delete();
+    delete fTracklets;
   }
 
+  if (fTracks){
+    fTracks->Delete();
+    delete fTracks;
+  }
+
+  delete fMcmSim;
+
 }
 
 //_____________________________________________________________________________
@@ -188,7 +202,7 @@ Bool_t AliTRDrawData::Digits2Raw(AliTRDdigitsManager *digitsManager)
   for (Int_t sect = 0; sect < fGeo->Nsector(); sect++) { 
 
     char name[1024];
-    sprintf(name,"TRD_%d.ddl",sect + AliTRDrawStreamBase::kDDLOffset);
+    snprintf(name,1024,"TRD_%d.ddl",sect + AliTRDrawStream::kDDLOffset);
 
     AliFstream* of = new AliFstream(name);
 
@@ -209,7 +223,7 @@ Bool_t AliTRDrawData::Digits2Raw(AliTRDdigitsManager *digitsManager)
     Bool_t bSMHasData = kFALSE;
     
     //iwbuffer[nheader++] = 0x0001a020;   // SM index words 
-    iwbuffer[nheader++] = 0x0044a020;   // SM index words | additional SM header:48 = 1 SM header + 47 dummy words(for future use)
+    iwbuffer[nheader++] = 0x0044b020;   // SM index words | additional SM header:48 = 1 SM header + 47 dummy words(for future use)
     iwbuffer[nheader++] = 0x10404071;   // SM header
     for ( Int_t i=0; i<66; i++ ) iwbuffer[nheader++] = 0x00000000;  // dummy words 
     iwbuffer[nheader++] = 0x10000000;   // end of dummy words
@@ -238,7 +252,7 @@ Bool_t AliTRDrawData::Digits2Raw(AliTRDdigitsManager *digitsManager)
     
     if ( fgDataSuppressionLevel==0 || bSMHasData ){
       iwbuffer[0] = iwbuffer[0] | bStackMask;  // add stack masks to SM index word
-      if (fgDataSuppressionLevel==0) iwbuffer[0] = 0x0044a03f;    // no suppression : all stacks are active
+      if (fgDataSuppressionLevel==0) iwbuffer[0] = 0x0044b03f;    // no suppression : all stacks are active
       of->WriteBuffer((char *) iwbuffer, nheader*4);
       AliDebug(11, Form("SM %d index word: %08x", sect, iwbuffer[0]));
       AliDebug(11, Form("SM %d header: %08x", sect, iwbuffer[1]));
@@ -291,6 +305,9 @@ Bool_t AliTRDrawData::Digits2Raw(AliTRDdigitsManager *digitsManager)
     of->Seekp(hpos);         // Rewind to header position
     of->WriteBuffer((char *) (& header), sizeof(header));
     delete of;
+
+    delete [] iwbuffer;
+
   } // loop over sector(SM)
   
   delete [] hcBuffer;
@@ -333,7 +350,7 @@ void AliTRDrawData::ProduceSMIndexData(UInt_t *buf, Int_t& nw){
        
     //buf[nw++] = 0x0001a03f;   // SM index words
     fSMindexPos = nw;       // memorize position of the SM index word for re-allocating stack mask
-    buf[nw++] = 0x0001a020; // SM index words
+    buf[nw++] = 0x0001b020; // SM index words
     buf[nw++] = 0x10404071; // SM header
 
     fStackindexPos = nw;    // memorize position of the stack index word for future adding
@@ -433,15 +450,13 @@ Int_t AliTRDrawData::ProduceHcData(AliTRDarrayADC *digits, Int_t side, Int_t det
 
        AliDebug(1,Form("Producing raw data for sect=%d layer=%d stack=%d side=%d",sect,layer,stack,side));
         
-       AliTRDmcmSim* mcm = new AliTRDmcmSim();
-
        UInt_t *tempBuffer = buf; // tempBuffer used to write ADC data
                                  // different in case of tracklet writing
        
        if (trackletOn) {
          tempBuffer = new UInt_t[maxSize];
-         tempnw = new Int_t(0);
-         tempof = new Int_t(0);
+         tempnw     = new Int_t(0);
+         tempof     = new Int_t(0);
        }
          
        WriteIntermediateWords(tempBuffer,*tempnw,*tempof,maxSize,det,side);
@@ -456,11 +471,11 @@ Int_t AliTRDrawData::ProduceHcData(AliTRDarrayADC *digits, Int_t side, Int_t det
            for (Int_t iMcmRB = 0; iMcmRB < fGeo->MCMmax(); iMcmRB++ ) {
              Int_t iMcm = 16 - 4*(iMcmRB/4 + 1) + (iMcmRB%4);
              
-             mcm->Init(det, iRob, iMcm);
-             mcm->SetData(digits);     // no filtering done here (already done in digitizer)
+             fMcmSim->Init(det, iRob, iMcm);
+             fMcmSim->SetData(digits);     // no filtering done here (already done in digitizer)
              if (trackletOn) {
-               mcm->Tracklet();
-               Int_t tempNw = mcm->ProduceTrackletStream(&buf[nw], maxSize - nw);
+               fMcmSim->Tracklet();
+               Int_t tempNw = fMcmSim->ProduceTrackletStream(&buf[nw], maxSize - nw);
                if(  tempNw < 0 ) {
                  of += tempNw;
                  nw += maxSize - nw;
@@ -469,10 +484,10 @@ Int_t AliTRDrawData::ProduceHcData(AliTRDarrayADC *digits, Int_t side, Int_t det
                  nw += tempNw;
                }
              }
-             mcm->ZSMapping();  // Calculate zero suppression mapping
+             fMcmSim->ZSMapping();  // Calculate zero suppression mapping
              // at the moment it has to be rerun here
              // Write MCM data to temp. buffer
-             Int_t tempNw = mcm->ProduceRawStream( &tempBuffer[*tempnw], maxSize - *tempnw, fEventCounter );
+             Int_t tempNw = fMcmSim->ProduceRawStream( &tempBuffer[*tempnw], maxSize - *tempnw, fEventCounter );
              if ( tempNw < 0 ) {
                *tempof += tempNw;
                *tempnw += maxSize - nw;
@@ -483,8 +498,6 @@ Int_t AliTRDrawData::ProduceHcData(AliTRDarrayADC *digits, Int_t side, Int_t det
            }
          }
          
-         delete mcm;
-
          // in case of tracklet writing copy temp data to final buffer
          if (trackletOn) {
            if (nw + *tempnw < maxSize) {
@@ -494,12 +507,15 @@ Int_t AliTRDrawData::ProduceHcData(AliTRDarrayADC *digits, Int_t side, Int_t det
            else {
              AliError("Buffer overflow detected");
            }
-           delete [] tempBuffer;
-           delete tempof;
-           delete tempnw;
          }
        }
 
+        if (trackletOn) {
+         delete [] tempBuffer;
+         delete tempof;
+          delete tempnw;
+       }
+    
        // Write end of raw data marker
        if (nw+3 < maxSize) {
           buf[nw++] = fgkEndOfDataMarker;
@@ -536,45 +552,38 @@ AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader)
   AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager();
   digitsManager->CreateArrays();
 
-  if (!fTrackletContainer) {
-    const Int_t kTrackletChmb=256;
-    fTrackletContainer = new UInt_t *[2];
-    fTrackletContainer[0] = new UInt_t[kTrackletChmb];
-    fTrackletContainer[1] = new UInt_t[kTrackletChmb];
-    memset(fTrackletContainer[0], 0, kTrackletChmb*sizeof(UInt_t)); //jkl
-    memset(fTrackletContainer[1], 0, kTrackletChmb*sizeof(UInt_t)); //jkl
-  }
-
-  AliTRDrawStreamBase *pinput = AliTRDrawStreamBase::GetRawStream(rawReader);
-  AliTRDrawStreamBase &input = *pinput;
-  input.SetRawVersion( fFee->GetRAWversion() ); //<= ADDED by MinJung
-
-  AliInfo(Form("Stream version: %s", input.IsA()->GetName()));
+  AliTRDrawStream input(rawReader);
 
   // ----- preparing tracklet output -----
   AliDataLoader *trklLoader = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets");
   if (!trklLoader) {
-    //AliInfo("Could not get the tracklets data loader, adding it now!");
     trklLoader = new AliDataLoader("TRD.Tracklets.root","tracklets", "tracklets");
     AliRunLoader::Instance()->GetLoader("TRDLoader")->AddDataLoader(trklLoader);
   }
+  if (!trklLoader) {
+    return 0x0;
+  }
   AliTreeLoader *trklTreeLoader = dynamic_cast<AliTreeLoader*> (trklLoader->GetBaseLoader("tracklets-raw"));
   if (!trklTreeLoader) {
     trklTreeLoader = new AliTreeLoader("tracklets-raw", trklLoader);
     trklLoader->AddBaseLoader(trklTreeLoader);
   }
+  if (!trklTreeLoader) {
+    return 0x0;
+  }
 
   if (!trklTreeLoader->Tree())
     trklTreeLoader->MakeTree();
 
+  input.SetTrackletArray(TrackletsArray());
+  input.SetTrackArray(TracksArray());
+
   // Loop through the digits
   Int_t det    = 0;
 
   while (det >= 0)
     {
-      det = input.NextChamber(digitsManager,fTrackletContainer);
-
-      if (*(fTrackletContainer[0]) > 0 || *(fTrackletContainer[1]) > 0) WriteTracklets(det);
+      det = input.NextChamber(digitsManager);
 
       if (det >= 0)
        {
@@ -591,20 +600,12 @@ AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader)
        }
     }
 
-  if (trklTreeLoader)
-    trklTreeLoader->WriteData("OVERWRITE");
-  if (trklLoader) 
-    trklLoader->UnloadAll();
-
-  if (fTrackletContainer){
-    delete [] fTrackletContainer[0];
-    delete [] fTrackletContainer[1];
-    delete [] fTrackletContainer;
-    fTrackletContainer = NULL;
+  for (Int_t iSector = 0; iSector < fGeo->Nsector(); iSector++) {
+    fTrgFlags[iSector] = input.GetTriggerFlags(iSector);
   }
 
-  delete pinput;
-  pinput = NULL;
+  trklTreeLoader->WriteData("OVERWRITE");
+  trklLoader->UnloadAll();
 
   return digitsManager;
 }
@@ -668,43 +669,22 @@ void AliTRDrawData::WriteIntermediateWords(UInt_t* buf, Int_t& nw, Int_t& of, co
     if (nw < maxSize) buf[nw++] = x; else of++;
 }
 
-//_____________________________________________________________________________
-Bool_t AliTRDrawData::WriteTracklets(Int_t det)
+TClonesArray *AliTRDrawData::TrackletsArray()
 {
-  //
-  // Write the raw data tracklets into seperate file
-  //
-
-  UInt_t **leaves = new UInt_t *[2];
-  for (Int_t i=0; i<2 ;i++){
-    leaves[i] = new UInt_t[258];
-    leaves[i][0] = det; // det
-    leaves[i][1] = i;   // side
-    memcpy(leaves[i]+2, fTrackletContainer[i], sizeof(UInt_t) * 256);
-  }
+  // Returns the array of on-line tracklets
 
-  if (!fTrackletTree){
-    AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
-    dl->MakeTree();
-    fTrackletTree = dl->Tree();
+  if (!fTracklets) {
+    fTracklets = new TClonesArray("AliTRDtrackletWord", 200);
   }
+  return fTracklets;
+}
 
-  TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
-  if (!trkbranch) {
-    trkbranch = fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
-  }
+TClonesArray* AliTRDrawData::TracksArray()
+{
+  // return array of GTU tracks (create TClonesArray if necessary)
 
-  for (Int_t i=0; i<2; i++){
-    if (leaves[i][2]>0) {
-      trkbranch->SetAddress(leaves[i]);
-      fTrackletTree->Fill();
-    }
+  if (!fTracks) {
+    fTracks = new TClonesArray("AliESDTrdTrack",100);
   }
-
-  //  AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets"); //jkl: wrong
-  //  dl->WriteData("OVERWRITE"); //jkl: wrong
-  //dl->Unload();
-  delete [] leaves;
-
-  return kTRUE;
+  return fTracks;
 }