]>
Commit | Line | Data |
---|---|---|
3b5beac9 | 1 | /* |
2 | EMCAL DA for online calibration | |
3 | ||
4 | Contact: silvermy@ornl.gov | |
452729ca | 5 | Run Type: PEDESTAL or PHYSICS or STANDALONE |
f4fc542c | 6 | DA Type: LDC (PEDESTAL), MON (PHYSICS or STANDALONE) |
07cc7773 | 7 | Number of events needed: ~1000 |
3b5beac9 | 8 | Input Files: argument list |
07cc7773 | 9 | Output Files: RESULT_FILE=EMCALCalibPedestal.root, to be exported to the DAQ FXS |
10 | fileId: FILE_ID=EMCALCalibPedestal | |
3b5beac9 | 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 | |
452729ca | 16 | and save results (class itself) in a file (named from RESULT_FILE define - see below). |
3b5beac9 | 17 | */ |
18 | ||
07cc7773 | 19 | #define RESULT_FILE "EMCALCalibPedestal.root" |
20 | #define FILE_ID "EMCALCalibPedestal" | |
3b5beac9 | 21 | #define AliDebugLevel() -1 |
27288fa6 | 22 | #define FILE_ClassName "emcCalibPedestal" |
f4fc542c | 23 | const int kNRCU = 2; |
24 | /* LOCAL_DEBUG is used to bypass daq* calls, for local testing */ | |
25 | // #define LOCAL_DEBUG 1 // comment out to run normally | |
3b5beac9 | 26 | |
27 | extern "C" { | |
28 | #include <daqDA.h> | |
29 | } | |
30 | #include "event.h" | |
31 | #include "monitor.h" | |
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 | ||
3b5beac9 | 42 | // |
43 | //AliRoot includes | |
44 | // | |
45 | #include "AliRawReader.h" | |
46 | #include "AliRawReaderDate.h" | |
47 | #include "AliRawEventHeaderBase.h" | |
48 | #include "AliCaloRawStream.h" | |
f4fc542c | 49 | #include "AliCaloAltroMapping.h" |
3b5beac9 | 50 | #include "AliLog.h" |
51 | ||
52 | // | |
53 | // EMC calibration-helper algorithm includes | |
54 | // | |
55 | #include "AliCaloCalibPedestal.h" | |
56 | ||
57 | /* | |
f4fc542c | 58 | Main routine, EMC pedestal detector algorithm |
3b5beac9 | 59 | Arguments: list of DATE raw data files |
60 | */ | |
61 | ||
62 | int main(int argc, char **argv) { | |
63 | ||
64 | AliLog::SetClassDebugLevel("AliCaloRawStream",-5); | |
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; |
3b5beac9 | 71 | } |
72 | ||
f4fc542c | 73 | /* magic line - for TStreamerInfo */ |
74 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
75 | "*", | |
76 | "TStreamerInfo", | |
77 | "RIO", | |
78 | "TStreamerInfo()"); | |
79 | ||
3b5beac9 | 80 | int i, status; |
81 | ||
82 | /* log start of process */ | |
83 | printf("EMCAL DA started - %s\n",__FILE__); | |
84 | ||
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); | |
94 | ||
95 | /* Retrieve mapping files from DAQ DB */ | |
96 | const char* mapFiles[kNRCU] = {"RCU0.data","RCU1.data"}; | |
97 | ||
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; | |
115 | for(Int_t i = 0; i < kNRCU; i++) { | |
116 | path2 = path; | |
117 | path2 += i; | |
118 | path2 += ".data"; | |
119 | mapping[i] = new AliCaloAltroMapping(path2.Data()); | |
120 | } | |
121 | ||
122 | /* set up our analysis class */ | |
123 | AliCaloCalibPedestal * calibPedestal = new AliCaloCalibPedestal(AliCaloCalibPedestal::kEmCal); // pedestal and noise calibration | |
124 | calibPedestal->SetAltroMapping( mapping ); | |
3b5beac9 | 125 | |
f4fc542c | 126 | AliRawReader *rawReader = NULL; |
127 | int nevents=0; | |
3b5beac9 | 128 | |
129 | /* loop over RAW data files */ | |
3b5beac9 | 130 | for ( i=1; i<argc; i++ ) { |
131 | ||
132 | /* define data source : this is argument i */ | |
133 | printf("Processing file %s\n", argv[i]); | |
f4fc542c | 134 | status=monitorSetDataSource( argv[i] ); |
135 | if (status!=0) { | |
136 | printf("monitorSetDataSource() failed. Error=%s. Exiting ...\n", monitorDecodeError(status)); | |
137 | return -1; | |
138 | } | |
3b5beac9 | 139 | |
140 | /* read until EOF */ | |
f4fc542c | 141 | struct eventHeaderStruct *event; |
142 | eventTypeType eventT; | |
143 | ||
144 | for ( ; ; ) { // infinite loop | |
3b5beac9 | 145 | |
146 | /* check shutdown condition */ | |
147 | if (daqDA_checkShutdown()) {break;} | |
148 | ||
f4fc542c | 149 | /* get next event (blocking call until timeout) */ |
150 | status=monitorGetEventDynamic((void **)&event); | |
151 | if (status==MON_ERR_EOF) { | |
152 | printf ("End of File %d (%s) detected\n", i, argv[i]); | |
153 | break; /* end of monitoring file has been reached */ | |
154 | } | |
155 | if (status!=0) { | |
156 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
157 | break; | |
158 | } | |
159 | ||
160 | /* retry if got no event */ | |
161 | if (event==NULL) { | |
162 | continue; | |
163 | } | |
164 | eventT = event->eventType; // just shorthand | |
165 | ||
166 | /* skip start/end of run events */ | |
167 | if ( (eventT != physicsEvent) && (eventT != calibrationEvent) ) { | |
168 | continue; | |
169 | } | |
170 | ||
171 | nevents++; // count how many acceptable events we have | |
172 | ||
173 | // Pedestal calibration | |
174 | rawReader = new AliRawReaderDate((void*)event); | |
175 | calibPedestal->ProcessEvent(rawReader); | |
176 | delete rawReader; | |
177 | ||
178 | /* free resources */ | |
179 | free(event); | |
180 | ||
181 | } //until EOF | |
3b5beac9 | 182 | } // loop over files |
183 | ||
184 | // | |
452729ca | 185 | // write class to rootfile |
3b5beac9 | 186 | // |
187 | ||
188 | printf ("%d physics/calibration events processed.\n",nevents); | |
452729ca | 189 | |
190 | TFile f(RESULT_FILE, "recreate"); | |
191 | if (!f.IsZombie()) { | |
192 | f.cd(); | |
27288fa6 | 193 | calibPedestal->Write(FILE_ClassName); |
452729ca | 194 | f.Close(); |
27288fa6 | 195 | printf("Object saved to file \"%s\" as \"%s\".\n", RESULT_FILE, FILE_ClassName); |
452729ca | 196 | } |
197 | else { | |
198 | printf("Could not save the object to file \"%s\".\n", RESULT_FILE); | |
199 | } | |
3b5beac9 | 200 | |
3b5beac9 | 201 | // see if we can delete our analysis helper also |
202 | delete calibPedestal; | |
f4fc542c | 203 | for(Int_t iFile=0; iFile<kNRCU; iFile++) { |
204 | if (mapping[iFile]) delete mapping[iFile]; | |
205 | } | |
206 | ||
207 | /* store the result file on FES */ | |
208 | #ifdef LOCAL_DEBUG | |
209 | #else | |
210 | status = daqDA_FES_storeFile(RESULT_FILE, FILE_ID); | |
211 | #endif | |
3b5beac9 | 212 | |
213 | return status; | |
214 | } |