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