]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/EMCALLEDda.cxx
adding LED Ref FEE channels to PED DA and execute LED DA for calibration events only
[u/mrichter/AliRoot.git] / EMCAL / EMCALLEDda.cxx
1 /*
2   EMCAL DA for online calibration: for LED studies
3   
4   Contact: silvermy@ornl.gov
5   Run Type: PHYSICS or STANDALONE
6   DA Type: MON 
7   Number of events needed: continously accumulating for all runs, rate ~0.1-1 Hz
8   Input Files: argument list
9   Output Files: RESULT_FILE=EMCALLED.root, to be exported to the DAQ FXS
10   fileId:  FILE_ID=EMCALLED    
11   Trigger types used: CALIBRATION_EVENT 
12 */
13 /*
14   This process reads RAW data from the files provided as command line arguments
15   and save results (class itself) in a file (named from RESULT_FILE define - 
16   see below).
17 */
18
19 #define RESULT_FILE  "EMCALLED.root"
20 #define FILE_ID "signal"
21 #define AliDebugLevel() -1
22 #define FILE_SIGClassName "emcCalibSignal"
23 const int kNRCU = 4;
24 /* LOCAL_DEBUG is used to bypass daq* calls that do not work locally */
25 //#define LOCAL_DEBUG 1 // comment out to run normally                                                            
26 extern "C" {
27 #include <daqDA.h>
28 }
29 #include "event.h" /* in $DATE_COMMON_DEFS/; includes definition of event types */
30 #include "monitor.h" /* in $DATE_MONITOR_DIR/; monitor* interfaces */
31
32 #include "stdio.h"
33 #include "stdlib.h"
34
35 // ROOT includes
36 #include <TFile.h> 
37 #include <TROOT.h> 
38 #include <TPluginManager.h> 
39 #include <TSystem.h> 
40
41 //
42 //AliRoot includes
43 //
44 #include "AliRawReader.h"
45 #include "AliRawReaderDate.h"
46 #include "AliRawEventHeaderBase.h"
47 #include "AliCaloRawStreamV3.h"
48 #include "AliCaloAltroMapping.h"
49 #include "AliLog.h"
50
51 //
52 // EMC calibration-helper algorithm includes
53 //
54 #include "AliCaloCalibSignal.h"
55
56 /*
57   Main routine, EMC signal detector algorithm 
58   Arguments: list of DATE raw data files
59 */
60
61 int main(int argc, char **argv) {
62
63   AliLog::SetClassDebugLevel("AliCaloRawStreamV3",-5);
64   AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
65   AliLog::SetModuleDebugLevel("RAW",-5);
66
67   if (argc<2) {
68     printf("Wrong number of arguments\n");
69     return -1;  
70   }
71
72   /* magic line - for TStreamerInfo */
73   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
74                                         "*",
75                                         "TStreamerInfo",
76                                         "RIO",
77                                         "TStreamerInfo()"); 
78   
79   int i, status;
80   
81   /* log start of process */
82   printf("EMCAL DA started - %s\n",__FILE__);
83   
84   /* declare monitoring program */
85   status=monitorDeclareMp( __FILE__ );
86   if (status!=0) {
87     printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
88     return -1;
89   }
90   /* define wait event timeout - 1s max */
91   monitorSetNowait();
92   monitorSetNoWaitNetworkTimeout(1000);
93   
94   /* Retrieve mapping files from DAQ DB */ 
95   const char* mapFiles[kNRCU] = {"RCU0A.data","RCU1A.data","RCU0C.data","RCU1C.data"};
96   
97   for(Int_t iFile=0; iFile<kNRCU; iFile++) {
98     int failed = daqDA_DB_getFile(mapFiles[iFile], mapFiles[iFile]);
99     if(failed) { 
100       printf("Cannot retrieve file %d : %s from DAQ DB. Exit now..\n",
101              iFile, mapFiles[iFile]);
102 #ifdef LOCAL_DEBUG
103 #else
104       return -1;
105 #endif
106     }
107   }
108   
109   /* Open mapping files */
110   AliCaloAltroMapping *mapping[kNRCU];
111   TString path = "./";
112   path += "RCU";
113   TString path2;
114   TString side[] = {"A","C"};//+ and - pseudorapidity supermodules
115   for(Int_t j = 0; j < 2; j++){
116     for(Int_t i = 0; i < 2; i++) {
117       path2 = path;
118       path2 += i;
119       path2 += side[j]; 
120       path2 += ".data";
121       mapping[j*2 + i] = new AliCaloAltroMapping(path2.Data());
122     }
123   }
124   
125   /* Retrieve cut=parameter file from DAQ DB */ 
126   const char* parameterFile = {"EMCALLEDda.dat"};
127   
128   int failed = daqDA_DB_getFile(parameterFile, parameterFile);
129   if (failed) { 
130     printf("Cannot retrieve file : %s from DAQ DB. Exit now..\n",
131            parameterFile);
132 #ifdef LOCAL_DEBUG
133 #else
134     return -1;
135 #endif
136   }
137   
138   /* set up our analysis classes */  
139   AliCaloCalibSignal * calibSignal = new AliCaloCalibSignal(AliCaloCalibSignal::kEmCal); 
140   calibSignal->SetAltroMapping( mapping );
141   calibSignal->SetParametersFromFile( parameterFile );
142   
143   AliRawReader *rawReader = NULL;
144   int nevents=0;
145   
146   /* loop over RAW data files */
147   for ( i=1; i<argc; i++ ) {
148     
149     /* define data source : this is argument i */
150     printf("Processing file %s\n", argv[i]);
151     status=monitorSetDataSource( argv[i] );
152     if (status!=0) {
153       printf("monitorSetDataSource() failed. Error=%s. Exiting ...\n", monitorDecodeError(status));
154       return -1;
155     }
156     
157     /* read until EOF */
158     struct eventHeaderStruct *event;
159     eventTypeType eventT;
160     
161     for ( ; ; ) { // infinite loop
162       
163       /* check shutdown condition */
164       if (daqDA_checkShutdown()) {break;}
165       
166       /* get next event (blocking call until timeout) */
167       status=monitorGetEventDynamic((void **)&event);
168       if (status==MON_ERR_EOF) {
169         printf ("End of File %d (%s) detected\n", i, argv[i]);
170         break; /* end of monitoring file has been reached */
171       }
172       if (status!=0) {
173         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
174         break;
175       }
176       
177       /* retry if got no event */
178       if (event==NULL) {
179         continue;
180       }
181       eventT = event->eventType; /* just convenient shorthand */
182       
183       /* only look at calibration events */
184       if ( eventT != calibrationEvent ) {
185         continue;
186       }
187       
188       nevents++; // count how many acceptable events we have
189       
190       //  Signal calibration
191       rawReader = new AliRawReaderDate((void*)event);
192       calibSignal->SetRunNumber(event->eventRunNb);
193       calibSignal->ProcessEvent(rawReader);
194       delete rawReader;
195       
196       /* free resources */
197       free(event);    
198       
199     } //until EOF
200   } // loop over files
201   
202   // calculate average values also, for the LED info
203   calibSignal->SetUseAverage(kTRUE);
204   calibSignal->Analyze();
205   
206   // by default, we only save the full info in debug mode  
207 #ifdef LOCAL_DEBUG
208 #else
209   // reset the full trees, when we are not in debug mode
210   calibSignal->GetTreeAmpVsTime()->Reset();
211   calibSignal->GetTreeLEDAmpVsTime()->Reset();
212 #endif
213   
214   //
215   // write class to rootfile
216   //
217   
218   printf ("%d calibration events processed.\n",nevents);
219   
220   TFile f(RESULT_FILE, "recreate");
221   if (!f.IsZombie()) { 
222     f.cd();
223     calibSignal->Write(FILE_SIGClassName);
224     f.Close();
225     printf("Objects saved to file \"%s\" as \"%s\".\n", 
226            RESULT_FILE, FILE_SIGClassName); 
227   } 
228   else {
229     printf("Could not save the object to file \"%s\".\n", 
230            RESULT_FILE);
231   }
232   
233   //
234   // closing down; see if we can delete our analysis helper(s) also
235   //
236   delete calibSignal;
237   for(Int_t iFile=0; iFile<kNRCU; iFile++) {
238     if (mapping[iFile]) delete mapping[iFile];
239   }
240   
241   /* store the result file on FES */
242 #ifdef LOCAL_DEBUG
243 #else
244   status = daqDA_FES_storeFile(RESULT_FILE, FILE_ID);
245 #endif
246   
247   return status;
248 }