feature added to store and fetch from DB for online gain calibration
[u/mrichter/AliRoot.git] / PMD / PMDPEDESTALda.cxx
CommitLineData
e43e472f 1/*
2PMD DA for online calibration
3
4contact: basanta@phy.iitb.ac.in
74c36477 5Link:
6Reference Run:/afs/cern.ch/user/b/bnandi/public/pedestaldata/run37820.raw
e43e472f 7Run Type: STANDALONE
722ccc67 8DA Type: LDC
e43e472f 9Number of events needed: 1000
74c36477 10Input Files:
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"
21//#include "daqDA.h"
22
23#include <Riostream.h>
24#include <stdio.h>
25#include <stdlib.h>
26
27//AliRoot
28#include "AliRawReaderDate.h"
29#include "AliPMDCalibPedestal.h"
30
31//ROOT
32#include "TFile.h"
33#include "TH1F.h"
34#include "TBenchmark.h"
35#include "TTree.h"
36#include "TROOT.h"
37#include "TPluginManager.h"
38
e43e472f 39/* Main routine
40 Arguments:
41 1- monitoring data source
42*/
43int main(int argc, char **argv) {
44
45 /* magic line from Rene */
46 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
47 "*",
48 "TStreamerInfo",
49 "RIO",
50 "TStreamerInfo()");
51
52
53 AliPMDCalibPedestal calibped;
54
70202332 55 TTree *ped = NULL;
e43e472f 56
70202332 57 // TH1F::AddDirectory(0);
e43e472f 58
59
60 // decoding the events
61
62 int status;
63
64 if (argc!=2) {
65 printf("Wrong number of arguments\n");
66 return -1;
67 }
68
e43e472f 69
70 /* define data source : this is argument 1 */
71 status=monitorSetDataSource( argv[1] );
72 if (status!=0) {
73 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
74 return -1;
75 }
76
77 /* declare monitoring program */
78 status=monitorDeclareMp( __FILE__ );
79 if (status!=0) {
80 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
81 return -1;
82 }
83
84 /* define wait event timeout - 1s max */
85 monitorSetNowait();
86 monitorSetNoWaitNetworkTimeout(1000);
87
88 /* log start of process */
21dc4b14 89 printf("PMD PED DA - started generating mean and rms of each channel\n");
e43e472f 90
91 /* init some counters */
722ccc67 92
e43e472f 93
94 struct eventHeaderStruct *event;
70202332 95 eventTypeType eventT = 0;
e43e472f 96 Int_t iev=0;
97
98 /* main loop (infinite) */
99 for(;;) {
100
101 /* check shutdown condition */
102 if (daqDA_checkShutdown()) {break;}
103
104 /* get next event (blocking call until timeout) */
105 status=monitorGetEventDynamic((void **)&event);
106 if (status==MON_ERR_EOF) {
107 printf ("End of File detected\n");
108 break; /* end of monitoring file has been reached */
109 }
110
111 if (status!=0) {
112 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
113 break;
114 }
115
116 /* retry if got no event */
117 if (event==NULL) {
118 continue;
119 }
120
121 iev++;
122
123 /* use event - here, just write event id to result file */
124 eventT=event->eventType;
125 switch (event->eventType){
126
127 /* START OF RUN */
128 case START_OF_RUN:
129 break;
130 /* END START OF RUN */
131
132 /* END OF RUN */
133 case END_OF_RUN:
134 break;
135
722ccc67 136 case PHYSICS_EVENT:
21dc4b14 137 //if(iev%100 == 0)printf(" event number = %i \n",iev);
138
e43e472f 139 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
70202332 140 TObjArray *pmdddlcont = new TObjArray();
141 calibped.ProcessEvent(rawReader,pmdddlcont);
e43e472f 142
70202332 143 delete pmdddlcont;
144 pmdddlcont = 0;
e43e472f 145 delete rawReader;
146 rawReader = 0x0;
147 }
148
149 /* free resources */
150 free(event);
151
152 /* exit when last event received, no need to wait for TERM signal */
722ccc67 153
e43e472f 154 }
40a42048 155
21dc4b14 156 printf(" Total number of events processed = %i \n",iev);
157
40a42048 158 ped = new TTree("ped","PMD Pedestal tree");
21dc4b14 159
70202332 160 if (eventT==END_OF_RUN) {
161 printf("EOR event detected\n");
70202332 162 calibped.Analyse(ped);
163 }
e43e472f 164
722ccc67 165 TFile * pedRun = new TFile ("PMD_PED.root","RECREATE");
e43e472f 166 ped->Write();
167 pedRun->Close();
168
70202332 169 delete ped;
170 ped = 0;
40a42048 171
d31b0352 172/* store the pedestal file in database */
173
174 status = daqDA_DB_storeFile("PMD_PED.root","PMD_PED.root");
175
176 if (!status)
177 {
178 printf("--- PEDESTAL root FILE IS IN THE DAQ DATABASE\n");
179 }
180 else
181 {
182 printf("--- Storing the root file into the database failed\n");
183 }
21dc4b14 184
d31b0352 185/* store the pedestal file on FES */
21dc4b14 186
187 status = daqDA_FES_storeFile("PMD_PED.root","pedestal");
188 if (status) {
189 status = -2;
190 }
191
d31b0352 192
193
194
e43e472f 195 return status;
196}