]>
Commit | Line | Data |
---|---|---|
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" |
21 | #define FILE_ID "EMCALLED" | |
07cc7773 | 22 | #define AliDebugLevel() -1 |
22580691 | 23 | #define FILE_PEDClassName "emcCalibPedestal" |
24 | #define FILE_SIGClassName "emcCalibSignal" | |
f4fc542c | 25 | const int kNRCU = 2; |
26 | /* LOCAL_DEBUG is used to bypass daq* calls that do not work locally */ | |
22580691 | 27 | //#define LOCAL_DEBUG 1 // comment out to run normally |
07cc7773 | 28 | extern "C" { |
29 | #include <daqDA.h> | |
30 | } | |
22580691 | 31 | #include "event.h" /* in $DATE_COMMON_DEFS/; includes definition of event types */ |
32 | #include "monitor.h" /* in $DATE_MONITOR_DIR/; monitor* interfaces */ | |
07cc7773 | 33 | |
34 | #include "stdio.h" | |
35 | #include "stdlib.h" | |
36 | ||
f4fc542c | 37 | // ROOT includes |
38 | #include <TFile.h> | |
39 | #include <TROOT.h> | |
40 | #include <TPluginManager.h> | |
41 | #include <TSystem.h> | |
42 | ||
07cc7773 | 43 | // |
44 | //AliRoot includes | |
45 | // | |
46 | #include "AliRawReader.h" | |
47 | #include "AliRawReaderDate.h" | |
48 | #include "AliRawEventHeaderBase.h" | |
49 | #include "AliCaloRawStream.h" | |
f4fc542c | 50 | #include "AliCaloAltroMapping.h" |
07cc7773 | 51 | #include "AliLog.h" |
52 | ||
53 | // | |
54 | // EMC calibration-helper algorithm includes | |
55 | // | |
22580691 | 56 | #include "AliCaloCalibPedestal.h" |
07cc7773 | 57 | #include "AliCaloCalibSignal.h" |
58 | ||
59 | /* | |
f4fc542c | 60 | Main routine, EMC signal detector algorithm |
07cc7773 | 61 | Arguments: list of DATE raw data files |
62 | */ | |
63 | ||
64 | int main(int argc, char **argv) { | |
65 | ||
66 | AliLog::SetClassDebugLevel("AliCaloRawStream",-5); | |
67 | AliLog::SetClassDebugLevel("AliRawReaderDate",-5); | |
68 | AliLog::SetModuleDebugLevel("RAW",-5); | |
69 | ||
70 | if (argc<2) { | |
71 | printf("Wrong number of arguments\n"); | |
f4fc542c | 72 | return -1; |
07cc7773 | 73 | } |
74 | ||
f4fc542c | 75 | /* magic line - for TStreamerInfo */ |
76 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
77 | "*", | |
78 | "TStreamerInfo", | |
79 | "RIO", | |
80 | "TStreamerInfo()"); | |
81 | ||
07cc7773 | 82 | int i, status; |
83 | ||
84 | /* log start of process */ | |
85 | printf("EMCAL DA started - %s\n",__FILE__); | |
86 | ||
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); | |
96 | ||
97 | /* Retrieve mapping files from DAQ DB */ | |
98 | const char* mapFiles[kNRCU] = {"RCU0.data","RCU1.data"}; | |
99 | ||
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; | |
117 | for(Int_t i = 0; i < kNRCU; i++) { | |
118 | path2 = path; | |
119 | path2 += i; | |
120 | path2 += ".data"; | |
121 | mapping[i] = new AliCaloAltroMapping(path2.Data()); | |
122 | } | |
123 | ||
22580691 | 124 | /* set up our analysis classes */ |
125 | AliCaloCalibPedestal * calibPedestal = new AliCaloCalibPedestal(AliCaloCalibPedestal::kEmCal); | |
126 | calibPedestal->SetAltroMapping( mapping ); | |
f4fc542c | 127 | AliCaloCalibSignal * calibSignal = new AliCaloCalibSignal(AliCaloCalibSignal::kEmCal); |
128 | calibSignal->SetAltroMapping( mapping ); | |
07cc7773 | 129 | |
f4fc542c | 130 | AliRawReader *rawReader = NULL; |
22580691 | 131 | AliRawReader *rawReader2 = NULL; |
f4fc542c | 132 | int nevents=0; |
07cc7773 | 133 | |
134 | /* loop over RAW data files */ | |
07cc7773 | 135 | for ( i=1; i<argc; i++ ) { |
136 | ||
137 | /* define data source : this is argument i */ | |
138 | printf("Processing file %s\n", argv[i]); | |
f4fc542c | 139 | status=monitorSetDataSource( argv[i] ); |
140 | if (status!=0) { | |
141 | printf("monitorSetDataSource() failed. Error=%s. Exiting ...\n", monitorDecodeError(status)); | |
142 | return -1; | |
143 | } | |
07cc7773 | 144 | |
145 | /* read until EOF */ | |
f4fc542c | 146 | struct eventHeaderStruct *event; |
147 | eventTypeType eventT; | |
148 | ||
149 | for ( ; ; ) { // infinite loop | |
07cc7773 | 150 | |
151 | /* check shutdown condition */ | |
152 | if (daqDA_checkShutdown()) {break;} | |
153 | ||
f4fc542c | 154 | /* get next event (blocking call until timeout) */ |
155 | status=monitorGetEventDynamic((void **)&event); | |
156 | if (status==MON_ERR_EOF) { | |
157 | printf ("End of File %d (%s) detected\n", i, argv[i]); | |
158 | break; /* end of monitoring file has been reached */ | |
159 | } | |
160 | if (status!=0) { | |
161 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
162 | break; | |
163 | } | |
164 | ||
165 | /* retry if got no event */ | |
166 | if (event==NULL) { | |
167 | continue; | |
168 | } | |
22580691 | 169 | eventT = event->eventType; /* just convenient shorthand */ |
f4fc542c | 170 | |
171 | /* skip start/end of run events */ | |
172 | if ( (eventT != physicsEvent) && (eventT != calibrationEvent) ) { | |
173 | continue; | |
174 | } | |
175 | ||
176 | nevents++; // count how many acceptable events we have | |
177 | ||
178 | // Signal calibration | |
179 | rawReader = new AliRawReaderDate((void*)event); | |
180 | calibSignal->ProcessEvent(rawReader); | |
181 | delete rawReader; | |
22580691 | 182 | // seems like we need a fresh rawreader for a 2nd read customer(?) |
183 | // otherwise, we have already fast-forwarded past the event(?) | |
184 | rawReader2 = new AliRawReaderDate((void*)event); | |
185 | calibPedestal->ProcessEvent(rawReader2); | |
186 | delete rawReader2; | |
f4fc542c | 187 | |
188 | /* free resources */ | |
189 | free(event); | |
190 | ||
191 | } //until EOF | |
07cc7773 | 192 | } // loop over files |
193 | ||
194 | // | |
195 | // write class to rootfile | |
196 | // | |
197 | ||
198 | printf ("%d physics/calibration events processed.\n",nevents); | |
199 | ||
200 | TFile f(RESULT_FILE, "recreate"); | |
201 | if (!f.IsZombie()) { | |
202 | f.cd(); | |
22580691 | 203 | calibPedestal->Write(FILE_PEDClassName); |
204 | calibSignal->Write(FILE_SIGClassName); | |
07cc7773 | 205 | f.Close(); |
22580691 | 206 | printf("Objects saved to file \"%s\" as \"%s\" and \"%s\".\n", |
207 | RESULT_FILE, FILE_PEDClassName, FILE_SIGClassName); | |
07cc7773 | 208 | } |
209 | else { | |
22580691 | 210 | printf("Could not save the object to file \"%s\".\n", |
211 | RESULT_FILE); | |
07cc7773 | 212 | } |
213 | ||
22580691 | 214 | // |
215 | // closing down; see if we can delete our analysis helper(s) also | |
216 | // | |
217 | delete calibPedestal; | |
07cc7773 | 218 | delete calibSignal; |
f4fc542c | 219 | for(Int_t iFile=0; iFile<kNRCU; iFile++) { |
220 | if (mapping[iFile]) delete mapping[iFile]; | |
221 | } | |
222 | ||
223 | /* store the result file on FES */ | |
224 | #ifdef LOCAL_DEBUG | |
225 | #else | |
226 | status = daqDA_FES_storeFile(RESULT_FILE, FILE_ID); | |
227 | #endif | |
07cc7773 | 228 | |
229 | return status; | |
230 | } |