]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/PHOSBCMda.cxx
Updated histogram limits (PHOS energy)
[u/mrichter/AliRoot.git] / PHOS / PHOSBCMda.cxx
1 /*
2 contact: Boris.Polishchuk@cern.ch
3 link: http://aliceinfo.cern.ch/static/phpBB3/viewtopic.php?f=4&t=17
4 reference run: /castor/cern.ch/alice/phos/2007/10/02/13/07000008232001.10.root
5 run type: STANDALONE
6 DA type: MON
7 number of events needed: 1000
8 input files: RCU0.data  RCU1.data  RCU2.data  RCU3.data
9 Output files: PHOS_Module2_BCM.root
10 Trigger types used: CALIBRATION_EVENT or PHYSICS
11 */
12
13
14 #include "event.h"
15 #include "monitor.h"
16 extern "C" {
17 #include "daqDA.h"
18 }
19
20 #include <stdio.h>
21 #include <stdlib.h>
22
23 #include <TSystem.h>
24 #include <TROOT.h>
25 #include <TPluginManager.h>
26
27 #include "AliRawReader.h"
28 #include "AliRawReaderDate.h"
29 #include "AliPHOSDA2.h"
30 #include "AliPHOSRawDecoderv1.h"
31 #include "AliCaloAltroMapping.h"
32
33
34 /* Main routine
35       Arguments: 
36       1- monitoring data source
37 */
38 int main(int argc, char **argv) {
39
40   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
41                                         "*",
42                                         "TStreamerInfo",
43                                         "RIO",
44                                         "TStreamerInfo()");
45
46   int status;
47   
48   if (argc!=2) {
49     printf("Wrong number of arguments\n");
50     return -1;
51   }
52   
53
54   /* Retrieve mapping files from DAQ DB */
55   const char* mapFiles[4] = {"RCU0.data","RCU1.data","RCU2.data","RCU3.data"};
56
57   for(Int_t iFile=0; iFile<4; iFile++) {
58     int failed = daqDA_DB_getFile(mapFiles[iFile], mapFiles[iFile]);
59     if(failed) {
60       printf("Cannot retrieve file %s from DAQ DB. Exit.\n",mapFiles[iFile]);
61       return -1;
62     }
63   }
64   
65   /* Open mapping files */
66   AliAltroMapping *mapping[4];
67   TString path = "./";
68   path += "RCU";
69   TString path2;
70   for(Int_t i = 0; i < 4; i++) {
71     path2 = path;
72     path2 += i;
73     path2 += ".data";
74     mapping[i] = new AliCaloAltroMapping(path2.Data());
75   }
76   
77
78   /* define data source : this is argument 1 */  
79   status=monitorSetDataSource( argv[1] );
80   if (status!=0) {
81     printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
82     return -1;
83   }
84
85
86   /* declare monitoring program */
87   status=monitorDeclareMp( __FILE__ );
88   if (status!=0) {
89     printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
90     return -1;
91   }
92
93
94   /* define wait event timeout - 1s max */
95   monitorSetNowait();
96   monitorSetNoWaitNetworkTimeout(1000);
97
98   
99   /* log start of process */
100   printf("DA2 (bad channels search) started.\n");  
101
102
103   /* init some counters */
104   int nevents_physics=0;
105   int nevents_total=0;
106
107   AliRawReader *rawReader = NULL;
108
109   AliPHOSDA2* da2 = new AliPHOSDA2(2); // DA2 ("Checking for bad channels") for module2
110   
111   Float_t q[64][56][2];
112
113   Int_t gain = -1;
114   Int_t X = -1;
115   Int_t Z = -1;
116   Int_t nFired = -1;
117
118   /* main loop (infinite) */
119   for(;;) {
120     struct eventHeaderStruct *event;
121     eventTypeType eventT;
122   
123     /* check shutdown condition */
124     if (daqDA_checkShutdown()) {break;}
125     
126     /* get next event (blocking call until timeout) */
127     status=monitorGetEventDynamic((void **)&event);
128     if (status==MON_ERR_EOF) {
129       printf ("End of File detected\n");
130       break; /* end of monitoring file has been reached */
131     }
132     
133     if (status!=0) {
134       printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
135       break;
136     }
137
138     /* retry if got no event */
139     if (event==NULL) {
140       continue;
141     }
142
143
144     /* use event - here, just write event id to result file */
145     eventT=event->eventType;
146     
147     if (eventT==PHYSICS_EVENT || eventT==CALIBRATION_EVENT) {
148       
149       for(Int_t iX=0; iX<64; iX++) {
150         for(Int_t iZ=0; iZ<56; iZ++) {
151           for(Int_t iGain=0; iGain<2; iGain++) {
152             q[iX][iZ][iGain] = 0.;
153           }
154         }
155       }
156
157       nFired = 0;
158
159       rawReader = new AliRawReaderDate((void*)event);
160       AliPHOSRawDecoderv1 dc(rawReader,mapping);
161       dc.SubtractPedestals(kTRUE);
162       
163       while(dc.NextDigit()) {
164
165         X = dc.GetRow() - 1;
166         Z = dc.GetColumn() - 1;
167
168         if(dc.IsLowGain()) gain = 0;
169         else
170           gain = 1;
171         
172         q[X][Z][gain] = dc.GetSampleQuality();
173
174         if(gain && dc.GetEnergy()>40)
175           nFired++;
176         
177       }
178       
179       da2->FillQualityHistograms(q);
180       da2->FillFiredCellsHistogram(nFired);
181       //da1.UpdateHistoFile();
182       
183       delete rawReader;     
184       nevents_physics++;
185     }
186     
187     nevents_total++;
188     
189     /* free resources */
190     free(event);
191     
192     /* exit when last event received, no need to wait for TERM signal */
193     if (eventT==END_OF_RUN) {
194       printf("EOR event detected\n");
195       break;
196     }
197   }
198   
199   for(Int_t i = 0; i < 4; i++) delete mapping[i];  
200
201   /* Be sure that all histograms are saved */
202   delete da2;
203   
204   /* Store output files to the File Exchange Server */
205   daqDA_FES_storeFile("PHOS_Module2_BCM.root","BAD_CHANNELS");
206
207   return status;
208 }