]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/EMCALLEDda.cxx
update from Per Thomas - new classes for NeuralNet and FastFit + code warning fixes
[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
07cc7773 11 Trigger types used: CALIBRATION_EVENT (temporarily also PHYSICS_EVENT to start with)
22580691 12 [When we have real data files later, we should only use CALIBRATION_EVENT]
07cc7773 13*/
14/*
15 This process reads RAW data from the files provided as command line arguments
22580691 16 and save results (class itself) in a file (named from RESULT_FILE define -
17 see below).
07cc7773 18*/
19
22580691 20#define RESULT_FILE "EMCALLED.root"
5ea60b80 21#define FILE_ID "signal"
07cc7773 22#define AliDebugLevel() -1
22580691 23#define FILE_SIGClassName "emcCalibSignal"
4d4676b3 24const int kNRCU = 4;
f4fc542c 25/* LOCAL_DEBUG is used to bypass daq* calls that do not work locally */
22580691 26//#define LOCAL_DEBUG 1 // comment out to run normally
07cc7773 27extern "C" {
28#include <daqDA.h>
29}
22580691 30#include "event.h" /* in $DATE_COMMON_DEFS/; includes definition of event types */
31#include "monitor.h" /* in $DATE_MONITOR_DIR/; monitor* interfaces */
07cc7773 32
33#include "stdio.h"
34#include "stdlib.h"
35
f4fc542c 36// ROOT includes
37#include <TFile.h>
38#include <TROOT.h>
39#include <TPluginManager.h>
40#include <TSystem.h>
41
07cc7773 42//
43//AliRoot includes
44//
45#include "AliRawReader.h"
46#include "AliRawReaderDate.h"
47#include "AliRawEventHeaderBase.h"
32cd4c24 48#include "AliCaloRawStreamV3.h"
f4fc542c 49#include "AliCaloAltroMapping.h"
07cc7773 50#include "AliLog.h"
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
07cc7773 85 /* declare monitoring program */
86 status=monitorDeclareMp( __FILE__ );
87 if (status!=0) {
88 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
89 return -1;
90 }
f4fc542c 91 /* define wait event timeout - 1s max */
92 monitorSetNowait();
93 monitorSetNoWaitNetworkTimeout(1000);
b07ee441 94
f4fc542c 95 /* Retrieve mapping files from DAQ DB */
b07ee441 96 const char* mapFiles[kNRCU] = {"RCU0A.data","RCU1A.data","RCU0C.data","RCU1C.data"};
97
f4fc542c 98 for(Int_t iFile=0; iFile<kNRCU; iFile++) {
99 int failed = daqDA_DB_getFile(mapFiles[iFile], mapFiles[iFile]);
100 if(failed) {
101 printf("Cannot retrieve file %d : %s from DAQ DB. Exit now..\n",
102 iFile, mapFiles[iFile]);
103#ifdef LOCAL_DEBUG
104#else
105 return -1;
106#endif
107 }
108 }
109
110 /* Open mapping files */
111 AliCaloAltroMapping *mapping[kNRCU];
112 TString path = "./";
113 path += "RCU";
114 TString path2;
b07ee441 115 TString side[] = {"A","C"};//+ and - pseudorapidity supermodules
116 for(Int_t j = 0; j < 2; j++){
117 for(Int_t i = 0; i < 2; i++) {
118 path2 = path;
119 path2 += i;
120 path2 += side[j];
121 path2 += ".data";
122 mapping[j*2 + i] = new AliCaloAltroMapping(path2.Data());
123 }
f4fc542c 124 }
b07ee441 125
126 /* Retrieve cut=parameter file from DAQ DB */
127 const char* parameterFile = {"EMCALLEDda.dat"};
128
129 int failed = daqDA_DB_getFile(parameterFile, parameterFile);
130 if (failed) {
131 printf("Cannot retrieve file : %s from DAQ DB. Exit now..\n",
132 parameterFile);
133#ifdef LOCAL_DEBUG
134#else
135 return -1;
136#endif
137 }
138
22580691 139 /* set up our analysis classes */
f4fc542c 140 AliCaloCalibSignal * calibSignal = new AliCaloCalibSignal(AliCaloCalibSignal::kEmCal);
141 calibSignal->SetAltroMapping( mapping );
b07ee441 142 calibSignal->SetParametersFromFile( parameterFile );
143
f4fc542c 144 AliRawReader *rawReader = NULL;
145 int nevents=0;
b07ee441 146
07cc7773 147 /* loop over RAW data files */
07cc7773 148 for ( i=1; i<argc; i++ ) {
b07ee441 149
07cc7773 150 /* define data source : this is argument i */
151 printf("Processing file %s\n", argv[i]);
f4fc542c 152 status=monitorSetDataSource( argv[i] );
153 if (status!=0) {
154 printf("monitorSetDataSource() failed. Error=%s. Exiting ...\n", monitorDecodeError(status));
155 return -1;
156 }
b07ee441 157
07cc7773 158 /* read until EOF */
f4fc542c 159 struct eventHeaderStruct *event;
160 eventTypeType eventT;
b07ee441 161
f4fc542c 162 for ( ; ; ) { // infinite loop
b07ee441 163
07cc7773 164 /* check shutdown condition */
165 if (daqDA_checkShutdown()) {break;}
b07ee441 166
f4fc542c 167 /* get next event (blocking call until timeout) */
168 status=monitorGetEventDynamic((void **)&event);
169 if (status==MON_ERR_EOF) {
170 printf ("End of File %d (%s) detected\n", i, argv[i]);
171 break; /* end of monitoring file has been reached */
172 }
173 if (status!=0) {
174 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
175 break;
176 }
b07ee441 177
f4fc542c 178 /* retry if got no event */
179 if (event==NULL) {
180 continue;
181 }
22580691 182 eventT = event->eventType; /* just convenient shorthand */
b07ee441 183
f4fc542c 184 /* skip start/end of run events */
185 if ( (eventT != physicsEvent) && (eventT != calibrationEvent) ) {
186 continue;
187 }
b07ee441 188
f4fc542c 189 nevents++; // count how many acceptable events we have
b07ee441 190
f4fc542c 191 // Signal calibration
192 rawReader = new AliRawReaderDate((void*)event);
b07ee441 193 calibSignal->SetRunNumber(event->eventRunNb);
f4fc542c 194 calibSignal->ProcessEvent(rawReader);
195 delete rawReader;
b07ee441 196
f4fc542c 197 /* free resources */
198 free(event);
b07ee441 199
f4fc542c 200 } //until EOF
07cc7773 201 } // loop over files
b07ee441 202
f436ee6d 203 // calculate average values also, for the LED info
204 calibSignal->SetUseAverage(kTRUE);
205 calibSignal->Analyze();
b07ee441 206
f436ee6d 207 // by default, we only save the full info in debug mode
208#ifdef LOCAL_DEBUG
209#else
210 // reset the full trees, when we are not in debug mode
211 calibSignal->GetTreeAmpVsTime()->Reset();
212 calibSignal->GetTreeLEDAmpVsTime()->Reset();
213#endif
b07ee441 214
07cc7773 215 //
216 // write class to rootfile
217 //
b07ee441 218
07cc7773 219 printf ("%d physics/calibration events processed.\n",nevents);
b07ee441 220
07cc7773 221 TFile f(RESULT_FILE, "recreate");
222 if (!f.IsZombie()) {
223 f.cd();
22580691 224 calibSignal->Write(FILE_SIGClassName);
07cc7773 225 f.Close();
30aa89b0 226 printf("Objects saved to file \"%s\" as \"%s\".\n",
227 RESULT_FILE, FILE_SIGClassName);
07cc7773 228 }
229 else {
22580691 230 printf("Could not save the object to file \"%s\".\n",
231 RESULT_FILE);
07cc7773 232 }
b07ee441 233
22580691 234 //
235 // closing down; see if we can delete our analysis helper(s) also
236 //
07cc7773 237 delete calibSignal;
f4fc542c 238 for(Int_t iFile=0; iFile<kNRCU; iFile++) {
239 if (mapping[iFile]) delete mapping[iFile];
240 }
b07ee441 241
f4fc542c 242 /* store the result file on FES */
243#ifdef LOCAL_DEBUG
244#else
245 status = daqDA_FES_storeFile(RESULT_FILE, FILE_ID);
246#endif
b07ee441 247
07cc7773 248 return status;
249}