AliRoot Core  3dc7879 (3dc7879)
EMCLEDda.cxx
Go to the documentation of this file.
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 
28 
29 #define RESULT_FILE "EMCALLED.root"
30 #define FILE_ID "signal"
31 #define AliDebugLevel() -1
32 #define FILE_SIGClassName "emcCalibSignal"
33 const int kNRCU = 4;
34 /* LOCAL_DEBUG is used to bypass daq* calls that do not work locally */
35 //#define LOCAL_DEBUG 1 // comment out to run normally
36 extern "C" {
37 #include <daqDA.h>
38 }
39 #include "event.h" /* in $DATE_COMMON_DEFS/; includes definition of event types */
40 #include "monitor.h" /* in $DATE_MONITOR_DIR/; monitor* interfaces */
41 
42 #include "stdio.h"
43 #include "stdlib.h"
44 
45 // ROOT includes
46 #include <TFile.h>
47 #include <TROOT.h>
48 #include <TPluginManager.h>
49 #include <TSystem.h>
50 
51 //
52 //AliRoot includes
53 //
54 #include "AliRawReader.h"
55 #include "AliRawReaderDate.h"
56 #include "AliRawEventHeaderBase.h"
57 #include "AliCaloRawStreamV3.h"
58 #include "AliCaloAltroMapping.h"
59 #include "AliLog.h"
60 #include "AliDAQ.h"
61 
62 //
63 // EMC calibration-helper algorithm includes
64 //
65 #include "AliCaloCalibSignal.h"
66 
72 int main(int argc, char **argv)
73 {
74  AliLog::SetClassDebugLevel("AliCaloRawStreamV3",-5);
75  AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
77 
78  if (argc<2)
79  {
80  printf("Wrong number of arguments\n");
81  return -1;
82  }
83 
84  /* magic line - for TStreamerInfo */
85  gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
86  "*",
87  "TStreamerInfo",
88  "RIO",
89  "TStreamerInfo()");
90 
91  /* another magic line - for TMinuit */
92  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
93  "Minuit",
94  "TMinuitMinimizer",
95  "Minuit",
96  "TMinuitMinimizer(const char*)");
97 
98  int i, status;
99 
100  /* log start of process */
101  printf("EMCAL DA started - %s\n",__FILE__);
102 
103  Int_t emcID = AliDAQ::DetectorID("EMCAL"); // bit 18..
104 
105  /* declare monitoring program */
106  status=monitorDeclareMp( __FILE__ );
107  if (status!=0)
108  {
109  printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
110  return -1;
111  }
112 
113  /* define wait event timeout - 1s max */
114  monitorSetNowait();
115  monitorSetNoWaitNetworkTimeout(1000);
116 
117  /* Retrieve mapping files from DAQ DB */
118  const char* mapFiles[kNRCU] = {"RCU0A.data","RCU1A.data","RCU0C.data","RCU1C.data"};
119 
120  for(Int_t iFile=0; iFile<kNRCU; iFile++)
121  {
122  int failed = daqDA_DB_getFile(mapFiles[iFile], mapFiles[iFile]);
123  if(failed)
124  {
125  printf("Cannot retrieve file %d : %s from DAQ DB. Exit now..\n",
126  iFile, mapFiles[iFile]);
127 #ifdef LOCAL_DEBUG
128 #else
129  return -1;
130 #endif
131  }
132  }
133 
134  /* Open mapping files */
135  AliCaloAltroMapping *mapping[kNRCU];
136  TString path = "./";
137  path += "RCU";
138  TString path2;
139  TString side[] = {"A","C"};//+ and - pseudorapidity supermodules
140  for(Int_t j = 0; j < 2; j++)
141  {
142  for(Int_t i = 0; i < 2; i++)
143  {
144  path2 = path;
145  path2 += i;
146  path2 += side[j];
147  path2 += ".data";
148  mapping[j*2 + i] = new AliCaloAltroMapping(path2.Data());
149  }
150  }
151 
152  /* Retrieve cut=parameter file from DAQ DB */
153  const char* parameterFile = {"EMCALLEDda.dat"};
154 
155  int failed = daqDA_DB_getFile(parameterFile, parameterFile);
156  if (failed)
157  {
158  printf("Cannot retrieve file : %s from DAQ DB. Exit now..\n",
159  parameterFile);
160 #ifdef LOCAL_DEBUG
161 #else
162  return -1;
163 #endif
164  }
165 
166  /* set up our analysis classes */
168  calibSignal->SetAltroMapping( mapping );
169  calibSignal->SetParametersFromFile( parameterFile );
170 
171  AliRawReader *rawReader = NULL;
172  int nevents=0;
173 
174  /* loop over RAW data files */
175  for ( i=1; i<argc; i++ ) {
176 
177  /* define data source : this is argument i */
178  printf("Processing file %s\n", argv[i]);
179  status=monitorSetDataSource( argv[i] );
180  if (status!=0) {
181  printf("monitorSetDataSource() failed. Error=%s. Exiting ...\n", monitorDecodeError(status));
182  return -1;
183  }
184 
185  /* read until EOF */
186  struct eventHeaderStruct *event;
187  eventTypeType eventT;
188 
189  for ( ; ; ) { // infinite loop
190 
191  /* check shutdown condition */
192  if (daqDA_checkShutdown()) {break;}
193 
194  /* get next event (blocking call until timeout) */
195  status=monitorGetEventDynamic((void **)&event);
196  if (status==MON_ERR_EOF) {
197  printf ("End of File %d (%s) detected\n", i, argv[i]);
198  break; /* end of monitoring file has been reached */
199  }
200  if (status!=0) {
201  printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
202  break;
203  }
204 
205  /* retry if got no event */
206  if (event==NULL)
207  {
208  continue;
209  }
210  eventT = event->eventType; /* just convenient shorthand */
211  /* only look at calibration events */
212  if ( eventT != calibrationEvent )
213  {
214  free(event);
215  continue;
216  }
217 
218  /* only look at events where EMCAL was included */
219  if (! TEST_DETECTOR_IN_PATTERN(event->eventDetectorPattern, emcID) )
220  {
221  free(event);
222  continue;
223  }
224 
225  nevents++; // count how many acceptable events we have
226 
227  // Signal calibration
228  rawReader = new AliRawReaderDate((void*)event);
229  calibSignal->SetRunNumber(event->eventRunNb);
230  calibSignal->ProcessEvent(rawReader);
231  delete rawReader;
232 
233  /* free resources */
234  free(event);
235 
236  } //until EOF
237  } // loop over files
238 
239  // calculate average values also, for the LED info
240  calibSignal->SetUseAverage(kTRUE);
241  calibSignal->Analyze();
242 
243  // by default, we only save the full info in debug mode
244 #ifdef LOCAL_DEBUG
245 #else
246  // reset the full trees, when we are not in debug mode
247  calibSignal->GetTreeAmpVsTime()->Reset();
248  calibSignal->GetTreeLEDAmpVsTime()->Reset();
249 #endif
250 
251  //
252  // write class to rootfile
253  //
254 
255  printf ("%d calibration events processed.\n",nevents);
256 
257  TFile f(RESULT_FILE, "recreate");
258  if (!f.IsZombie()) {
259  f.cd();
260  calibSignal->Write(FILE_SIGClassName);
261  f.Close();
262  printf("Objects saved to file \"%s\" as \"%s\".\n",
264  }
265  else {
266  printf("Could not save the object to file \"%s\".\n",
267  RESULT_FILE);
268  }
269 
270  //
271  // closing down; see if we can delete our analysis helper(s) also
272  //
273  delete calibSignal;
274  for(Int_t iFile=0; iFile<kNRCU; iFile++)
275  {
276  if (mapping[iFile]) delete mapping[iFile];
277  }
278 
279  /* store the result file on FES */
280 #ifdef LOCAL_DEBUG
281 #else
282  status = daqDA_FES_storeFile(RESULT_FILE, FILE_ID);
283  status = daqDA_DB_storeFile(RESULT_FILE, RESULT_FILE); // also to DAQ DB
284 #endif
285 
286  return status;
287 }
Bool_t ProcessEvent(AliRawReader *rawReader)
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
void SetRunNumber(int runNo)
TTree * GetTreeLEDAmpVsTime() const
const int kNRCU
Definition: EMCLEDda.cxx:33
static void SetClassDebugLevel(const char *className, Int_t level)
Definition: AliLog.cxx:513
const char * path
void SetUseAverage(bool b)
TROOT * gROOT
static Int_t DetectorID(const char *detectorName)
Definition: AliDAQ.cxx:204
class for signal monitoring and calibration tools
int main(int argc, char **argv)
Definition: EMCLEDda.cxx:72
void SetParametersFromFile(const char *parameterFile)
#define FILE_ID
Definition: EMCLEDda.cxx:30
void SetAltroMapping(AliCaloAltroMapping **mapp)
static void SetModuleDebugLevel(const char *module, Int_t level)
Definition: AliLog.cxx:485
TF1 * f
Definition: interpolTest.C:21
TTree * GetTreeAmpVsTime() const
#define RESULT_FILE
Definition: EMCLEDda.cxx:29
#define FILE_SIGClassName
Definition: EMCLEDda.cxx:32