Clean-up of the DA code
authorcholm <cholm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 2 Aug 2012 12:41:27 +0000 (12:41 +0000)
committercholm <cholm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 2 Aug 2012 12:41:27 +0000 (12:41 +0000)
FMD/AliFMDBaseDA.cxx
FMD/AliFMDBaseDA.h
FMD/AliFMDGainDA.cxx
FMD/AliFMDGainDA.h
FMD/AliFMDPedestalDA.cxx
FMD/AliFMDPedestalDA.h
FMD/CMakelibFMDutil.pkg
FMD/FMDBaseda.cxx
FMD/FMDGainda.cxx
FMD/FMDPedestalda.cxx

index ad9febb..83fb7b4 100644 (file)
 #include <TDatime.h>
 #include <TSystem.h>
 #include <TH2F.h>
+#include <TStopwatch.h>
+#include <TROOT.h>
+#include <TPluginManager.h>
 #include <iostream>
 #include <fstream>
+
 //_____________________________________________________________________
 ClassImp(AliFMDBaseDA)
 #if 0 
@@ -191,16 +195,23 @@ AliFMDBaseDA::~AliFMDBaseDA()
 }
 
 //_____________________________________________________________________
+Bool_t AliFMDBaseDA::HaveEnough(Int_t nEvents) const
+{
+  return nEvents > GetRequiredEvents();
+}
+//_____________________________________________________________________
+UShort_t AliFMDBaseDA::GetProgress(Int_t nEvents) const
+{
+  return UShort_t((nEvents *100)/ GetRequiredEvents());
+}
+
+//_____________________________________________________________________
 void AliFMDBaseDA::Run(AliRawReader* reader) 
 {
   //Run the FMD DA
   TFile* diagFile = 0;
-  if (fSaveHistograms)
-    diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
-
-  
-  
-  
+  // if (fSaveHistograms)
+  //  diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
   
   reader->Reset();
   fRunno = reader->GetRunNumber();
@@ -230,37 +241,48 @@ void AliFMDBaseDA::Run(AliRawReader* reader)
   }
   
   InitContainer(diagFile);
+  if (AliLog::GetDebugLevel("FMD","") >= 3) { 
+    fDetectorArray.ls();
+  }
   
   if(!sodread) 
     AliWarning("No SOD event detected!");
   
   int lastProgress = 0;
   
-  
-  
-  for(Int_t n =1;n <= GetRequiredEvents(); n++) {
-    if(!reader->NextEvent()) continue;
+  for(Int_t i = 0; i< 3;i++) fNEventsPerDetector[i] = 0;
+
+  for(Int_t n = 1; !HaveEnough(n); n++) {
+    if(!reader->NextEvent()) { n--; continue; }
     SetCurrentEvent(n);
     digitArray->Clear();
     fmdReader->ReadAdcs(digitArray);
     
+    Bool_t seen[] = { false, false, false };
     for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
       AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
-      fSeenDetectors[digit->Detector()-1] = kTRUE;
+      UShort_t det = digit->Detector();
+      fSeenDetectors[det-1] = true;
+      seen[det-1]           = true;
       FillChannels(digit);
     }
     
-   
+    for(Int_t i = 0; i< 3;i++) 
+      if (seen[i]) (fNEventsPerDetector[i])++;
+      
     FinishEvent();
     
-    int progress = int((n *100)/ GetRequiredEvents()) ;
+    int progress = GetProgress(n);
     if (progress <= lastProgress) continue;
     lastProgress = progress;
     std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
     
   }
   
-  AliInfo(Form("Looped over %d events",GetCurrentEvent()));
+  AliInfoF("Looped over %d events (%d,%d,%d)",GetCurrentEvent(),
+          fNEventsPerDetector[0], 
+          fNEventsPerDetector[1], 
+          fNEventsPerDetector[2]);
   WriteHeaderToFile();
   
   for(UShort_t det=1;det<=3;det++) {
@@ -281,8 +303,8 @@ void AliFMDBaseDA::Run(AliRawReader* reader)
        }
        std::cout << '.' << std::flush;
       }
-      if(fSaveHistograms)
-       diagFile->Flush();
+      // if(fSaveHistograms)
+      // diagFile->Flush();
       std::cout << "done" << std::endl;
     }
   }
@@ -295,7 +317,9 @@ void AliFMDBaseDA::Run(AliRawReader* reader)
   Terminate(diagFile);
     
   if(fSaveHistograms ) {
-    
+    diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
+    fDetectorArray.Write("FMD", TObject::kSingleKey);
+    fSummaries.Write();
     AliInfo("Closing diagnostics file - please wait ...");
     // diagFile->Write();
     diagFile->Close();
@@ -307,16 +331,13 @@ void AliFMDBaseDA::Run(AliRawReader* reader)
 
 void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
 {
-  //Prepare container for diagnostics
-  TObjArray* detArray;
-  TObjArray* ringArray;
-  TObjArray* sectorArray;
-    
+  //Prepare container for diagnostics    
   TDirectory* savDir   = gDirectory;
 
   for(UShort_t det=1;det<=3;det++) {
-    detArray = new TObjArray();
+    TObjArray* detArray = new TObjArray(det == 1 ? 1 : 2);
     detArray->SetOwner();
+    detArray->SetName(GetDetectorPath(det, false));
     fDetectorArray.AddAtAndExpand(detArray,det);
 
     TDirectory* detDir = 0;
@@ -330,8 +351,9 @@ void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
       Char_t   ring = (ir == 0 ? 'O' : 'I');
       UShort_t nsec = (ir == 0 ? 40  : 20);
       UShort_t nstr = (ir == 0 ? 256 : 512);
-      ringArray = new TObjArray();
+      TObjArray* ringArray = new TObjArray(nsec);
       ringArray->SetOwner();
+      ringArray->SetName(GetRingPath(det, ring, false));
       detArray->AddAtAndExpand(ringArray,ir);
 
 
@@ -343,8 +365,9 @@ void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
       
 
       for(UShort_t sec =0; sec < nsec;  sec++)  {
-       sectorArray = new TObjArray();
+       TObjArray* sectorArray = new TObjArray(nstr);
        sectorArray->SetOwner();
+       sectorArray->SetName(GetSectorPath(det, ring, sec, false));
        ringArray->AddAtAndExpand(sectorArray,sec);
 
 
@@ -359,8 +382,13 @@ void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
            secDir->cd();
            secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
          }
-         AddChannelContainer(sectorArray, det, ring, sec, strip);
+         TObjArray* stripArray = new TObjArray(0);
+         stripArray->SetOwner(true);
+         stripArray->SetName(GetStripPath(det, ring, sec, strip, false));
+         sectorArray->AddAtAndExpand(stripArray, strip);
+         AddChannelContainer(stripArray, det, ring, sec, strip);
        }
+       AddSectorSummary(sectorArray, det, ring, sec, nstr);
       }
     }
   }
@@ -526,13 +554,281 @@ AliFMDBaseDA::MakeSummaryHistogram(const char* prefix, const char* title,
                      nX, -0.5, nX-0.5, nY, -0.5, nY-0.5);
   ret->SetXTitle("Sector #");
   ret->SetYTitle("Strip #");
-
+  ret->SetDirectory(0);
   // if (!fSummaries) fSummaries = new TObjArray;
   fSummaries.Add(ret);
   return ret;
 }
 
 //_____________________________________________________________________ 
+TObjArray*
+AliFMDBaseDA::GetDetectorArray(UShort_t det)
+{
+  if (det < 1 || det > 3) { 
+    AliErrorF("Detector index %d out of bounds", det);
+    return 0;
+  }
+  return static_cast<TObjArray*>(fDetectorArray.At(det));
+}
+//_____________________________________________________________________ 
+TObjArray*
+AliFMDBaseDA::GetRingArray(UShort_t det, Char_t ring)
+{
+  Int_t idx = (ring == 'O' || ring == 'o' ? 0 : 1);
+  TObjArray* array = GetDetectorArray(det);
+  if (!array) return 0;
+  array = static_cast<TObjArray*>(array->At(idx));
+  if (!array) AliErrorF("No ring array for FMD%d%c (%d)", det, ring, idx);
+  return array;
+}
+//_____________________________________________________________________ 
+TObjArray*
+AliFMDBaseDA::GetSectorArray(UShort_t det, Char_t ring, UShort_t sector)
+{
+  TObjArray* array = GetRingArray(det,ring);
+  if (!array) return 0;
+  array = static_cast<TObjArray*>(array->At(sector));
+  if (!array) AliErrorF("No sector array for FMD%d%c[%02d]", det, ring, sector);
+  return array;
+}
+//_____________________________________________________________________ 
+TObjArray*
+AliFMDBaseDA::GetStripArray(UShort_t det, Char_t ring, 
+                           UShort_t sector, UShort_t strip)
+{
+  TObjArray* array = GetSectorArray(det,ring,sector);
+  if (!array) return 0;
+  array = static_cast<TObjArray*>(array->At(strip));
+  if (!array) AliErrorF("No strip array for FMD%d%c[%02d,%03d]", 
+                       det, ring, sector, strip);
+  return array;
+}
+
+//=====================================================================
+AliFMDBaseDA::Runner::Runner()
+  : fReader(0),
+    fDiagFile(""), 
+    fDiag(false)
+{}
+
+//_____________________________________________________________________ 
+void
+AliFMDBaseDA::Runner::AddHandlers()
+{
+  gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
+                                       "*",
+                                       "TStreamerInfo",
+                                       "RIO",
+                                       "TStreamerInfo()");
+  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", "Minuit", 
+                                       "TMinuitMinimizer",
+                                       "Minuit", 
+                                       "TMinuitMinimizer(const char *)");
+  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
+                                       "GSLMultiMin", 
+                                       "ROOT::Math::GSLMinimizer",
+                                       "MathMore", 
+                                       "GSLMinimizer(const char *)");
+  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
+                                       "GSLMultiFit", 
+                                       "ROOT::Math::GSLNLSMinimizer",
+                                       "MathMore", "GSLNLSMinimizer(int)");
+  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
+                                       "GSLSimAn", 
+                                       "ROOT::Math::GSLSimAnMinimizer",
+                                       "MathMore", 
+                                       "GSLSimAnMinimizer(int)");
+  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
+                                       "Linear", 
+                                       "TLinearMinimizer",
+                                       "Minuit", 
+                                       "TLinearMinimizer(const char *)");
+  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
+                                       "Fumili", 
+                                       "TFumiliMinimizer",
+                                       "Fumili", 
+                                       "TFumiliMinimizer(int)");
+}
+//_____________________________________________________________________ 
+void
+AliFMDBaseDA::Runner::ShowUsage(std::ostream& o, const char* progname)
+{
+  o << "Usage: " << progname << " SOURCE [OPTIONS]\n\n"
+    << "Options:\n"
+    << "   -h,--help                Show this help\n"
+    << "   -d,--diagnostics[=FILE]  Write diagnostics to file\n"
+    << "   -D,--debug=LEVEL         Set the debug level\n\n"
+    << "SOURCE is one of\n"
+    << " * FILE.raw                Raw data file\n"
+    << " * FILE.root               ROOT'ified raw data file\n"
+    << " * collection://FILE.root  Event list in a ROOT file\n"
+    << " * collection://FILE       File containing list of ROOT files\n"
+    << " * ^FMD                    Monitor source\n"
+    << "There are other options too.  Check the AliRawReader docs\n"
+    << std::endl;
+}
+//_____________________________________________________________________ 
+namespace {
+  Bool_t ExtractValue(const TString& arg, TString& val)
+  {
+    val = "";
+    Int_t eq = arg.Index("=");
+    if (eq == kNPOS) return false;
+    
+    val = arg(eq+1, arg.Length()-eq-1);
+    return true;
+  }
+}
+      
+//_____________________________________________________________________ 
+Int_t
+AliFMDBaseDA::Runner::Init(int argc, char** argv)
+{
+  AddHandlers();
+
+  // --- Process the command line ------------------------------------
+  TString source;
+  Int_t   debugLevel  = 0;
+  Bool_t  help        = false;
+  
+  for (int i = 1; i < argc; i++) { 
+    TString arg(argv[i]);
+    Bool_t  badOption   = false;
+    
+    if (arg[0] == '-') { // It's an option 
+      if (arg[1] == '-') { // It's a long option 
+       TString val;
+       if      (arg.EqualTo("--help"))     help = true; 
+       else if (arg.BeginsWith("--debug")) {
+         if (ExtractValue(arg, val))
+           debugLevel = val.Atoi();
+       }
+       else if (arg.BeginsWith("--diagnostics")) { 
+         fDiag = true;
+         if (ExtractValue(arg, val)) 
+           fDiagFile = val;
+       }
+       else badOption = true;
+      }
+      else { // Short option 
+       TString next(i < argc-1 ? argv[i+1] : "");
+       switch (arg[1]) { 
+       case 'h': help = true; break;
+       case 'd': fDiag = true; 
+         if (!next.IsNull() && next[0] != '-') {
+           fDiagFile = next;
+           i++;
+         }
+         break;
+       case 'D': 
+         if (!next.IsNull() && next[0] != '-') {
+           debugLevel = next.Atoi();
+           i++;
+         }
+         break;
+       default: badOption = true;
+       }
+      } // End of options
+      if (badOption) { 
+       std::cerr << argv[0] << ": Unknown option " << argv[i] 
+                 << std::endl;
+       return -1;
+      }
+    }
+    else { // source or compatibility debug level 
+      if (source.IsNull()) source = arg;
+      else                 debugLevel = arg.Atoi();
+    }
+  }
+  
+  // --- Check if help was requested ---------------------------------
+  if (help) { 
+    ShowUsage(std::cout, argv[0]);
+    return 1;
+  }
+
+  // --- Check if we have a source -----------------------------------
+  if (source.IsNull()) { 
+    std::cerr << "No source given" << std::endl;
+    return -2;
+  }
+
+  // --- Initialize various things -----------------------------------
+  AliFMDParameters::Instance()->Init(kFALSE,0);
+
+  //This will only work for FDR 1 data. When newer data becomes
+  //available the ! must be removed!
+  Bool_t old = kTRUE;
+  AliFMDParameters::Instance()->UseCompleteHeader(old);
+  
+  AliLog::EnableDebug(debugLevel > 0);
+  AliLog::SetModuleDebugLevel("FMD", debugLevel);
+
+  // --- Make our reader ---------------------------------------------
+  fReader = AliRawReader::Create(source);
+  if (!fReader) { 
+    std::cerr << "Failed to make raw reader for source \"" << source 
+             << "\"" << std::endl;
+    return -3;
+  }
+  return 0;
+}
+
+//_____________________________________________________________________ 
+Int_t
+AliFMDBaseDA::Runner::RunNumber() const
+{ 
+  if (!fReader) return -1;
+  return fReader->GetRunNumber(); 
+}
+
+//_____________________________________________________________________ 
+void
+AliFMDBaseDA::Runner::Exec(AliFMDBaseDA& da)
+{
+  TStopwatch timer;
+  timer.Start();
+
+  da.SetSaveDiagnostics(fDiag || !fDiagFile.IsNull());
+  if (!fDiagFile.IsNull()) da.SetDiagnosticsFilename(fDiagFile);
+
+  da.Run(fReader);
+
+  timer.Stop();
+  timer.Print();
+
+#ifdef ALI_AMORE
+  try { 
+    amore::da::AmoreDA myAmore(amore::da::AmoreDA::kSender);
+
+    for (UShort_t det = 1; det <= 3; det++) {
+      if (!da.HasSeenDetector(det)) continue;
+      TObject* runNo = new TObject;
+      runNo->SetUniqueID(fReader->GetRunNumber());
+      myAmore.Send(Form("gainRunNoFMD%d", det), runNo);
+    }
+    
+    TIter     next(&da.GetSummaries());
+    TObject*  obj = 0;
+    while ((obj = next())) 
+      myAmore.Send(obj->GetName(), obj);
+    
+  }
+  catch (exception& e) {
+    cerr << "Failed to make AMORE instance: " << e.what() << endl;
+  }
+                              
+#endif
+}
+
+
+  
+  
+  
+//_____________________________________________________________________ 
+
+//_____________________________________________________________________ 
 //
 // EOF
 //
index 36fda2e..921efef 100644 (file)
@@ -69,6 +69,12 @@ public:
    */
   void SetSaveDiagnostics(Bool_t save) {fSaveHistograms = save;}
   /** 
+   * Set the diagnostics file name 
+   * 
+   * @param f Diagnostics file name 
+   */
+  void SetDiagnosticsFilename(const TString& f) { fDiagnosticsFilename = f; }
+  /** 
    * Set whether to make summary histograms to be published to AMORE
    * 
    * @param save If true, will generate summary QA histograms
@@ -100,6 +106,24 @@ public:
    * @return true if the code has seen data from the detector 
    */
   Bool_t HasSeenDetector(UShort_t d) const;
+
+  /**
+   * Class to run the DAs 
+   */
+  struct Runner {
+    Runner();
+    Runner(const Runner&) : fReader(0), fDiagFile(""), fDiag(false) {}
+    ~Runner() {} 
+    Runner& operator=(const Runner&) { return *this; }
+    void   AddHandlers();
+    void   ShowUsage(std::ostream& o, const char* progname);
+    Int_t  Init(int argc, char** argv);
+    void   Exec(AliFMDBaseDA& da);
+    Int_t  RunNumber() const;
+    AliRawReader* fReader;
+    TString       fDiagFile;
+    Bool_t        fDiag;
+  };
 protected:
   /** 
    * Initialize 
@@ -123,6 +147,12 @@ protected:
   virtual void AddChannelContainer(TObjArray*, UShort_t, Char_t, 
                                   UShort_t, UShort_t )  {};
   /** 
+   * Add summary(s) for sectors 
+   * 
+   */
+  virtual void AddSectorSummary(TObjArray*, UShort_t, Char_t, UShort_t, 
+                               UShort_t) {}
+  /** 
    * End of event
    */
   virtual void FinishEvent()  {};
@@ -233,6 +263,11 @@ protected:
    */  
   const char* GetStripPath(UShort_t det, Char_t ring, UShort_t sec, 
                           UShort_t str, Bool_t full=kTRUE) const;
+  TObjArray* GetDetectorArray(UShort_t det);
+  TObjArray* GetRingArray(UShort_t det, Char_t ring);
+  TObjArray* GetSectorArray(UShort_t det, Char_t ring, UShort_t sector);
+  TObjArray* GetStripArray(UShort_t det, Char_t ring, 
+                          UShort_t sector, UShort_t strip);
   /** 
    * Write conditions file 
    * 
@@ -250,7 +285,7 @@ protected:
    * 
    * @param dir Directory to make containers in 
    */
-  void InitContainer(TDirectory* dir);
+  virtual void InitContainer(TDirectory* dir);
   /** 
    * Utility function for defining summary histograms 
    *
@@ -266,6 +301,9 @@ protected:
    * 
    */
   virtual void  MakeSummary(UShort_t, Char_t) { }
+  
+  virtual Bool_t HaveEnough(Int_t nEvent) const;
+  virtual UShort_t GetProgress(Int_t nEvent) const;
 
 
 
@@ -280,6 +318,7 @@ protected:
   TArrayS       fPulseSize;            // Pulse size for gain calib
   TArrayS       fPulseLength;          // Pulse length for gain calib
   Bool_t        fSeenDetectors[3];     // Detectors seen so far
+  UInt_t        fNEventsPerDetector[3];// # events per detector
   Int_t         fRequiredEvents;       // # events required for this calib
   Int_t         fCurrentEvent;         // the current event       
   UInt_t        fRunno;                // Current run number 
index 10f5e0f..b00cfc8 100644 (file)
@@ -50,7 +50,6 @@ ClassImp(AliFMDGainDA)
 //_____________________________________________________________________
 AliFMDGainDA::AliFMDGainDA() 
   : AliFMDBaseDA(),
-    fGainArray(),
     fHighPulse(256), 
     fEventsPerChannel(10),
     fCurrentPulse(10),
@@ -76,13 +75,12 @@ AliFMDGainDA::AliFMDGainDA()
   fCurrentPulse.Reset(0);
   fCurrentChannel.Reset(0);
   fOutputFile.open("gains.csv");
-  fGainArray.SetOwner(); 
+  fDiagnosticsFilename = "diagnosticsGain.root";
 }
 
 //_____________________________________________________________________
 AliFMDGainDA::AliFMDGainDA(const AliFMDGainDA & gainDA) 
   : AliFMDBaseDA(gainDA),
-    fGainArray(gainDA.fGainArray),
     fHighPulse(gainDA.fHighPulse),
     fEventsPerChannel(gainDA.fEventsPerChannel),
     fCurrentPulse(gainDA.fCurrentPulse),
@@ -133,37 +131,37 @@ void AliFMDGainDA::Init()
       nEvents = (fPulseLength.At(idx)*fHighPulse) / fPulseSize.At(idx);
     fEventsPerChannel.AddAt(nEvents,idx);
     if(nEvents>nEventsRequired) 
-      nEventsRequired = nEvents * fNumberOfStripsPerChip;
-    
+      nEventsRequired = nEvents * fNumberOfStripsPerChip;    
   }
-  
   SetRequiredEvents(nEventsRequired); 
-  
-  TObjArray* detArray;
-  TObjArray* ringArray;
-  TObjArray* sectorArray;
+}
+
+//_____________________________________________________________________
+void AliFMDGainDA::InitContainer(TDirectory* dir) 
+{
+  AliFMDBaseDA::InitContainer(dir);
   
   for(UShort_t det=1;det<=3;det++) {
-    detArray = new TObjArray();
-    detArray->SetOwner();
-    fGainArray.AddAtAndExpand(detArray,det);
-    for (UShort_t ir = 0; ir < 2; ir++) {
+    UShort_t sr = (det == 1 ? 1 : 0);
+    for (UShort_t ir = sr; ir < 2; ir++) {
       Char_t   ring = (ir == 0 ? 'O' : 'I');
       UShort_t nsec = (ir == 0 ? 40  : 20);
-      UShort_t nstr = (ir == 0 ? 2 : 4);
-      ringArray = new TObjArray();
-      ringArray->SetOwner();
-      detArray->AddAtAndExpand(ringArray,ir);
+      UShort_t nva  = (ir == 0 ? 2 : 4);
       for(UShort_t sec =0; sec < nsec;  sec++)  {
-       sectorArray = new TObjArray();
-       sectorArray->SetOwner();
-       ringArray->AddAtAndExpand(sectorArray,sec);
-       for(UShort_t strip = 0; strip < nstr; strip++) {
-         TH1S* hChannel = new TH1S(Form("hFMD%d%c_%d_%d",det,ring,sec,strip),
-                                   Form("hFMD%d%c_%d_%d",det,ring,sec,strip),
-                                   1024,0,1023);
+       TObjArray* sectorArray = GetSectorArray(det, ring, sec);
+       TObjArray* cache = new TObjArray(nva);
+       cache->SetName("Cache");
+       cache->SetOwner();
+       Int_t n = sectorArray->GetEntriesFast();
+       sectorArray->AddAtAndExpand(cache, n);
+       for(UShort_t va = 0; va < nva; va++) {
+         TH1S* hChannel = new TH1S(Form("FMD%d%c[%02d]_va%d",
+                                        det,ring,sec,va),
+                                   Form("FMD%d%c[%02d] VA%d Cache",
+                                        det,ring,sec,va),
+                                   1024,-.5,1023.5);
          hChannel->SetDirectory(0);
-         sectorArray->AddAtAndExpand(hChannel,strip);
+         cache->AddAtAndExpand(hChannel,va);
        }
       }
     }
@@ -171,7 +169,7 @@ void AliFMDGainDA::Init()
 }
 
 //_____________________________________________________________________
-void AliFMDGainDA::AddChannelContainer(TObjArray* sectorArray, 
+void AliFMDGainDA::AddChannelContainer(TObjArray* stripArray, 
                                       UShort_t det  , 
                                       Char_t   ring,  
                                       UShort_t sec, 
@@ -185,11 +183,36 @@ void AliFMDGainDA::AddChannelContainer(TObjArray* sectorArray,
   //  ring           Ring identifier 
   //  sec            Sector number
   //  strip          Strip number
-  TGraphErrors* hChannel  = new TGraphErrors();
-  hChannel->SetName(Form("FMD%d%c[%02d,%03d]", det, ring, sec, strip));
-  hChannel->SetTitle(Form("FMD%d%c[%02d,%03d] ADC vs DAC", 
+
+  AliFMDParameters* pars     = AliFMDParameters::Instance();
+  UShort_t          board    = pars->GetAltroMap()->Sector2Board(ring, sec);
+  Int_t             halfring = GetHalfringIndex(det,ring,board/16);
+  Int_t             dPulse   = fPulseSize.At(halfring);
+  Int_t             nPulses  = dPulse > 0 ? fHighPulse / dPulse : 0;
+
+  TGraphErrors* gChannel  = new TGraphErrors(nPulses);
+  gChannel->SetName(Form("FMD%d%c[%02d,%03d]", det, ring, sec, strip));
+  gChannel->SetTitle(Form("FMD%d%c[%02d,%03d] ADC vs DAC", 
                          det, ring, sec, strip));
-  sectorArray->AddAtAndExpand(hChannel,strip);
+  stripArray->AddAtAndExpand(gChannel,0);
+}
+
+//_____________________________________________________________________
+void AliFMDGainDA::AddSectorSummary(TObjArray* sectorArray, 
+                                   UShort_t det, 
+                                   Char_t   ring, 
+                                   UShort_t sec, 
+                                   UShort_t nStr) 
+{
+  TH1F* summary = new TH1F("Summary", Form("Summary of gains in FMD%d%c[%02d]", 
+                                          det, ring, sec), 
+                          nStr, -.5, nStr-.5);
+  summary->SetXTitle("Strip");
+  summary->SetYTitle("Gain [ADC/DAC]");
+  summary->SetDirectory(0);
+
+  Int_t n = sectorArray->GetEntriesFast();
+  sectorArray->AddAtAndExpand(summary, n);
 }
 
 //_____________________________________________________________________
@@ -211,8 +234,8 @@ void AliFMDGainDA::FillChannels(AliFMDDigit* digit)
   if((sec%2)     && ((strip+1) % fNumberOfStripsPerChip)) return;
   if(((sec+1)%2) && (strip % fNumberOfStripsPerChip)) return;
   
-  Int_t vaChip   = strip / fNumberOfStripsPerChip; 
-  TH1S* hChannel = GetChannelHistogram(det, ring, sec, vaChip);
+  UShort_t vaChip   = strip / fNumberOfStripsPerChip; 
+  TH1S*    hChannel = GetChannelHistogram(det, ring, sec, vaChip);
   hChannel->Fill(digit->Counts());
   UpdatePulseAndADC(det,ring,sec,strip);
 }
@@ -330,26 +353,9 @@ void AliFMDGainDA::Analyse(UShort_t det,
 
     // }
   if(fSaveHistograms) {
-    gDirectory->cd(GetSectorPath(det,ring, sec, kTRUE));
-    
-    TH1F* summary = dynamic_cast<TH1F*>(gDirectory->Get("Summary"));
-    if (!summary) { 
-      Int_t nStr = (ring == 'I' ? 512 : 256);
-      summary = new TH1F("Summary", Form("Summary of gains in FMD%d%c[%02d]", 
-                                        det, ring, sec), 
-                        nStr, -.5, nStr-.5);
-      summary->SetXTitle("Strip");
-      summary->SetYTitle("Gain [ADC/DAC]");
-      summary->SetDirectory(gDirectory);
-    }
+    TH1F* summary = GetSectorSummary(det, ring, sec);
     summary->SetBinContent(strip+1, fitFunc.GetParameter(1));
     summary->SetBinError(strip+1, fitFunc.GetParError(1));
-    
-    gDirectory->cd(GetStripPath(det,ring,sec,strip, kTRUE));
-    grChannel->SetName(Form("FMD%d%c[%02d,%03d]",det,ring,sec,strip));
-    // grChannel->SetDirectory(gDirectory);
-    grChannel->Write();
-    // grChannel->Write(Form("grFMD%d%c_%d_%d",det,ring,sec,strip));
   }  
 }
 
@@ -384,15 +390,14 @@ void AliFMDGainDA::WriteHeaderToFile()
                    "Strip, "
                    "Gain, "
                    "Error, "
-                   "Chi2/NDF \n",56);
-  
+                   "Chi2/NDF \n",56);  
 }
 
 //_____________________________________________________________________
 TH1S* AliFMDGainDA::GetChannelHistogram(UShort_t det, 
                                        Char_t   ring, 
                                        UShort_t sec, 
-                                       UShort_t strip) 
+                                       UShort_t va) 
 {
   // Get the current histogram of a single strip
   // 
@@ -400,17 +405,11 @@ TH1S* AliFMDGainDA::GetChannelHistogram(UShort_t det,
   //  det            Detector number
   //  ring           Ring identifier 
   //  sec            Sector number
-  //  strip          Strip number
-  
-  UShort_t  lRing = 1;
-  if(ring == 'O')
-    lRing = 0;
-  
-  
-  TObjArray* detArray  = static_cast<TObjArray*>(fGainArray.At(det));
-  TObjArray* ringArray = static_cast<TObjArray*>(detArray->At(lRing));
-  TObjArray* secArray  = static_cast<TObjArray*>(ringArray->At(sec));
-  TH1S* hChannel       = static_cast<TH1S*>(secArray->At(strip));
+  //  va             VA number
+  TObjArray* secArray  = GetSectorArray(det, ring, sec);
+  Int_t      n         = secArray->GetEntriesFast();
+  TObjArray* cache     = static_cast<TObjArray*>(secArray->At(n-1));
+  TH1S* hChannel       = static_cast<TH1S*>(cache->At(va));
   
   return hChannel;
 }
@@ -428,16 +427,23 @@ TGraphErrors* AliFMDGainDA::GetChannel(UShort_t det,
   //  ring           Ring identifier 
   //  sec            Sector number
   //  strip          Strip number
-  UShort_t      iring     = (ring == 'O' ? 0 : 1);
-  TObjArray*    detArray  = static_cast<TObjArray*>(fDetectorArray.At(det));
-  TObjArray*    ringArray = static_cast<TObjArray*>(detArray->At(iring));
-  TObjArray*    secArray  = static_cast<TObjArray*>(ringArray->At(sec));
-  TGraphErrors* hChannel  = static_cast<TGraphErrors*>(secArray->At(strip));
+  TObjArray*    stripArray = GetStripArray(det, ring, sec, strip);
+  TGraphErrors* hChannel   = static_cast<TGraphErrors*>(stripArray->At(0));
   
   return hChannel;
 }
 
 //_____________________________________________________________________
+TH1F* AliFMDGainDA::GetSectorSummary(UShort_t det, 
+                                    Char_t   ring, 
+                                    UShort_t sec) 
+{
+  TObjArray* secArray    = GetSectorArray(det, ring, sec);
+  Int_t      n           = secArray->GetEntriesFast();
+  return static_cast<TH1F*>(secArray->At(n-2)); // Cache added later
+}
+
+//_____________________________________________________________________
 void AliFMDGainDA::UpdatePulseAndADC(UShort_t det, 
                                     Char_t ring, 
                                     UShort_t sec, 
@@ -451,24 +457,20 @@ void AliFMDGainDA::UpdatePulseAndADC(UShort_t det,
   //  sec            Sector number
   //  strip          Strip number
   
-  AliFMDParameters* pars = AliFMDParameters::Instance();
-  // UInt_t ddl, board,chip,ch;
-  UShort_t board = pars->GetAltroMap()->Sector2Board(ring, sec);
-  // pars->Detector2Hardware(det,ring,sec,strip,ddl,board,chip,ch);
-  /// pars->GetAltroMap()->Strip2Channel(
-  Int_t halfring = GetHalfringIndex(det,ring,board/16);
+  AliFMDParameters* pars     = AliFMDParameters::Instance();
+  UShort_t          board    = pars->GetAltroMap()->Sector2Board(ring, sec);
+  Int_t             halfring = GetHalfringIndex(det,ring,board/16);
   
   if(GetCurrentEvent()> (fNumberOfStripsPerChip*fEventsPerChannel.At(halfring)))
     return;
   
-  if((sec%2)     && ((strip+1) % fNumberOfStripsPerChip)) return;
-  
-  if(((sec+1)%2) && (strip % fNumberOfStripsPerChip)) return;
+  if ((sec       % 2) && ((strip+1) % fNumberOfStripsPerChip)) return;
+  if (((sec + 1) % 2) && (strip     % fNumberOfStripsPerChip)) return;
   
   if(((GetCurrentEvent()) % fPulseLength.At(halfring)) 
      && GetCurrentEvent() > 0) return;
      
-  Int_t vaChip = strip/fNumberOfStripsPerChip; 
+  Int_t vaChip   = strip/fNumberOfStripsPerChip; 
   TH1S* hChannel = GetChannelHistogram(det,ring,sec,vaChip);
   
   if(!hChannel->GetEntries()) {
@@ -489,25 +491,25 @@ void AliFMDGainDA::UpdatePulseAndADC(UShort_t det,
   
   hChannel->GetXaxis()->SetRange(firstBin,lastBin);
   
-  Int_t    channelNumber      = (strip + 
-                                (GetCurrentEvent()-1)
-                                / ((fPulseLength.At(halfring)*fHighPulse)
-                                   / fPulseSize.At(halfring))); 
-  if(sec%2)
-    channelNumber      = (strip - 
-                         (GetCurrentEvent()-1)
-                         / ((fPulseLength.At(halfring)*fHighPulse)
-                            / fPulseSize.At(halfring))); 
-  
-  TGraphErrors* channel = GetChannel(det,ring,sec,channelNumber);
-  
+  Int_t         channelOff = ((GetCurrentEvent()-1)
+                             / ((fPulseLength.At(halfring)*fHighPulse)
+                                / fPulseSize.At(halfring)));
+  Int_t         channelNo  = (strip + ((sec % 2 == 1) ? -1 : 1) * channelOff);
+  TGraphErrors* channel    = GetChannel(det,ring,sec,channelNo);
+
   channel->SetPoint(fCurrentPulse.At(halfring),pulse,mean);
   channel->SetPointError(fCurrentPulse.At(halfring),0,rms);
   
   if(fSaveHistograms) {
-    gDirectory->cd(GetStripPath(det,ring,sec,channelNumber));
-    hChannel->Write(Form("%s_pulse_%03d",hChannel->GetName(),(Int_t)pulse));
-    
+    TH1S* out = 
+      static_cast<TH1S*>(hChannel->Clone(Form("FMD%d%c[%02d,%03d]_0x%02x",
+                                             det, ring, sec, channelNo, 
+                                             int(pulse))));
+    out->SetTitle(Form("FMD%d%c[%02d,%03d] DAC=0x%02x (%3d)",
+                      det, ring, sec, channelNo, int(pulse), int(pulse)));
+    out->SetDirectory(0);
+    TObjArray* arr = GetStripArray(det, ring, sec, channelNo);
+    arr->AddAtAndExpand(out, fCurrentPulse.At(halfring)+1);
   }
     
   hChannel->Reset();
index ae64e0e..0b4033f 100644 (file)
@@ -74,6 +74,18 @@ protected:
                           UShort_t det, Char_t ring, 
                           UShort_t sec, UShort_t strip);
   /** 
+   * Add summary(s) for sectors 
+   * 
+   * @param secArray 
+   * @param det 
+   * @param ring 
+   * @param sector 
+   * @param nStrip 
+   */
+  virtual void AddSectorSummary(TObjArray* secArray, UShort_t det, 
+                               Char_t ring, UShort_t sector, 
+                               UShort_t nStrip);
+  /** 
    * Fill channel histogram 
    * 
    * @param digit Digit to fill from
@@ -121,6 +133,12 @@ protected:
    * @param dummy Not used
    */
   void Terminate(TFile* dummy);
+  /** 
+   * Initialize container 
+   * 
+   * @param dir Directory to make containers in 
+   */
+  virtual void InitContainer(TDirectory* dir);
 
 private:
   /** 
@@ -129,12 +147,12 @@ private:
    * @param det         Detector # 
    * @param ring        Ring identifier 
    * @param sec         Sector number
-   * @param strip       Strip number
+   * @param va          VA chip number
    * 
    * @return Histogram
    */  
   TH1S* GetChannelHistogram(UShort_t det, Char_t ring, UShort_t sec, 
-                           UShort_t strip);
+                           UShort_t va);
   /** 
    * Get strip graph
    * 
@@ -147,7 +165,17 @@ private:
    */
   TGraphErrors* GetChannel(UShort_t det, Char_t ring, 
                           UShort_t sec, UShort_t strip);
-  TObjArray fGainArray;          // Array of gains 
+  /** 
+   * Get the summary for a sector
+   * 
+   * @param det    Detector
+   * @param ring   Ring 
+   * @param sec    Sector 
+   * @param pedNotNoise Option
+   * 
+   * @return histogram 
+   */
+  TH1F* GetSectorSummary(UShort_t det, Char_t   ring, UShort_t sec);
   Int_t     fHighPulse;          // Highest pulse
   TArrayS   fEventsPerChannel;   // # of events per pulse step
   TArrayS   fCurrentPulse;       // The current pulse size 
index 2be9347..956f15d 100644 (file)
@@ -73,6 +73,7 @@ AliFMDPedestalDA::AliFMDPedestalDA()
   fZSfileFMD2.open("ddl3073.csv");
   Rotate("ddl3074.csv", 10);
   fZSfileFMD3.open("ddl3074.csv");  
+  fDiagnosticsFilename = "diagnosticsPedestal.root";
 }
 
 //_____________________________________________________________________
@@ -113,7 +114,7 @@ void AliFMDPedestalDA::Init()
 }
 
 //_____________________________________________________________________
-void AliFMDPedestalDA::AddChannelContainer(TObjArray* sectorArray, 
+void AliFMDPedestalDA::AddChannelContainer(TObjArray* sampleArray, 
                                           UShort_t det, 
                                           Char_t   ring, 
                                           UShort_t sec, 
@@ -129,17 +130,38 @@ void AliFMDPedestalDA::AddChannelContainer(TObjArray* sectorArray,
   //     strip        Strip
   AliFMDParameters* pars        = AliFMDParameters::Instance();
   UInt_t            samples     = pars->GetSampleRate(det, ring, sec, strip);
-  TObjArray*        sampleArray = new TObjArray(samples);
-  sampleArray->SetOwner();
   for (UInt_t sample = 0; sample < samples; sample++) {
     TString name(Form("FMD%d%c[%02d,%03d]_%d", det,ring,sec,strip,sample));
     TH1S* hSample = new TH1S(name.Data(),name.Data(), 1024,-.5,1023.5);
     hSample->SetXTitle("ADC");
     hSample->SetYTitle("Events");
     hSample->SetDirectory(0);
-    sampleArray->AddAt(hSample, sample);
+    sampleArray->AddAtAndExpand(hSample, sample);
   }
-  sectorArray->AddAtAndExpand(sampleArray, strip);
+}
+
+//_____________________________________________________________________
+void AliFMDPedestalDA::AddSectorSummary(TObjArray* sectorArray, 
+                                       UShort_t det, 
+                                       Char_t   ring, 
+                                       UShort_t sec, 
+                                       UShort_t nStr) 
+{
+  TH1F* sumPed = new TH1F("Pedestals", 
+                         Form("Summary of pedestals in FMD%d%c[%02d]", 
+                              det, ring, sec), 
+                         nStr, -.5, nStr-.5);
+  sumPed->SetXTitle("Strip");
+  sumPed->SetYTitle("Pedestal [ADC]");
+  sumPed->SetDirectory(0);
+  
+  TH1F* sumNoise = static_cast<TH1F*>(sumPed->Clone("Noise"));
+  sumNoise->SetYTitle("Noise [ADC]");
+  sumNoise->SetDirectory(0);
+  
+  Int_t n = sectorArray->GetEntriesFast();
+  sectorArray->AddAtAndExpand(sumPed,   n + kPedestalOffset - 1);
+  sectorArray->AddAtAndExpand(sumNoise, n + kNoiseOffset - 1);
 }
 
 //_____________________________________________________________________
@@ -158,6 +180,8 @@ void AliFMDPedestalDA::FillChannels(AliFMDDigit* digit)
   UInt_t            samples  = pars->GetSampleRate(det, ring, sec, strip);
   for (UInt_t sample = 0; sample < samples; sample++) {
     TH1S* hSample = GetChannel(det, ring, sec, strip, sample);
+    if (!hSample) continue;
+    
     hSample->Fill(digit->Count(sample));
   }
   
@@ -167,7 +191,8 @@ void AliFMDPedestalDA::FillChannels(AliFMDDigit* digit)
 void AliFMDPedestalDA::MakeSummary(UShort_t det, Char_t ring)
 {
   //Create summary hists for FMD pedestals
-  std::cout << "Making summary for FMD" << det << ring << " ..." << std::endl;
+  // std::cout << "Making summary for FMD" << det << ring << " ..." 
+  //           << std::endl;
   switch (det) { 
   case 1: 
     fSummaryFMD1i = MakeSummaryHistogram("ped", "Pedestals", det, ring);
@@ -226,18 +251,19 @@ void AliFMDPedestalDA::Analyse(UShort_t det,
     }
     break;
   }
+#if 0
   static bool first = true;
   if (summary && first) { 
     std::cout << "Filling summary " << summary->GetName() << std::endl;
     first = false;
   }
-
+#endif
   // Float_t           factor   = pars->GetPedestalFactor();
   UInt_t            samples  = pars->GetSampleRate(det, ring, sec, strip);
   for (UShort_t sample = 0; sample < samples; sample++) {
   
     TH1S* hChannel = GetChannel(det, ring, sec, strip,sample);
-    if(hChannel->GetEntries() == 0) {
+    if(!hChannel || hChannel->GetEntries() == 0) {
       //AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d",
       //           det,ring,sec,strip));
       return;
@@ -297,6 +323,8 @@ void AliFMDPedestalDA::Analyse(UShort_t det,
     if      (samples == 2) sampleToWrite = 1;
     else if (samples <  2) sampleToWrite = 0;
     
+    hChannel->GetXaxis()->SetRange(1,1024);
+
     if(sample != sampleToWrite) continue;
     
     
@@ -317,6 +345,9 @@ void AliFMDPedestalDA::Analyse(UShort_t det,
     }
 
     if(fSaveHistograms  ) {
+      TH1F* sumPed   = GetSectorSummary(det, ring, sec, true);
+      TH1F* sumNoise = GetSectorSummary(det, ring, sec, false);
+#if 0
       gDirectory->cd(GetSectorPath(det, ring, sec, kTRUE));
       TH1F* sumPed   = dynamic_cast<TH1F*>(gDirectory->Get("Pedestals"));
       TH1F* sumNoise = dynamic_cast<TH1F*>(gDirectory->Get("Noise"));
@@ -340,24 +371,29 @@ void AliFMDPedestalDA::Analyse(UShort_t det,
        
        sumNoise->SetDirectory(gDirectory);
       }
+#endif
       sumPed->SetBinContent(strip+1, mean);
       sumPed->SetBinError(strip+1, rms);
       sumNoise->SetBinContent(strip+1, rms);
-      
+
+#if 0
       if(sumNoise->GetEntries() == nStr)
        sumNoise->Write(sumNoise->GetName(),TObject::kOverwrite);
       if(sumPed->GetEntries() == nStr)
        sumPed->Write(sumPed->GetName(),TObject::kOverwrite);
-      
+#endif
       fPedSummary.SetBinContent(fCurrentChannel,mean);
       
       fNoiseSummary.SetBinContent(fCurrentChannel,rms);
       fCurrentChannel++;
-      
+
+#if 0      
       gDirectory->cd(GetStripPath(det, ring, sec, strip, kTRUE));
       hChannel->GetXaxis()->SetRange(1,1024);
       
       hChannel->Write();
+#endif
     }
   }
 }
@@ -367,7 +403,7 @@ void AliFMDPedestalDA::Terminate(TFile* diagFile)
 {
   // Called at the end of a job.  Fills in missing time-bins and
   // closes output files
-  if(fSaveHistograms) {
+  if(fSaveHistograms && diagFile) {
     diagFile->cd();
     
     fPedSummary.Write();
@@ -489,15 +525,34 @@ TH1S* AliFMDPedestalDA::GetChannel(UShort_t det,
   //
   // Return:
   //     ADC spectra of a strip.
-  UShort_t   iring       = (ring == 'O' ? 0 : 1);
-  TObjArray* detArray    = static_cast<TObjArray*>(fDetectorArray.At(det));
-  TObjArray* ringArray   = static_cast<TObjArray*>(detArray->At(iring));
-  TObjArray* secArray    = static_cast<TObjArray*>(ringArray->At(sec));
-  TObjArray* sampleArray = static_cast<TObjArray*>(secArray->At(strip));
+  TObjArray* sampleArray = GetStripArray(det, ring, sec, strip);
+  if (!sampleArray) return 0;
   TH1S*      hSample     = static_cast<TH1S*>(sampleArray->At(sample));
+  if (!hSample) {
+    AliErrorF("No channel histogram for FMD%d%c[%02d,%03d]_%d", 
+             det, ring, sec, strip, sample);
+    sampleArray->ls();
+    AliErrorF("Path is %s <- %s <- %s <- %s", 
+             sampleArray->GetName(),
+             GetSectorArray(det, ring, sec)->GetName(), 
+             GetRingArray(det, ring)->GetName(),
+             GetDetectorArray(det)->GetName());
+    
+  }
   return hSample;
   
 }
+//_____________________________________________________________________
+TH1F* AliFMDPedestalDA::GetSectorSummary(UShort_t det, 
+                                        Char_t   ring, 
+                                        UShort_t sec, 
+                                        Bool_t   pedNotNoise) 
+{
+  TObjArray* secArray    = GetSectorArray(det, ring, sec);
+  Int_t      n           = secArray->GetEntriesFast();
+  Int_t      i           = n - (pedNotNoise ? kNoiseOffset : kPedestalOffset);
+  return static_cast<TH1F*>(secArray->At(i));
+}
 
 //_____________________________________________________________________
 //
index da291d3..b69ca8e 100644 (file)
@@ -49,6 +49,10 @@ public:
   void Init();
  
 protected:
+  enum { 
+    kPedestalOffset = 1, 
+    kNoiseOffset   = 2
+  };
   /** 
    * Add a channel to the containers. 
    * 
@@ -61,6 +65,18 @@ protected:
   void AddChannelContainer(TObjArray* sectorArray, UShort_t det, 
                           Char_t ring, UShort_t sec, UShort_t strip);
   /** 
+   * Add summary(s) for sectors 
+   * 
+   * @param secArray 
+   * @param det 
+   * @param ring 
+   * @param sector 
+   * @param nStrip 
+   */
+  virtual void AddSectorSummary(TObjArray* secArray, UShort_t det, 
+                               Char_t ring, UShort_t sector, 
+                               UShort_t nStrip);
+  /** 
    * Fill ADC values from a digit into the corresponding histogram.
    * 
    * @param digit Digit to fill ADC values for.
@@ -108,6 +124,18 @@ private:
   TH1S* GetChannel(UShort_t det, Char_t ring, UShort_t sec, 
                   UShort_t strip, UInt_t sample);
   /** 
+   * Get the summary for a sector
+   * 
+   * @param det    Detector
+   * @param ring   Ring 
+   * @param sec    Sector 
+   * @param pedNotNoise Option
+   * 
+   * @return histogram 
+   */
+  TH1F* GetSectorSummary(UShort_t det, Char_t   ring, UShort_t sec, 
+                        Bool_t   pedNotNoise);
+  /** 
    * Calculate the hardware index
    * 
    * @param ddl    DDL number
index 1b677ab..5482ff8 100644 (file)
@@ -48,6 +48,10 @@ if( ALICE_TARGET STREQUAL "win32gcc")
     ${SOFLAGS} -L${ALICE_ROOT}/lib/tgt_${ALICE_TARGET} -lFMDrec -lFMDbase 
     -lSTEER -lCDB -lESD -lSTEERBase -lRAWDatarec -L${ROOTLIBDIR} -lGeom)
 endif( ALICE_TARGET STREQUAL "win32gcc")
+
+install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/FMDGainda ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/FMDPedestalda ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/FMDBaseda
+  DESTINATION bin/tgt_${ALICE_TARGET})
+
 #
 # EOF
 #
index 398634a..4cebf14 100644 (file)
@@ -11,6 +11,7 @@
   Output Files:            conditions.csv
   Trigger types used:      PHYSICS_EVENT
 */
+#include <cstdlib>
 #include <Riostream.h>
 #include "monitor.h"
 #include "event.h"
 #include "TROOT.h"
 #include "TPluginManager.h"
 
-
+void
+usage(std::ostream& o, const char* progname)
+{
+  o << "Usage: " << progname << " FILE [OPTIONS]\n\n"
+    << "Options:\n"
+    << "\t-h,--help         Show this help\n"
+    << "\t-d,--diagnostics  Create diagnostics\n"
+    << "\t-D,--debug LEVEL  Set the debug level\n"
+    << std::endl;
+}
 
 int main(int argc, char **argv) 
 {
@@ -51,18 +61,50 @@ int main(int argc, char **argv)
   AliFMDParameters::Instance()->UseCompleteHeader(old);
   struct eventHeaderStruct *event;
   int status;
-  /* define data source : this is argument 1 */  
-  if (argc < 2) { 
-    cout << "No monitor source set" << endl;
+
+  Int_t  debugLevel = 0;
+  Bool_t badOption  = false;
+  char*  source     = 0;
+  for (int i = 1; i < argc; i++) { 
+    if (argv[i][0] == '-') { // Options 
+      if (argv[i][1] == '-') { // Long option 
+       TString arg(&(argv[i][2])); 
+       if      (arg.EqualTo("help")) { usage(std::cout, argv[0]); return 0; }
+       if      (arg.EqualTo("diagnostics")) { }
+       else if (arg.EqualTo("debug")) debugLevel = atoi(argv[++i]); 
+       else                             badOption = true;
+      }
+      else { // Short option 
+       switch (argv[i][1]) { 
+       case 'h': usage(std::cout, argv[0]); return 0; 
+       case 'd': break; 
+       case 'D': debugLevel = atoi(argv[++i]); break;
+       default:  badOption = true;
+       }
+      }
+      if (badOption) { 
+       std::cerr << argv[0] << ": Unknown option " << argv[i] 
+                 << std::endl;
+       return 1;
+      }
+    }
+    else { 
+      if (!source) source     = argv[i];
+      else         debugLevel = atoi(argv[i]);
+    }
+  }
+  if (!source) { 
+    printf("%s: No data source specified\n", argv[0]);
     return -1;
   }
-  status=monitorSetDataSource( argv[1] );
+  status=monitorSetDataSource(source);
   if (status!=0) {
-    printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
+    printf("monitorSetDataSource() failed for %s: %s\n",
+          source, monitorDecodeError(status));
     return -1;
   }
   
-  if (argc > 2) AliLog::SetModuleDebugLevel("FMD", atoi(argv[2]));
+  AliLog::SetModuleDebugLevel("FMD", debugLevel);
   /* declare monitoring program */
   status=monitorDeclareMp( __FILE__ );
   if (status!=0) {
@@ -91,7 +133,8 @@ int main(int argc, char **argv)
     }
     
     if (status!=0) {
-      printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
+      printf("monitorGetEventDynamic() failed : %s\n",
+            monitorDecodeError(status));
       break;
     }
     
index ea6c7dd..5a18972 100644 (file)
   Output Files:            gains.csv
   Trigger types used:      GAIN
 */
-#include <Riostream.h>
-#include <TSystem.h>
-#include <TString.h>
-#include <AliFMDParameters.h>
-#include <AliRawReader.h>
-#include <TStopwatch.h>
 #include <AliFMDGainDA.h>
-#include <AliRawReaderDate.h>
-#include <AliRawReaderRoot.h>
-#include <AliLog.h>
-#include "daqDA.h"
-#include "TROOT.h"
-#include "TPluginManager.h"
-#ifdef ALI_AMORE
-# include <AmoreDA.h>
-# include <TH2.h>
-#endif
-
-
+#include <AliFMDParameters.h>
+#include "FMDUtilda.h"
+#include <iostream>
 
 int main(int argc, char **argv) 
 {
-
-  gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
-                                       "*",
-                                       "TStreamerInfo",
-                                       "RIO",
-                                       "TStreamerInfo()");
-  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", "Minuit", 
-                                       "TMinuitMinimizer",
-                                       "Minuit", 
-                                       "TMinuitMinimizer(const char *)");
-  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
-                                       "GSLMultiMin", 
-                                       "ROOT::Math::GSLMinimizer",
-                                       "MathMore", 
-                                       "GSLMinimizer(const char *)");
-  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
-                                       "GSLMultiFit", 
-                                       "ROOT::Math::GSLNLSMinimizer",
-                                       "MathMore", "GSLNLSMinimizer(int)");
-  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
-                                       "GSLSimAn", 
-                                       "ROOT::Math::GSLSimAnMinimizer",
-                                       "MathMore", 
-                                       "GSLSimAnMinimizer(int)");
-  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
-                                       "Linear", 
-                                       "TLinearMinimizer",
-                                       "Minuit", 
-                                       "TLinearMinimizer(const char *)");
-  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
-                                       "Fumili", 
-                                       "TFumiliMinimizer",
-                                       "Fumili", 
-                                       "TFumiliMinimizer(int)");
-  
-  
-  Bool_t diagnostics = kFALSE;
-  Char_t* fileName = argv[1];
-  TString secondArgument(argv[2]);
+  AliFMDBaseDA::Runner r;
   
-  for (int i = 2; i < argc; i++) { 
-    TString arg(argv[i]);
-    if      (arg.Contains("--diagnostics=true")) diagnostics = kTRUE;
-    else if (arg.Contains("--help")) { 
-      cout << "Usage: " << argv[0] << " FILENAME [OPTIONS]\n\n"
-               << "Options:\n" 
-               << "    --diagnostics=BOOL Make diagnostics ROOT file\n"
-               << endl;
-      return 0;
-    }
-    else { 
-      cerr << "Unknown option: " << arg << "\n"
-               << "Try '" << argv[0] << " --help" << endl;
-      return 1;
-    }
-  }
-  Bool_t old = kTRUE;
-    
-  AliFMDParameters::Instance()->Init(kFALSE,0);
+  Int_t ret = r.Init(argc, argv);
+  if (ret < 0) return -ret;
+  if (ret > 0) return 0;
 
-  //This will only work for FDR 1 data. When newer data becomes available the ! must be removed!
-  AliFMDParameters::Instance()->UseCompleteHeader(old);
-  
-  AliLog::EnableDebug(kFALSE);
-  
-  AliRawReader *reader = 0;
-  TString fileNam(fileName);
-  if (fileNam.EndsWith(".root")) 
-    reader = new AliRawReaderRoot(fileName);
-  else reader = new AliRawReaderDate(fileName);
-  if (!reader) { 
-    cerr << "Don't know how to make reader for " << fileNam 
-             << endl;
-    return -2;
-  }
-
-  
-  TStopwatch timer;
-  timer.Start();
   AliFMDGainDA gainDA;
-  gainDA.SetSaveDiagnostics(diagnostics);
 #ifdef ALI_AMORE
   gainDA.SetMakeSummaries(kTRUE);
 #endif
-  gainDA.Run(reader);
-  
-  timer.Stop();
-  timer.Print();
-  
-  Int_t  retvalConditions = 
-    daqDA_FES_storeFile("conditions.csv", 
-                       AliFMDParameters::Instance()->GetConditionsShuttleID());
-  Int_t  retvalGain = 
-    daqDA_FES_storeFile("gains.csv", 
-                       AliFMDParameters::Instance()->GetGainShuttleID());
+  r.Exec(gainDA);
 
-  if(retvalConditions!=0 || retvalGain!=0)
-    cerr << "Pedestal DA failed" << endl;
-  
-#ifdef ALI_AMORE
-  try { 
-    amore::da::AmoreDA myAmore(amore::da::AmoreDA::kSender);
+  const char* files[] = { "conditions.csv", 
+                         "gains.csv", 
+                         0 }; 
+  const char* ids[] = { AliFMDParameters::Instance()->GetConditionsShuttleID(), 
+                       AliFMDParameters::Instance()->GetGainShuttleID(),
+                       0 };
+  ret = UploadFiles(files, ids);
 
-    UShort_t det = 0;
-    for (det = 1; det <= 3; det++) 
-      if (gainDA.HasSeenDetector(det)) break;
-    if (det >= 1 && det <= 3) { 
-      TObject* runNo = new TObject;
-      runNo->SetUniqueID(reader->GetRunNumber());
-      myAmore.Send(Form("gainRunNoFMD%d", det), runNo);
-    }
-                  
-    TIter     next(&gainDA.GetSummaries());
-    TObject*  obj = 0;
-    while ((obj = next())) 
-      myAmore.Send(obj->GetName(), obj);
-    
-  }
-  catch (exception& e) {
-    cerr << "Failed to make AMORE instance: " << e.what() << endl;
-  }
-                              
-#endif
+  if(ret > 0) std::cerr << "Gain DA failed" << std::endl;
 
-  if(retvalGain != 0) return retvalGain;
-  return retvalConditions;
+  PostSummaries(gainDA, "gain", r.RunNumber());
 
+  return ret;
 }
 //
 // EOF
index 5160565..0ce1d53 100644 (file)
@@ -1,5 +1,4 @@
 /*
-
   FMD DA for online calibration of conditions
 
   Contact:                 canute@nbi.dk
   Output Files:            peds.csv
   Trigger types used:      PEDESTAL
 */
-#include <iostream>
-#include <TSystem.h>
-#include <TString.h>
-#include <AliFMDParameters.h>
-#include <AliRawReader.h>
-#include <TStopwatch.h>
 #include <AliFMDPedestalDA.h>
-#include <AliRawReaderDate.h>
-#include <AliRawReaderRoot.h>
-#include "daqDA.h"
-#include "TROOT.h"
-#include "TPluginManager.h"
-#include <AliLog.h>
-#ifdef ALI_AMORE
-# include <AmoreDA.h>
-# include <TH2.h>
-#endif
+#include <AliFMDParameters.h>
+#include "FMDUtilda.h"
+#include <iostream>
 
 int main(int argc, char **argv) 
 {
-  /* magic line from Rene - for future reference! */
-  gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
-                                       "*",
-                                       "TStreamerInfo",
-                                       "RIO",
-                                       "TStreamerInfo()");
-  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", "Minuit", 
-                                       "TMinuitMinimizer",
-                                       "Minuit", 
-                                       "TMinuitMinimizer(const char *)");
-  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
-                                       "GSLMultiMin", 
-                                       "ROOT::Math::GSLMinimizer",
-                                       "MathMore", 
-                                       "GSLMinimizer(const char *)");
-  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
-                                       "GSLMultiFit", 
-                                       "ROOT::Math::GSLNLSMinimizer",
-                                       "MathMore", "GSLNLSMinimizer(int)");
-  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
-                                       "GSLSimAn", 
-                                       "ROOT::Math::GSLSimAnMinimizer",
-                                       "MathMore", 
-                                       "GSLSimAnMinimizer(int)");
-  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
-                                       "Linear", 
-                                       "TLinearMinimizer",
-                                       "Minuit", 
-                                       "TLinearMinimizer(const char *)");
-  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
-                                       "Fumili", 
-                                       "TFumiliMinimizer",
-                                       "Fumili", 
-                                       "TFumiliMinimizer(int)");
-
-
-  
-  
-  Bool_t diagnostics = kFALSE;
-  if (argc < 2) { 
-    std::cerr << "No input file given" << std::endl;
-    return 1;
-  }
-  TString fileName(argv[1]);
-  if (fileName.Contains("--help")) { 
-    std::cout << "Usage: " << argv[0] << " FILENAME [OPTIONS]\n\n"
-             << "Options:\n" 
-             << "    --diagnostics=BOOL Make diagnostics ROOT file\n"
-             << std::endl;
-    return 0;
-  }
-      
-  for (int i = 2; i < argc; i++) { 
-    TString arg(argv[i]);
-    if      (arg.Contains("--diagnostics=true")) diagnostics = kTRUE;
-    else if (arg.Contains("--help")) { 
-      std::cout << "Usage: " << argv[0] << " FILENAME [OPTIONS]\n\n"
-               << "Options:\n" 
-               << "    --diagnostics=BOOL Make diagnostics ROOT file\n"
-               << std::endl;
-      return 0;
-    }
-    else { 
-      std::cerr << "Unknown option: " << arg << "\n"
-               << "Try '" << argv[0] << " --help" << std::endl;
-      return 1;
-    }
-  }
-  Bool_t old = kTRUE;
+  AliFMDBaseDA::Runner r;
 
-  AliLog::EnableDebug(kFALSE);
-  AliFMDParameters::Instance()->Init(kFALSE,0);
-  AliFMDParameters::Instance()->UseCompleteHeader(old);
+  Int_t ret = r.Init(argc, argv);
+  if (ret < 0) return -ret;
+  if (ret > 0) return 0;
 
-  AliRawReader *reader = 0;
-  if (fileName.EndsWith(".root")) 
-    reader = new AliRawReaderRoot(fileName.Data());
-  else 
-    reader = new AliRawReaderDate(fileName.Data());
-  if (!reader) { 
-    std::cerr << "Don't know how to make reader for " << fileName
-             << std::endl;
-    return -2;
-  }
-  TStopwatch timer;
-  timer.Start();
   AliFMDPedestalDA pedDA;
-  pedDA.SetSaveDiagnostics(diagnostics);
 #ifdef ALI_AMORE
   pedDA.SetMakeSummaries(kTRUE);
 #endif
-  pedDA.Run(reader);
-  
-  timer.Stop();
-  timer.Print();
-  Int_t  retvalConditions = 
-    daqDA_FES_storeFile("conditions.csv", 
-                       AliFMDParameters::Instance()->GetConditionsShuttleID());
-  Int_t  retvalPeds = 
-    daqDA_FES_storeFile("peds.csv", 
-                       AliFMDParameters::Instance()->GetPedestalShuttleID());
+  r.Exec(pedDA);
 
-  if(retvalConditions!=0 || retvalPeds!=0)
-    std::cerr << "Pedestal DA failed" << std::endl;
-  
-#ifdef ALI_AMORE
-  try { 
-    amore::da::AmoreDA myAmore(amore::da::AmoreDA::kSender);
+  const char* files[] = { "conditions.csv", 
+                         "peds.csv", 
+                         0 };
+  const char* ids[] = { AliFMDParameters::Instance()->GetConditionsShuttleID(),
+                       AliFMDParameters::Instance()->GetPedestalShuttleID(), 
+                       0 };
+  ret = UploadFiles(files, ids);
 
-    UShort_t det = 0;
-    for (det = 1; det <= 3; det++) 
-      if (pedDA.HasSeenDetector(det)) break;
-    if (det >= 1 && det <= 3) { 
-      TObject* runNo = new TObject;
-      runNo->SetUniqueID(reader->GetRunNumber());
-      myAmore.Send(Form("pedRunNoFMD%d", det), runNo);
-    }
-
-    TIter     next(&pedDA.GetSummaries());
-    TObject*  obj = 0;
-    while ((obj = next())) 
-      myAmore.Send(obj->GetName(), obj);
-  }
-  catch (std::exception& e) {
-    std::cerr << "Failed to make AMORE instance: " << e.what() << std::endl;
-  }
-                              
-#endif
-  if(retvalPeds != 0) return retvalPeds;
-  return retvalConditions;
+  if(ret > 0) std::cerr << "Pedestal DA failed" << std::endl;
 
+  PostSummaries(pedDA, "ped", r.RunNumber());
+  
+  return ret;
 }
+//
+// EOF
+//
+