]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/EMCALLEDda.cxx
EMCAL_FIRSTYEARV1 - geometry for December 2009 to December 2010 run period;
[u/mrichter/AliRoot.git] / EMCAL / EMCALLEDda.cxx
CommitLineData
07cc7773 1/*
22580691 2 EMCAL DA for online calibration: for LED studies
07cc7773 3
4 Contact: silvermy@ornl.gov
5 Run Type: PHYSICS or STANDALONE
f4fc542c 6 DA Type: MON
22580691 7 Number of events needed: continously accumulating for all runs, rate ~0.1-1 Hz
07cc7773 8 Input Files: argument list
22580691 9 Output Files: RESULT_FILE=EMCALLED.root, to be exported to the DAQ FXS
10 fileId: FILE_ID=EMCALLED
29f94584 11 Trigger types used: CALIBRATION_EVENT
07cc7773 12*/
13/*
14 This process reads RAW data from the files provided as command line arguments
22580691 15 and save results (class itself) in a file (named from RESULT_FILE define -
16 see below).
07cc7773 17*/
18
22580691 19#define RESULT_FILE "EMCALLED.root"
5ea60b80 20#define FILE_ID "signal"
07cc7773 21#define AliDebugLevel() -1
22580691 22#define FILE_SIGClassName "emcCalibSignal"
4d4676b3 23const int kNRCU = 4;
f4fc542c 24/* LOCAL_DEBUG is used to bypass daq* calls that do not work locally */
22580691 25//#define LOCAL_DEBUG 1 // comment out to run normally
07cc7773 26extern "C" {
27#include <daqDA.h>
28}
22580691 29#include "event.h" /* in $DATE_COMMON_DEFS/; includes definition of event types */
30#include "monitor.h" /* in $DATE_MONITOR_DIR/; monitor* interfaces */
07cc7773 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"
32cd4c24 47#include "AliCaloRawStreamV3.h"
f4fc542c 48#include "AliCaloAltroMapping.h"
07cc7773 49#include "AliLog.h"
4f488635 50#include "AliDAQ.h"
07cc7773 51
52//
53// EMC calibration-helper algorithm includes
54//
55#include "AliCaloCalibSignal.h"
56
57/*
f4fc542c 58 Main routine, EMC signal detector algorithm
07cc7773 59 Arguments: list of DATE raw data files
60*/
61
62int main(int argc, char **argv) {
63
32cd4c24 64 AliLog::SetClassDebugLevel("AliCaloRawStreamV3",-5);
07cc7773 65 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
66 AliLog::SetModuleDebugLevel("RAW",-5);
67
68 if (argc<2) {
69 printf("Wrong number of arguments\n");
f4fc542c 70 return -1;
07cc7773 71 }
72
f4fc542c 73 /* magic line - for TStreamerInfo */
74 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
75 "*",
76 "TStreamerInfo",
77 "RIO",
78 "TStreamerInfo()");
b07ee441 79
07cc7773 80 int i, status;
b07ee441 81
07cc7773 82 /* log start of process */
83 printf("EMCAL DA started - %s\n",__FILE__);
b07ee441 84
4f488635 85 Int_t emcID = AliDAQ::DetectorID("EMCAL"); // bit 18..
86
07cc7773 87 /* declare monitoring program */
88 status=monitorDeclareMp( __FILE__ );
89 if (status!=0) {
90 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
91 return -1;
92 }
f4fc542c 93 /* define wait event timeout - 1s max */
94 monitorSetNowait();
95 monitorSetNoWaitNetworkTimeout(1000);
b07ee441 96
f4fc542c 97 /* Retrieve mapping files from DAQ DB */
b07ee441 98 const char* mapFiles[kNRCU] = {"RCU0A.data","RCU1A.data","RCU0C.data","RCU1C.data"};
99
f4fc542c 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;
b07ee441 117 TString side[] = {"A","C"};//+ and - pseudorapidity supermodules
118 for(Int_t j = 0; j < 2; j++){
119 for(Int_t i = 0; i < 2; i++) {
120 path2 = path;
121 path2 += i;
122 path2 += side[j];
123 path2 += ".data";
124 mapping[j*2 + i] = new AliCaloAltroMapping(path2.Data());
125 }
f4fc542c 126 }
b07ee441 127
128 /* Retrieve cut=parameter file from DAQ DB */
129 const char* parameterFile = {"EMCALLEDda.dat"};
130
131 int failed = daqDA_DB_getFile(parameterFile, parameterFile);
132 if (failed) {
133 printf("Cannot retrieve file : %s from DAQ DB. Exit now..\n",
134 parameterFile);
135#ifdef LOCAL_DEBUG
136#else
137 return -1;
138#endif
139 }
140
22580691 141 /* set up our analysis classes */
f4fc542c 142 AliCaloCalibSignal * calibSignal = new AliCaloCalibSignal(AliCaloCalibSignal::kEmCal);
143 calibSignal->SetAltroMapping( mapping );
b07ee441 144 calibSignal->SetParametersFromFile( parameterFile );
145
f4fc542c 146 AliRawReader *rawReader = NULL;
147 int nevents=0;
b07ee441 148
07cc7773 149 /* loop over RAW data files */
07cc7773 150 for ( i=1; i<argc; i++ ) {
b07ee441 151
07cc7773 152 /* define data source : this is argument i */
153 printf("Processing file %s\n", argv[i]);
f4fc542c 154 status=monitorSetDataSource( argv[i] );
155 if (status!=0) {
156 printf("monitorSetDataSource() failed. Error=%s. Exiting ...\n", monitorDecodeError(status));
157 return -1;
158 }
b07ee441 159
07cc7773 160 /* read until EOF */
f4fc542c 161 struct eventHeaderStruct *event;
162 eventTypeType eventT;
4f488635 163
f4fc542c 164 for ( ; ; ) { // infinite loop
b07ee441 165
07cc7773 166 /* check shutdown condition */
167 if (daqDA_checkShutdown()) {break;}
b07ee441 168
f4fc542c 169 /* get next event (blocking call until timeout) */
170 status=monitorGetEventDynamic((void **)&event);
171 if (status==MON_ERR_EOF) {
172 printf ("End of File %d (%s) detected\n", i, argv[i]);
173 break; /* end of monitoring file has been reached */
174 }
175 if (status!=0) {
176 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
177 break;
178 }
b07ee441 179
f4fc542c 180 /* retry if got no event */
181 if (event==NULL) {
182 continue;
183 }
22580691 184 eventT = event->eventType; /* just convenient shorthand */
29f94584 185 /* only look at calibration events */
186 if ( eventT != calibrationEvent ) {
4f488635 187 free(event);
f4fc542c 188 continue;
189 }
b07ee441 190
4f488635 191 /* only look at events where EMCAL was included */
192 if (! TEST_DETECTOR_IN_PATTERN(event->eventDetectorPattern, emcID) ) {
193 free(event);
194 continue;
195 }
196
f4fc542c 197 nevents++; // count how many acceptable events we have
b07ee441 198
f4fc542c 199 // Signal calibration
200 rawReader = new AliRawReaderDate((void*)event);
b07ee441 201 calibSignal->SetRunNumber(event->eventRunNb);
f4fc542c 202 calibSignal->ProcessEvent(rawReader);
203 delete rawReader;
b07ee441 204
f4fc542c 205 /* free resources */
206 free(event);
b07ee441 207
f4fc542c 208 } //until EOF
07cc7773 209 } // loop over files
b07ee441 210
f436ee6d 211 // calculate average values also, for the LED info
212 calibSignal->SetUseAverage(kTRUE);
213 calibSignal->Analyze();
b07ee441 214
f436ee6d 215 // by default, we only save the full info in debug mode
216#ifdef LOCAL_DEBUG
217#else
218 // reset the full trees, when we are not in debug mode
219 calibSignal->GetTreeAmpVsTime()->Reset();
220 calibSignal->GetTreeLEDAmpVsTime()->Reset();
221#endif
b07ee441 222
07cc7773 223 //
224 // write class to rootfile
225 //
b07ee441 226
29f94584 227 printf ("%d calibration events processed.\n",nevents);
b07ee441 228
07cc7773 229 TFile f(RESULT_FILE, "recreate");
230 if (!f.IsZombie()) {
231 f.cd();
22580691 232 calibSignal->Write(FILE_SIGClassName);
07cc7773 233 f.Close();
30aa89b0 234 printf("Objects saved to file \"%s\" as \"%s\".\n",
235 RESULT_FILE, FILE_SIGClassName);
07cc7773 236 }
237 else {
22580691 238 printf("Could not save the object to file \"%s\".\n",
239 RESULT_FILE);
07cc7773 240 }
b07ee441 241
22580691 242 //
243 // closing down; see if we can delete our analysis helper(s) also
244 //
07cc7773 245 delete calibSignal;
f4fc542c 246 for(Int_t iFile=0; iFile<kNRCU; iFile++) {
247 if (mapping[iFile]) delete mapping[iFile];
248 }
b07ee441 249
f4fc542c 250 /* store the result file on FES */
251#ifdef LOCAL_DEBUG
252#else
253 status = daqDA_FES_storeFile(RESULT_FILE, FILE_ID);
254#endif
b07ee441 255
07cc7773 256 return status;
257}