]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/icepack/iceconvert/IceRawTWR.cxx
21-feb-2007 NvE IceRawTWR.cxx updated to subtract 1 day from the GPS timestamp for all
[u/mrichter/AliRoot.git] / RALICE / icepack / iceconvert / IceRawTWR.cxx
CommitLineData
0cfe76b5 1/*******************************************************************************
2 * Copyright(c) 2003, IceCube Experiment at the South Pole. All rights reserved.
3 *
4 * Author: The IceCube RALICE-based Offline Project.
5 * Contributors are mentioned in the code where appropriate.
6 *
7 * Permission to use, copy, modify and distribute this software and its
8 * documentation strictly for non-commercial purposes is hereby granted
9 * without fee, provided that the above copyright notice appears in all
10 * copies and that both the copyright notice and this permission notice
11 * appear in the supporting documentation.
12 * The authors make no claims about the suitability of this software for
13 * any purpose. It is provided "as is" without express or implied warranty.
14 *******************************************************************************/
15
16// $Id$
17
18///////////////////////////////////////////////////////////////////////////
19// Class IceRawTWR
20// Conversion of Amanda raw TWR data into IceEvent data structures.
21// The code to actually read the TWR raw data structures is an Ralice/IcePack
22// implementation of Wolfgang Wagner's (Dortmund University, Germany)
23// original read_twr_binary_file.cxx and wf2hit_new.cxx source code.
24// The trigger information as encountered in the raw data, is available
25// in the IceEvent structure via a device named "Trigger".
26// The various triggers (and times) have been stored as different "hits"
27// in this "Trigger" device, just like it was done in the IceF2k processor
28// for the mu-daq F2K data.
29// An indication of the active DAQ system is available in the IceEvent structure
30// via a device named "Daq". Here the various daq systems (TWR, Muon, ...)
31// from which the actual hits (ADC, LE, TOT) eventually will be composed
32// are indicated as "signals" of the device itself.
33// This class is derived from AliJob providing a task-based processing
34// structure on an event-by-event basis.
35// The main object in the job environment is an IceEvent* pointer.
36// In case the user has provided sub-tasks, these will be executed
37// on an event-by-event basis after the IceEvent structure has been filled
38// with the raw TWR data and before the final structures are written out.
39// Note that the data structures are only written out if an outputfile has
40// been specified via the SetOutputFile memberfunction.
41// In case no outputfile has been specified, this class provides a facility
42// to investigate/analyse raw TWR data using the Ralice/IcePack analysis tools.
43//
44// Usage example :
45// ---------------
46//
47// gSystem->Load("ralice");
48// gSystem->Load("icepack");
49// gSystem->Load("iceconvert");
50//
51// IceRawTWR q("IceRawTWR","TWR raw data to IcePack data structure conversion");
52//
53// // Limit the number of entries for testing
54// q.SetMaxEvents(10);
55//
56// // Print frequency to produce a short summary print every printfreq events
57// q.SetPrintFreq(1);
58//
59// // The TWR raw data input filename(s)
60// q.AddInputFile("twr_2005_101_009225_0983_57784_57850.dat.twr.to_tape_1");
61//
62// // Output file for the event structures
63// q.SetOutputFile("events.root");
64//
65// ///////////////////////////////////////////////////////////////////
66// // Here the user can specify his/her sub-tasks to be executed
67// // on an event-by-event basis after the IceEvent structure
68// // has been filled and before the data is written out.
69// // Sub-tasks (i.e. a user classes derived from TTask) are entered
70// // as follows :
71// //
72// // MyXtalk task1("task1","Cross talk correction");
73// // MyClean task2("task2","Hit cleaning");
74// // q.Add(&task1);
75// // q.Add(&task2);
76// //
77// // The sub-tasks will be executed in the order as they are entered.
78// ///////////////////////////////////////////////////////////////////
79//
80// // Perform the conversion and execute subtasks (if any)
81// // on an event-by-event basis
82// q.ExecuteJob();
83//
84//--- Author: Nick van Eijndhoven 12-dec-2006 Utrecht University
85//- Modified: NvE $Date$ Utrecht University
86///////////////////////////////////////////////////////////////////////////
87
88#include "IceRawTWR.h"
89#include "Riostream.h"
90
91ClassImp(IceRawTWR) // Class implementation to enable ROOT I/O
92
93IceRawTWR::IceRawTWR(const char* name,const char* title) : AliJob(name,title)
94{
95// Default constructor.
96// By default maxevent=-1, split=0, bsize=32000, printfreq=1.
97
98 fSplit=0;
99 fBsize=32000;
100 fMaxevt=-1;
101 fPrintfreq=1;
102 fInfiles=0;
103 fOutfile=0;
104}
105///////////////////////////////////////////////////////////////////////////
106IceRawTWR::~IceRawTWR()
107{
108// Default destructor.
109
110 if (fInfiles)
111 {
112 delete fInfiles;
113 fInfiles=0;
114 }
115}
116///////////////////////////////////////////////////////////////////////////
117void IceRawTWR::SetMaxEvents(Int_t n)
118{
119// Set the maximum number of events to be processed.
120// n=-1 implies processing of the complete input file, which is the default
121// initialisation in the constructor.
122 fMaxevt=n;
123}
124///////////////////////////////////////////////////////////////////////////
125void IceRawTWR::SetPrintFreq(Int_t f)
126{
127// Set the printfrequency to produce info every f events.
128// f=1 is the default initialisation in the constructor.
129 if (f>=0) fPrintfreq=f;
130}
131///////////////////////////////////////////////////////////////////////////
132void IceRawTWR::SetSplitLevel(Int_t split)
133{
134// Set the split level for the ROOT data file.
135// split=0 is the default initialisation in the constructor.
136 if (split>=0) fSplit=split;
137}
138///////////////////////////////////////////////////////////////////////////
139void IceRawTWR::SetBufferSize(Int_t bsize)
140{
141// Set the buffer size for the ROOT data file.
142// bsize=32000 is the default initialisation in the constructor.
143 if (bsize>=0) fBsize=bsize;
144}
145///////////////////////////////////////////////////////////////////////////
146void IceRawTWR::AddInputFile(TString name)
147{
148// Add the name of this TWR raw data input file to the list to be processed.
149
150 if (!fInfiles)
151 {
152 fInfiles=new TObjArray();
153 fInfiles->SetOwner();
154 }
155
156 TObjString* s=new TObjString();
157 s->SetString(name);
158 fInfiles->Add(s);
159}
160///////////////////////////////////////////////////////////////////////////
161void IceRawTWR::SetOutputFile(TFile* ofile)
162{
163// Set the output file for the ROOT data.
164 if (fOutfile) delete fOutfile;
165 fOutfile=ofile;
166}
167///////////////////////////////////////////////////////////////////////////
168void IceRawTWR::SetOutputFile(TString name)
169{
170// Create the output file for the ROOT data.
171 if (fOutfile) delete fOutfile;
6280c0e2 172 fOutfile=new TFile(name.Data(),"RECREATE","TWR raw data in IceEvent structure");
0cfe76b5 173}
174///////////////////////////////////////////////////////////////////////////
175TFile* IceRawTWR::GetOutputFile()
176{
177// Provide pointer to the ROOT output file.
178 return fOutfile;
179}
180///////////////////////////////////////////////////////////////////////////
181void IceRawTWR::Exec(Option_t* opt)
182{
183// Job to loop over the specified number of events and convert the
184// TWR raw data into the IceEvent structure.
185// If maxevents<0 (default) all the entries of the input file
186// will be processed.
187// Every "printfreq" events a short event summary will be printed.
188// The default value is printfreq=1.
189// The output will be written on a standard output tree named "T".
190//
191// Notes :
192// -------
193// 1) This class is derived from AliJob, allowing a task based processing.
194// After the conversion of a raw data event into an IceEvent structure,
195// the processing of all available sub-tasks (if any) is invoked.
196// This provides an event-by-event (sub)task processing before the
197// final data structures are written out.
198// 2) The main object in this job environment is an IceEvent* pointer.
199
200 if (!fInfiles)
201 {
202 cout << " *IceRawTWR Exec* No data input file(s) specified." << endl;
203 return;
204 }
205
206 Int_t ninfiles=fInfiles->GetEntries();
207 if (!ninfiles)
208 {
209 cout << " *IceRawTWR Exec* No data input file(s) specified." << endl;
210 return;
211 }
212
213 TTree* otree=0;
214 if (fOutfile)
215 {
216 otree=new TTree("T","TWR raw data converted to IceEvent structures");
217 otree->SetDirectory(fOutfile);
218 }
219
220 IceEvent* evt=new IceEvent();
221 evt->SetTrackCopy(1);
222 evt->SetDevCopy(1);
223
224 // Branch in the tree for the event structure
225 if (otree) otree->Branch("IceEvent","IceEvent",&evt,fBsize,fSplit);
226
227 // Initialise the job working environment
228 SetMainObject(evt);
229 if (fOutfile)
230 {
231 AddObject(fOutfile);
232 AddObject(otree);
233 }
234
235 TString inputfile;
236
237 cout << " ***" << endl;
238 cout << " *** Start processing of job " << GetName() << " ***" << endl;
239 cout << " ***" << endl;
240 for (Int_t i=0; i<ninfiles; i++)
241 {
242 TObjString* sx=(TObjString*)fInfiles->At(i);
243 if (!sx) continue;
244 inputfile=sx->GetString();
245 cout << " TWR raw data input file : " << inputfile.Data() << endl;
246 }
247 cout << " Maximum number of events to be processed : " << fMaxevt << endl;
248 cout << " Print frequency : " << fPrintfreq << endl;
249 if (fOutfile)
250 {
251 cout << " ROOT output file : " << fOutfile->GetName() << endl;
252 cout << " Output characteristics : splitlevel = " << fSplit << " buffersize = " << fBsize << endl;
253 }
254
255 ListEnvironment();
256
257 // Storage of the used parameters in the IceRawTWR device
258 AliDevice params;
259 params.SetNameTitle("IceRawTWR","IceRawTWR processor parameters");
260 params.SetSlotName("Nchannels",1);
261 params.SetSlotName("Ntriggers",2);
262 params.SetSlotName("BaselineOffset",3);
263 params.SetSignal(float(N_OF_CHANNELS),1);
264 params.SetSignal(float(N_OF_TRIGGERS),2);
265 params.SetSignal(float(BASELINE_MEAN_MAGIC),3);
266
267 // Set DAQ device info
268 AliDevice daq;
269 daq.SetName("Daq");
270 daq.SetSlotName("TWR",1);
271 daq.SetSignal(1,1);
272
273 twr_raw_data_file_t twr_file;
274 Int_t year,runnum,evtnum;
275
276 Int_t error;
277 UInt_t nhead;
278
279 GPS_t gps;
280 UInt_t gpslow,gpshigh,gpssecs; // The GPS time information
281 Int_t seconds,nsecs; // Seconds and nanoseconds since start of the UT year
282
283 Int_t nevt=0;
284 fHeader=0;
285 for (Int_t ifile=0; ifile<ninfiles; ifile++)
286 {
287 TObjString* sx=(TObjString*)fInfiles->At(ifile);
288 if (!sx) continue;
289
290 inputfile=sx->GetString();
291 if (inputfile=="") continue;
292
293 // Open the TWR raw data input file in binary mode
294 fInput=fopen(inputfile.Data(),"rb");
295
296 if (!fInput)
297 {
298 cout << " *IceRawTWR Exec* No input file found with name : " << inputfile.Data() << endl;
299 continue;
300 }
301
302 // Extract info like run number, file number etc... from filename
303 extract_info_from_filename((char*)inputfile.Data(),&twr_file);
304
305 year=twr_file.year;
306 runnum=twr_file.run_no;
307
308 // Initialise the event structure
309 clear_event(&fEvent);
310
311 // Read the file header information
312 error=read_header_from_file(fInput,&fHeader,&nhead);
313
314 if (error || !nhead)
315 {
316 cout << " *IceRawTWR Exec* Error in header for input file : " << inputfile.Data() << endl;
317 continue;
318 }
319
320 // Correct the mapping
321 update_system(fHeader,runnum);
322
323 while (!read_event(fInput,fHeader,&fEvent))
324 {
325 if (fMaxevt>-1 && nevt>=fMaxevt) break;
326
327 evtnum=fEvent.eventcounter;
328
329 // The GPS telegram info
330 gps=fEvent.gps;
6280c0e2 331 gpslow=gps.seconds & 0x00FFFFFF; // The low 24 bits of the seconds count
332 gpshigh=gps.info.bits.seconds; // The high 8 bits of the seconds count
0cfe76b5 333 gpssecs=gpshigh<<24;
334 gpssecs+=gpslow;
335
45bba4c4 336 cout << " GPS year in hex : " << hex << gps.info.bits.year << dec << endl;
337
0cfe76b5 338 // Seconds and nanoseconds since the start of the UT year
339 seconds=gpssecs;
340 nsecs=100*gps.count_10MHz;
45bba4c4 341
342 // Correction for GPS telegram interpretation in the TWR Daq
343 if (year<2007) seconds-=24*3600;
0cfe76b5 344
345 // Reset the complete Event structure
346 evt->Reset();
347
348 evt->SetRunNumber(runnum);
349 evt->SetEventNumber(evtnum);
350 evt->SetUT(year,0,seconds,nsecs);
351
352 evt->AddDevice(params);
353 evt->AddDevice(daq);
354
355 PutTrigger(year);
356
357 PutWaveforms(year);
358
359 // Invoke all available sub-tasks (if any)
360 CleanTasks();
361 ExecuteTasks(opt);
362
363 if (fPrintfreq)
364 {
365 if (!(nevt%fPrintfreq)) evt->HeaderData();
366 }
367
368 // Write the complete structure to the output Tree
369 if (otree) otree->Fill();
370
371 // Update event counter
372 nevt++;
373
374 // Reset the raw event structure
375 clear_event(&fEvent);
376 } // End of event reading loop
377
378 // Delete the file header structure
379 clear_system(fHeader);
380
381 if (fMaxevt>-1 && nevt>=fMaxevt) break;
382
383 } // End of input file loop
384
385 // Flush possible memory resident data to the output file
386 if (fOutfile) fOutfile->Write();
387
388 // Remove the IceEvent object from the environment
389 // and delete it as well
390 if (evt)
391 {
392 RemoveObject(evt);
393 delete evt;
394 }
395}
396///////////////////////////////////////////////////////////////////////////
397void IceRawTWR::PutWaveforms(Int_t year)
398{
399// Get the waveform info from the raw data event into the IcePack structure.
400
401 IceEvent* evt=(IceEvent*)GetMainObject();
402 if (!evt) return;
403
404 // Loop over all the waveforms and add the histo(s) to the corresponding OM's
405 TH1F histo;
406 Int_t nbins=0;
407 Float_t xlow=0;
408 Float_t xup=0;
409 TString hname;
410 IceAOM om;
411 IceAOM* omx=0;
45bba4c4 412 Int_t twrid;
0cfe76b5 413 Int_t omid;
414 Int_t omidmax=680;
415 Int_t error;
416 Float_t baseline;
417 for (Int_t i=0; i<N_OF_CHANNELS; i++)
418 {
419 if (!fEvent.wfm_filled[i]) continue;
420
45bba4c4 421 twrid=fEvent.twr_id_of_om[i];
422 if (!twrid) continue;
423
424 omid=i+1;
0cfe76b5 425 if (omid<=0 || omid>omidmax) continue; // Skip trigger channels
426
427 // Get corresponding device from the current event structure
428 omx=(IceAOM*)evt->GetIdDevice(omid);
429 if (!omx)
430 {
431 om.Reset(1);
432 om.SetUniqueID(omid);
433 evt->AddDevice(om);
434 omx=(IceAOM*)evt->GetIdDevice(omid);
435 }
436
437 if (!omx) continue;
438
439 clear_waveform_analysis(&fWform);
440 error=restore_waveform(fEvent.wfm[i],&fWform,year);
441
442 if (error) continue;
443
444 baseline=fWform.frag_mean[0];
445
446 hname="BASELINE-WF";
447 hname+=omx->GetNwaveforms()+1;
448 omx->AddNamedSlot(hname);
449 omx->SetSignal(baseline,hname);
450
451 // Fill the waveform histogram
452 hname="OM";
453 hname+=omid;
454 hname+="-WF";
455 hname+=omx->GetNwaveforms()+1;
456
457 histo.Reset();
458 histo.SetName(hname.Data());
459 nbins=fWform.n_point;
460 xlow=fWform.wfm_x[0];
461 xup=fWform.wfm_x[nbins-1];
462 histo.SetBins(nbins,xlow,xup);
463
464 for (Int_t jbin=1; jbin<=nbins; jbin++)
465 {
466 histo.SetBinContent(jbin,baseline-fWform.wfm_y[jbin-1]);
467 }
468
469 omx->SetWaveform(&histo,omx->GetNwaveforms()+1);
470 }
471}
472///////////////////////////////////////////////////////////////////////////
473void IceRawTWR::PutTrigger(Int_t year)
474{
475// Get the trigger info from the raw data event into the IcePack structure.
476// Currently only the trigger settings for the years 2005 and 2006 have been
477// implemented.
478// In addition to the hardware and software triggers as encountered in the
479// raw data, an artificial "main" trigger has been introduced.
480// This artificial "main" trigger is just an "or" of the standard hard and soft
481// triggers (except calibration and random triggers) and serves only to
482// provide a generic "main" trigger a la Amanda mu-daq so that the default
483// "IceCleanHits" hit cleaning procedure will work correctly.
484// The trigger time for the artificial "main" trigger is taken to be the
485// time of the earliest hardware trigger pulse. In case there is no hardware
486// trigger pulse available, the "main" trigger time is set to 0.
487// For other years, only the artificial "main" trigger with a trigger time
488// set to 0 will be stored in the IceEvent structure.
489
490 // Fill the trigger structure
491 Int_t error=retrigger(&fEvent,&fTrigger);
492 if (error) return;
493
494 IceEvent* evt=(IceEvent*)GetMainObject();
495 if (!evt) return;
496
497 AliDevice trig;
498 trig.SetNameTitle("Trigger","Amanda/IceCube event triggers");
499 AliSignal s;
500 Float_t trigtime=0;
501
502 if (year !=2005 && year != 2006)
503 {
504 s.SetName("main");
505 s.SetUniqueID(0);
506 s.SetSlotName("trig_pulse_le",1);
507 s.SetSignal(trigtime,1);
508 trig.AddHit(s);
509 // Store the trigger data into the IceEvent structure
510 evt->AddDevice(trig);
511 return;
512 }
513
514 // Trigger settings for 2005 and 2006
515 if (!fTrigger.n_software_trigger && !fTrigger.n_hardware_trigger) return;
516
517 TString trignames[N_OF_TRIGGERS]={"m24","m18","string","spase","cal-t0","cal-la","m12",
518 "main-logic","main-or","random","m20-frag","volume"};
519 Int_t imain=0;
520 for (Int_t i=0; i<N_OF_TRIGGERS; i++)
521 {
522 if (!fTrigger.trigger_active[i]) continue;
523
524 s.Reset(1);
525 s.SetName(trignames[i]);
526 s.SetUniqueID(i);
527 trigtime=0;
528 if (fTrigger.trigger_has_pulse[i]) trigtime=fTrigger.trigger_time[i];
529 s.SetSlotName("trig_pulse_le",1);
530 s.SetSignal(trigtime,1);
531 trig.AddHit(s);
532 // Set flag to indicate creation of artificial "main" trigger
533 if (i!=4 && i!=5 && i!=9) imain=1;
534 }
535
536 // Set the artificial "main" trigger
537 if (imain)
538 {
539 s.Reset(1);
540 s.SetName("main");
541 s.SetUniqueID(N_OF_TRIGGERS);
542 s.SetSlotName("trig_pulse_le",1);
543 trigtime=0;
544 if (fTrigger.first_trigger>=0) trigtime=fTrigger.first_trigger_time;
545 s.SetSignal(trigtime,1);
546 trig.AddHit(s);
547 }
548
549 // Store the trigger data into the IceEvent structure
550 evt->AddDevice(trig);
551}
552///////////////////////////////////////////////////////////////////////////
553Int_t IceRawTWR::extract_info_from_filename(char* fname,twr_raw_data_file_t* twr_file)
554{
555 char start_str[20],year_str[20],day_str[20],run_no_str[20],
556 file_no_str[20],begin_str[20],end_str[20];
557 char* filename;
558
559 filename = strstr(fname, "twr");
560 if(filename == NULL)
561 if(strncmp("twr_", start_str, 4))
562 {
563 printf("%s\n", filename);
564 return(ERROR_NOT_VALID_FILENAME);
565 }
566
567 strncpy(start_str, filename, 4);
568 if(strncmp("twr_", start_str, 4))
569 {
570 printf("%s %s\n", filename, start_str);
571 return(ERROR_NOT_VALID_FILENAME);
572 }
573 strncpy(year_str, &filename[4], 4);
574 twr_file->year = strtol(year_str, 0, 10);
575
576 if(twr_file->year==2003)
577 {
578 strncpy(day_str, &filename[9], 3);
579 day_str[3] = '\0';
580 twr_file->day = strtol(day_str, 0, 10);
581
582 strncpy(run_no_str, &filename[13], 4);
583 run_no_str[4] = '\0';
584 twr_file->run_no = strtol(run_no_str, 0, 10);
585
586 strncpy(file_no_str, &filename[18], 4);
587 file_no_str[4] = '\0';
588 twr_file->file_no = strtol(file_no_str, 0, 10);
589 }
590
591 if(twr_file->year==2004)
592 {
593 strncpy(day_str, &filename[9], 3);
594 day_str[3] = '\0';
595 twr_file->day = strtol(day_str, 0, 10);
596
597 strncpy(run_no_str, &filename[13], 4);
598 run_no_str[4] = '\0';
599 twr_file->run_no = strtol(run_no_str, 0, 10);
600
601 strncpy(file_no_str, &filename[18], 4);
602 file_no_str[4] = '\0';
603 twr_file->file_no = strtol(file_no_str, 0, 10);
604
605 strncpy(begin_str, &filename[23], 5);
606 begin_str[5] = '\0';
607 twr_file->begin = strtol(begin_str, 0, 10);
608
609 strncpy(end_str, &filename[29], 5);
610 end_str[5] = '\0';
611 twr_file->end = strtol(end_str, 0, 10);
612 }
613
614 if(twr_file->year > 2004)
615 {
616 strncpy(day_str, &filename[9], 3);
617 day_str[3] = '\0';
618 twr_file->day = strtol(day_str, 0, 10);
619
620 strncpy(run_no_str, &filename[13], 6);
621 run_no_str[6] = '\0';
622 twr_file->run_no = strtol(run_no_str, 0, 10);
623
624 strncpy(file_no_str, &filename[20], 4);
625 file_no_str[4] = '\0';
626 twr_file->file_no = strtol(file_no_str, 0, 10);
627
628 strncpy(begin_str, &filename[25], 5);
629 begin_str[5] = '\0';
630 twr_file->begin = strtol(begin_str, 0, 10);
631
632 strncpy(end_str, &filename[31], 5);
633 end_str[5] = '\0';
634 twr_file->end = strtol(end_str, 0, 10);
635 }
636 return(0);
637}
638///////////////////////////////////////////////////////////////////////////
639Int_t IceRawTWR::clear_system(sys_config_t* sys)
640{
641// Deletion of the file header structure.
642
643 if (!sys) return 0;
644
f9556244 645 for(Int_t icrate=0; icrate < int(sys->n_crates); icrate++)
0cfe76b5 646 {
647 if (!sys->crate[icrate]) continue;
f9556244 648 for(Int_t itwr=0; itwr < int(sys->crate[icrate]->n_twr); itwr++)
0cfe76b5 649 {
650 if (sys->crate[icrate]->twr[itwr]) delete sys->crate[icrate]->twr[itwr];
651 }
652 delete sys->crate[icrate];
653 }
654 delete sys;
655 sys=0;
656 return 0;
657}
658///////////////////////////////////////////////////////////////////////////
659Int_t IceRawTWR::clear_event(event_t* event_ptr)
660{
661 Int_t i_value;
662 Int_t *int_ptr = (int*) event_ptr;
663
f9556244 664 for(i_value=0; i_value < int(sizeof(event_t)/sizeof(Int_t)); i_value++)
0cfe76b5 665 {
666 *int_ptr++ = 0;
667 }
668 return(0);
669}
670///////////////////////////////////////////////////////////////////////////
671Int_t IceRawTWR::read_header_from_file(FILE* fin,sys_config_t** system_ptr,UInt_t* header_length)
672{
673 Int_t i_crate, i_twr, i_channel;
674 UInt_t count_twr_in_system = 0;
0cfe76b5 675 UInt_t dummy;
676
677 sys_config_t *sys;
678
679 // allocating memory for sys_config structure
680 sys = (sys_config_t*) malloc( sizeof(sys_config_t) );
681
682 fread(&dummy,sizeof(UInt_t),1,fin); // Header Begin Mark
683
684 fread(header_length,sizeof(UInt_t),1,fin); // Length of header
685 fread(&sys->clockdiv,sizeof(UInt_t),1,fin);
686 fread(&sys->n_crates,sizeof(UInt_t),1,fin);
687
688 if( (sys->n_crates > MAX_N_CRATES) || (sys->n_crates < 0) )
689 return(ERROR_TOO_MANY_CRATES);
690
f9556244 691 for(i_crate=0; i_crate < int(sys->n_crates); i_crate++)
0cfe76b5 692 {
693 sys->crate[i_crate] =
694 (crate_config_t*) malloc( sizeof(crate_config_t) );
695
696 fread(&sys->crate[i_crate]->vme_base_bridge,sizeof(UInt_t),1,fin);
697 fread(&sys->crate[i_crate]->vme_base_100MHz,sizeof(UInt_t),1,fin);
698 fread(&sys->crate[i_crate]->base_gps,sizeof(UInt_t),1,fin);
699 fread(&sys->crate[i_crate]->n_twr,sizeof(UInt_t),1,fin);
700
701 if( (sys->crate[i_crate]->n_twr > MAX_N_TWR_PER_CRATE)
702 || (sys->crate[i_crate]->n_twr < 0) )
703 return(ERROR_TOO_MANY_TWRS);
704
f9556244 705 for(i_twr=0; i_twr < int(sys->crate[i_crate]->n_twr); i_twr++)
0cfe76b5 706 {
707 sys->crate[i_crate]->twr[i_twr] =
708 (twr_config_t*) malloc( sizeof(twr_config_t) );
709 count_twr_in_system++;
710 fread(&sys->crate[i_crate]->twr[i_twr]->base,
711 sizeof(UInt_t),1,fin);
712 fread(&sys->crate[i_crate]->twr[i_twr]->id,
713 sizeof(UInt_t),1,fin);
714
715 sys->crate[i_crate]->twr[i_twr]->id
716 = sys->crate[i_crate]->twr[i_twr]->id - 0x10; /* Correct */
717
718
719 fread(&dummy,sizeof(UInt_t),1,fin); /* stat_reg */
720 fread(&sys->crate[i_crate]->twr[i_twr]->mod_id,
721 sizeof(UInt_t),1,fin);
722 fread(&dummy,sizeof(UInt_t),1,fin); /* acq_ctrl */
723 fread(&sys->crate[i_crate]->twr[i_twr]->ext_start,
724 sizeof(UInt_t),1,fin);
725 fread(&sys->crate[i_crate]->twr[i_twr]->ext_stop,
726 sizeof(UInt_t),1,fin);
727 fread(&dummy,sizeof(UInt_t),1,fin); /* evtconfig */
728
729 for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++)
730 {
731 fread(&sys->crate[i_crate]->twr[i_twr]->om_no[i_channel],
732 sizeof(UInt_t),1,fin);
733 }
734
735 for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++)
736 {
737 fread(&sys->crate[i_crate]->twr[i_twr]->om_is_optical[i_channel],
738 sizeof(UInt_t),1,fin);
739 }
740
741 for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++)
742 {
743 fread(&sys->crate[i_crate]->twr[i_twr]->baseline[i_channel],
744 sizeof(UInt_t),1,fin);
745 }
746
747 for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++)
748 {
749 fread(&sys->crate[i_crate]->twr[i_twr]->threshold[i_channel],
750 sizeof(UInt_t),1,fin);
751 }
752
753 sys->twr_field[(i_crate * 0x10) + i_twr]
754 = sys->crate[i_crate]->twr[i_twr];
755
756 /* Bug fix needed */
757 for(i_channel=0; i_channel < 8; i_channel++)
758 {
759 if( sys->crate[i_crate]->twr[i_twr]->om_no[i_channel] == 9000 )
760 sys->crate[i_crate]->twr[i_twr]->om_no[i_channel]
761 = N_OF_CHANNELS - 1;
762 }
763 }
764 }
765
766 // Set number of TWRs in system
767 sys->n_twr = count_twr_in_system;
768
769 *system_ptr = sys;
770 return(0);
771}
772///////////////////////////////////////////////////////////////////////////
773Int_t IceRawTWR::update_system(sys_config_t* sys,Int_t run_number)
774{
775 Int_t i_crate, i_twr, i_channel;
776
0cfe76b5 777 /* Data for bug fix 1 */
0cfe76b5 778 UInt_t om_no_r1[CHANNELS_PER_TWR]
779 = {111, 112, 113, 114, 115, 116, 39, 118};
780 UInt_t om_is_optical_r1[CHANNELS_PER_TWR]
781 = {0, 0, 0, 0, 0, 0, 0, 0};
782 UInt_t threshold_r1[CHANNELS_PER_TWR]
783 = {50, 50, 50, 50, 50, 50, 80, 50};
784
0cfe76b5 785 UInt_t om_no_r2[CHANNELS_PER_TWR]
786 = {473, 484, 485, 486, 487, 475, 490, 491};
787 UInt_t om_is_optical_r2[CHANNELS_PER_TWR]
788 = {1, 1, 1, 1, 1, 1, 1, 1};
789 UInt_t threshold_r2[CHANNELS_PER_TWR]
790 = {15, 50, 55, 40, 15, 23, 15, 15};
791
792
793 /* Bugfix 1 Andreas Bug */
794
795 /*
796 By accident this TWR was counted twice in TWR.cnf
797 as Crate 0 TWR 7 and Crate 4 TWR 7
798 from run up to run
799 TWR_OM 639 642 1 9 10 11 12 30
800 OPTICAL 0 0 0 0 0 0 0 0
801 TWR_BASELINE 110 120 110 140 150 160 170 180
802 TWR_THRESHOLD 50 50 80 80 80 80 80 80
803
804 Crate 4 TWR 7 should be replaced with this TWR
805 TWR_OM 111 112 113 114 115 116 39 118
806 OPTICAL 0 0 0 0 0 0 0 0
807 TWR_BASELINE 110 120 130 140 150 160 170 180
808 TWR_THRESHOLD 50 50 50 50 50 50 80 50
809 */
810
811 if(
812 (run_number >= 9153 ) /* Begin season 2005 13.2.05 */
813 && (run_number < 9800) /* Timo corrected TWR.cnf on after run ??? */
814 /* Need to find exact date */
815 )
816 {
817 i_crate = 4;
818 i_twr = 7;
819 for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++)
820 {
821 sys->crate[i_crate]->twr[i_twr]->om_no[i_channel]
822 = om_no_r1[i_channel];
823 sys->crate[i_crate]->twr[i_twr]->om_is_optical[i_channel]
824 = om_is_optical_r1[i_channel];
825 sys->crate[i_crate]->twr[i_twr]->threshold[i_channel]
826 = threshold_r1[i_channel];
827 }
828 }
829
830 /* Bugfix 2 Timos Bug */
831
832 /*
833 By accident this TWR was counted twice in TWR.cnf
834 as Crate 0 TWR 1 and Crate 5 TWR b
835 from run 9153 up to run 9188
836
837 TWR_OM 492 493 495 496 497 499 500 501
838 OPTICAL 1 1 1 1 1 1 1 1
839 TWR_BASELINE 110 120 130 140 150 160 170 180
840 TWR_THRESHOLD 16 45 25 42 35 46 15 15
841
842 Crate 5 TWR b should be corrected to
843 TWR_OM 473 484 485 486 487 475 490 491
844 OPTICAL 1 1 1 1 1 1 1 1
845 TWR_BASELINE 4000 120 130 140 150 4000 170 180
846 TWR_THRESHOLD 15 50 55 40 15 23 15 15
847 */
848
849 if(
850 (run_number >= 9153 ) /* Begin season 2005 = Feb 2nd 05 */
851 && (run_number < 9189) /* Timo corrected TWR.cnf on */
852 /* Mar 15th 05 = day 74 after run 9188 */
853 )
854 {
855 i_crate = 5;
856 i_twr = 0xb;
857 for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++)
858 {
859 sys->crate[i_crate]->twr[i_twr]->om_no[i_channel]
860 = om_no_r2[i_channel];
861 sys->crate[i_crate]->twr[i_twr]->om_is_optical[i_channel] =
862 om_is_optical_r2[i_channel];
863 sys->crate[i_crate]->twr[i_twr]->threshold[i_channel] =
864 threshold_r2[i_channel];
865 }
866 }
867 return(0);
868}
869///////////////////////////////////////////////////////////////////////////
870Int_t IceRawTWR::read_event(FILE* fin,sys_config_t* sys,event_t* event_ptr)
871{
f9556244 872 Int_t i_wfm;
873 UInt_t length_of_event_block;
0cfe76b5 874
875 Int_t n_twr, n_of_waveforms_in_event, read_number;
876 UInt_t length_wfm[CHANNELS_PER_TWR];
877 UInt_t dummy, channel_no, om_no, twr_no;
878
879 // Reset waveform filled register
880 memset(&event_ptr->wfm_filled[0], 0, sizeof(UInt_t) * N_OF_CHANNELS);
881
882 if( !fread(&dummy,sizeof(UInt_t),1,fin) ) return(1);
883
884 if(dummy != 0xbbbbbbbb)
885 {
886 printf("Wrong event begin mark %x\n", dummy);
887 while( (dummy !=0xbbbbbbbb)
888 && (fread(&dummy,sizeof(UInt_t),1,fin) != 0) )
889 {;//printf("dummy:%x\n", dummy);
890 }
891 }
892 if( !fread(&length_of_event_block,sizeof(UInt_t),1,fin) ) return(1);
893 if( !fread(&event_ptr->eventcounter,sizeof(UInt_t),1,fin) ) return(1);
894 if( !fread(&event_ptr->which_trigger,sizeof(UInt_t),1,fin) ) return(1);
895 if( !fread(&event_ptr->gps,sizeof(GPS_t),1,fin) ) return(1);
896
897 // --reading waveforms from TWR blocks
898 n_twr = 0;
f9556244 899 while(n_twr < int(sys->n_twr))
0cfe76b5 900 {
901 // --read TWR header
902 if( !fread(&dummy,sizeof(UInt_t),1,fin) ) return(1);
903 if(dummy != 0xffffffff)
904 {printf("Wrong twr begin mark %x\n", dummy); return(2);}
905 if( !fread(&twr_no,sizeof(UInt_t),1,fin) ) return(1);
906
907 // nur voruebergehend !!
908 twr_no -= 0x10;
909
910 if( !fread(&event_ptr->twr[twr_no].timestamp,sizeof(UInt_t),1,fin) )
911 return(1);
912 if( !fread(&n_of_waveforms_in_event,sizeof(UInt_t),1,fin) )
913 return(1);
914 event_ptr->twr[twr_no].n_wfm = n_of_waveforms_in_event;
915
916 for(i_wfm=0; i_wfm < n_of_waveforms_in_event; i_wfm++)
917 {
918 if( !fread(&length_wfm[i_wfm],sizeof(UInt_t),1,fin) ) return(1);
919 }
920
921 // read waveforms
922 for(i_wfm=0; i_wfm < n_of_waveforms_in_event; i_wfm++)
923 {
924 if(length_wfm[i_wfm] != 0)
925 {
926 if( !fread(&channel_no,sizeof(UInt_t),1,fin) ) return(1);
927 if(sys->twr_field[twr_no]->om_no[channel_no]
928 < N_OF_CHANNELS)
929 om_no = sys->twr_field[twr_no]->om_no[channel_no];
930 else
931 om_no = N_OF_CHANNELS-1;
932
933 /* Fix needed */
934
935 event_ptr->twr_id_of_om[om_no] = twr_no;
936
937 read_number = fread(&event_ptr->wfm[om_no],
938 length_wfm[i_wfm]-sizeof(UInt_t),1,fin);
939 event_ptr->wfm_filled[om_no] = 1;
940 if( !read_number ) return(1);
941
942 // read_number correction for usage of fread() instead of read()
943 read_number*=length_wfm[i_wfm]-sizeof(UInt_t);
944
f9556244 945 if( read_number != int(length_wfm[i_wfm]-sizeof(UInt_t)) )
0cfe76b5 946 {
947 cout << " read_number : " << read_number
948 << " length_wfm["<<i_wfm<<"] : " << length_wfm[i_wfm]
949 << " sizeof(UInt_t) : " << sizeof(UInt_t) << endl;
950 return(2);
951 }
952 }
953 }
954 n_twr++;
955 } // end while n_twr
956 return(0);
957}
958///////////////////////////////////////////////////////////////////////////
959Int_t IceRawTWR::retrigger(event_t* ev,trigger_hits_t* trig)
960{
961// Returns the active trigger(s)
962
963 // Initialise the trigger_hits_t structure with zeroes
964 memset(trig, 0, sizeof(trigger_hits_t) );
965
966 // Obtain the software trigger info
967 trig->n_software_trigger=0;
968 for(Int_t itrigger=0; itrigger<N_OF_TRIGGERS; itrigger++)
969 {
970 if(ev->which_trigger & trigger_bits[itrigger])
971 {
972 //printf("SetTrigger %i\n", i_trigger);
973 trig->trigger_active[itrigger]=1;
974 trig->n_software_trigger++;
975 }
976 else
977 {
978 trig->trigger_active[itrigger]=0;
979 }
980 }
981
982 // Obtain the hardware trigger info
983 trig->n_hardware_trigger=0;
984 trig->first_trigger_time=10000000;
985 trig->first_trigger=-1;
986
987 for(Int_t jtrigger=0; jtrigger<N_OF_TRIGGERS; jtrigger++)
988 {
989 if(!trigger_channel[jtrigger]) continue;
990
991 if(ev->wfm_filled[trigger_channel[jtrigger]])
992 {
993 trig->trigger_active[jtrigger]=1;
994 trig->trigger_time[jtrigger]=(ev->wfm[trigger_channel[jtrigger]].value[2] & 0xfff);
995 trig->trigger_has_pulse[jtrigger]=1;
996 if (trig->trigger_time[jtrigger] < trig->first_trigger_time)
997 {
998 trig->first_trigger_time=trig->trigger_time[jtrigger];
999 trig->first_trigger=jtrigger;
1000 }
1001 trig->n_hardware_trigger++;
1002 }
1003 }
1004 return 0;
1005}
1006///////////////////////////////////////////////////////////////////////////
1007Int_t IceRawTWR::clear_waveform_analysis(waveform_analyse_t* wfm_om)
1008{
1009 Int_t i_value, i_frag, i_edge, i_peak;
1010
1011 if(wfm_om == 0) return(1);
1012
1013 // output from analysis
1014 wfm_om->n_frag = 0;
1015 for(i_frag=0; i_frag < MAX_N_OF_FRAGS; i_frag++)
1016 {
1017 wfm_om->frag_n_points[i_frag] = 0;
1018 wfm_om->frag_begin[i_frag] = 0;
1019 wfm_om->frag_end[i_frag] = 0;
1020 wfm_om->frag_mean[i_frag] = 0;
1021 wfm_om->frag_begin_time[i_frag] = 0;
1022 }
1023
1024 wfm_om->n_peak = 0;
1025 for(i_peak=0; i_peak < MAX_N_OF_PEAKS; i_peak++)
1026 {
1027 wfm_om->peak_begin[i_peak] = 0;
1028 wfm_om->peak_end[i_peak] = 0;
1029 wfm_om->peak_max[i_peak] = 0;
1030 wfm_om->peak_TDC_edge[i_peak] = 0;
1031 wfm_om->peak_local_minimum[i_peak] = 0;
1032 wfm_om->crosstalk_charge_n_value[i_peak] = 0;
1033 wfm_om->peak_in_fragment[i_peak] = 0;
1034
1035 wfm_om->peak_mean[i_peak] = 0.0;
1036
1037 wfm_om->peak_m[i_peak] = 0.0;
1038 wfm_om->peak_b[i_peak] = 0.0;
1039 wfm_om->peak_t0[i_peak] = 0.0;
1040 wfm_om->peak_begin_time[i_peak] = 0.0;
1041 wfm_om->peak_charge[i_peak] = 0.0;
1042 wfm_om->peak_height[i_peak] = 0.0;
1043 wfm_om->fitted_amplitude[i_peak] = 0.0;
1044 wfm_om->fitted_TOT[i_peak] = 0.0;
1045 wfm_om->crosstalk_charge[i_peak] = 0.0;
1046 wfm_om->crosstalk_slope[i_peak] = 0.0;
1047 }
1048
1049 wfm_om->n_point = 0;
1050 wfm_om->wfm_min = 4095;
1051 wfm_om->wfm_max = 0;
1052 wfm_om->b_out_of_range = 0;
1053
1054 for(i_value=0; i_value < 1024; i_value++)
1055 {
1056 wfm_om->wfm_x[i_value] = 0;
1057 wfm_om->wfm_y[i_value] = 0;
1058 }
1059
1060 wfm_om->n_tdc_edges = 0;
1061 for(i_edge=0; i_edge < MAX_N_OF_TDC_EDGES; i_edge++)
1062 {
1063 wfm_om->leading_edge[i_edge] = 0.0;
1064 wfm_om->falling_edge[i_edge] = 0.0;
1065 wfm_om->identified_twr_hit[i_edge] = -1;
1066 }
1067
1068 return(0);
1069}
1070///////////////////////////////////////////////////////////////////////////
1071Int_t IceRawTWR::restore_waveform(waveform_t f_wfm,waveform_analyse_t* wfm_om,Int_t year)
1072{
1073 UShort_t wfm_length, mean;
1074 static UShort_t tmp_wf[2000];
1075
1076 Int_t debug = 0;
1077 Int_t fragment_start = 0;
1078 Int_t frag_count = 0; // position in current fragment
1079 Int_t n_position = 0; // position in displayed waveform
1080 UInt_t n_word = 2; // position in featured waveform
1081 Int_t n_fragment = 0; // actual fragment
1082 Int_t b_wrong_value = 0;
1083
1084 UShort_t assumed_frag_begin, last_value; /* bug in eventbuilder */
1085
1086 wfm_om->wfm_min = 4095.0;
1087 wfm_om->wfm_max = 0.0;
1088
1089 if( (f_wfm.value[0] & 0xf000) != 0xf000 ) return(1);
1090 wfm_length = (f_wfm.value[0] & 0xfff)/2;
1091
1092 mean = f_wfm.value[1] + BASELINE_MEAN_MAGIC;
1093 while( ((f_wfm.value[n_word] & 0xf000) == 0x4000) &&
1094 (n_word < wfm_length) &&
1095 (n_fragment < MAX_N_OF_FRAGS) )
1096 {
1097 fragment_start = f_wfm.value[n_word] & 0xfff;
1098 n_word++;
1099 wfm_om->frag_begin_time[n_fragment]
1100 = fragment_start * NSECS_PER_TWR_BIN;
1101 wfm_om->frag_begin[n_fragment] = n_position;
1102 wfm_om->frag_mean[n_fragment] = mean;
1103
1104 b_wrong_value = 0;
1105 frag_count = 0;
1106
1107 while( ((f_wfm.value[n_word] & 0xf000) != 0x2000) &&
1108 ((f_wfm.value[n_word] & 0xf000) != 0x4000) &&/*Reconstructable*/
1109 !b_wrong_value && /* Buggy */
1110 (n_word < wfm_length) )
1111 {
1112 if(year > 2004)
1113 {
1114 /* 2005 2006 data */
1115 if(frag_count == 0)
1116 {
1117 tmp_wf[n_word] = f_wfm.value[n_word] + mean;
1118 wfm_om->wfm_y[n_position] = (float) tmp_wf[n_word];
1119 wfm_om->wfm_x[n_position] = (float)
1120 wfm_om->frag_begin_time[n_fragment]
1121 + (frag_count * NSECS_PER_TWR_BIN);
1122 }
1123 else if(frag_count == 1)
1124 {
1125 tmp_wf[n_word] = f_wfm.value[n_word] + tmp_wf[n_word-1];
1126 wfm_om->wfm_y[n_position] = (float) tmp_wf[n_word];
1127 wfm_om->wfm_x[n_position] = (float)
1128 wfm_om->frag_begin_time[n_fragment]
1129 + (frag_count * NSECS_PER_TWR_BIN);
1130 }
1131 else
1132 {
1133 tmp_wf[n_word] =
1134 2*tmp_wf[n_word-1] + f_wfm.value[n_word];
1135 tmp_wf[n_word] -= tmp_wf[n_word-2];
1136
1137 wfm_om->wfm_y[n_position] = (float) tmp_wf[n_word];
1138 wfm_om->wfm_x[n_position] = (float)
1139 wfm_om->frag_begin_time[n_fragment]
1140 + (frag_count * NSECS_PER_TWR_BIN);
1141 }
1142
1143
1144 /*
1145 Hack for wrongly merged overlapping fragments
1146 */
1147 if(tmp_wf[n_word] > 0x1fff)
1148 {
1149 /* BUG FIXXXX */
1150 /* assume that fragment merge in eventbuilder caused */
1151 /* problem two fragments overlap in EXACTLY ONE point */
1152 /* and are merged first point of the added part of */
1153 /* the fragment is encoded using the former fragment */
1154 /* start as a data point */
1155
1156 last_value = tmp_wf[n_word-1];
1157 assumed_frag_begin = 0x4000 + fragment_start + frag_count;
1158 tmp_wf[n_word] = f_wfm.value[n_word] + 2 * last_value;
1159 tmp_wf[n_word] -= assumed_frag_begin;
1160 wfm_om->wfm_y[n_position] = (float) tmp_wf[n_word];
1161
1162 /* Look if value is still buggy */
1163 if(tmp_wf[n_word] > 0x1fff) b_wrong_value = 1;
1164
1165 debug = ERROR_MISS_FRAG_STOP;
1166 }
1167 } /* end year >= 2005 */
1168 else
1169 {
1170 /* 2003 2004 data */
1171 wfm_om->wfm_y[n_position] = (float) f_wfm.value[n_word];
1172 wfm_om->wfm_x[n_position] = (float)
1173 wfm_om->frag_begin_time[n_fragment]
1174 + (frag_count * NSECS_PER_TWR_BIN);
1175 } /* end year 2003 2004 */
1176
1177 /* Set min and max Y */
1178
1179 if(wfm_om->wfm_y[n_position] > wfm_om->wfm_max)
1180 wfm_om->wfm_max = wfm_om->wfm_y[n_position];
1181 if(wfm_om->wfm_y[n_position] < wfm_om->wfm_min)
1182 wfm_om->wfm_min = wfm_om->wfm_y[n_position];
1183
1184 n_position++;
1185 n_word++;
1186 frag_count++;
1187 }
1188
1189 if((f_wfm.value[n_word] & 0xf000) == 0x2000) /* Normal wavf */
1190 {
1191
1192 wfm_om->frag_end[n_fragment] = n_position - 1;
1193 wfm_om->frag_n_points[n_fragment] =
1194 wfm_om->frag_end[n_fragment]
1195 - wfm_om->frag_begin[n_fragment] + 1;
1196 wfm_om->n_point += wfm_om->frag_n_points[n_fragment];
1197 n_word++;
1198 }
1199 else
1200 return(ERROR_CORRUPTED_WF);
1201
1202 n_fragment++;
1203 } /* end while fragment */
1204
1205
1206 wfm_om->n_frag = n_fragment;
1207 if( !(n_word & 0x1) ) n_word++;
1208
1209 if(n_fragment >= MAX_N_OF_FRAGS) return(ERROR_MAX_N_FRAGMENTS_EXCEEDED);
1210
1211
1212 // Hack to get rid of last value of waveform always set to 0
1213 if (wfm_om->wfm_y[wfm_om->n_point] == 0.0)
1214 {
1215 // erase last point of waveform
1216 wfm_om->n_point--;
1217
1218 // Shorten last pulse if necessary
1219 // if( wfm_om.peak_end[wfm_om.n_peak-1]
1220 // == wfm_om.frag_end[wfm_om.n_frag-1] )
1221 // wfm_om.peak_end[wfm_om.n_peak-1]--;
1222
1223 // Shorten last fragment
1224 wfm_om->frag_n_points[wfm_om->n_frag-1]--;
1225 wfm_om->frag_end[wfm_om->n_frag-1]--;
1226
1227 wfm_om->wfm_min = 4095.0;
1228 wfm_om->wfm_max = 0.0;
1229 for (Int_t i_value=0; i_value < wfm_om->n_point; i_value++)
1230 {
1231 if (wfm_om->wfm_y[i_value] > wfm_om->wfm_max) wfm_om->wfm_max=wfm_om->wfm_y[i_value];
1232 if (wfm_om->wfm_y[i_value] < wfm_om->wfm_min) wfm_om->wfm_min=wfm_om->wfm_y[i_value];
1233 }
1234 }
1235
1236 return(debug);
1237}
1238///////////////////////////////////////////////////////////////////////////