5 This program connects to the DAQ data source passed as argument
6 and populates local "./result.txt" file with the ids of events received
9 The program exits when being asked to shut down (daqDA_checkshutdown)
12 Messages on stdout are exported to DAQ log system.
14 contact: alice-datesupport@cern.ch
25 #include <Riostream.h>
30 #include "AliTOFRawStream.h"
31 #include "AliRawReaderDate.h"
32 #include "AliTOFGeometry.h"
33 #include "AliTOFGeometryV5.h"
34 #include "AliT0digit.h"
35 #include "AliT0RawReader.h"
42 #include "TBenchmark.h"
48 1- monitoring data source
50 int main(int argc, char **argv) {
52 AliTOFGeometry * geomV5 = new AliTOFGeometryV5();
53 AliTOFGeometry * geom = new AliTOFGeometry();
55 static const Int_t size = geomV5->NPadXSector()*geomV5->NSectors();
56 static const Int_t nbins = 500;
57 static const Int_t binmin = -20;
58 const Float_t c = 2.99792458E10; //speed of light
59 TH1F::AddDirectory(0);
60 TH2S * htofPartial = new TH2S("htof","histo with delays", size,-0.5,size*1.-0.5,nbins,binmin-0.5,nbins*1.+binmin-0.5);
62 TRandom *rand = new TRandom(); //to be used for testing with cosmic data
63 rand->SetSeed(0); //to be used for testing with cosmic data
65 //TTree *tree = 0x0; // tree for T0 decoder
67 // decoding the events
72 printf("Wrong number of arguments\n");
76 /* open result file */
78 fp=fopen("./result.txt","a");
80 printf("Failed to open file\n");
84 /* define data source : this is argument 1 */
85 status=monitorSetDataSource( argv[1] );
87 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
91 /* declare monitoring program */
92 status=monitorDeclareMp( __FILE__ );
94 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
98 /* define wait event timeout - 1s max */
100 monitorSetNoWaitNetworkTimeout(1000);
102 /* log start of process */
103 printf("DA example case2 monitoring program started\n");
105 /* init some counters */
106 int nevents_physics=0;
109 struct equipmentStruct *equipment;
115 struct eventHeaderStruct *event;
116 eventTypeType eventT;
119 /* main loop (infinite) */
122 /* check shutdown condition */
123 if (daqDA_checkShutdown()) {break;}
125 /* get next event (blocking call until timeout) */
126 status=monitorGetEventDynamic((void **)&event);
127 if (status==MON_ERR_EOF) {
128 printf ("End of File detected\n");
129 break; /* end of monitoring file has been reached */
133 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
137 /* retry if got no event */
144 /* use event - here, just write event id to result file */
145 eventT=event->eventType;
146 switch (event->eventType){
151 /* END START OF RUN */
158 printf(" event number = %i \n",iev);
159 //if (iev%10000 ==0) printf(" event number = %i \n",iev);
160 //if (iev > 50000) break;
161 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
162 // rawReader->RequireHeader(kFALSE);
163 //rawReader->LoadEquipmentIdsMap("TOFmap.txt"); //to be used if no exact mapping implemented
167 // TTree *tree = new TTree(); // tree for T0 decoder
168 AliT0RawReader *rawReaderT0 = new AliT0RawReader(rawReader);
169 // printf("rawReaderT0 = %p \n", rawReaderT0);
170 //printf("rawReader = %p \n", rawReader);
171 //printf("event = %p \n", event);
172 // AliT0digit *digit = 0x0;
173 //tree->SetBranchAddress("T0",&digit);
175 if (!rawReaderT0->Next())
176 printf(" no raw data found!! %i", rawReaderT0->Next());
177 Int_t allData[110][5];
178 for (Int_t i=0; i<110; i++) {
179 allData[i][0]=rawReaderT0->GetData(i,0);
181 meantime = allData[49][0];
182 printf("time zero (ns) = %i (%f) \n", meantime, meantime*25*1E-3-200);
188 AliTOFRawStream *rawStreamTOF = new AliTOFRawStream(rawReader);
190 //loop the event data
191 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
193 printf("before T0 \n");
195 while(rawStreamTOF->Next()){
196 for (Int_t ii=0; ii<5; ii++) detectorIndex[ii] = -1;
198 detectorIndex[0] = (Int_t)rawStreamTOF->GetSector();
199 detectorIndex[1] = (Int_t)rawStreamTOF->GetPlate();
200 detectorIndex[2] = (Int_t)rawStreamTOF->GetStrip();
201 detectorIndex[3] = (Int_t)rawStreamTOF->GetPadZ();
202 detectorIndex[4] = (Int_t)rawStreamTOF->GetPadX();
204 if (detectorIndex[0]==-1 ||
205 detectorIndex[1]==-1 ||
206 detectorIndex[2]==-1 ||
207 detectorIndex[3]==-1 ||
208 detectorIndex[4]==-1) continue;
210 Float_t tdc = (Float_t)rawStreamTOF->GetTDC();
211 Int_t tof = (Int_t)rawStreamTOF->GetTofBin();
212 Int_t detID[5]={0,0,0,0,0};
213 detectorIndex[0] = rawStreamTOF->GetSector();
214 detectorIndex[1] = rawStreamTOF->GetPlate();
215 detectorIndex[2] = rawStreamTOF->GetStrip();
216 detectorIndex[3] = rawStreamTOF->GetPadZ();
217 detectorIndex[4] = rawStreamTOF->GetPadX();
218 Int_t index = rawStreamTOF->GetIndex(detectorIndex);
220 geomV5->GetPosPar(detectorIndex,pos);
221 Float_t texp=TMath::Sqrt(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2])/c*1E9; //expected time in ns
222 Float_t texpBin=(texp*1E3-32)/AliTOFGeometry::TdcBinWidth(); //expected time in number of TDC bin
223 //to be uded with cosmics
224 //Float_t tsim = (Float_t)rand->Gaus(texp,1E-1); //TDC measured time in ns, simulated to be used for testing with cosmic data
225 //Float_t delta = tsim-texp;
226 //Int_t deltabin = (Int_t)((delta*1E3-32)/AliTOFGeometry::TdcBinWidth()); //to be used for testing with cosmics data
227 Int_t deltabin = tof-TMath::Nint(texpBin); //to be used with real data; rounding expected time to Int_t
228 htofPartial->Fill(index,deltabin); //channel index start from 0, bin index from 1
229 //debugging printings
230 printf("sector %i, plate %i, strip %i, padz %i, padx %i \n",detectorIndex[0],detectorIndex[1],detectorIndex[2],detectorIndex[3],detectorIndex[4]);
231 //printf("pos x = %f, pos y = %f, pos z = %f \n",pos[0],pos[1],pos[2]);
232 //printf ("expected time = %f (ns)\n",texp);
233 //printf ("expected time bin = %f (TDC bin)\n",texpBin);
234 printf ("measured time bin = %i (TDC bin)\n",tof);
235 // printf("index = %i, deltabin = %i , filling index = %i, and bin = % i\n",index, deltabin, index, deltabin);
250 /* exit when last event received, no need to wait for TERM signal */
251 if (eventT==END_OF_RUN) {
252 printf("EOR event detected\n");
262 //write the Run level file
263 TFile * fileRun = new TFile ("outciccioTOFT0daRun.root","RECREATE");
264 TBenchmark *bench = new TBenchmark();
266 htofPartial->Write();
271 TFile * filetot = new TFile ("outciccioTOFT0daTotal.root","READ");
272 printf("dopo aver aperto il file in modalita' lettura \n");
275 if (!filetot->IsZombie()){
276 printf("il file non e' zombie \n");
277 TIter next(filetot->GetListOfKeys());
279 //look for the histogram
280 while ((key=(TKey*)next())){
281 const char * namekey = key->GetName();
282 if (strcmp(namekey,"htoftot")==0){
283 printf(" histo found \n");
284 htoftot = (TH2S*) filetot->Get("htoftot");
285 htoftot->AddDirectory(0);
286 htoftot->Add(htofPartial);
293 printf(" no file found \n");
294 htoftot = new TH2S(*htofPartial);
295 htoftot->SetName("htoftot");
296 htoftot->AddDirectory(0);
299 filetot = new TFile ("outciccioTOFT0daTotal.root","RECREATE");
317 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
319 /* close result file */