]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | ||
3 | Contact: r.bailhache@gsi.de | |
4 | Link: | |
5 | Reference run: 12170 | |
6 | Run Type: PEDESTAL | |
7 | DA Type: LDC | |
8 | Number of events needed: 100 | |
9 | Input Files: TRD raw files | |
10 | Output Files: trdCalibration.root | |
11 | Trigger types used: PHYSICS_EVENT | |
12 | ||
13 | */ | |
14 | ||
15 | #define RESULT_FILE "trdPedestal.root" | |
16 | #define FILE_ID "PADSTATUS" | |
17 | ||
18 | extern "C" { | |
19 | #include <daqDA.h> | |
20 | } | |
21 | ||
22 | #include "event.h" | |
23 | #include "monitor.h" | |
24 | #include <stdio.h> | |
25 | #include <stdlib.h> | |
26 | ||
27 | // | |
28 | // Root includes | |
29 | // | |
30 | #include <TFile.h> | |
31 | #include <TStopwatch.h> | |
32 | #include "TROOT.h" | |
33 | #include "TPluginManager.h" | |
34 | #include "TSystem.h" | |
35 | // | |
36 | // AliRoot includes | |
37 | // | |
38 | #include "AliRawReader.h" | |
39 | #include "AliRawReaderDate.h" | |
40 | #include "AliTRDrawFastStream.h" | |
41 | #include "AliTRDrawStreamBase.h" | |
42 | #include "AliTRDgeometry.h" | |
43 | #include "AliCDBManager.h" | |
44 | ||
45 | // | |
46 | //AMORE | |
47 | // | |
48 | #include <AmoreDA.h> | |
49 | ||
50 | // | |
51 | // AliRoot TRD calib classes | |
52 | // | |
53 | #include "AliTRDCalibPadStatus.h" | |
54 | ||
55 | //functios, implementation below | |
56 | void SendToAmoreDB(TObject *o, unsigned long32 runNb); | |
57 | ||
58 | /* Main routine | |
59 | Arguments: list of DATE raw data files | |
60 | */ | |
61 | int main(int argc, char **argv) { | |
62 | ||
63 | /* magic line from Rene */ | |
64 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
65 | "*", | |
66 | "TStreamerInfo", | |
67 | "RIO", | |
68 | "TStreamerInfo()"); | |
69 | ||
70 | int status; | |
71 | ||
72 | ||
73 | /* log start of process */ | |
74 | printf("TRD DA PEDESTAL started\n"); | |
75 | ||
76 | ||
77 | /* check that we got some arguments = list of files */ | |
78 | if (argc<2) { | |
79 | printf("Wrong number of arguments\n"); | |
80 | return -1; | |
81 | } | |
82 | ||
83 | ||
84 | /* copy locally a file from daq detector config db */ | |
85 | //status=daqDA_DB_getFile("myconfig","./myconfig.txt"); | |
86 | //if (status) { | |
87 | // printf("Failed to get config file : %d\n",status); | |
88 | // return -1; | |
89 | //} | |
90 | /* and possibly use it */ | |
91 | ||
92 | ||
93 | /* init some counters */ | |
94 | int nevents_total=0; | |
95 | int nevents =0; | |
96 | ||
97 | //Instance of AliCDBManager: needed by AliTRDRawStream | |
98 | //AliCDBManager *man = AliCDBManager::Instance(); | |
99 | //man->SetDefaultStorage("local://$ALICE_ROOT/OCDB"); | |
100 | //man->SetRun(0); | |
101 | // AliTRDCalibPadStatus object | |
102 | AliTRDCalibPadStatus calipad = AliTRDCalibPadStatus(); | |
103 | Bool_t passpadstatus = kTRUE; | |
104 | unsigned long32 runNb=0; //run number | |
105 | ||
106 | // setting | |
107 | AliTRDrawFastStream::DisableSkipData(); | |
108 | ||
109 | ||
110 | /* read the data files */ | |
111 | int n; | |
112 | for (n=1;n<argc;n++) { | |
113 | ||
114 | /* define data source : this is argument i */ | |
115 | printf("Processing file %s\n",argv[n]); | |
116 | status=monitorSetDataSource( argv[n] ); | |
117 | if (status!=0) { | |
118 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
119 | return -1; | |
120 | } | |
121 | ||
122 | /* read the file until EOF */ | |
123 | for(;;) { | |
124 | struct eventHeaderStruct *event; | |
125 | eventTypeType eventT; | |
126 | ||
127 | /* get next event */ | |
128 | status=monitorGetEventDynamic((void **)&event); | |
129 | if (status==MON_ERR_EOF) { | |
130 | printf("End of File %d detected\n",n); | |
131 | break; /* end of monitoring file has been reached */ | |
132 | } | |
133 | if (status!=0) { | |
134 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
135 | break; | |
136 | } | |
137 | ||
138 | /* retry if got no event */ | |
139 | if (event==NULL) { | |
140 | break; | |
141 | } | |
142 | ||
143 | /* use event - here, just write event id to result file */ | |
144 | eventT=event->eventType; | |
145 | ||
146 | if((eventT==PHYSICS_EVENT) && (passpadstatus)){ | |
147 | ||
148 | AliRawReader *rawReader = new AliRawReaderDate((void*)event); | |
149 | rawReader->Select("TRD"); | |
150 | // for debug | |
151 | //rawReader->SelectEquipment(-1,1024,1025); | |
152 | ||
153 | Int_t result = calipad.ProcessEvent2((AliRawReader *) rawReader); | |
154 | // 0 error, 1 no input, 2 output | |
155 | if(result == 2) nevents++; | |
156 | if(result == 0) passpadstatus = kFALSE; | |
157 | delete rawReader; | |
158 | ||
159 | } | |
160 | ||
161 | nevents_total++; | |
162 | ||
163 | // get the run number | |
164 | runNb = event->eventRunNb; | |
165 | ||
166 | /* free resources */ | |
167 | free(event); | |
168 | } | |
169 | } | |
170 | ||
171 | ||
172 | /* report progress */ | |
173 | printf("%d events processed and %d used\n",nevents_total,nevents); | |
174 | ||
175 | /* write file in any case to see what happens in case of problems*/ | |
176 | TFile *fileTRD = new TFile(RESULT_FILE,"recreate"); | |
177 | if(nevents < 30) calipad.Destroy(); | |
178 | calipad.AnalyseHisto(); | |
179 | calipad.Write("calibpadstatus"); | |
180 | fileTRD->Close(); | |
181 | ||
182 | /* Send to amore */ | |
183 | SendToAmoreDB(&calipad,runNb); | |
184 | ||
185 | ||
186 | /* store the result file on FES */ | |
187 | status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID); | |
188 | if (status) { | |
189 | printf("Failed to export file : %d\n",status); | |
190 | return -1; | |
191 | } | |
192 | ||
193 | ||
194 | return status; | |
195 | ||
196 | } | |
197 | void SendToAmoreDB(TObject *calipad, unsigned long32 runNb) | |
198 | { | |
199 | //cheet a little -- temporary solution (hopefully) | |
200 | // | |
201 | //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql | |
202 | //table in which the calib objects are stored. This table is dropped each time AmoreDA | |
203 | //is initialised. This of course makes a problem if we would like to store different | |
204 | //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB | |
205 | //the AMORE_DA_NAME env variable is overwritten. | |
206 | ||
207 | ||
208 | // | |
209 | // The reference data are stored in: | |
210 | // PadStatus1 for sm-00-01-02 | |
211 | // PadStatus2 for sm-03-04-05 | |
212 | // PadStatus3 for sm-06-07-08 | |
213 | // PadStatus4 for sm-09-10-11 | |
214 | // PadStatus5 for sm-12-13-14 | |
215 | // PadStatus6 for sm-15-16-17 | |
216 | // PadStatus0 if nothing found..means problems | |
217 | // | |
218 | ||
219 | /////////////////// | |
220 | // Find wich LDC | |
221 | /////////////////// | |
222 | Int_t ldcnumber = -1; | |
223 | Int_t sm = -1; | |
224 | for (Int_t idet=0; idet<540; idet++) { | |
225 | AliTRDCalROC *rocMean = ((AliTRDCalibPadStatus *) calipad)->GetCalRocMean(idet, kFALSE); | |
226 | if ( rocMean ) { | |
227 | sm = AliTRDgeometry::GetSector(idet); | |
228 | if((sm==0) || (sm==1) || (sm==2)) ldcnumber = 1; | |
229 | if((sm==3) || (sm==4) || (sm==5)) ldcnumber = 2; | |
230 | if((sm==6) || (sm==7) || (sm==8)) ldcnumber = 3; | |
231 | if((sm==9) || (sm==10) || (sm==11)) ldcnumber = 4; | |
232 | if((sm==12) || (sm==13) || (sm==14)) ldcnumber = 5; | |
233 | if((sm==15) || (sm==16) || (sm==17)) ldcnumber = 6; | |
234 | } | |
235 | } | |
236 | const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME"); | |
237 | ||
238 | gSystem->Setenv("AMORE_DA_NAME",Form("TRD-dataQA-%02d-%s",ldcnumber,FILE_ID)); | |
239 | ||
240 | ///////////////////// | |
241 | // Send the stuff | |
242 | //////////////////// | |
243 | if (ldcnumber>-1){ | |
244 | TDatime time; | |
245 | TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString())); | |
246 | ||
247 | amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender); | |
248 | Int_t statusDA=0; | |
249 | statusDA+=amoreDA.Send("Pedestals",calipad); | |
250 | statusDA+=amoreDA.Send("Info",&info); | |
251 | if ( statusDA ) | |
252 | printf("Waring: Failed to write one of the calib objects to the AMORE database\n"); | |
253 | } else { | |
254 | printf("Waring: No data found!\n"); | |
255 | } | |
256 | ||
257 | // reset env var | |
258 | if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig); | |
259 | ||
260 | } | |
261 | ||
262 | ||
263 | ||
264 |