]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - PMD/PMDPEDESTALda.cxx
Bug fix for HMPID bits in readout list.
[u/mrichter/AliRoot.git] / PMD / PMDPEDESTALda.cxx
... / ...
CommitLineData
1/*
2PMD DA for online calibration
3
4contact: basanta@phy.iitb.ac.in
5Link: https://twiki.cern.ch/twiki/bin/view/ALICE/DA
6Reference Run:/afs/cern.ch/user/s/sjena/public/run83496.raw
7Run Type: PEDESTAL
8DA Type: LDC
9Number of events needed: 1000
10Input Files: PMD/Calib/Mapping/Run0_999999999_v0_s0.root
11Output Files: pmd_ped.root, to be exported to the DAQ FXS, pedestal230*.ped
12Trigger types used: PHYSICS_EVENT
13
14*/
15extern "C" {
16#include <daqDA.h>
17}
18
19#include "event.h"
20#include "monitor.h"
21
22#include <Riostream.h>
23#include <stdio.h>
24#include <stdlib.h>
25
26//AliRoot
27#include "AliRawReaderDate.h"
28#include "AliPMDCalibPedestal.h"
29#include "AliLog.h"
30#include "AliCDBManager.h"
31
32//ROOT
33#include "TFile.h"
34#include "TH1F.h"
35#include "TBenchmark.h"
36#include "TTree.h"
37#include "TROOT.h"
38#include "TPluginManager.h"
39#include "TSystem.h"
40
41/* Main routine
42 Arguments:
43 1- monitoring data source
44*/
45int main(int argc, char **argv) {
46
47 /* magic line from Rene */
48 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
49 "*",
50 "TStreamerInfo",
51 "RIO",
52 "TStreamerInfo()");
53
54
55 AliPMDCalibPedestal *calibped = new AliPMDCalibPedestal();
56
57 TTree *ped = NULL;
58
59 // TH1F::AddDirectory(0);
60
61
62 // decoding the events
63
64 int status;
65
66 if (argc!=2) {
67 printf("Wrong number of arguments\n");
68 return -1;
69 }
70
71
72 /* define data source : this is argument 1 */
73 status=monitorSetDataSource( argv[1] );
74 if (status!=0) {
75 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
76 return -1;
77 }
78
79 /* declare monitoring program */
80 status=monitorDeclareMp( __FILE__ );
81 if (status!=0) {
82 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
83 return -1;
84 }
85
86 /* define wait event timeout - 1s max */
87 monitorSetNowait();
88 monitorSetNoWaitNetworkTimeout(1000);
89
90 /* log start of process */
91 printf("PMD PED DA - started generating mean and rms of each channel\n");
92
93 /* init some counters */
94
95
96 struct eventHeaderStruct *event;
97 eventTypeType eventT = 0;
98 Int_t iev=0;
99
100 // Get run number
101
102 int runNr = 0;
103 if (getenv("DATE_RUN_NUMBER")==0) {
104 printf("DATE_RUN_NUMBER not properly set.\n");
105 //return -1;
106 printf("Run Number is set to Zero \n");
107 }
108 else
109 {
110 runNr = atoi(getenv("DATE_RUN_NUMBER"));
111 }
112
113 if (gSystem->AccessPathName("localOCDB/PMD/Calib/Mapping",kFileExists))
114 {
115 if (gSystem->mkdir("localOCDB/PMD/Calib/Mapping",kTRUE) != 0)
116 {
117 printf("Failed to create directory: localOCDB/PMD/Calib/Mapping");
118 return -1;
119 }
120 }
121 status = daqDA_DB_getFile("PMD/Calib/Mapping/Run0_999999999_v0_s0.root","localOCDB/PMD/Calib/Mapping/Run0_999999999_v0_s0.root");
122 if (status)
123 {
124 printf("Failed to get PMD-Mapping file (PMD/Calib/Mapping/Run0_999999999_v0_s0.root) from DAQdetDB, status=%d\n", status);
125 return -1;
126 }
127
128 // Global initializations
129 AliLog::SetGlobalLogLevel(AliLog::kError);
130 AliCDBManager *man = AliCDBManager::Instance();
131 man->SetDefaultStorage("local://localOCDB");
132 man->SetRun(runNr);
133
134
135 /* main loop (infinite) */
136 for(;;) {
137
138 /* check shutdown condition */
139 if (daqDA_checkShutdown()) {break;}
140
141 /* get next event (blocking call until timeout) */
142 status=monitorGetEventDynamic((void **)&event);
143 if (status==MON_ERR_EOF) {
144 printf ("End of File detected\n");
145 break; /* end of monitoring file has been reached */
146 }
147
148 if (status!=0) {
149 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
150 break;
151 }
152
153 /* retry if got no event */
154 if (event==NULL) {
155 continue;
156 }
157
158 iev++;
159
160 /* use event - here, just write event id to result file */
161 eventT=event->eventType;
162 switch (event->eventType){
163
164 /* START OF RUN */
165 case START_OF_RUN:
166 break;
167 /* END START OF RUN */
168
169 /* END OF RUN */
170 case END_OF_RUN:
171 break;
172
173 case PHYSICS_EVENT:
174
175 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
176 TObjArray *pmdddlcont = new TObjArray();
177 calibped->ProcessEvent(rawReader,pmdddlcont);
178
179 delete pmdddlcont;
180 pmdddlcont = 0;
181 delete rawReader;
182 rawReader = 0x0;
183 }
184
185 /* free resources */
186 free(event);
187
188 /* exit when last event received, no need to wait for TERM signal */
189
190 // either END_OF_RUN or 1000 events
191
192 if (iev == 1000)
193 {
194 printf("-- 1000 pedestal events processed : terminating --\n");
195 printf("-- eventT is set to END_OF_RUN --\n");
196 eventT = END_OF_RUN;
197 break;
198 }
199
200 }
201
202 printf(" Total number of events processed = %i \n",iev);
203
204 ped = new TTree("ped","PMD Pedestal tree");
205
206 if (eventT==END_OF_RUN) {
207 printf("EOR event detected\n");
208 calibped->Analyse(ped);
209 }
210
211 TFile * pedRun = new TFile ("PMD_PED.root","RECREATE");
212 ped->Write();
213 pedRun->Close();
214
215 delete ped;
216 ped = 0;
217
218 delete calibped;
219
220/* store the pedestal file in database */
221
222 status = daqDA_DB_storeFile("PMD_PED.root","PMD_PED.root");
223
224 if (!status)
225 {
226 printf("--- PEDESTAL root FILE IS IN THE DAQ DATABASE\n");
227 }
228 else
229 {
230 printf("--- Storing the root file into the database failed\n");
231 }
232
233/* store the pedestal file on FES */
234
235 status = daqDA_FES_storeFile("PMD_PED.root","PMD_PED.root");
236 if (status) {
237 status = -2;
238 }
239
240
241
242
243 return status;
244}