]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/EMCALSignalda.cxx
52dfec8e75a16cf5a6faca8e9ab7e3fb44c1c90b
[u/mrichter/AliRoot.git] / EMCAL / EMCALSignalda.cxx
1 /*
2   EMCAL DA for online calibration
3   
4   Contact: silvermy@ornl.gov
5   Run Type: PHYSICS or STANDALONE
6   DA Type: LDC
7   Number of events needed: ~1000
8   Input Files: argument list
9   Output Files: RESULT_FILE=EMCALCalibSignal.root, to be exported to the DAQ FXS
10   fileId:  FILE_ID=EMCALCalibSignal    
11   Trigger types used: CALIBRATION_EVENT (temporarily also PHYSICS_EVENT to start with)
12
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 - see below).
17 */
18
19 #define RESULT_FILE  "EMCALCalibSignal.root"
20 #define FILE_ID "EMCALCalibSignal"
21 #define AliDebugLevel() -1
22 #define FILE_ClassName "emcCalibSignal"
23
24 extern "C" {
25 #include <daqDA.h>
26 }
27 #include "event.h"
28 #include "monitor.h"
29
30 #include "stdio.h"
31 #include "stdlib.h"
32
33 //
34 //AliRoot includes
35 //
36 #include "AliRawReader.h"
37 #include "AliRawReaderDate.h"
38 #include "AliRawEventHeaderBase.h"
39 #include "AliCaloRawStream.h"
40 #include "AliLog.h"
41
42 //
43 // EMC calibration-helper algorithm includes
44 //
45 #include "AliCaloCalibSignal.h"
46 #include <TFile.h> // ROOT 
47
48 /*
49   Main routine, EMC signal detector algorithm to be run on EMC LDC
50   Arguments: list of DATE raw data files
51 */
52
53 int main(int argc, char **argv) {
54
55   AliLog::SetClassDebugLevel("AliCaloRawStream",-5);
56   AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
57   AliLog::SetModuleDebugLevel("RAW",-5);
58
59   if (argc<2) {
60     printf("Wrong number of arguments\n");
61     return -1;
62   }
63
64   int i, status;
65
66   /* log start of process */
67   printf("EMCAL DA started - %s\n",__FILE__);
68
69   /* declare monitoring program */
70   status=monitorDeclareMp( __FILE__ );
71   if (status!=0) {
72     printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
73     return -1;
74   }
75
76   AliCaloCalibSignal * calibSignal = new 
77     AliCaloCalibSignal(AliCaloCalibSignal::kEmCal); // signal and noise calibration
78
79   /* loop over RAW data files */
80   int nevents=0;
81   for ( i=1; i<argc; i++ ) {
82
83     /* define data source : this is argument i */
84     printf("Processing file %s\n", argv[i]);
85
86     AliRawReader *rawReader = new AliRawReaderDate(argv[i]);
87     AliCaloRawStream *in = new AliCaloRawStream(rawReader,"EMCAL");
88     AliRawEventHeaderBase *aliHeader=NULL;
89
90     /* read until EOF */
91     while ( rawReader->NextEvent() ) {
92
93       /* check shutdown condition */
94       if (daqDA_checkShutdown()) {break;}
95
96       aliHeader = (AliRawEventHeaderBase*) rawReader->GetEventHeader();
97       calibSignal->SetRunNumber( aliHeader->Get("RunNb") ); // just for fun; keep info on last run looked at
98
99       // select physics and calibration events now (only calibration in future)
100       if ( aliHeader->Get("Type") == AliRawEventHeaderBase::kPhysicsEvent || 
101            aliHeader->Get("Type") == AliRawEventHeaderBase::kCalibrationEvent  ) {
102
103         nevents++;
104
105         //  Signal calibration
106         calibSignal->ProcessEvent(in, aliHeader);
107       }
108     } // loop over all events in file
109     /* cleanup the reading handles */
110     delete in;
111     delete rawReader;    
112   } // loop over files
113
114   //
115   // write class to rootfile
116   //
117
118   printf ("%d physics/calibration events processed.\n",nevents);
119
120   TFile f(RESULT_FILE, "recreate");
121   if (!f.IsZombie()) { 
122     f.cd();
123     calibSignal->Write(FILE_ClassName);
124     f.Close();
125     printf("Object saved to file \"%s\" as \"%s\".\n", RESULT_FILE, FILE_ClassName); 
126   } 
127   else {
128     printf("Could not save the object to file \"%s\".\n", RESULT_FILE);
129   }
130
131   /* store the result file on FES */
132   status = daqDA_FES_storeFile(RESULT_FILE, FILE_ID);
133
134   // see if we can delete our analysis helper also
135   delete calibSignal;
136
137   return status;
138 }