]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/MUONTRKOCCda.cxx
Hopefully now Coverity will be happy
[u/mrichter/AliRoot.git] / MUON / MUONTRKOCCda.cxx
index 3d2c5d7470cdb083f3646172d2863bf667904a5b..09b7b7d7af337e8364b86ec96e0342aaaa17fc28 100644 (file)
@@ -6,7 +6,7 @@
  Run Type: PHYSICS STANDALONE
  DA Type: MON
  Number of events needed: all (or at least as much as possible...)
- Input Files:
+ Input Files: 10000119041028.20.raw 10000130367042.10.raw 10000120691024.50.raw
  Output Files: mch.occupancy, to be exported to the DAQ FXS
  Trigger types used: PHYSICS_EVENT
 */
@@ -36,6 +36,7 @@
 ///
 /// $Id$
 
+#include "AliDAQ.h"
 #include "AliMUON2DMap.h"
 #include "AliMUONCalibParamNI.h"
 #include "AliMUONRawStreamTrackerHP.h"
@@ -51,6 +52,7 @@
 #include "daqDA.h"
 #include "event.h"
 #include "monitor.h"
+#include "signal.h"
 
 #ifdef ALI_AMORE
 #include <AmoreDA.h>
@@ -60,7 +62,7 @@
 #endif
 
 const char* OUTPUT_FILE = "mch.occupancy";
-const char* DAVERSION = "MUONTRKOCCda v1.0";
+const char* DAVERSION = "MUONTRKOCCda v1.61 ($Id$)";
 
 //______________________________________________________________________________
 void Add(AliMUONVStore& destStore, const AliMUONVStore& srcStore)
@@ -86,7 +88,7 @@ void Add(AliMUONVStore& destStore, const AliMUONVStore& srcStore)
       {
         for ( Int_t j = 0; j  < source->Dimension(); ++j ) 
         {
-          dest->SetValueAsInt(i,j,dest->ValueAsInt(i,j)+source->ValueAsInt(i,j));
+          dest->SetValueAsIntFast(i,j,dest->ValueAsIntFast(i,j)+source->ValueAsIntFast(i,j));
         }
       }
     }
@@ -95,7 +97,7 @@ void Add(AliMUONVStore& destStore, const AliMUONVStore& srcStore)
 
 //______________________________________________________________________________
 void GenerateOutputFile(const AliMUONVStore& store, ostream& out, 
-                        Int_t runNumber, Int_t nevents)
+                        Int_t runNumber, Int_t nevents, Int_t numberOfEventsWithMCH)
 {
   /// Write the channel hit count (grouped by manu) in the output file.
   
@@ -111,20 +113,31 @@ void GenerateOutputFile(const AliMUONVStore& store, ostream& out,
   out << "//---------------------------------------------------------------------------" << endl;
   out << "//  BP   MANU  SUM_N  NEVENTS" << endl;
   out << "//---------------------------------------------------------------------------" << endl;
+
+  Int_t nlines(0);
   
   while ( ( manu = static_cast<AliMUONVCalibParam*>(next()) ) )
   {
     Int_t sum(0);
-//    Int_t nevents(0);
     
     for ( Int_t i = 0; i < manu->Size(); ++i ) 
     {
       sum += manu->ValueAsInt(i);
-      //      nevents = TMath::Max(nevents,manu->ValueAsInt(i,1));
-      // nevents = TMath::Max(nevents,manu->ValueAsInt(i,1));
     }
     
     out << Form("%5d %5d %10d %10d",manu->ID0(),manu->ID1(),sum,nevents) << endl;
+    ++nlines;
+  }
+  
+  if (!nlines)
+  {
+    // ok : empty output. Is it because the run was empty ? 
+    if ( !numberOfEventsWithMCH )
+    {
+      // yes. Let give a hint in the file so the Shuttle preprocessor will know about this...
+      out << Form("%5d %5d %10d %10d",-1,-1,0,0) << endl;
+    }
+    // else the preprocessor will fail, and that's good because there's something wrong somewhere...
   }
 }
   
@@ -144,6 +157,8 @@ int main(int argc, char **argv)
   /// were seen per manu, and the number of events.
   ///
   
+  signal(SIGSEGV,SIG_DFL); // to be able to get core dumps...
+  
   TStopwatch timers;
   timers.Start(kTRUE); 
   
@@ -170,6 +185,8 @@ int main(int argc, char **argv)
   Int_t numberOfBadEvents(0);
   Int_t numberOfUsedEvents(0);
   
+  Int_t numberOfEventsWithMCH(0);
+  
   AliMUON2DMap oneEventData(kTRUE);
   AliMUON2DMap accumulatedData(kTRUE);
   
@@ -181,7 +198,7 @@ int main(int argc, char **argv)
     AliRawReaderDate* rawReader(0x0);
     
 // define data source : 
-   status=monitorSetDataSource(argv[1]);
+   status=monitorSetDataSource(argv[i]);
     if (status!=0) 
     {
       printf("MCH Occupancy DA ERROR: monitorSetDataSource() failed: %s\n", monitorDecodeError(status));
@@ -201,34 +218,40 @@ int main(int argc, char **argv)
     
     for(;;)
     {
-      struct eventHeaderStruct *event;
+      struct eventHeaderStruct *event(0x0);
       eventTypeType eventT;
       
       status=monitorGetEventDynamic((void **)&event);
       if (status!=0)
       {
-       printf("MCH Occupancy DA ERROR: %s\n", monitorDecodeError(status));
-       break;
+        printf("MCH Occupancy DA ERROR: %s\n", monitorDecodeError(status));
+        delete event;
+        break;
       }
 
       /* check shutdown condition */
-      if (daqDA_checkShutdown()) break;
-      
-// Check if one gets the event properly
-      if (status!=0)
+      if (daqDA_checkShutdown())
       {
-        printf("MCH Occupancy DA ERROR: monitorGetEventDynamic() failed: %s\n", monitorDecodeError(status));
-        return -1;
+        delete event;
+        break;
       }
-
+      
       /* retry if got no event */
       if (event==NULL) continue;
 
       ++numberOfEvents;
 
       eventT=event->eventType;
-      if ((eventT == END_OF_RUN)||(eventT == END_OF_RUN_FILES)) break;
-      if (eventT != PHYSICS_EVENT) continue;
+      if ((eventT == END_OF_RUN)||(eventT == END_OF_RUN_FILES)) 
+      {
+        delete event;
+        break;
+      }
+      if (eventT != PHYSICS_EVENT) 
+      {
+        delete event;
+        continue;
+      }
                  
       ++numberOfPhysicsEvent;
       
@@ -239,15 +262,41 @@ int main(int argc, char **argv)
         if ( runNumber != 0 ) 
         {
           cout << "Uh oh. That's bad... Changing of run number ???" << endl;
+          delete event;
+          delete rawReader;
           return -9999;
         }
         runNumber = rawReader->GetRunNumber();
       }
       
+      // *without* using the MUONTRK event decoder, we update the number
+      // of events where we have information about MUONTRK.
+      // this should be what is called subevents in the logbook
+      // we do *not* use the MCH decoder on purpose, to not mistakenly
+      // believe there's no event if the data is corrupted (and thus the decoder
+      // "sees" nothing).
+      
+      Bool_t mchThere(kFALSE);
+      
+      for ( int iDDL = 0; iDDL < AliDAQ::NumberOfDdls("MUONTRK") && !mchThere; ++iDDL )
+      {
+        rawReader->Reset();
+        rawReader->Select("MUONTRK",iDDL,iDDL);
+        if (rawReader->ReadHeader() )
+        {
+          if (rawReader->GetEquipmentSize() ) mchThere = kTRUE;
+        }      
+      }
+
+      if ( mchThere) ++numberOfEventsWithMCH;
+      
+      rawReader->Reset();
+      
+      // now do our real work with the MCH decoder
+      
       AliMUONRawStreamTrackerHP stream(rawReader);
       
       stream.DisableWarnings();
-      stream.EnabbleErrorLogger();
       
       oneEventData.Clear();
       
@@ -282,43 +331,50 @@ int main(int argc, char **argv)
       {
         ++numberOfBadEvents;
       }
-    }
-    
-    delete rawReader;
+
+      delete event;
+      
+      delete rawReader;
+    }    
   }
   
   
-  cout << Form("%12d events processed : %12d physics %d used ones %d bad ones",
-               numberOfEvents,numberOfPhysicsEvent,numberOfUsedEvents,numberOfBadEvents) << endl;
+  cout << Form("%12d events processed : %12d physics %d used ones %d bad ones [ %d with MCH information ]",
+               numberOfEvents,numberOfPhysicsEvent,numberOfUsedEvents,numberOfBadEvents,numberOfEventsWithMCH) << endl;
     
   ofstream fout(OUTPUT_FILE);
   
-  GenerateOutputFile(accumulatedData,fout,runNumber,numberOfUsedEvents);
+  GenerateOutputFile(accumulatedData,fout,runNumber,numberOfUsedEvents,numberOfEventsWithMCH);
   
   fout.close();
   
+  /* store the result file on FXS */  
+  if (daqDA_FES_storeFile(OUTPUT_FILE,"OCCUPANCY")) return -9;
+    
 #ifdef ALI_AMORE
   
-  // Send occupancy store (as a big string) to the AMORE DB
-  amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
-  
-  ostringstream str;
-  
-  GenerateOutputFile(accumulatedData,str,runNumber,numberOfUsedEvents);
+  if ( numberOfUsedEvents ) // do not update the AMORE pool with an empty object...
+  {
+    // Send occupancy store (as a big string) to the AMORE DB
+    amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
+    
+    ostringstream str;
     
-  TObjString occupancyAsString(str.str().c_str());
+    GenerateOutputFile(accumulatedData,str,runNumber,numberOfUsedEvents,numberOfEventsWithMCH);
+    
+    TObjString occupancyAsString(str.str().c_str());
+    
+    cout << "will send to amore" << endl;
+    
+    Int_t status = amoreDA.Send("Occupancy",&occupancyAsString);
+    if ( status )
+    {
+      cerr << "ERROR : Failed to write occupancies in the AMORE database : " << status << endl;
+    } 
+  }
   
-  Int_t status = amoreDA.Send("Occupancy",&occupancyAsString);
-  if ( status )
-  {
-    cerr << "ERROR : Failed to write occupancies in the AMORE database : " << status << endl;
-  } 
-
 #endif
-  
-  /* store the result file on FXS */  
-  if (daqDA_FES_storeFile(OUTPUT_FILE,"OCCUPANCY")) return -9;
-
+    
   timers.Stop();
   printf("\nExecution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());