]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Move all AMORE linked parts from AliMUONPedestal and AliMUONGain
authorlaphecet <laphecet@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 7 Jul 2009 21:42:54 +0000 (21:42 +0000)
committerlaphecet <laphecet@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 7 Jul 2009 21:42:54 +0000 (21:42 +0000)
classes into DAs.
Replacement of the method MakePedStore(TString) by the sequence :
Finalize();
MakeASCIIoutput(ostream& );
MakeControlHistos()

Guillaume B.

MUON/AliMUONGain.cxx
MUON/AliMUONPedestal.cxx
MUON/AliMUONPedestal.h
MUON/MUONTRKGAINda.cxx
MUON/MUONTRKPEDda.cxx

index 9b7b51cec03c35ad3b4fecf09c57a171bcc8322e..5244914c9e474d0a9c3de4f8706ec06390c126fc 100644 (file)
 #include <Riostream.h>
 
 #include <sstream>
-//
-//AMORE
-//
-#ifdef ALI_AMORE
-#include <AmoreDA.h>
-#include "TSystem.h"
-#endif
 
 #define  NFITPARAMS 4
 
@@ -167,16 +160,21 @@ void AliMUONGain::MakePedStoreForGain(TString shuttleFile)
 
 
 
+  Finalize();
+  MakeControlHistos();
   if(fPrintLevel>0)
     {
       // compute and store mean DAC values (like pedestals)
       sprintf(flatFile,"%s.ped",fprefixDA);
       outputFile=flatFile;
       cout << "\n" << fprefixDA << " : Flat file  generated  : " << flatFile << "\n";
-      MakePedStore(outputFile);
+      if (!outputFile.IsNull())  
+      {
+        ofstream out(outputFile.Data());
+       MakeASCIIoutput(out);
+       out.close();
+      }      
     }
-  else
-    MakePedStore("");
 
   TString mode("UPDATE");
 
@@ -354,17 +352,12 @@ void AliMUONGain::MakeGainStore(TString shuttleFile)
       }
 
 
-
-
-  //  Write Ascii file -> Shuttle
+  // file outputs for gain
 
   ofstream pfilew;
   pfilew.open(shuttleFile.Data());
+  // Write Header Data of the .par file
   pfilew << WriteGainHeader(fnInit,nEntries,nbpf2,numrun,injCharge);
-#ifdef ALI_AMORE
-  ostringstream stringout; // String to be sent to AMORE_DB
-  stringout << WriteGainHeader(fnInit,nEntries,nbpf2,numrun,injCharge);
-#endif
 
   // print mean and sigma values in file
   FILE *pfilep = 0;
@@ -670,12 +663,7 @@ void AliMUONGain::MakeGainStore(TString shuttleFile)
            }
 
 
-         tempstring = WriteGainData(busPatchId,manuId,channelId,par[1],par[2],threshold,q);
-         pfilew << tempstring;
-#ifdef ALI_AMORE
-         stringout << tempstring;
-#endif
-
+         pfilew << WriteGainData(busPatchId,manuId,channelId,par[1],par[2],threshold,q);
        }
       nmanu++;
       if(nmanu % 500 == 0)std::cout << " Nb manu = " << nmanu << std::endl;
@@ -729,27 +717,7 @@ void AliMUONGain::MakeGainStore(TString shuttleFile)
        << " mV/fC (capa= " << capaManu << " pF)" 
        <<  "  Prob(chi2)>  = " <<  meanProbChi2 << endl;
   
-  // file outputs for gain
-
   pfilew.close();
-#ifdef ALI_AMORE
-  //
-  //Send objects to the AMORE DB
-  //
-  const char *role=gSystem->Getenv("AMORE_DA_NAME");
-  if ( role ){
-    amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
-//  TObjString peddata(stringout.str().c_str());
-    TObjString gaindata(stringout.str().c_str());
-    Int_t status =0;
-    status = amoreDA.Send("Pedestals",&gaindata);
-    if ( status )
-      cout << "Warning: Failed to write Pedestals in the AMORE database : " << status << endl;
-  } 
-  else {
-    cout << "Warning: environment variable 'AMORE_DA_NAME' not set. Cannot write to the AMORE database" << endl;
-  }
-#endif
 
   if(fPlotLevel>0){tg->Write();histoFile->Close();}
   if(fPrintLevel>1){fclose(pfilep); fclose(pfilen);}
index d9c224b78415e99c479bb3796f1905026c684554..95a1e71b6f491b2ac49c82991dca81008e1cc6e5 100644 (file)
 #include <Riostream.h>
 
 #include <sstream>
-//
-//AMORE
-//
-#ifdef ALI_AMORE
-#include <AmoreDA.h>
-#include "TSystem.h"
-#endif
 
 //-----------------------------------------------------------------------------
 /// \class AliMUONPedestal
@@ -80,6 +73,7 @@ fIndex(-1)
 AliMUONPedestal::~AliMUONPedestal()
 {
 /// Destructor
+  delete fPedestalStore;
 }
 
 //______________________________________________________________________________
@@ -123,112 +117,14 @@ void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, I
 }
 
 //______________________________________________________________________________
-TString AliMUONPedestal::WritePedHeader(void) 
+void AliMUONPedestal::Finalize()
 {
-///
-
-  ostringstream stream;
-  stream<<"//===========================================================================" << endl;
-  stream<<"//                       Pedestal file calculated by MUONTRKda"<<endl;
-  stream<<"//===========================================================================" << endl;
-  stream<<"//       * Run           : " << fRunNumber << endl; 
-  stream<<"//       * Date          : " << fDate->AsString("l") <<endl;
-  stream<<"//       * Statictics    : " << fNEvents << endl;
-  stream<<"//       * # of MANUS    : " << fNManu << endl;
-  stream<<"//       * # of channels : " << fNChannel << endl;
-  if (fErrorBuspatchTable->GetSize())
-  {
-    stream<<"//"<<endl;
-    stream<<"//       * Buspatches with less statistics (due to parity errors)"<<endl;
-    TIterator* iter = fErrorBuspatchTable->MakeIterator();
-    AliMUONErrorCounter* parityerror;
-    while((parityerror = (AliMUONErrorCounter*) iter->Next()))
-    {
-      stream<<"//         bp "<<parityerror->BusPatch()<<" events used "<<fNEvents-parityerror->Events()<<endl;
-    }
-  }  
-  stream<<"//"<<endl;
-  stream<<"//---------------------------------------------------------------------------" << endl;
-  stream<<"//---------------------------------------------------------------------------" << endl;
-  stream<<"//      BP     MANU     CH.      MEAN    SIGMA"<<endl;
-  stream<<"//---------------------------------------------------------------------------" << endl;
-
-  return TString(stream.str().c_str());
-}
-
-//______________________________________________________________________________
-TString AliMUONPedestal::WritePedData(Int_t BP, Int_t Manu, Int_t ch, Double_t pedMean, Double_t pedSigma) 
-{
-///
-
-  ostringstream stream("");
-  stream << "\t" << BP << "\t" << Manu <<"\t"<< ch << "\t"
-         << pedMean <<"\t"<< pedSigma << endl;
-  return TString(stream.str().c_str());
-
-}
-
-//______________________________________________________________________________
-void AliMUONPedestal::MakePedStore(TString shuttleFile_1 = "") 
-{
-
-  /// Store pedestals in ASCII files
   Double_t pedMean;
   Double_t pedSigma;
-  ofstream fileout;
-#ifdef ALI_AMORE
-  ostringstream stringout; // String to be sent to AMORE_DB
-#endif
-  TString tempstring;  
   Int_t busPatchId;
   Int_t manuId;
   Int_t channelId;
 
-// histo
-  TFile*  histoFile = 0;
-  TTree* tree = 0;
-  TH1F* pedMeanHisto = 0;
-  TH1F* pedSigmaHisto = 0;
-
-  if (fIndex<0) // Pedestal run (fIndex=-1)
-  {
-    sprintf(fHistoFileName,"%s.root",fprefixDA);
-    histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals");
-
-    Char_t name[255];
-    Char_t title[255];
-    sprintf(name,"pedmean_allch");
-    sprintf(title,"Pedestal mean all channels");
-    Int_t nx = kADCMax+1;
-    Int_t xmin = 0;
-    Int_t xmax = kADCMax; 
-    pedMeanHisto = new TH1F(name,title,nx,xmin,xmax);
-    pedMeanHisto->SetDirectory(histoFile);
-
-    sprintf(name,"pedsigma_allch");
-    sprintf(title,"Pedestal sigma all channels");
-    nx = 201;
-    xmin = 0;
-    xmax = 200; 
-    pedSigmaHisto = new TH1F(name,title,nx,xmin,xmax);
-    pedSigmaHisto->SetDirectory(histoFile);
-
-    tree = new TTree("t","Pedestal tree");
-    tree->Branch("bp",&busPatchId,"bp/I");
-    tree->Branch("manu",&manuId,",manu/I");
-    tree->Branch("channel",&channelId,",channel/I");
-    tree->Branch("pedMean",&pedMean,",pedMean/D");
-    tree->Branch("pedSigma",&pedSigma,",pedSigma/D");
-  }
-
-  if (!shuttleFile_1.IsNull()) {
-    fileout.open(shuttleFile_1.Data());
-    tempstring = WritePedHeader();
-    fileout << tempstring;
-#ifdef ALI_AMORE
-    stringout << tempstring;
-#endif
-  }
   // print in logfile
   if (fErrorBuspatchTable->GetSize())
   {
@@ -244,7 +140,6 @@ void AliMUONPedestal::MakePedStore(TString shuttleFile_1 = "")
 
   }
 
-
 // iterator over pedestal
   TIter next(fPedestalStore ->CreateIterator());
   AliMUONVCalibParam* ped;
@@ -280,74 +175,152 @@ void AliMUONPedestal::MakePedStore(TString shuttleFile_1 = "")
     manuCounter = (AliMUONErrorCounter*)fManuBuspatchTable->FindObject(bpmanuname);
     occupancy = manuCounter->Events()/64/eventCounter;
     if(occupancy>1)
-      {
+    {
        cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in  BP = " << busPatchId << " occupancy (>1) = " << occupancy << endl;
        (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in  BP = " << busPatchId << " occupancy (>1) = " << occupancy <<endl;
-     }
+    }
 
-    for (channelId = 0; channelId < ped->Size() ; ++channelId) {
+    for (channelId = 0; channelId < ped->Size() ; ++channelId) 
+    {
       pedMean  = ped->ValueAsDouble(channelId, 0);
 
       if (pedMean > 0) // connected channels
-       {
+      {
          ped->SetValueAsDouble(channelId, 0, pedMean/(Double_t)eventCounter);
          pedMean  = ped->ValueAsDouble(channelId, 0);
          pedSigma = ped->ValueAsDouble(channelId, 1);
          ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)eventCounter - pedMean*pedMean)));
          if(manuId == 0 || occupancy>1)
-           {
+         {
              ped->SetValueAsDouble(channelId, 0, kADCMax);
              ped->SetValueAsDouble(channelId, 1, kADCMax);
-           }
-        }
+         }
+      }
       else
-       {
+      {
          ped->SetValueAsDouble(channelId, 0, kADCMax);
          ped->SetValueAsDouble(channelId, 1, kADCMax);
-       }
+      }
+    }
+  }
+}
 
-      pedMean  = ped->ValueAsDouble(channelId, 0);
-      pedSigma = ped->ValueAsDouble(channelId, 1);
+//______________________________________________________________________________
+void AliMUONPedestal::MakeASCIIoutput(ostream& out) const
+{
+/// put pedestal store in the output stream
+
+  out<<"//===========================================================================" << endl;
+  out<<"//                       Pedestal file calculated by MUONTRKda"<<endl;
+  out<<"//===========================================================================" << endl;
+  out<<"//       * Run           : " << fRunNumber << endl; 
+  out<<"//       * Date          : " << fDate->AsString("l") <<endl;
+  out<<"//       * Statictics    : " << fNEvents << endl;
+  out<<"//       * # of MANUS    : " << fNManu << endl;
+  out<<"//       * # of channels : " << fNChannel << endl;
+  if (fErrorBuspatchTable->GetSize())
+  {
+    out<<"//"<<endl;
+    out<<"//       * Buspatches with less statistics (due to parity errors)"<<endl;
+    TIterator* iter = fErrorBuspatchTable->MakeIterator();
+    AliMUONErrorCounter* parityerror;
+    while((parityerror = (AliMUONErrorCounter*) iter->Next()))
+    {
+      out<<"//         bp "<<parityerror->BusPatch()<<" events used "<<fNEvents-parityerror->Events()<<endl;
+    }
+  }  
+  out<<"//"<<endl;
+  out<<"//---------------------------------------------------------------------------" << endl;
+  out<<"//---------------------------------------------------------------------------" << endl;
+  out<<"//      BP     MANU     CH.      MEAN    SIGMA"<<endl;
+  out<<"//---------------------------------------------------------------------------" << endl;
 
-        if (!shuttleFile_1.IsNull()) {
-          tempstring = WritePedData(busPatchId,manuId,channelId,pedMean,pedSigma);
-          fileout << tempstring;
-#ifdef ALI_AMORE
-          stringout << tempstring;
-#endif
-        }
-        if(fIndex<0) // Pedestal Run
-        {
-          pedMeanHisto->Fill(pedMean);
-          pedSigmaHisto->Fill(pedSigma);
-          tree->Fill();
-        }
+  // iterator over pedestal
+  TIter next(fPedestalStore ->CreateIterator());
+  AliMUONVCalibParam* ped;
+  
+  while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
+  {
+    Int_t busPatchId = ped->ID0();
+    Int_t manuId = ped->ID1();
+    
+    for ( Int_t channelId = 0; channelId < ped->Size(); ++channelId ) 
+    {
+      Double_t pedMean  = ped->ValueAsDouble(channelId, 0);
+      Double_t pedSigma = ped->ValueAsDouble(channelId, 1);
+        
+      out << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t" << pedMean <<"\t"<< pedSigma << endl;        
     }
   }
+}
+
+//______________________________________________________________________________
+void AliMUONPedestal::MakeControlHistos()
+{
 
-// file outputs
-  if (!shuttleFile_1.IsNull())  fileout.close();
-
-// Outputs to root file and AMORE DB
-#ifdef ALI_AMORE
-  //
-  //Send objects to the AMORE DB
-  //
-    amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
-    TObjString peddata(stringout.str().c_str());
-    Int_t status =0;
-    status = amoreDA.Send("Pedestals",&peddata);
-    if ( status )
-      cout << "Warning: Failed to write Pedestals in the AMORE database : " << status << endl;
-    else 
-      cout << "amoreDA.Send(Pedestals) ok" << endl;  
-#else
-  cout << "Warning: MCH DA not compiled with AMORE support" << endl;
-#endif
-  if(fIndex<0) // Pedestal Run
-  { 
-    histoFile->Write();  
-    histoFile->Close(); 
-    delete fPedestalStore ;
+  if (fIndex>=0) return; // Pedestal run (fIndex=-1)
+
+  Double_t pedMean;
+  Double_t pedSigma;
+  Int_t busPatchId;
+  Int_t manuId;
+  Int_t channelId;
+
+// histo
+  TFile*  histoFile = 0;
+  TTree* tree = 0;
+  TH1F* pedMeanHisto = 0;
+  TH1F* pedSigmaHisto = 0;
+    
+  sprintf(fHistoFileName,"%s.root",fprefixDA);
+  histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals");
+
+  Char_t name[255];
+  Char_t title[255];
+  sprintf(name,"pedmean_allch");
+  sprintf(title,"Pedestal mean all channels");
+  Int_t nx = kADCMax+1;
+  Int_t xmin = 0;
+  Int_t xmax = kADCMax; 
+  pedMeanHisto = new TH1F(name,title,nx,xmin,xmax);
+  pedMeanHisto->SetDirectory(histoFile);
+
+  sprintf(name,"pedsigma_allch");
+  sprintf(title,"Pedestal sigma all channels");
+  nx = 201;
+  xmin = 0;
+  xmax = 200; 
+  pedSigmaHisto = new TH1F(name,title,nx,xmin,xmax);
+  pedSigmaHisto->SetDirectory(histoFile);
+
+  tree = new TTree("t","Pedestal tree");
+  tree->Branch("bp",&busPatchId,"bp/I");
+  tree->Branch("manu",&manuId,",manu/I");
+  tree->Branch("channel",&channelId,",channel/I");
+  tree->Branch("pedMean",&pedMean,",pedMean/D");
+  tree->Branch("pedSigma",&pedSigma,",pedSigma/D");
+
+  // iterator over pedestal
+  TIter next(fPedestalStore ->CreateIterator());
+  AliMUONVCalibParam* ped;
+  
+  while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
+  {
+    busPatchId = ped->ID0();
+    manuId = ped->ID1();
+    
+    for ( channelId = 0; channelId < ped->Size(); ++channelId ) 
+    {
+      pedMean  = ped->ValueAsDouble(channelId, 0);
+      pedSigma = ped->ValueAsDouble(channelId, 1);
+          
+      pedMeanHisto->Fill(pedMean);
+      pedSigmaHisto->Fill(pedSigma);
+      tree->Fill();  
+    }
   }
+    
+  histoFile->Write();  
+  histoFile->Close(); 
+
 }
index ada5625bdd776646938272068fc62f9158b4556b..1ef1e5842670fce2a2fe56a6d3affbdd55fc05a0 100644 (file)
@@ -48,14 +48,17 @@ class AliMUONPedestal : public TObject
     /// return the name of DAPedestal .root file
     Char_t* GetHistoFileName() {return fHistoFileName;}
     void MakePed(Int_t bp,Int_t manu,Int_t ch,Int_t charge);
-    void MakePedStore(TString flatfile);
-    TString WritePedData(Int_t bp, Int_t manu, Int_t ch, Double_t mean, Double_t sigma);
-    TString WritePedHeader();
 
     /// set specific  DA prefixname
     void SetprefixDA(char* folder) {sprintf(fprefixDA,"%s",folder);}
     /// set the index of calibration runs
     void SetAliIndex(Int_t ind) {fIndex = ind;}
+    /// Compute the pedestal data (mean, sigma)
+    void Finalize();
+    /// Create String to be put into file or AMORE DB
+    void MakeASCIIoutput(ostream& out) const;
+    /// Fill Histograms
+    void MakeControlHistos();
 
   protected:
     Int_t fN; ///<
index c1c6f5c38ef8b68ee6f000cbaf76177c3daa1410..be6987e614e0a4097d3fa6f37471f1bae260cc8f 100644 (file)
@@ -261,6 +261,24 @@ int main(Int_t argc, Char_t **argv)
      muonGain->SetAliInit(nInit); // fnInit
      muonGain->SetAliNbpf1(nbpf1); // fnbpf1
      muonGain->MakeGainStore(shuttleFile);
+#ifdef ALI_AMORE
+     std::ifstream in(shuttleFile.Data());
+     ostringstream stringout;
+     char line[1024];
+     while ( in.getline(line,1024) )
+       stringout << line << "\n";  
+     in.close();
+
+     amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
+     TObjString gaindata(stringout.str().c_str());
+     status = amoreDA.Send("Gains",&gaindata);
+     if ( status )
+       cout << "Warning: Failed to write Pedestals in the AMORE database : " << status << endl;
+     else 
+       cout << "amoreDA.Send(Gains) ok" << endl;  
+#else
+     cout << "Warning: MCH DA not compiled with AMORE support" << endl;
+#endif
    }
 
 
@@ -480,6 +498,7 @@ int main(Int_t argc, Char_t **argv)
      muonGain->SetAliRunNumber(runNumber);
      muonGain->SetAliNChannel(nChannel);
      muonGain->MakePedStoreForGain(shuttleFile);
+     
 
      // writing some counters
      cout << endl;
@@ -507,6 +526,24 @@ int main(Int_t argc, Char_t **argv)
          muonGain->SetAliEntries(nEntries); // fnEntries
          muonGain->SetAliNbpf1(nbpf1); // fnbpf1
          muonGain->MakeGainStore(shuttleFile);
+#ifdef ALI_AMORE  
+          std::ifstream in(shuttleFile.Data());
+          ostringstream stringout;
+          char line[1024];
+          while ( in.getline(line,1024) )
+           stringout << line << "\n";  
+          in.close();
+         
+          amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
+          TObjString gaindata(stringout.str().c_str());
+          status = amoreDA.Send("Gains",&gaindata);
+          if ( status )
+            cout << "Warning: Failed to write Pedestals in the AMORE database : " << status << endl;
+          else 
+            cout << "amoreDA.Send(Gains) ok" << endl;  
+#else
+          cout << "Warning: MCH DA not compiled with AMORE support" << endl;
+#endif
        }
 
 // ouput files
index 5646e0ca5d7f534781e696325ba1a9aac32d30de..9dafddfa0e1d835388f863143cf8282aca022fb2 100644 (file)
@@ -82,6 +82,12 @@ extern "C" {
 #include "TObjString.h"
 #include "THashTable.h"
 #include <THashList.h>
+//
+//AMORE
+//
+#ifdef ALI_AMORE
+#include <AmoreDA.h>
+#endif
 
 #include "AliMUONPedestal.h"
 #include "AliMUONErrorCounter.h"
@@ -398,7 +404,34 @@ int main(Int_t argc, Char_t **argv)
   muonPedestal->SetAliNEvents(nEvents);
   muonPedestal->SetAliRunNumber(runNumber);
   muonPedestal->SetAliNChannel(nChannel);
-  muonPedestal->MakePedStore(shuttleFile);
+  
+  muonPedestal->Finalize();  
+  muonPedestal->MakeControlHistos();  
+  if (!shuttleFile.IsNull())  
+  {
+    ofstream out(shuttleFile.Data());  
+    muonPedestal->MakeASCIIoutput(out);
+    out.close();
+#ifdef ALI_AMORE
+  //
+  //Send objects to the AMORE DB
+  //
+    ostringstream stringout;
+    muonPedestal->MakeASCIIoutput(stringout);
+    
+    amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
+    TObjString peddata(stringout.str().c_str());
+    Int_t status =0;
+    status = amoreDA.Send("Pedestals",&peddata);
+    if ( status )
+      cout << "Warning: Failed to write Pedestals in the AMORE database : " << status << endl;
+    else 
+      cout << "amoreDA.Send(Pedestals) ok" << endl;  
+#else
+    cout << "Warning: MCH DA not compiled with AMORE support" << endl;
+#endif
+    
+  }
 
   // writing some counters
   cout << endl;