]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/PHOSBCMda.cxx
Bugfix: lowercase b should be upper case B for component id: TPCClusterFinder32Bit
[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 "AliPHOSRawFitterv1.h"
31 #include "AliCaloAltroMapping.h"
32 #include "AliCaloRawStreamV3.h"
33
34
35 /* Main routine
36       Arguments: 
37       1- monitoring data source
38 */
39 int main(int argc, char **argv) {
40
41   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
42                                         "*",
43                                         "TStreamerInfo",
44                                         "RIO",
45                                         "TStreamerInfo()");
46
47   int status;
48   
49   if (argc!=2) {
50     printf("Wrong number of arguments\n");
51     return -1;
52   }
53   
54
55   /* Retrieve mapping files from DAQ DB */
56   const char* mapFiles[4] = {"RCU0.data","RCU1.data","RCU2.data","RCU3.data"};
57
58   for(Int_t iFile=0; iFile<4; iFile++) {
59     int failed = daqDA_DB_getFile(mapFiles[iFile], mapFiles[iFile]);
60     if(failed) {
61       printf("Cannot retrieve file %s from DAQ DB. Exit.\n",mapFiles[iFile]);
62       return -1;
63     }
64   }
65   
66   /* Open mapping files */
67   AliAltroMapping *mapping[4];
68   TString path = "./";
69   path += "RCU";
70   TString path2;
71   for(Int_t i = 0; i < 4; i++) {
72     path2 = path;
73     path2 += i;
74     path2 += ".data";
75     mapping[i] = new AliCaloAltroMapping(path2.Data());
76   }
77   
78
79   /* define data source : this is argument 1 */  
80   status=monitorSetDataSource( argv[1] );
81   if (status!=0) {
82     printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
83     return -1;
84   }
85
86
87   /* declare monitoring program */
88   status=monitorDeclareMp( __FILE__ );
89   if (status!=0) {
90     printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
91     return -1;
92   }
93
94
95   /* define wait event timeout - 1s max */
96   monitorSetNowait();
97   monitorSetNoWaitNetworkTimeout(1000);
98
99   
100   /* log start of process */
101   printf("DA2 (bad channels search) started.\n");  
102
103
104   /* init some counters */
105   int nevents_physics=0;
106   int nevents_total=0;
107
108   AliRawReader *rawReader = NULL;
109
110   AliPHOSDA2* da2 = new AliPHOSDA2(2); // DA2 ("Checking for bad channels") for module2
111   
112   Float_t q[64][56][2];
113
114   Int_t gain     = -1;
115   Int_t cellX    = -1;
116   Int_t cellZ    = -1;
117   Int_t nBunches =  0;
118   Int_t nFired   = -1;
119   Int_t sigStart, sigLength;
120
121   /* main loop (infinite) */
122   for(;;) {
123     struct eventHeaderStruct *event;
124     eventTypeType eventT;
125   
126     /* check shutdown condition */
127     if (daqDA_checkShutdown()) {break;}
128     
129     /* get next event (blocking call until timeout) */
130     status=monitorGetEventDynamic((void **)&event);
131     if (status==MON_ERR_EOF) {
132       printf ("End of File detected\n");
133       break; /* end of monitoring file has been reached */
134     }
135     
136     if (status!=0) {
137       printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
138       break;
139     }
140
141     /* retry if got no event */
142     if (event==NULL) {
143       continue;
144     }
145
146
147     /* use event - here, just write event id to result file */
148     eventT=event->eventType;
149     
150     if (eventT==PHYSICS_EVENT || eventT==CALIBRATION_EVENT) {
151       
152       for(Int_t iX=0; iX<64; iX++) {
153         for(Int_t iZ=0; iZ<56; iZ++) {
154           for(Int_t iGain=0; iGain<2; iGain++) {
155             q[iX][iZ][iGain] = 0.;
156           }
157         }
158       }
159
160       nFired = 0;
161
162       rawReader = new AliRawReaderDate((void*)event);
163       AliCaloRawStreamV3 stream(rawReader,"PHOS",mapping);
164       AliPHOSRawFitterv0 fitter();
165       fitter.SubtractPedestals(kTRUE); // assume that data is non-ZS
166       
167       while (stream.NextDDL()) {
168         while (stream.NextChannel()) {
169
170           cellX    = stream.GetCellX();
171           cellZ    = stream.GetCellZ();
172           caloFlag = stream.GetCaloFlag();  // 0=LG, 1=HG, 2=TRU
173
174           // In case of oscillating signals with ZS, a channel can have several bunches
175           nBunches = 0;
176           while (stream.NextBunch()) {
177             nBunches++;
178             if (nBunches > 1) continue;
179             sigStart  = fRawStream.GetStartTimeBin();
180             sigLength = fRawStream.GetBunchLength();
181             fitter.SetSamples(fRawStream->GetSignals(),sigStart,sigLength);
182           } // End of NextBunch()
183           
184           fitter.SetNBunches(nBunches);
185           fitter.SetChannelGeo(module,cellX,cellZ,caloFlag);
186           fitter.Eval();
187
188           if (nBunches>1 || caloFlag!=0 || caloFlag!=1 || fitter.GetSignalQuality()>1) continue;
189           
190           q[cellX][cellZ][caloFlag] = fitter.GetSignalQuality();
191           
192           if(gain && dc.GetEnergy()>40)
193             nFired++;
194         }
195       }
196         
197       da2->FillQualityHistograms(q);
198       da2->FillFiredCellsHistogram(nFired);
199       //da1.UpdateHistoFile();
200       
201       delete rawReader;     
202       nevents_physics++;
203     }
204     
205     nevents_total++;
206     
207     /* free resources */
208     free(event);
209     
210     /* exit when last event received, no need to wait for TERM signal */
211     if (eventT==END_OF_RUN) {
212       printf("EOR event detected\n");
213       break;
214     }
215   }
216   
217   for(Int_t i = 0; i < 4; i++) delete mapping[i];  
218
219   /* Be sure that all histograms are saved */
220   delete da2;
221   
222   /* Store output files to the File Exchange Server */
223   daqDA_FES_storeFile("PHOS_Module2_BCM.root","BAD_CHANNELS");
224
225   return status;
226 }