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