Type narrorwing could get flagged as error, cast properly. From: Lukas Nellen --- Trigger/MiReadout/src/FEFileReadout.cc | 345 ++++++++++++++++---------------- 1 file changed, 174 insertions(+), 171 deletions(-) diff --git a/Trigger/MiReadout/src/FEFileReadout.cc b/Trigger/MiReadout/src/FEFileReadout.cc index 14c6f14..90980b1 100644 --- a/Trigger/MiReadout/src/FEFileReadout.cc +++ b/Trigger/MiReadout/src/FEFileReadout.cc @@ -55,27 +55,27 @@ using FdUtil::TimeConvert; int FEFileReadout::fgPrintLevel = 0; FEFileReadout::FEFileReadout(const char * /* ini_file */,FILE* log_file) - : fEndOfFile(false), fEvent(new TMirrorEvent), + : fEndOfFile(false), fEvent(new TMirrorEvent), fEventFile(NULL), fEventLoaded(false), fEventPtr(NULL), - fLogfile(log_file), + fLogfile(log_file), fRunHeader(NULL), fRunTrailer(NULL), fMode(kFromFile) //fFADCResolution(TFADCData::kFADC_DEFAULT_RESOLUTION), fNFADCBins(0) { VirtualReadout::fColumnList = 0x1fffff; // all modules present - + SetName("FEFileReadout"); - + // -- set the logging stream - + if ( !fLogfile ) fLogfile = stdout; - - fprintf( fLogfile, "Class FEFileReadout sets fColumnList= 0x%x\n", + + fprintf( fLogfile, "Class FEFileReadout sets fColumnList= 0x%x\n", (unsigned int)fColumnList ); fflush( fLogfile ); // --- read the initial parameters from ini-file etc. - + Init(); } @@ -83,25 +83,25 @@ FEFileReadout::FEFileReadout(const char * /* ini_file */,FILE* log_file) FEFileReadout::FEFileReadout(TMirrorEvent **event, const char * /* ini_file */,FILE * log_file) - : fEndOfFile(false), fEvent(NULL), - fEventFile(NULL), fEventLoaded(false), fEventPtr(event), + : fEndOfFile(false), fEvent(NULL), + fEventFile(NULL), fEventLoaded(false), fEventPtr(event), fLogfile(log_file), fMode(kFromEvent) //fFADCResolution(TFADCData::kFADC_DEFAULT_RESOLUTION), fNFADCBins(0) { assert( event != NULL ); VirtualReadout::fColumnList = 0x1fffff; - + // -- set the logging stream - + if ( !fLogfile ) fLogfile = stdout; - - fprintf( fLogfile, "Class FEFileReadout sets fColumnList= 0x%x\n", + + fprintf( fLogfile, "Class FEFileReadout sets fColumnList= 0x%x\n", (unsigned int)fColumnList ); fflush( fLogfile ); // --- read the initial parameters from ini-file etc. - + Init(); } @@ -122,18 +122,18 @@ int FEFileReadout::AcquisitionInit() if ( fgPrintLevel > 2 ) { FD_COUT << "FEFileReadout::AcquisitionInit()" << endl; } - + // already done in ctor ! #if 0 // --- read the initial parameters from ini-file etc. - + Init(); #endif // --- print the parameters - + PrintSettings( FD_LOGSTREAM( FdUtil::ErrorLogger::eInfo ) ); - + return 0; } @@ -144,34 +144,34 @@ int FEFileReadout::AcquisitionStart() if ( fgPrintLevel > 2 ) { FD_COUT << "FEFileReadout::AcquisitionStart()" << endl; } - + // --- re-read initial parameters (-> might be modified by shifters) - + Init(); - + // --- print the parameters - + PrintSettings( FD_LOGSTREAM( FdUtil::ErrorLogger::eInfo ) ); if ( fMode == kFromFile ) { - + // could be a symlink to a real data file - + FD_CINFO << "FEFileReadout::AcquisitionStart() - " << "trying to open " << fDataFilename << " for reading..." - << endl; - + << endl; + fEventFile = new TMirrorEventFile( fDataFilename.c_str() ); if ( fEventFile ) { FD_CWARN << "FEFileReadout::AcquisitionStart() - " << "data file " << fDataFilename << " opened successfuly !" - << endl; + << endl; fprintf( fLogfile, "TMirrorEventFile opened successfuly !\n" ); fflush( fLogfile ); - + // --- no try to read run header and trailer ... if ( fEventFile->ReadRunHeader( &fRunHeader ) != kTRUE ) { @@ -184,7 +184,7 @@ int FEFileReadout::AcquisitionStart() << "Could not find run trailer in file !" << endl; } } - + fEndOfFile = false; fEventLoaded = false; } @@ -192,7 +192,7 @@ int FEFileReadout::AcquisitionStart() fEndOfFile = false; fEventLoaded = true; } - + return 0; } @@ -203,14 +203,14 @@ int FEFileReadout::AcquisitionStop() if ( fgPrintLevel > 2 ) { FD_COUT << "FEFileReadout::AcquisitionStop()" << endl; } - + if ( fMode == kFromFile ) { - + delete fEventFile; fEventFile = NULL; delete fRunHeader; fRunHeader = NULL; delete fRunTrailer; fRunTrailer = NULL; } - + return 0; } @@ -223,7 +223,7 @@ void FEFileReadout::DeleteEvent(FEPageDesc * /* page_desc */) if ( fMode == kFromFile ) { fEventLoaded = false; } - + MEASURE_TIME_STOP(fDeleteEvent); } @@ -232,19 +232,19 @@ void FEFileReadout::DeleteEvent(FEPageDesc * /* page_desc */) void FEFileReadout::FillRunHeader(TMirrorRunHeader* header) { if ( fEventFile ) { - + if ( fRunHeader != NULL ) { - + int option; fRunHeader->GetOption( TMirrorRunHeader::RUNH_OPT_FDHWLIB_VERSION, option ); header->SetOption( TMirrorRunHeader::RUNH_OPT_FDHWLIB_VERSION, option ); - + fRunHeader->GetOption( TMirrorRunHeader::RUNH_OPT_FLT_INTEGRATION_TIME, option ); header->SetOption( TMirrorRunHeader::RUNH_OPT_FLT_INTEGRATION_TIME, option ); fRunHeader->GetOption( TMirrorRunHeader::RUNH_OPT_FLT_STATISTIC_SAMPLES, option ); header->SetOption( TMirrorRunHeader::RUNH_OPT_FLT_STATISTIC_SAMPLES, option ); - + fRunHeader->GetOption( TMirrorRunHeader::RUNH_OPT_FLT_STATISTIC_OFFSET, option ); header->SetOption( TMirrorRunHeader::RUNH_OPT_FLT_STATISTIC_OFFSET, option ); } @@ -267,31 +267,31 @@ void FEFileReadout::FillRunTrailer(TMirrorRunTrailer* trailer) // -------------------------------------------------------------------------- TMirrorEventHeader * -FEFileReadout::GetEventHeader(FEPageDesc *page_desc, +FEFileReadout::GetEventHeader(FEPageDesc *page_desc, TMirrorEventHeader* header) { TMirrorEventHeader * local_header = header; - + MEASURE_TIME_START(fEventHeader); struct timezone tz; struct timeval tv; - + gettimeofday( &tv, &tz ); if ( fMode == kFromEvent ) { fEvent = *fEventPtr; assert( fEvent != NULL ); } - + if ( !local_header ) local_header = fEvent->GetEventHeader(); else *local_header = *fEvent->GetEventHeader(); - + local_header->SetNextPageTime( page_desc->fSecond ); local_header->SetNextPageNanoTime( page_desc->fNanoSecond ); - + MEASURE_TIME_STOP(fEventHeader); return local_header; @@ -299,62 +299,62 @@ FEFileReadout::GetEventHeader(FEPageDesc *page_desc, // -------------------------------------------------------------------------- -TFADCData *FEFileReadout::GetFADCData(FEPageDesc * /* page_desc */, +TFADCData *FEFileReadout::GetFADCData(FEPageDesc * /* page_desc */, TFADCData *fadc) { assert( fadc != NULL ); - + if ( fMode == kFromEvent ) { fEvent = *fEventPtr; assert( fEvent != NULL ); } - - TFADCData *fadc_buffer = + + TFADCData *fadc_buffer = fEvent->GetFADCData()->GetPixelFADCData( fadc->GetPixelNumber() ); // --- copy the data and delete the buffer afterwards - + if ( fadc_buffer ) { - + TFADCData::EFADCTraceResolution res = fadc->GetTraceResolution(); - + while ( fgPrintLevel ) { static bool printed = false; - + if ( printed ) break; - + //FD_CDEBUG(1) << "FEFileReadout::GetFADCData() - " FD_CWARN << "FEFileReadout::GetFADCData() - " - << "default resolution: " << TFADCData::GetDefaultResolution() - << " " << TFADCData::GetNFADCBins( TFADCData::GetDefaultResolution() ) - << " bins" << endl; + << "default resolution: " << TFADCData::GetDefaultResolution() + << " " << TFADCData::GetNFADCBins( TFADCData::GetDefaultResolution() ) + << " bins" << endl; //FD_CDEBUG(1) << "FEFileReadout::GetFADCData() - " FD_CWARN << "FEFileReadout::GetFADCData() - " - << "resolution in file: " << fadc_buffer->GetTraceResolution() - << " " << TFADCData::GetNFADCBins( fadc_buffer->GetTraceResolution() ) - << " bins" << endl; + << "resolution in file: " << fadc_buffer->GetTraceResolution() + << " " << TFADCData::GetNFADCBins( fadc_buffer->GetTraceResolution() ) + << " bins" << endl; //FD_CDEBUG(1) << "FEFileReadout::GetFADCData() - " FD_CWARN << "FEFileReadout::GetFADCData() - " - << "requested resolution: " << res - << " " << TFADCData::GetNFADCBins( res ) - << " bins" << endl; - + << "requested resolution: " << res + << " " << TFADCData::GetNFADCBins( res ) + << " bins" << endl; + printed = true; } - + // set FADC resolution if ( res == TFADCData::kFADC_RESOLUTION_4000_BINS ) { - + FD_CWARN << "FEFileReadout::GetFADCData() - " << "FADC resolution of 4000 is not supported!" << endl; - + res = TFADCData::kFADC_RESOLUTION_2000_BINS; - + fadc->SetTraceResolution( res ); } else fadc->SetTraceResolution( res ); - + if ( res == fadc_buffer->GetTraceResolution() ) { *fadc = *fadc_buffer; } @@ -372,7 +372,7 @@ TFADCData *FEFileReadout::GetFADCData(FEPageDesc * /* page_desc */, else FD_CERR << "FEFileReadout::GetFADCData() - " << "non-existing pixel requested!" << endl; - + return fadc; } @@ -380,14 +380,14 @@ TFADCData *FEFileReadout::GetFADCData(FEPageDesc * /* page_desc */, TFADCData* FEFileReadout::GetFADCData(FEPageDesc *page_desc, FdUtil::Fd::PixelNumber pixel, - TFADCData* fadc) + TFADCData* fadc) { TFADCData::FADCTraceInfoRec info; - + // make sure that the FADCTraceInfo is defined - + if ( fadc == NULL ) { - + // Note: It is assumed that TFADCData::fgDefaultResolution has been set // properly before, which is done in the ctor of this class unsigned int n_fadc_bins = TFADCData::GetNFADCBins( TFADCData::GetDefaultResolution() ); @@ -398,7 +398,7 @@ TFADCData* FEFileReadout::GetFADCData(FEPageDesc *page_desc, } else info = *(fadc->GetTraceInfo()); - + return GetFADCData( page_desc, pixel, &info, fadc ); } @@ -406,8 +406,8 @@ TFADCData* FEFileReadout::GetFADCData(FEPageDesc *page_desc, TFADCData* FEFileReadout::GetFADCData(FEPageDesc *page_desc, FdUtil::Fd::PixelNumber pixel, - TFADCData::FADCTraceInfo info, - TFADCData *fadc) + TFADCData::FADCTraceInfo info, + TFADCData *fadc) { if ( fadc != NULL ) { @@ -420,20 +420,20 @@ TFADCData* FEFileReadout::GetFADCData(FEPageDesc *page_desc, TFADCData * local_fadc = new TFADCData(); if ( local_fadc ) { - + local_fadc->SetPixelNumber( pixel ); local_fadc->SetTraceInfo( info ); - + if ( GetFADCData( page_desc, local_fadc ) == NULL ) { FD_CERR << "FEFileReadout::GetFADCData() - " << "non-existing pixel requested!" << endl; delete local_fadc; - local_fadc = NULL; + local_fadc = NULL; } } - + return local_fadc; // needs to be deleted afterwards } } @@ -451,51 +451,51 @@ void FEFileReadout::GetFADCData(FEPageDesc * /* page_desc */, MEASURE_TIME_START(fFADCReadout); for ( unsigned int n_pixel=0; n_pixelGetNumPixels(); n_pixel++ ) { - + Fd::PixelNumber pixel = pixel_list->GetPixel( n_pixel ); TFADCData *src = fEvent->GetFADCData()->GetPixelFADCData( pixel ); TFADCData *dest = fadc->GetPixelFADCData( pixel ); - + MEASURE_TIME_START(fTraceReadout); assert( src != NULL ); assert( dest != NULL ); - + *dest = *src; - - ExtendedPixelList *ext_pixel_list + + ExtendedPixelList *ext_pixel_list = dynamic_cast( pixel_list ); - - if ( ext_pixel_list != NULL ) { + + if ( ext_pixel_list != NULL ) { dest->SetTraceStartBin( ext_pixel_list->GetStartBin( n_pixel ) ); dest->SetTraceEndBin( ext_pixel_list->GetEndBin( n_pixel ) ); } MEASURE_TIME_STOP(fTraceReadout); - + delete src; delete dest; } - + MEASURE_TIME_STOP(fFADCReadout); } #endif // -------------------------------------------------------------------------- -TFADCData::PixelMonitorData +TFADCData::PixelMonitorData FEFileReadout::GetMonitorData(FEPageDesc * /* page_desc */, - Fd::PixelNumber pixel, - TFADCData::PixelMonitorData data) + Fd::PixelNumber pixel, + TFADCData::PixelMonitorData data) { TFADCData::PixelMonitorData local_data = data; - + if ( fMode == kFromEvent ) { fEvent = *fEventPtr; assert( fEvent != NULL ); } - + MEASURE_TIME_START(fMonitorReadout); if ( !local_data ) @@ -511,34 +511,34 @@ FEFileReadout::GetMonitorData(FEPageDesc * /* page_desc */, // -------------------------------------------------------------------------- TMirrorPixelData * -FEFileReadout::GetPixelData(FEPageDesc * /* page_desc */, +FEFileReadout::GetPixelData(FEPageDesc * /* page_desc */, TMirrorPixelData *pixel_data) { TMirrorPixelData *local_pixel_data = pixel_data; - + MEASURE_TIME_START(fPixelReadout); - + if ( fMode == kFromEvent ) { fEvent = *fEventPtr; assert( fEvent != NULL ); } - + if ( !local_pixel_data ) local_pixel_data = fEvent->GetPixelData(); else *local_pixel_data = *fEvent->GetPixelData(); - + // --- temporary: clear the Ext Trigger bit #warning Ext Trigger bit cleared here ! - + TMirrorPixelData::PixelDataWord pixel_data_ptr = local_pixel_data->GetPixelData(); - + for ( unsigned int i=0; iGetMultiplicityData(); int mult_sum = 0; @@ -548,8 +548,8 @@ FEFileReadout::GetPixelData(FEPageDesc * /* page_desc */, if ( mult_sum == 0 ) { FD_CWARN << "FEFileReadout::GetPixelData() - " << "there are no multiplicity data available, " - << "creating them on-the-fly!" << endl; - + << "creating them on-the-fly!" << endl; + TMirrorPixelData::CreateMultiplicityData( fEvent->GetFADCData(), fEvent->GetPixelList(), v4_mult ); } @@ -558,7 +558,7 @@ FEFileReadout::GetPixelData(FEPageDesc * /* page_desc */, // << "mult_sum= " << mult_sum << endl; MEASURE_TIME_STOP(fPixelReadout); - + return local_pixel_data; } @@ -567,25 +567,25 @@ FEFileReadout::GetPixelData(FEPageDesc * /* page_desc */, void FEFileReadout::Init() { using FdUtil::Inifile; - + // --- initial settings ... - + fDataFilename = "data.root"; fDoLoop = false; fReadDelay = 0; fReadRandom = false; fFileFormat = kMirrorEvent; - + // --- read from ini-file - + FdUtil::Inifile *inifile; - + inifile = ReadoutConfig::GetInstance()->GetInifile(); - + if ( inifile != NULL ) { - + const char *section = "FEFileReadout"; - + if ( inifile->SpecifyGroup( section ) != Inifile::kSUCCESS ) { FD_CERR << "FEFileReadout::Init() - " << "section [" << section << "] not found !!!" << endl; @@ -597,9 +597,9 @@ void FEFileReadout::Init() fDoLoop = (inifile->GetFirstValue( "loop", 0 ) != 0); fReadDelay = inifile->GetFirstValue( "delay", 0 ); fReadRandom = (inifile->GetFirstValue( "random", 0 ) != 0); - + string file_format = inifile->GetFirstString( "format", "mirror" ); - + if ( file_format.find( "mirror" ) != string::npos ) { fFileFormat = kMirrorEvent; } @@ -607,22 +607,22 @@ void FEFileReadout::Init() fFileFormat = kEyeEvent; FD_CWARN << "FEFileReadout::Init() - " - << "[FEFileReadout] format=eye is not supported, yet!" - << endl; + << "[FEFileReadout] format=eye is not supported, yet!" + << endl; FD_CWARN << " using format=mirror instead !" - << endl; + << endl; } else { FD_CWARN << "FEFileReadout::Init() - " - << "[FEFileReadout] format=" << file_format << " is unknown!" - << endl; + << "[FEFileReadout] format=" << file_format << " is unknown!" + << endl; FD_CWARN << " using format=mirror instead !" - << endl; + << endl; } - + int error; int printlevel = inifile->GetFirstValue( "printlevel", 0, &error ); - + if ( !error ) SetPrintLevel( printlevel ); } } @@ -630,8 +630,8 @@ void FEFileReadout::Init() FD_CERR << "FEFileReadout::Init() - no Inifile handle!" << endl; // --- initialize (primitive) random generator - - srand(190463); + + srand(190463); } // -------------------------------------------------------------------------- @@ -641,15 +641,15 @@ void FEFileReadout::PrintSettings(std::ostream& ostr) ostr << endl; ostr << "=== FEFileReadout - settings === " << endl; ostr << endl; - + ostr << "\tfgPrintLevel= " << fgPrintLevel << endl; - + ostr << "\tfDataFilename= " << fDataFilename << endl; ostr << "\tfFileFormat= " << ((fFileFormat == kEyeEvent) ? "eye" : "mirror") << endl; ostr << "\tfDoLoop= " << (fDoLoop ? "true" : "false") << endl; ostr << "\tfReadDelay= " << fReadDelay << " msec" << endl; ostr << "\tfReadRandom= " << (fReadRandom ? "true" : "false") << endl; - + ostr << endl; ostr << "==========================================" << endl; } @@ -663,108 +663,111 @@ FEPageDesc* FEFileReadout::WaitForNextPage() FD_CERR << "FEFileReadout::WaitForNextPage() - no TMirrorEventFile !" << endl; return NULL; } - + static int page_id = 1; static struct timeval tv_last = { 0, 0 }; - static struct timeval tv_delay = { fReadDelay/1000, (fReadDelay * 1000) % 1000000 }; + static struct timeval tv_delay = { + fReadDelay/1000, + static_cast((fReadDelay * 1000) % 1000000) + }; struct timezone tz; struct timeval tv_limit, tv_now; - + FEPageDesc *page_desc = NULL; - + if ( !fEventLoaded && !fEndOfFile ) { - + if ( fReadDelay != 0 ) { // only when set - + if ( tv_last.tv_sec == 0 && tv_last.tv_usec == 0 ) { gettimeofday( &tv_last, &tz ); } else { gettimeofday( &tv_now, &tz ); - + timeradd( &tv_last, &tv_delay, &tv_limit ); - + if ( timercmp( &tv_now, &tv_limit, < ) ) { return NULL; - } - - tv_last = tv_now; + } + + tv_last = tv_now; } } - + if ( fReadRandom ) { unsigned int pos = rand() % fEventFile->GetNEvents(); - + fEventFile->Seek( pos ); fEventLoaded = fEventFile->ReadMirrorEvent( &fEvent ); } else fEventLoaded = fEventFile->ReadMirrorEvent( &fEvent ); - + if ( fEventLoaded ) { - + TMirrorEventHeader * header = fEvent->GetEventHeader(); - - FD_CINFO << "FEFileReadout::WaitForNextPage() - loaded event # " + + FD_CINFO << "FEFileReadout::WaitForNextPage() - loaded event # " << header->GetEventNo() << " " - << TMirrorEventHeader::GetVerboseEventType(header->GetEventType()) - << " " - << TMirrorEventHeader::GetVerboseEventLabel(header->GetEventLabel()) - << " src= 0x" << hex << header->GetTriggerSource() << dec - << endl; - + << TMirrorEventHeader::GetVerboseEventType(header->GetEventType()) + << " " + << TMirrorEventHeader::GetVerboseEventLabel(header->GetEventLabel()) + << " src= 0x" << hex << header->GetTriggerSource() << dec + << endl; + page_desc = new FEPageDesc( page_id ); - + page_id++; // this is just a simulation, doesn't matter really ! if ( page_id > 64 /* FE_PAGES */ ) page_id = 1; - + // need the current time ... - + gettimeofday( &tv_now, &tz ); - + page_desc->fSecond = TimeConvert::GetGPSTime(); page_desc->fNanoSecond = tv_now.tv_usec * 1000; - + page_desc->fPageId = page_id; - + // TimeStampHigh are the seconds page_desc->fNxPgTimeStampHigh = header->GetTimeStampHigh(); // TimeStampLow is a composite binary value page_desc->fNxPgTimeStampLow = header->GetTimeStampLow(); - + page_desc->fTriggerSource = header->GetTriggerSource(); - + page_desc->fTimeStamp = (long long)page_desc->fSecond * 1000000 - + page_desc->fNanoSecond / 1000; - + + page_desc->fNanoSecond / 1000; + page_desc->fDeadTimeCounter = header->GetDeadTimeCounter(); page_desc->fVetoTimeCounter = header->GetVetoTimeCounter(); - + // --- correction for some very old data (with possible hw defect) - + if ( (int)page_desc->fTriggerSource == 0 ) { page_desc->fTriggerSource = TMirrorEventHeader::kUnknownTrigger; - FD_CERR << "FEFileReadout::WaitForNextPage() - trigger src corrected !" - << endl; + FD_CERR << "FEFileReadout::WaitForNextPage() - trigger src corrected !" + << endl; } } else { // end-of-file encountered if ( fDoLoop ) { fEventFile->Rewind(); - - FD_CWARN << "FEFileReadout::WaitForNextPage() - " - << "end of file encountered, rewinding..." << endl; + + FD_CWARN << "FEFileReadout::WaitForNextPage() - " + << "end of file encountered, rewinding..." << endl; } else - + fEndOfFile = true; } } - + return page_desc; }