memory leakage solved, writes pedestal ascii file to be loaded to
[u/mrichter/AliRoot.git] / PMD / PMDPEDESTALda.cxx
CommitLineData
e43e472f 1/*
2PMD DA for online calibration
3
4contact: basanta@phy.iitb.ac.in
5Link:/afs/cern.ch/user/a/alicepmd/public/pedestaldata/run31270.raw
6Run Type: STANDALONE
722ccc67 7DA Type: LDC
e43e472f 8Number of events needed: 1000
9Input Files: data raw
10Output Files: pmd_ped.root, to be exported to the DAQ FXS
722ccc67 11Trigger types used: PHYSICS_EVENT
e43e472f 12
13*/
14extern "C" {
15#include <daqDA.h>
16}
17
18#include "event.h"
19#include "monitor.h"
20//#include "daqDA.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
30//ROOT
31#include "TFile.h"
32#include "TH1F.h"
33#include "TBenchmark.h"
34#include "TTree.h"
35#include "TROOT.h"
36#include "TPluginManager.h"
37
38
39
40/* Main routine
41 Arguments:
42 1- monitoring data source
43*/
44int main(int argc, char **argv) {
45
46 /* magic line from Rene */
47 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
48 "*",
49 "TStreamerInfo",
50 "RIO",
51 "TStreamerInfo()");
52
53
54 AliPMDCalibPedestal calibped;
55
70202332 56 TTree *ped = NULL;
e43e472f 57
70202332 58 // TH1F::AddDirectory(0);
e43e472f 59
60
61 // decoding the events
62
63 int status;
64
65 if (argc!=2) {
66 printf("Wrong number of arguments\n");
67 return -1;
68 }
69
e43e472f 70
71 /* define data source : this is argument 1 */
72 status=monitorSetDataSource( argv[1] );
73 if (status!=0) {
74 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
75 return -1;
76 }
77
78 /* declare monitoring program */
79 status=monitorDeclareMp( __FILE__ );
80 if (status!=0) {
81 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
82 return -1;
83 }
84
85 /* define wait event timeout - 1s max */
86 monitorSetNowait();
87 monitorSetNoWaitNetworkTimeout(1000);
88
89 /* log start of process */
90 printf("DA example case2 monitoring program started\n");
91
92 /* init some counters */
722ccc67 93
e43e472f 94
95 struct eventHeaderStruct *event;
70202332 96 eventTypeType eventT = 0;
e43e472f 97 Int_t iev=0;
98
99 /* main loop (infinite) */
100 for(;;) {
101
102 /* check shutdown condition */
103 if (daqDA_checkShutdown()) {break;}
104
105 /* get next event (blocking call until timeout) */
106 status=monitorGetEventDynamic((void **)&event);
107 if (status==MON_ERR_EOF) {
108 printf ("End of File detected\n");
109 break; /* end of monitoring file has been reached */
110 }
111
112 if (status!=0) {
113 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
114 break;
115 }
116
117 /* retry if got no event */
118 if (event==NULL) {
119 continue;
120 }
121
122 iev++;
123
124 /* use event - here, just write event id to result file */
125 eventT=event->eventType;
126 switch (event->eventType){
127
128 /* START OF RUN */
129 case START_OF_RUN:
130 break;
131 /* END START OF RUN */
132
133 /* END OF RUN */
134 case END_OF_RUN:
135 break;
136
722ccc67 137 case PHYSICS_EVENT:
e43e472f 138 printf(" event number = %i \n",iev);
722ccc67 139 //if (iev == 10) break;
e43e472f 140 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
70202332 141 TObjArray *pmdddlcont = new TObjArray();
142 calibped.ProcessEvent(rawReader,pmdddlcont);
e43e472f 143
70202332 144 delete pmdddlcont;
145 pmdddlcont = 0;
e43e472f 146 delete rawReader;
147 rawReader = 0x0;
148 }
149
150 /* free resources */
151 free(event);
152
153 /* exit when last event received, no need to wait for TERM signal */
722ccc67 154
e43e472f 155 }
156
70202332 157 if (eventT==END_OF_RUN) {
158 printf("EOR event detected\n");
159 ped = new TTree("ped","PMD Pedestal tree");
160 calibped.Analyse(ped);
161 }
e43e472f 162
722ccc67 163 TFile * pedRun = new TFile ("PMD_PED.root","RECREATE");
e43e472f 164 ped->Write();
165 pedRun->Close();
166
70202332 167 delete ped;
168 ped = 0;
e43e472f 169 return status;
170}