]>
Commit | Line | Data |
---|---|---|
dfd5ff54 | 1 | /* |
2 | CPV GAIN DA for processing physics runs and producing amplitude histograms in every channel for further calibration coefs calulation. | |
3 | ||
4 | Contact: Sergey Evdokimov <sevdokim@cern.ch> | |
5 | Link: https://twiki.cern.ch/twiki/bin/view/ALICE/CPVda | |
6 | Reference run: 214340 (/afs/cern.ch/user/s/sevdokim/public/CPV_run214340_standalone.raw) | |
7 | Run Type: PHYSICS | |
8 | DA Type: MON | |
9 | Number of events needed: 1M events | |
10 | Input files: thr?_??.dat CpvBadMap.root PHOSCPVGAINda.cfg | |
11 | Output files: CpvCalibrSupply.root | |
12 | Trigger types used: PHYSICS_EVENT | |
13 | */ | |
14 | ||
15 | //daqDA | |
16 | #include "event.h" | |
17 | #include "monitor.h" | |
18 | #include "daqDA.h" | |
19 | //AMORE monitoring framework | |
20 | #include <AmoreDA.h> | |
21 | ||
22 | //system | |
23 | #include <Riostream.h> | |
24 | #include <stdlib.h> | |
25 | #include <fstream> | |
26 | #include <string> | |
27 | ||
28 | //AliRoot | |
29 | #include "AliPHOSCpvRawDigiProducer.h" | |
30 | #include "AliPHOSCpvGainCalibDA.h" | |
31 | #include "AliPHOSCpvParam.h" | |
32 | #include "AliRawReaderDate.h" | |
33 | #include "AliBitPacking.h" | |
34 | #include "AliPHOSDigit.h" | |
35 | #include "AliPHOSGeometry.h" | |
36 | ||
37 | //ROOT | |
38 | #include "TROOT.h" | |
39 | #include "TPluginManager.h" | |
40 | #include "TSAXParser.h" | |
41 | #include "TTree.h" | |
42 | #include "TList.h" | |
43 | #include "TMath.h" | |
44 | #include "TString.h" | |
45 | #include "TFile.h" | |
46 | #include "TSystem.h" | |
47 | #include "TKey.h" | |
48 | #include "TH2S.h" | |
49 | #include "TH2F.h" | |
50 | #include "TObject.h" | |
51 | #include "TBenchmark.h" | |
52 | #include "TMath.h" | |
53 | #include "TRandom.h" | |
54 | ||
55 | ||
56 | int main( int argc, char **argv ) | |
57 | { | |
58 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
59 | "*", | |
60 | "TStreamerInfo", | |
61 | "RIO", | |
62 | "TStreamerInfo()"); | |
63 | Int_t status,statusBadCh=0,statusCalibrSupply=0,print; | |
64 | Int_t sigcut=3; | |
65 | Int_t minAmpl = 10;//minimal amplitude for consideration, to be read from DAQ DB | |
66 | Int_t minOccupancy = 100;//min occupancy for publishing in OCDB, to be read from DAQ DB | |
67 | Bool_t turbo = kTRUE; | |
68 | ||
69 | if (argc!=2) { | |
70 | printf("Wrong number of arguments\n"); | |
71 | return -1; | |
72 | } | |
73 | ||
74 | // log start of process | |
75 | printf("Cpv gain calibration DA program started\n"); | |
76 | ||
77 | /* report progress */ | |
78 | daqDA_progressReport(0); | |
79 | ||
80 | /* retrieve configuration file from DAQ DB */ | |
81 | status=daqDA_DB_getFile("PHOSCPVGAINda.cfg", "PHOSCPVGAINda.cfg"); | |
82 | if(!status) { | |
83 | char buf[500]; | |
84 | FILE * fConf = fopen("PHOSCPVGAINda.cfg","r"); | |
85 | while(fgets(buf, 500, fConf)){ | |
86 | if(buf[0]=='#') continue;//comment indicator | |
87 | if(strstr(buf,"minOccupancy")) sscanf(buf,"%*s %d",&minOccupancy); | |
88 | if(strstr(buf,"minAmpl")) sscanf(buf,"%*s %d",&minAmpl); | |
89 | } | |
90 | } | |
91 | ||
92 | ||
93 | /* retrieve pedestal tables from DAQ DB */ | |
94 | for(int iDDL = 0; iDDL<2*AliPHOSCpvParam::kNDDL; iDDL+=2){ | |
95 | if(iDDL!=4) continue; // only one module with DDL=4 by now | |
96 | for (int iCC = 0; iCC<AliPHOSCpvParam::kNRows; iCC++){ | |
97 | status=daqDA_DB_getFile(Form("thr%d_%02d.dat", iDDL, iCC),Form("thr%d_%02d.dat", iDDL, iCC)); | |
98 | if(status!=0) { | |
99 | printf("cannot retrieve file %s from DAQ DB. Exit.\n", Form("thr%d_%02d.dat", iDDL, iCC)); | |
100 | //return -1; | |
101 | } | |
102 | } | |
103 | } | |
104 | ||
105 | /* retrieve Bad Channel Map from DAQ DB */ | |
106 | statusBadCh=daqDA_DB_getFile("CpvBadMap.root", "CpvBadMap.root"); | |
107 | if(statusBadCh!=0) printf("Cannot retrieve file CpvBadMap.root from DAQ DB! Bad channels map will not be used!"); | |
108 | ||
109 | /* retrieve previously collected histograms from DAQ DB */ | |
110 | statusCalibrSupply=daqDA_DB_getFile("CpvCalibrSupply.root", "CpvCalibrSupply.root"); | |
111 | if(statusCalibrSupply!=0) printf("Cannot retrieve file CpvCalibrSupply.root from DAQ DB! No previously collected histograms found!"); | |
112 | ||
113 | /* connecting to raw data */ | |
114 | status=monitorSetDataSource( argv[1] ); | |
115 | if (status!=0) { | |
116 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
117 | return -1; | |
118 | } | |
119 | ||
120 | /* declare monitoring program */ | |
121 | status=monitorDeclareMp( __FILE__ ); | |
122 | if (status!=0) { | |
123 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
124 | return -1; | |
125 | } | |
126 | ||
127 | /* define wait event timeout - 1s max */ | |
128 | monitorSetNowait(); | |
129 | monitorSetNoWaitNetworkTimeout(1000); | |
130 | ||
131 | /* report progress */ | |
132 | daqDA_progressReport(5); | |
133 | ||
134 | ||
135 | // init event counter | |
136 | Int_t iPhysEvnt=0; | |
137 | Int_t iTotEvnt =0; | |
138 | ||
139 | // Reader | |
140 | AliRawReader * reader; | |
141 | ||
142 | //digiProducer | |
143 | AliPHOSCpvRawDigiProducer* digiProducer = new AliPHOSCpvRawDigiProducer(); | |
144 | digiProducer->SetTurbo(turbo); | |
145 | digiProducer->LoadPedFiles(); | |
146 | digiProducer->SetCpvMinAmp(minAmpl); | |
147 | ||
148 | //digits | |
149 | TClonesArray *digits = new TClonesArray("AliPHOSDigit",1); | |
150 | digits->SetName("DIGITS"); | |
151 | ||
152 | //DA object | |
153 | AliPHOSCpvGainCalibDA *fDA = new AliPHOSCpvGainCalibDA(); | |
154 | TFile *fCalibrSupplyRoot=0x0; | |
155 | if(!statusCalibrSupply) fCalibrSupplyRoot = TFile::Open("CpvCalibrSupply.root"); | |
156 | fDA->InitCalibration(fCalibrSupplyRoot); | |
157 | if(fCalibrSupplyRoot)fCalibrSupplyRoot->Close(); | |
158 | if(!statusBadCh)fDA->SetDeadChannelMapFromFile("CpvBadMap.root"); | |
159 | ||
160 | /* report progress */ | |
161 | daqDA_progressReport(10); | |
162 | ||
163 | /* main loop (infinite) */ | |
164 | for(;;) { // infinite loop | |
165 | struct eventHeaderStruct *event; | |
166 | eventTypeType eventT; | |
167 | ||
168 | /* check shutdown condition */ | |
169 | if (daqDA_checkShutdown()) {break;} | |
170 | ||
171 | // get next event | |
172 | status=monitorGetEventDynamic((void **)&event); | |
173 | if (status==MON_ERR_EOF) { // end of monitoring file has been reached | |
174 | printf("End of monitoring file has been reached! \n"); | |
175 | break; | |
176 | } | |
177 | ||
178 | if (status!=0) { | |
179 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
180 | break; | |
181 | } | |
182 | ||
183 | // retry if got no event | |
184 | if (event==NULL) continue; | |
185 | ||
186 | // use event - here, just write event id to result file | |
187 | eventT=event->eventType; | |
188 | if (eventT==PHYSICS_EVENT) { //we use PHYSICS_EVENT for pedestal not CALIBRATION_EVENT??? | |
189 | iTotEvnt++; | |
190 | reader = new AliRawReaderDate((void*)event); | |
191 | digiProducer->LoadNewEvent(reader); | |
192 | digiProducer->MakeDigits(digits); | |
193 | if(digits->GetEntriesFast()>0) iPhysEvnt++; | |
194 | fDA->FillAmplA0Histos(digits); | |
195 | digits->Clear("C"); | |
196 | delete reader; | |
197 | } // if PHYSICS_EVENT | |
198 | ||
199 | free(event); | |
200 | ||
201 | /* exit when last event received, no need to wait for TERM signal */ | |
202 | if (eventT==END_OF_RUN) { | |
203 | printf("EOR event detected\n"); | |
204 | break; | |
205 | } | |
206 | } | |
207 | ||
208 | Printf(" Received %d events, %d good events",iTotEvnt,iPhysEvnt); | |
209 | /* report progress */ | |
210 | daqDA_progressReport(90); | |
211 | ||
212 | /* save collected histos, send files to DBs */ | |
213 | fDA->WriteA0HistosToFile(); | |
214 | ||
215 | //calculate occupancy | |
216 | Double_t Occupancy = 0; | |
217 | TFile* fSave = TFile::Open("CpvCalibrSupply.root"); | |
218 | for(Int_t iDDL = 0;iDDL<2*AliPHOSCpvParam::kNDDL; iDDL+=2){ | |
219 | if(iDDL!=4)continue; | |
220 | if(fSave->Get(Form("hEntriesMap%d",iDDL))){ | |
221 | TH2* hEntries = (TH2*)(fSave->Get(Form("hEntriesMap%d",iDDL))); | |
222 | Occupancy = hEntries->GetEntries()/7680.; | |
223 | } | |
224 | } | |
225 | fSave->Close(); | |
226 | cout<<"Occupancy = "<<Occupancy<<"; minOccupancy = "<<minOccupancy<<endl; | |
227 | if(Occupancy>minOccupancy){//if we have enough statistics to calculate calibration | |
228 | status = daqDA_FES_storeFile("CpvCalibrSupply.root","CpvCalibrSupply.root"); | |
229 | if(status) printf("Failed to store CpvCalibrSupply.root in DAQ FXS!\n"); | |
230 | TFile * fDummy = TFile::Open("dummy.root"); | |
231 | status = daqDA_DB_storeFile("dummy.root","CpvCalibrSupply.root"); | |
232 | if(status) printf("Failed to store dummy.root as CpvCalibrSupply.root in DAQ DB!\n"); | |
233 | } | |
234 | else{//store CpvCalibrSupply.root in DAQ DB for future | |
235 | status = daqDA_DB_storeFile("CpvCalibrSupply.root","CpvCalibrSupply.root"); | |
236 | if(status) printf("Failed to CpvCalibrSupply.root in DAQ DB!\n"); | |
237 | ||
238 | } | |
239 | //send pictures to amore | |
240 | TList* histos = fDA->GetQAHistos(); | |
241 | amore::da::AmoreDA* myAmore = new amore::da::AmoreDA(amore::da::AmoreDA::kSender); | |
242 | Int_t iHist = 0; | |
243 | while(histos->At(iHist)){ | |
244 | myAmore->Send(histos->At(iHist)->GetName(),histos->At(iHist)); | |
245 | iHist++; | |
246 | } | |
247 | ||
248 | /* report progress */ | |
249 | daqDA_progressReport(100); | |
250 | ||
251 | ||
252 | return 0; | |
253 | } |