]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/EMCALLEDda.cxx
In Open() and GotoEvent() try the ESD operations first, fallback to run-loader.
[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 "EMCALLED"
22 #define AliDebugLevel() -1
23 #define FILE_PEDClassName "emcCalibPedestal"
24 #define FILE_SIGClassName "emcCalibSignal"
25 const int kNRCU = 2;
26 /* LOCAL_DEBUG is used to bypass daq* calls that do not work locally */
27 //#define LOCAL_DEBUG 1 // comment out to run normally                                                            
28 extern "C" {
29 #include <daqDA.h>
30 }
31 #include "event.h" /* in $DATE_COMMON_DEFS/; includes definition of event types */
32 #include "monitor.h" /* in $DATE_MONITOR_DIR/; monitor* interfaces */
33
34 #include "stdio.h"
35 #include "stdlib.h"
36
37 // ROOT includes
38 #include <TFile.h> 
39 #include <TROOT.h> 
40 #include <TPluginManager.h> 
41 #include <TSystem.h> 
42
43 //
44 //AliRoot includes
45 //
46 #include "AliRawReader.h"
47 #include "AliRawReaderDate.h"
48 #include "AliRawEventHeaderBase.h"
49 #include "AliCaloRawStream.h"
50 #include "AliCaloAltroMapping.h"
51 #include "AliLog.h"
52
53 //
54 // EMC calibration-helper algorithm includes
55 //
56 #include "AliCaloCalibPedestal.h"
57 #include "AliCaloCalibSignal.h"
58
59 /*
60   Main routine, EMC signal detector algorithm 
61   Arguments: list of DATE raw data files
62 */
63
64 int main(int argc, char **argv) {
65
66   AliLog::SetClassDebugLevel("AliCaloRawStream",-5);
67   AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
68   AliLog::SetModuleDebugLevel("RAW",-5);
69
70   if (argc<2) {
71     printf("Wrong number of arguments\n");
72     return -1;  
73   }
74
75   /* magic line - for TStreamerInfo */
76   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
77                                         "*",
78                                         "TStreamerInfo",
79                                         "RIO",
80                                         "TStreamerInfo()"); 
81
82   int i, status;
83
84   /* log start of process */
85   printf("EMCAL DA started - %s\n",__FILE__);
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   /* define wait event timeout - 1s max */
94   monitorSetNowait();
95   monitorSetNoWaitNetworkTimeout(1000);
96
97   /* Retrieve mapping files from DAQ DB */ 
98   const char* mapFiles[kNRCU] = {"RCU0.data","RCU1.data"};
99
100   for(Int_t iFile=0; iFile<kNRCU; iFile++) {
101     int failed = daqDA_DB_getFile(mapFiles[iFile], mapFiles[iFile]);
102     if(failed) { 
103       printf("Cannot retrieve file %d : %s from DAQ DB. Exit now..\n",
104              iFile, mapFiles[iFile]);
105 #ifdef LOCAL_DEBUG
106 #else
107       return -1;
108 #endif
109     }
110   }
111   
112   /* Open mapping files */
113   AliCaloAltroMapping *mapping[kNRCU];
114   TString path = "./";
115   path += "RCU";
116   TString path2;
117   for(Int_t i = 0; i < kNRCU; i++) {
118     path2 = path;
119     path2 += i;
120     path2 += ".data";
121     mapping[i] = new AliCaloAltroMapping(path2.Data());
122   }
123   
124   /* set up our analysis classes */  
125   AliCaloCalibPedestal * calibPedestal = new AliCaloCalibPedestal(AliCaloCalibPedestal::kEmCal); 
126   calibPedestal->SetAltroMapping( mapping );
127   AliCaloCalibSignal * calibSignal = new AliCaloCalibSignal(AliCaloCalibSignal::kEmCal); 
128   calibSignal->SetAltroMapping( mapping );
129
130   AliRawReader *rawReader = NULL;
131   int nevents=0;
132
133   /* loop over RAW data files */
134   for ( i=1; i<argc; i++ ) {
135
136     /* define data source : this is argument i */
137     printf("Processing file %s\n", argv[i]);
138     status=monitorSetDataSource( argv[i] );
139     if (status!=0) {
140       printf("monitorSetDataSource() failed. Error=%s. Exiting ...\n", monitorDecodeError(status));
141       return -1;
142     }
143
144     /* read until EOF */
145     struct eventHeaderStruct *event;
146     eventTypeType eventT;
147
148     for ( ; ; ) { // infinite loop
149
150       /* check shutdown condition */
151       if (daqDA_checkShutdown()) {break;}
152
153       /* get next event (blocking call until timeout) */
154       status=monitorGetEventDynamic((void **)&event);
155       if (status==MON_ERR_EOF) {
156         printf ("End of File %d (%s) detected\n", i, argv[i]);
157         break; /* end of monitoring file has been reached */
158       }
159       if (status!=0) {
160         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
161         break;
162       }
163
164       /* retry if got no event */
165       if (event==NULL) {
166         continue;
167       }
168       eventT = event->eventType; /* just convenient shorthand */
169
170       /* skip start/end of run events */
171       if ( (eventT != physicsEvent) && (eventT != calibrationEvent) ) {
172         continue;
173       }
174
175       nevents++; // count how many acceptable events we have
176
177       //  Signal calibration
178       rawReader = new AliRawReaderDate((void*)event);
179       calibSignal->ProcessEvent(rawReader);
180       rawReader->Reset();
181       calibPedestal->ProcessEvent(rawReader);
182       delete rawReader;
183
184       /* free resources */
185       free(event);    
186
187     } //until EOF
188   } // loop over files
189
190   //
191   // write class to rootfile
192   //
193
194   printf ("%d physics/calibration events processed.\n",nevents);
195
196   TFile f(RESULT_FILE, "recreate");
197   if (!f.IsZombie()) { 
198     f.cd();
199     calibPedestal->Write(FILE_PEDClassName);
200     calibSignal->Write(FILE_SIGClassName);
201     f.Close();
202     printf("Objects saved to file \"%s\" as \"%s\" and \"%s\".\n", 
203            RESULT_FILE, FILE_PEDClassName, FILE_SIGClassName); 
204   } 
205   else {
206     printf("Could not save the object to file \"%s\".\n", 
207            RESULT_FILE);
208   }
209
210   //
211   // closing down; see if we can delete our analysis helper(s) also
212   //
213   delete calibPedestal;
214   delete calibSignal;
215   for(Int_t iFile=0; iFile<kNRCU; iFile++) {
216     if (mapping[iFile]) delete mapping[iFile];
217   }
218
219   /* store the result file on FES */
220 #ifdef LOCAL_DEBUG
221 #else
222   status = daqDA_FES_storeFile(RESULT_FILE, FILE_ID);
223 #endif
224
225   return status;
226 }