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