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