]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/PMDPEDESTALda.cxx
mapping files for this years commissioning of 200 chains
[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: PEDESTAL
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 /* Main routine
40       Arguments: 
41       1- monitoring data source
42 */
43 int 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
55     TTree *ped = NULL;
56
57     //    TH1F::AddDirectory(0);
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
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 */
89     printf("PMD PED DA - started generating mean and rms of each channel\n");  
90     
91     /* init some counters */
92
93
94     struct eventHeaderStruct *event;
95     eventTypeType eventT = 0;
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                 
136             case PHYSICS_EVENT:
137
138                 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
139                 TObjArray *pmdddlcont = new TObjArray();
140                 calibped.ProcessEvent(rawReader,pmdddlcont);
141                 
142                 delete pmdddlcont;
143                 pmdddlcont = 0;
144                 delete rawReader;
145                 rawReader = 0x0;
146         }
147         
148         /* free resources */
149         free(event);
150         
151         /* exit when last event received, no need to wait for TERM signal */
152
153         // either END_OF_RUN or 1000 events
154
155         if (iev == 1000)
156           {
157             printf("-- 1000 pedestal events processed : terminating --\n");
158             printf("-- eventT is set to END_OF_RUN --\n");
159             eventT = END_OF_RUN;
160             break;
161           }
162
163     }
164
165     printf(" Total number of events processed = %i \n",iev);
166
167     ped = new TTree("ped","PMD Pedestal tree");
168     
169     if (eventT==END_OF_RUN) {
170       printf("EOR event detected\n");
171       calibped.Analyse(ped);
172     }
173     
174     TFile * pedRun = new TFile ("PMD_PED.root","RECREATE"); 
175     ped->Write();
176     pedRun->Close();
177
178     delete ped;
179     ped = 0;
180
181 /* store the pedestal file in database */
182
183     status = daqDA_DB_storeFile("PMD_PED.root","PMD_PED.root");
184
185     if (!status)
186       {
187         printf("--- PEDESTAL root FILE IS IN THE DAQ DATABASE\n");
188       }
189     else
190       {
191         printf("--- Storing the root file into the database failed\n");
192       }
193
194 /* store the pedestal file on FES */
195  
196     status = daqDA_FES_storeFile("PMD_PED.root","PMD_PED.root");
197     if (status) {
198         status = -2;
199     }
200
201
202
203
204     return status;
205 }