bug fix
[u/mrichter/AliRoot.git] / FMD / FMDGainda.cxx
1 /*
2
3   FMD DA for online calibration of conditions
4
5   Contact:                 canute@nbi.dk
6   Link:                    fmd.nbi.dk/fmd/offline
7   Run Type:                GAIN
8   DA Type:                 LDC
9   Number of events needed: usually 102400
10   Input Files:             raw data 
11   Output Files:            gains.csv
12   Trigger types used:      GAIN
13 */
14 #include <TSystem.h>
15 #include <TString.h>
16 #include <AliFMDParameters.h>
17 #include <AliRawReader.h>
18 #include <TStopwatch.h>
19 #include <AliFMDGainDA.h>
20 #include <AliRawReaderDate.h>
21 #include <AliRawReaderRoot.h>
22 #include <AliLog.h>
23 #include "daqDA.h"
24 #include "TROOT.h"
25 #include "TPluginManager.h"
26 #ifdef ALI_AMORE
27 # include <AmoreDA.h>
28 # include <TH2.h>
29 #endif
30
31
32
33 int main(int argc, char **argv) 
34 {
35
36   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
37                                         "*",
38                                         "TStreamerInfo",
39                                         "RIO",
40                                         "TStreamerInfo()");
41   gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", "Minuit", 
42                                         "TMinuitMinimizer",
43                                         "Minuit", 
44                                         "TMinuitMinimizer(const char *)");
45   gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
46                                         "GSLMultiMin", 
47                                         "ROOT::Math::GSLMinimizer",
48                                         "MathMore", 
49                                         "GSLMinimizer(const char *)");
50   gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
51                                         "GSLMultiFit", 
52                                         "ROOT::Math::GSLNLSMinimizer",
53                                         "MathMore", "GSLNLSMinimizer(int)");
54   gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
55                                         "GSLSimAn", 
56                                         "ROOT::Math::GSLSimAnMinimizer",
57                                         "MathMore", 
58                                         "GSLSimAnMinimizer(int)");
59   gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
60                                         "Linear", 
61                                         "TLinearMinimizer",
62                                         "Minuit", 
63                                         "TLinearMinimizer(const char *)");
64   gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", 
65                                         "Fumili", 
66                                         "TFumiliMinimizer",
67                                         "Fumili", 
68                                         "TFumiliMinimizer(int)");
69   
70   
71   Bool_t diagnostics = kFALSE;
72   Char_t* fileName = argv[1];
73   TString secondArgument(argv[2]);
74   
75   for (int i = 2; i < argc; i++) { 
76     TString arg(argv[i]);
77     if      (arg.Contains("--diagnostics=true")) diagnostics = kTRUE;
78     else if (arg.Contains("--help")) { 
79       std::cout << "Usage: " << argv[0] << " FILENAME [OPTIONS]\n\n"
80                 << "Options:\n" 
81                 << "    --diagnostics=BOOL Make diagnostics ROOT file\n"
82                 << std::endl;
83       return 0;
84     }
85     else { 
86       std::cerr << "Unknown option: " << arg << "\n"
87                 << "Try '" << argv[0] << " --help" << std::endl;
88       return 1;
89     }
90   }
91   Bool_t old = kTRUE;
92     
93   AliFMDParameters::Instance()->Init(kFALSE,0);
94
95   //This will only work for FDR 1 data. When newer data becomes available the ! must be removed!
96   AliFMDParameters::Instance()->UseCompleteHeader(old);
97   
98   AliLog::EnableDebug(kFALSE);
99   
100   AliRawReader *reader = 0;
101   TString fileNam(fileName);
102   if (fileNam.EndsWith(".root")) 
103     reader = new AliRawReaderRoot(fileName);
104   else reader = new AliRawReaderDate(fileName);
105   if (!reader) { 
106     std::cerr << "Don't know how to make reader for " << fileNam 
107               << std::endl;
108     return -2;
109   }
110
111   
112   TStopwatch timer;
113   timer.Start();
114   AliFMDGainDA gainDA;
115   gainDA.SetSaveDiagnostics(diagnostics);
116 #ifdef ALI_AMORE
117   gainDA.SetMakeSummaries(kTRUE);
118 #endif
119   gainDA.Run(reader);
120   
121   timer.Stop();
122   timer.Print();
123   
124   Int_t  retvalConditions = 
125     daqDA_FES_storeFile("conditions.csv", 
126                         AliFMDParameters::Instance()->GetConditionsShuttleID());
127   Int_t  retvalGain = 
128     daqDA_FES_storeFile("gains.csv", 
129                         AliFMDParameters::Instance()->GetGainShuttleID());
130
131   if(retvalConditions!=0 || retvalGain!=0)
132     std::cerr << "Pedestal DA failed" << std::endl;
133   
134 #ifdef ALI_AMORE
135   try { 
136     amore::da::AmoreDA myAmore(amore::da::AmoreDA::kSender);
137
138     UShort_t det = 0;
139     for (det = 1; det <= 3; det++) 
140       if (gainDA.HasSeenDetector(det)) break;
141     if (det >= 1 && det <= 3) { 
142       TObject* runNo = new TObject;
143       runNo->SetUniqueID(reader->GetRunNumber());
144       myAmore.Send(Form("gainRunNoFMD%d", det), runNo);
145     }
146                    
147     TIter     next(&gainDA.GetSummaries());
148     TObject*  obj = 0;
149     while ((obj = next())) 
150       myAmore.Send(obj->GetName(), obj);
151     
152   }
153   catch (std::exception& e) {
154     std::cerr << "Failed to make AMORE instance: " << e.what() << std::endl;
155   }
156                                
157 #endif
158
159   if(retvalGain != 0) return retvalGain;
160   return retvalConditions;
161
162 }
163 //
164 // EOF
165 //
166