macro title as filename
[u/mrichter/AliRoot.git] / PMD / PMDPEDESTALda.cxx
CommitLineData
e43e472f 1/*
2PMD DA for online calibration
3
8a09f5aa 4contact: basanta@iitb.ac.in, Satyajit.Jena@cern.ch
f30b7e6c 5Link: https://twiki.cern.ch/twiki/bin/view/ALICE/DA
ee562d68 6Reference Run:/afs/cern.ch/user/s/sjena/public/run83496.raw
6b1a10fc 7Run Type: PEDESTAL
722ccc67 8DA Type: LDC
e43e472f 9Number of events needed: 1000
6159ad12 10Input Files: PMD/Calib/Mapping/Run0_999999999_v0_s0.root
74c36477 11Output Files: pmd_ped.root, to be exported to the DAQ FXS, pedestal230*.ped
722ccc67 12Trigger types used: PHYSICS_EVENT
e43e472f 13
14*/
15extern "C" {
16#include <daqDA.h>
17}
18
19#include "event.h"
20#include "monitor.h"
e43e472f 21
22#include <Riostream.h>
23#include <stdio.h>
24#include <stdlib.h>
25
26//AliRoot
27#include "AliRawReaderDate.h"
28#include "AliPMDCalibPedestal.h"
ee562d68 29#include "AliLog.h"
30#include "AliCDBManager.h"
e43e472f 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"
ee562d68 39#include "TSystem.h"
e43e472f 40
e43e472f 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
b9007181 55 AliPMDCalibPedestal *calibped = new AliPMDCalibPedestal();
e43e472f 56
70202332 57 TTree *ped = NULL;
e43e472f 58
70202332 59 // TH1F::AddDirectory(0);
e43e472f 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
e43e472f 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 */
21dc4b14 91 printf("PMD PED DA - started generating mean and rms of each channel\n");
e43e472f 92
93 /* init some counters */
722ccc67 94
e43e472f 95
96 struct eventHeaderStruct *event;
70202332 97 eventTypeType eventT = 0;
e43e472f 98 Int_t iev=0;
ee562d68 99
100 // Get run number
0073c15c 101
28816992 102 int runNr = 0;
ee562d68 103 if (getenv("DATE_RUN_NUMBER")==0) {
104 printf("DATE_RUN_NUMBER not properly set.\n");
28816992 105 //return -1;
106 printf("Run Number is set to Zero \n");
ee562d68 107 }
28816992 108 else
109 {
110 runNr = atoi(getenv("DATE_RUN_NUMBER"));
111 }
ee562d68 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 }
6159ad12 121 status = daqDA_DB_getFile("PMD/Calib/Mapping/Run0_999999999_v0_s0.root","localOCDB/PMD/Calib/Mapping/Run0_999999999_v0_s0.root");
ee562d68 122 if (status)
123 {
6159ad12 124 printf("Failed to get PMD-Mapping file (PMD/Calib/Mapping/Run0_999999999_v0_s0.root) from DAQdetDB, status=%d\n", status);
ee562d68 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
e43e472f 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
722ccc67 173 case PHYSICS_EVENT:
21dc4b14 174
e43e472f 175 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
70202332 176 TObjArray *pmdddlcont = new TObjArray();
b9007181 177 calibped->ProcessEvent(rawReader,pmdddlcont);
e43e472f 178
70202332 179 delete pmdddlcont;
180 pmdddlcont = 0;
e43e472f 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 */
722ccc67 189
5f487e91 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
e43e472f 200 }
40a42048 201
21dc4b14 202 printf(" Total number of events processed = %i \n",iev);
203
40a42048 204 ped = new TTree("ped","PMD Pedestal tree");
21dc4b14 205
70202332 206 if (eventT==END_OF_RUN) {
207 printf("EOR event detected\n");
b9007181 208 calibped->Analyse(ped);
70202332 209 }
e43e472f 210
722ccc67 211 TFile * pedRun = new TFile ("PMD_PED.root","RECREATE");
e43e472f 212 ped->Write();
213 pedRun->Close();
214
70202332 215 delete ped;
216 ped = 0;
40a42048 217
b9007181 218 delete calibped;
219
d31b0352 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 }
21dc4b14 232
d31b0352 233/* store the pedestal file on FES */
21dc4b14 234
a5f36c63 235 status = daqDA_FES_storeFile("PMD_PED.root","PMD_PED.root");
21dc4b14 236 if (status) {
237 status = -2;
238 }
239
d31b0352 240
241
242
e43e472f 243 return status;
244}