]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/PMDPEDESTALda.cxx
root file on FES
[u/mrichter/AliRoot.git] / PMD / PMDPEDESTALda.cxx
1 /*
2 PMD DA for online calibration
3
4 contact: basanta@phy.iitb.ac.in
5 Link:
6 Reference Run:/afs/cern.ch/user/b/bnandi/public/pedestaldata/run37820.raw
7 Run Type: STANDALONE
8 DA Type: LDC
9 Number of events needed: 1000
10 Input Files: 
11 Output Files: pmd_ped.root, to be exported to the DAQ FXS, pedestal230*.ped
12 Trigger types used: PHYSICS_EVENT
13
14 */
15 extern "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
39
40
41 /* Main routine
42       Arguments: 
43       1- monitoring data source
44 */
45 int 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;
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     /* main loop (infinite) */
101     for(;;) {
102         
103         /* check shutdown condition */
104         if (daqDA_checkShutdown()) {break;}
105         
106         /* get next event (blocking call until timeout) */
107         status=monitorGetEventDynamic((void **)&event);
108         if (status==MON_ERR_EOF) {
109             printf ("End of File detected\n");
110             break; /* end of monitoring file has been reached */
111         }
112         
113         if (status!=0) {
114             printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
115             break;
116         }
117         
118         /* retry if got no event */
119         if (event==NULL) {
120             continue;
121         }
122         
123         iev++; 
124         
125         /* use event - here, just write event id to result file */
126         eventT=event->eventType;
127         switch (event->eventType){
128             
129             /* START OF RUN */
130             case START_OF_RUN:
131                 break;
132                 /* END START OF RUN */
133                 
134                 /* END OF RUN */
135             case END_OF_RUN:
136                 break;
137                 
138             case PHYSICS_EVENT:
139               //if(iev%100 == 0)printf(" event number = %i \n",iev);
140
141                 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
142                 TObjArray *pmdddlcont = new TObjArray();
143                 calibped.ProcessEvent(rawReader,pmdddlcont);
144                 
145                 delete pmdddlcont;
146                 pmdddlcont = 0;
147                 delete rawReader;
148                 rawReader = 0x0;
149         }
150         
151         /* free resources */
152         free(event);
153         
154         /* exit when last event received, no need to wait for TERM signal */
155
156     }
157
158     printf(" Total number of events processed = %i \n",iev);
159
160     ped = new TTree("ped","PMD Pedestal tree");
161     
162     if (eventT==END_OF_RUN) {
163       printf("EOR event detected\n");
164       calibped.Analyse(ped);
165     }
166     
167     TFile * pedRun = new TFile ("PMD_PED.root","RECREATE"); 
168     ped->Write();
169     pedRun->Close();
170
171     delete ped;
172     ped = 0;
173
174
175 /* store the result file on FES */
176  
177     status = daqDA_FES_storeFile("PMD_PED.root","pedestal");
178     if (status) {
179         status = -2;
180     }
181
182     return status;
183 }