<commit_before>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/*

Adapted from TRD
Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
*/

#include <TClonesArray.h>
#include <TObjArray.h>

#include "AliCDBManager.h"
#include "AliCDBEntry.h"
#include "AliLog.h"

#include "AliEMCALTriggerDCSConfigDB.h"
#include "AliEMCALTriggerDCSConfig.h"
#include "AliEMCALTriggerSTUDCSConfig.h"
#include "AliEMCALTriggerTRUDCSConfig.h"

ClassImp(AliEMCALTriggerDCSConfigDB)

AliEMCALTriggerDCSConfigDB* AliEMCALTriggerDCSConfigDB::fgInstance   = 0;
Bool_t                      AliEMCALTriggerDCSConfigDB::fgTerminated = kFALSE;

//_____________________________________________________________________________
AliEMCALTriggerDCSConfigDB* AliEMCALTriggerDCSConfigDB::Instance()
{
	//
	// Singleton implementation
	// Returns an instance of this class, it is created if neccessary
	//

	if (fgTerminated != kFALSE)
	{
		return 0;
	}

	if (fgInstance == 0)
	{
		fgInstance = new AliEMCALTriggerDCSConfigDB();
	}

	return fgInstance;
}

//_____________________________________________________________________________
void AliEMCALTriggerDCSConfigDB::Terminate()
{
	//
	// Singleton implementation
	// Deletes the instance of this class and sets the terminated flag,
	// instances cannot be requested anymore
	// This function can be called several times.
	//

	fgTerminated = kTRUE;

	if (fgInstance != 0)
	{
		delete fgInstance;
		fgInstance = 0;
	}
}

//_____________________________________________________________________________
AliEMCALTriggerDCSConfigDB::AliEMCALTriggerDCSConfigDB() : TObject()
,fRun(-1)
{
	//
	// Default constructor
	//
	// TODO Default runnumber is set to 0, this should be changed later
	//      to an invalid value (e.g. -1) to prevent
	// TODO invalid calibration data to be used.
	//

	for (Int_t i = 0; i < kCDBCacheSize; ++i)
	{
		fCDBCache[i]   = 0;
		fCDBEntries[i] = 0;
	}
}

//_____________________________________________________________________________
AliEMCALTriggerDCSConfigDB::AliEMCALTriggerDCSConfigDB(const AliEMCALTriggerDCSConfigDB &c) : TObject(c)
,fRun(-1)
{
	//
	// Copy constructor (not that it make any sense for a singleton...)
	//

	for (Int_t i = 0; i < kCDBCacheSize; ++i)
	{
		fCDBCache[i]   = 0;
		fCDBEntries[i] = 0;
	}
}

//_____________________________________________________________________________
AliEMCALTriggerDCSConfigDB &AliEMCALTriggerDCSConfigDB::operator=(const AliEMCALTriggerDCSConfigDB &c)
{
	//
	// Assignment operator (same as above ...)
	//
	if (this != &c)
	{
		AliFatal("No assignment operator defined");
	}

	return *this;
}

//_____________________________________________________________________________
AliEMCALTriggerDCSConfigDB::~AliEMCALTriggerDCSConfigDB()
{
	//
	// destructor
	//
	Invalidate();
}

//_____________________________________________________________________________
const TObject *AliEMCALTriggerDCSConfigDB::GetCachedCDBObject(Int_t id)
{
	//
	// Retrieves a cdb object with the given id. The objects are cached as
	// long as the run number is not changed.
	//
	switch (id)
	{
		// Parameters defined per pad and chamber
		case kIDTriggerConfig :
			return CacheCDBEntry(kIDTriggerConfig, "EMCAL/Calib/Trigger");
			break;
		default:
			AliError("Object not found!");
			break;
	}

	return 0x0;
}

//_____________________________________________________________________________
AliCDBEntry* AliEMCALTriggerDCSConfigDB::GetCDBEntry(const char *cdbPath)
{
	//
	// Retrieves an entry with path <cdbPath> from the CDB.
	//
	AliCDBEntry *entry = AliCDBManager::Instance()->Get(cdbPath,fRun);

	if (!entry)
	{
		AliError(Form("Failed to get entry: %s",cdbPath));
		return 0;
	}

	return entry;
}

//_____________________________________________________________________________
const TObject *AliEMCALTriggerDCSConfigDB::CacheCDBEntry(Int_t id, const char *cdbPath)
{
	//
	// Caches the entry <id> with cdb path <cdbPath>
	//

	if (!fCDBCache[id])
	{
		fCDBEntries[id] = GetCDBEntry(cdbPath);

		if (fCDBEntries[id]) fCDBCache[id] = fCDBEntries[id]->GetObject();
	}

	return fCDBCache[id];
}

//_____________________________________________________________________________
void AliEMCALTriggerDCSConfigDB::SetRun(Long64_t run)
{
  //
  // Sets current run number. Calibration data is read from the corresponding file.
  // When the run number changes the caching is invalidated.
  //

  if (fRun == run) return;

  fRun = run;

  Invalidate();
}

//_____________________________________________________________________________
void AliEMCALTriggerDCSConfigDB::Invalidate()
{
	//
	// Invalidates cache (when run number is changed).
	//
	for (Int_t i = 0; i < kCDBCacheSize; ++i)
	{
		if (fCDBEntries[i])
		{
			if (AliCDBManager::Instance()->GetCacheFlag() == kFALSE)
			{
				if ((fCDBEntries[i]->IsOwner() == kFALSE) && (fCDBCache[i])) delete fCDBCache[i];

				delete fCDBEntries[i];
			}

			fCDBEntries[i] = 0;
			fCDBCache[i]   = 0;
		}
	}
}

//_____________________________________________________________________________
const AliEMCALTriggerDCSConfig* AliEMCALTriggerDCSConfigDB::GetTriggerDCSConfig()
{
	//
	//
	//
	const AliEMCALTriggerDCSConfig* dcsConf = dynamic_cast<const AliEMCALTriggerDCSConfig*>(GetCachedCDBObject(kIDTriggerConfig));

	if (!dcsConf)
	{
		AliError("Trigger DCS configuration not found!");
		return 0x0;
	}
	else
		return dcsConf;
}

//_____________________________________________________________________________
void AliEMCALTriggerDCSConfigDB::GetSTUSegmentation(Int_t ssg[], Int_t spg[], Int_t ssj[], Int_t spj[])
{
	//
	//
	//
	const AliEMCALTriggerDCSConfig* dcsConf = dynamic_cast<const AliEMCALTriggerDCSConfig*>(GetCachedCDBObject(kIDTriggerConfig));
  if(dcsConf){
    AliEMCALTriggerSTUDCSConfig* stuConf = dcsConf->GetSTUDCSConfig();
    if(stuConf){
      Int_t fw = stuConf->GetFw();

      switch ( fw )
      {
        case 2223:
          ssg[0] = 1;
          ssg[1] = 1;
          spg[0] = 2;
          spg[1] = 2;

          ssj[0] = 4;
          ssj[1] = 4;
          spj[0] = 2;
          spj[1] = 2;
          break;
        default:
          AliError("Firmware version do not match!");
          break;
      }
    }
    else {
      AliError("STUDCSConfig is null!");
    }
  }
  else {
    AliError("DCSConfig is null!");
  }

}

//_____________________________________________________________________________
Int_t AliEMCALTriggerDCSConfigDB::GetTRUSegmentation(Int_t iTRU)
{
	//
	const AliEMCALTriggerDCSConfig* dcsConf = dynamic_cast<const AliEMCALTriggerDCSConfig*>(GetCachedCDBObject(kIDTriggerConfig));
  if(dcsConf){
    AliEMCALTriggerTRUDCSConfig* truConf = dcsConf->GetTRUDCSConfig(iTRU);
    if(truConf){
      Int_t sel = truConf->GetL0SEL();

      if (sel & 0x0001)
        return 2;
      else
        return 1;
    } else AliFatal("TRUDCSConf Null!") ;
  }else AliFatal("TriggerDCSConf Null!") ;

  return -1;
}

//_____________________________________________________________________________
Int_t AliEMCALTriggerDCSConfigDB::GetTRUGTHRL0(Int_t iTRU)
{
	//
	//
	//
	const AliEMCALTriggerDCSConfig* dcsConf = dynamic_cast<const AliEMCALTriggerDCSConfig*>(GetCachedCDBObject(kIDTriggerConfig));
  if(dcsConf){
    AliEMCALTriggerTRUDCSConfig* truConf = dcsConf->GetTRUDCSConfig(iTRU);
    if(truConf){
      return truConf->GetGTHRL0();
    } else AliFatal("TRUDCSConf Null!") ;
  }else AliFatal("TriggerDCSConf Null!") ;

  return -1;
}
<commit_msg>Change AliFatal by AliError<commit_after>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/*

Adapted from TRD
Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
*/

#include <TClonesArray.h>
#include <TObjArray.h>

#include "AliCDBManager.h"
#include "AliCDBEntry.h"
#include "AliLog.h"

#include "AliEMCALTriggerDCSConfigDB.h"
#include "AliEMCALTriggerDCSConfig.h"
#include "AliEMCALTriggerSTUDCSConfig.h"
#include "AliEMCALTriggerTRUDCSConfig.h"

ClassImp(AliEMCALTriggerDCSConfigDB)

AliEMCALTriggerDCSConfigDB* AliEMCALTriggerDCSConfigDB::fgInstance   = 0;
Bool_t                      AliEMCALTriggerDCSConfigDB::fgTerminated = kFALSE;

//_____________________________________________________________________________
AliEMCALTriggerDCSConfigDB* AliEMCALTriggerDCSConfigDB::Instance()
{
	//
	// Singleton implementation
	// Returns an instance of this class, it is created if neccessary
	//

	if (fgTerminated != kFALSE)
	{
		return 0;
	}

	if (fgInstance == 0)
	{
		fgInstance = new AliEMCALTriggerDCSConfigDB();
	}

	return fgInstance;
}

//_____________________________________________________________________________
void AliEMCALTriggerDCSConfigDB::Terminate()
{
	//
	// Singleton implementation
	// Deletes the instance of this class and sets the terminated flag,
	// instances cannot be requested anymore
	// This function can be called several times.
	//

	fgTerminated = kTRUE;

	if (fgInstance != 0)
	{
		delete fgInstance;
		fgInstance = 0;
	}
}

//_____________________________________________________________________________
AliEMCALTriggerDCSConfigDB::AliEMCALTriggerDCSConfigDB() : TObject()
,fRun(-1)
{
	//
	// Default constructor
	//
	// TODO Default runnumber is set to 0, this should be changed later
	//      to an invalid value (e.g. -1) to prevent
	// TODO invalid calibration data to be used.
	//

	for (Int_t i = 0; i < kCDBCacheSize; ++i)
	{
		fCDBCache[i]   = 0;
		fCDBEntries[i] = 0;
	}
}

//_____________________________________________________________________________
AliEMCALTriggerDCSConfigDB::AliEMCALTriggerDCSConfigDB(const AliEMCALTriggerDCSConfigDB &c) : TObject(c)
,fRun(-1)
{
	//
	// Copy constructor (not that it make any sense for a singleton...)
	//

	for (Int_t i = 0; i < kCDBCacheSize; ++i)
	{
		fCDBCache[i]   = 0;
		fCDBEntries[i] = 0;
	}
}

//_____________________________________________________________________________
AliEMCALTriggerDCSConfigDB &AliEMCALTriggerDCSConfigDB::operator=(const AliEMCALTriggerDCSConfigDB &c)
{
	//
	// Assignment operator (same as above ...)
	//
	if (this != &c)
	{
		AliFatal("No assignment operator defined");
	}

	return *this;
}

//_____________________________________________________________________________
AliEMCALTriggerDCSConfigDB::~AliEMCALTriggerDCSConfigDB()
{
	//
	// destructor
	//
	Invalidate();
}

//_____________________________________________________________________________
const TObject *AliEMCALTriggerDCSConfigDB::GetCachedCDBObject(Int_t id)
{
	//
	// Retrieves a cdb object with the given id. The objects are cached as
	// long as the run number is not changed.
	//
	switch (id)
	{
		// Parameters defined per pad and chamber
		case kIDTriggerConfig :
			return CacheCDBEntry(kIDTriggerConfig, "EMCAL/Calib/Trigger");
			break;
		default:
			AliError("Object not found!");
			break;
	}

	return 0x0;
}

//_____________________________________________________________________________
AliCDBEntry* AliEMCALTriggerDCSConfigDB::GetCDBEntry(const char *cdbPath)
{
	//
	// Retrieves an entry with path <cdbPath> from the CDB.
	//
	AliCDBEntry *entry = AliCDBManager::Instance()->Get(cdbPath,fRun);

	if (!entry)
	{
		AliError(Form("Failed to get entry: %s",cdbPath));
		return 0;
	}

	return entry;
}

//_____________________________________________________________________________
const TObject *AliEMCALTriggerDCSConfigDB::CacheCDBEntry(Int_t id, const char *cdbPath)
{
	//
	// Caches the entry <id> with cdb path <cdbPath>
	//

	if (!fCDBCache[id])
	{
		fCDBEntries[id] = GetCDBEntry(cdbPath);

		if (fCDBEntries[id]) fCDBCache[id] = fCDBEntries[id]->GetObject();
	}

	return fCDBCache[id];
}

//_____________________________________________________________________________
void AliEMCALTriggerDCSConfigDB::SetRun(Long64_t run)
{
  //
  // Sets current run number. Calibration data is read from the corresponding file.
  // When the run number changes the caching is invalidated.
  //

  if (fRun == run) return;

  fRun = run;

  Invalidate();
}

//_____________________________________________________________________________
void AliEMCALTriggerDCSConfigDB::Invalidate()
{
	//
	// Invalidates cache (when run number is changed).
	//
	for (Int_t i = 0; i < kCDBCacheSize; ++i)
	{
		if (fCDBEntries[i])
		{
			if (AliCDBManager::Instance()->GetCacheFlag() == kFALSE)
			{
				if ((fCDBEntries[i]->IsOwner() == kFALSE) && (fCDBCache[i])) delete fCDBCache[i];

				delete fCDBEntries[i];
			}

			fCDBEntries[i] = 0;
			fCDBCache[i]   = 0;
		}
	}
}

//_____________________________________________________________________________
const AliEMCALTriggerDCSConfig* AliEMCALTriggerDCSConfigDB::GetTriggerDCSConfig()
{
	//
	//
	//
	const AliEMCALTriggerDCSConfig* dcsConf = dynamic_cast<const AliEMCALTriggerDCSConfig*>(GetCachedCDBObject(kIDTriggerConfig));

	if (!dcsConf)
	{
		AliError("Trigger DCS configuration not found!");
		return 0x0;
	}
	else
		return dcsConf;
}

//_____________________________________________________________________________
void AliEMCALTriggerDCSConfigDB::GetSTUSegmentation(Int_t ssg[], Int_t spg[], Int_t ssj[], Int_t spj[])
{
	//
	//
	//
	const AliEMCALTriggerDCSConfig* dcsConf = dynamic_cast<const AliEMCALTriggerDCSConfig*>(GetCachedCDBObject(kIDTriggerConfig));
  if(dcsConf){
    AliEMCALTriggerSTUDCSConfig* stuConf = dcsConf->GetSTUDCSConfig();
    if(stuConf){
      Int_t fw = stuConf->GetFw();

      switch ( fw )
      {
        case 2223:
          ssg[0] = 1;
          ssg[1] = 1;
          spg[0] = 2;
          spg[1] = 2;

          ssj[0] = 4;
          ssj[1] = 4;
          spj[0] = 2;
          spj[1] = 2;
          break;
        default:
          AliError("Firmware version do not match!");
          break;
      }
    }
    else {
      AliError("STUDCSConfig is null!");
    }
  }
  else {
    AliError("DCSConfig is null!");
  }

}

//_____________________________________________________________________________
Int_t AliEMCALTriggerDCSConfigDB::GetTRUSegmentation(Int_t iTRU)
{
	//
	const AliEMCALTriggerDCSConfig* dcsConf = dynamic_cast<const AliEMCALTriggerDCSConfig*>(GetCachedCDBObject(kIDTriggerConfig));
  if(dcsConf){
    AliEMCALTriggerTRUDCSConfig* truConf = dcsConf->GetTRUDCSConfig(iTRU);
    if(truConf){
      Int_t sel = truConf->GetL0SEL();

      if (sel & 0x0001)
        return 2;
      else
        return 1;
    } else AliError("TRUDCSConf Null!") ;
  }else AliError("TriggerDCSConf Null!") ;

  return -1;
}

//_____________________________________________________________________________
Int_t AliEMCALTriggerDCSConfigDB::GetTRUGTHRL0(Int_t iTRU)
{
	//
	//
	//
	const AliEMCALTriggerDCSConfig* dcsConf = dynamic_cast<const AliEMCALTriggerDCSConfig*>(GetCachedCDBObject(kIDTriggerConfig));
  if(dcsConf){
    AliEMCALTriggerTRUDCSConfig* truConf = dcsConf->GetTRUDCSConfig(iTRU);
    if(truConf){
      return truConf->GetGTHRL0();
    } else AliError("TRUDCSConf Null!") ;
  }else AliError("TriggerDCSConf Null!") ;

  return -1;
}
<|endoftext|>


<commit_before>#include <stingray/toolkit/Factory.h>

#include <stingray/toolkit/any.h>

#include <stingray/app/PushVideoOnDemand.h>
#include <stingray/app/application_context/AppChannel.h>
#include <stingray/app/application_context/ChannelList.h>
#include <stingray/app/scheduler/ScheduledEvents.h>
#include <stingray/app/tests/AutoFilter.h>
#include <stingray/app/zapper/User.h>
#include <stingray/ca/BasicSubscription.h>
#include <stingray/crypto/PlainCipherKey.h>
#include <stingray/hdmi/IHDMI.h>
#include <stingray/media/ImageFileMediaData.h>
#include <stingray/media/MediaInfoBase.h>
#include <stingray/media/Mp3MediaInfo.h>
#include <stingray/media/formats/flv/MediaInfo.h>
#include <stingray/media/formats/mp4/MediaInfo.h>
#include <stingray/media/formats/mp4/Stream.h>
#include <stingray/media/formats/mp4/StreamDescriptors.h>
#include <stingray/mpeg/Stream.h>
#include <stingray/net/DHCPInterfaceConfiguration.h>
#include <stingray/net/IgnoredInterfaceConfiguration.h>
#include <stingray/net/LinkLocalInterfaceConfiguration.h>
#include <stingray/net/ManualInterfaceConfiguration.h>
#include <stingray/parentalcontrol/AgeRating.h>
#ifdef PLATFORM_EMU
#	include <stingray/platform/emu/scanner/Channel.h>
#endif
#ifdef PLATFORM_MSTAR
#	include <stingray/platform/mstar/crypto/HardwareCipherKey.h>
#endif
#ifdef PLATFORM_OPENSSL
#	include <stingray/platform/openssl/crypto/Certificate.h>
#endif
#ifdef PLATFORM_OPENSSL
#	include <stingray/platform/openssl/crypto/EvpKey.h>
#endif
#include <stingray/records/FileSystemRecord.h>
#include <stingray/rpc/UrlObjectId.h>
#include <stingray/scanner/DVBServiceId.h>
#include <stingray/scanner/DefaultDVBTBandInfo.h>
#include <stingray/scanner/DefaultMpegService.h>
#include <stingray/scanner/DefaultMpegStreamDescriptor.h>
#include <stingray/scanner/DefaultScanParams.h>
#include <stingray/scanner/DreCasGeographicRegion.h>
#include <stingray/scanner/IServiceId.h>
#include <stingray/scanner/LybidScanParams.h>
#include <stingray/scanner/TricolorGeographicRegion.h>
#include <stingray/scanner/TricolorScanParams.h>
#include <stingray/scanner/lybid/LybidServiceMetaInfo.h>
#include <stingray/scanner/tricolor/TricolorServiceMetaInfo.h>
#include <stingray/streams/PlaybackStreamContent.h>
#include <stingray/streams/RecordStreamContent.h>
#include <stingray/streams/RecordStreamMetaInfo.h>
#include <stingray/tuners/TunerState.h>
#include <stingray/tuners/dvbs/Antenna.h>
#include <stingray/tuners/dvbs/DefaultDVBSTransport.h>
#include <stingray/tuners/dvbs/Satellite.h>
#include <stingray/tuners/dvbt/DVBTTransport.h>
#include <stingray/tuners/ip/TsOverIpTransport.h>
#include <stingray/update/DefaultUpdateRequirement.h>
#include <stingray/update/system/EraseFlashPartition.h>
#include <stingray/update/system/WriteFlashPartition.h>

/* WARNING! This is autogenerated file, DO NOT EDIT! */

namespace stingray { namespace Detail
{
	void Factory::RegisterTypes()
	{
#ifdef BUILD_SHARED_LIB
		/*nothing*/
#else
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::PVODVideoInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::AppChannel);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(::stingray::Detail::any::ObjectHolder<stingray::app::AppChannelPtr>);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ChannelList);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::CinemaHallScheduledViewing);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ContinuousScheduledEvent);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::DeferredStandby);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::InfiniteScheduledEvent);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ScheduledEvent);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ScheduledRecord);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ScheduledViewing);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::AutoFilter);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::User);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(BasicSubscription);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(BasicSubscriptionProvider);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(PlainCipherKey);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(HDMIConfig);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(ImageFileMediaInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(ImageFileMediaPreview);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(InMemoryImageMediaPreview);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MediaInfoBase);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(Mp3MediaInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(flv::MediaInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(mp4::MediaInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(mp4::Stream);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(mp4::Mp4MediaAudioStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(mp4::Mp4MediaVideoStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(mpeg::Stream);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DHCPInterfaceConfiguration);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(IgnoredInterfaceConfiguration);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(LinkLocalInterfaceConfiguration);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(ManualInterfaceConfiguration);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(AgeRating);
#ifdef PLATFORM_EMU
		TOOLKIT_REGISTER_CLASS_EXPLICIT(emu::EmuServiceId);
#endif
#ifdef PLATFORM_EMU
		TOOLKIT_REGISTER_CLASS_EXPLICIT(emu::RadioChannel);
#endif
#ifdef PLATFORM_EMU
		TOOLKIT_REGISTER_CLASS_EXPLICIT(emu::StreamDescriptor);
#endif
#ifdef PLATFORM_EMU
		TOOLKIT_REGISTER_CLASS_EXPLICIT(emu::TVChannel);
#endif
#ifdef PLATFORM_MSTAR
		TOOLKIT_REGISTER_CLASS_EXPLICIT(mstar::HardwareCipherKey);
#endif
#ifdef PLATFORM_OPENSSL
		TOOLKIT_REGISTER_CLASS_EXPLICIT(openssl::Certificate);
#endif
#ifdef PLATFORM_OPENSSL
		TOOLKIT_REGISTER_CLASS_EXPLICIT(openssl::EvpKey);
#endif
		TOOLKIT_REGISTER_CLASS_EXPLICIT(FileSystemRecord);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(rpc::UrlObjectId);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DVBServiceId);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultDVBTBandInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultMpegRadioChannel);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultMpegService);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultMpegTVChannel);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegAudioStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegDataCarouselStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegPcrStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegSubtitlesStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegTeletextBasedSubtitlesStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegTeletextStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegVideoStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultScanParams);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DreCasGeographicRegion);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(::stingray::Detail::any::ObjectHolder<stingray::ServiceId>);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(LybidScanParams);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(TricolorGeographicRegion);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(TricolorScanParams);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(LybidServiceMetaInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(TricolorServiceMetaInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(PlaybackStreamContent);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(RecordStreamContent);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(RecordStreamMetaInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(CircuitedTunerState);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(LockedTunerState);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(UnlockedTunerState);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(Antenna);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultDVBSTransport);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(Satellite);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DVBTTransport);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(TsOverIpTransport);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultMinimalVersionRequirement);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(EraseFlashPartition);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(WriteFlashPartition);
#endif
	}
}}
<commit_msg>Added ChannelViewingEventInfo<commit_after>#include <stingray/toolkit/Factory.h>

#include <stingray/toolkit/any.h>

#include <stingray/app/PushVideoOnDemand.h>
#include <stingray/app/application_context/AppChannel.h>
#include <stingray/app/application_context/ChannelList.h>
#include <stingray/app/scheduler/ScheduledEvents.h>
#include <stingray/app/tests/AutoFilter.h>
#include <stingray/app/zapper/User.h>
#include <stingray/ca/BasicSubscription.h>
#include <stingray/crypto/PlainCipherKey.h>
#include <stingray/hdmi/IHDMI.h>
#include <stingray/media/ImageFileMediaData.h>
#include <stingray/media/MediaInfoBase.h>
#include <stingray/media/Mp3MediaInfo.h>
#include <stingray/media/formats/flv/MediaInfo.h>
#include <stingray/media/formats/mp4/MediaInfo.h>
#include <stingray/media/formats/mp4/Stream.h>
#include <stingray/media/formats/mp4/StreamDescriptors.h>
#include <stingray/mpeg/Stream.h>
#include <stingray/net/DHCPInterfaceConfiguration.h>
#include <stingray/net/IgnoredInterfaceConfiguration.h>
#include <stingray/net/LinkLocalInterfaceConfiguration.h>
#include <stingray/net/ManualInterfaceConfiguration.h>
#include <stingray/parentalcontrol/AgeRating.h>
#ifdef PLATFORM_EMU
#	include <stingray/platform/emu/scanner/Channel.h>
#endif
#ifdef PLATFORM_MSTAR
#	include <stingray/platform/mstar/crypto/HardwareCipherKey.h>
#endif
#ifdef PLATFORM_OPENSSL
#	include <stingray/platform/openssl/crypto/Certificate.h>
#endif
#ifdef PLATFORM_OPENSSL
#	include <stingray/platform/openssl/crypto/EvpKey.h>
#endif
#include <stingray/records/FileSystemRecord.h>
#include <stingray/rpc/UrlObjectId.h>
#include <stingray/scanner/DVBServiceId.h>
#include <stingray/scanner/DefaultDVBTBandInfo.h>
#include <stingray/scanner/DefaultMpegService.h>
#include <stingray/scanner/DefaultMpegStreamDescriptor.h>
#include <stingray/scanner/DefaultScanParams.h>
#include <stingray/scanner/DreCasGeographicRegion.h>
#include <stingray/scanner/IServiceId.h>
#include <stingray/scanner/LybidScanParams.h>
#include <stingray/scanner/TricolorGeographicRegion.h>
#include <stingray/scanner/TricolorScanParams.h>
#include <stingray/scanner/lybid/LybidServiceMetaInfo.h>
#include <stingray/scanner/tricolor/TricolorServiceMetaInfo.h>
#include <stingray/stats/ChannelViewingEventInfo.h>
#include <stingray/streams/PlaybackStreamContent.h>
#include <stingray/streams/RecordStreamContent.h>
#include <stingray/streams/RecordStreamMetaInfo.h>
#include <stingray/tuners/TunerState.h>
#include <stingray/tuners/dvbs/Antenna.h>
#include <stingray/tuners/dvbs/DefaultDVBSTransport.h>
#include <stingray/tuners/dvbs/Satellite.h>
#include <stingray/tuners/dvbt/DVBTTransport.h>
#include <stingray/tuners/ip/TsOverIpTransport.h>
#include <stingray/update/DefaultUpdateRequirement.h>
#include <stingray/update/system/EraseFlashPartition.h>
#include <stingray/update/system/WriteFlashPartition.h>

/* WARNING! This is autogenerated file, DO NOT EDIT! */

namespace stingray { namespace Detail
{
	void Factory::RegisterTypes()
	{
#ifdef BUILD_SHARED_LIB
		/*nothing*/
#else
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::PVODVideoInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::AppChannel);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(::stingray::Detail::any::ObjectHolder<stingray::app::AppChannelPtr>);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ChannelList);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::CinemaHallScheduledViewing);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ContinuousScheduledEvent);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::DeferredStandby);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::InfiniteScheduledEvent);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ScheduledEvent);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ScheduledRecord);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ScheduledViewing);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::AutoFilter);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::User);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(BasicSubscription);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(BasicSubscriptionProvider);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(PlainCipherKey);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(HDMIConfig);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(ImageFileMediaInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(ImageFileMediaPreview);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(InMemoryImageMediaPreview);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MediaInfoBase);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(Mp3MediaInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(flv::MediaInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(mp4::MediaInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(mp4::Stream);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(mp4::Mp4MediaAudioStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(mp4::Mp4MediaVideoStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(mpeg::Stream);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DHCPInterfaceConfiguration);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(IgnoredInterfaceConfiguration);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(LinkLocalInterfaceConfiguration);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(ManualInterfaceConfiguration);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(AgeRating);
#ifdef PLATFORM_EMU
		TOOLKIT_REGISTER_CLASS_EXPLICIT(emu::EmuServiceId);
#endif
#ifdef PLATFORM_EMU
		TOOLKIT_REGISTER_CLASS_EXPLICIT(emu::RadioChannel);
#endif
#ifdef PLATFORM_EMU
		TOOLKIT_REGISTER_CLASS_EXPLICIT(emu::StreamDescriptor);
#endif
#ifdef PLATFORM_EMU
		TOOLKIT_REGISTER_CLASS_EXPLICIT(emu::TVChannel);
#endif
#ifdef PLATFORM_MSTAR
		TOOLKIT_REGISTER_CLASS_EXPLICIT(mstar::HardwareCipherKey);
#endif
#ifdef PLATFORM_OPENSSL
		TOOLKIT_REGISTER_CLASS_EXPLICIT(openssl::Certificate);
#endif
#ifdef PLATFORM_OPENSSL
		TOOLKIT_REGISTER_CLASS_EXPLICIT(openssl::EvpKey);
#endif
		TOOLKIT_REGISTER_CLASS_EXPLICIT(FileSystemRecord);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(rpc::UrlObjectId);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DVBServiceId);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultDVBTBandInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultMpegRadioChannel);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultMpegService);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultMpegTVChannel);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegAudioStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegDataCarouselStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegPcrStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegSubtitlesStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegTeletextBasedSubtitlesStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegTeletextStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegVideoStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultScanParams);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DreCasGeographicRegion);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(::stingray::Detail::any::ObjectHolder<stingray::ServiceId>);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(LybidScanParams);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(TricolorGeographicRegion);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(TricolorScanParams);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(LybidServiceMetaInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(TricolorServiceMetaInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(::stingray::Detail::any::ObjectHolder<stingray::ChannelViewingEventInfo>);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(PlaybackStreamContent);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(RecordStreamContent);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(RecordStreamMetaInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(CircuitedTunerState);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(LockedTunerState);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(UnlockedTunerState);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(Antenna);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultDVBSTransport);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(Satellite);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DVBTTransport);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(TsOverIpTransport);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultMinimalVersionRequirement);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(EraseFlashPartition);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(WriteFlashPartition);
#endif
	}
}}
<|endoftext|>


<commit_before>// $Id$
// Main authors: Matevz Tadel & Alja Mrak-Tadel & Bogdan Vulpescu: 2006, 2007

/**************************************************************************
 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
 * full copyright notice.                                                 *
 **************************************************************************/

#include "AliEveMUONChamberData.h"

#include <AliMUONGeometryTransformer.h>
#include <mapping/AliMpDEIterator.h>
#include <mapping/AliMpSector.h>
#include <mapping/AliMpPad.h>
#include <mapping/AliMpSegmentation.h>

#include <TVector2.h>

#include <EveBase/AliEveEventManager.h>

///////////////////////////////////////////////////////////////////////////////
///
/// AliEveMUONChamberData: geometry and digits
///
///////////////////////////////////////////////////////////////////////////////

ClassImp(AliEveMUONChamberData)

AliMUONGeometryTransformer* AliEveMUONChamberData::fgTransformer = 0;

//______________________________________________________________________________
AliEveMUONChamberData::AliEveMUONChamberData(Int_t chamber) :
  TObject(),
  fChamberID(0),
  fNDetElem(0),
  fNDigits(0),
  fNClusters(0),
  fNHits(0)
{
  //
  // constructor
  //

  fChamberID = chamber;
  fNDetElem  = 0;
  fNDigits   = 0;
  fNClusters = 0;
  fNHits     = 0;

  for (Int_t i = 0; i < 26; i++) {
    for (Int_t j = 0; j < 4; j++) {
      fFrameCoord[i][j] = 0.0;
    }
  }
  for (Int_t i = 0; i < 7*4096; i++) {
    fDigitBuffer[i] = 0.0;
  }
  for (Int_t i = 0; i < 5*256; i++) {
    fClusterBuffer[i] = 0.0;
  }
  for (Int_t i = 0; i < 3*256; i++) {
    fHitBuffer[i] = 0.0;
  }

  for (Int_t i = 0; i < 3; i++) {
    fChamberBox[i*2  ] = +9999;
    fChamberBox[i*2+1] = -9999;
  }

  if (fgTransformer == 0) {
    AliEveEventManager::AssertGeometry();
    fgTransformer = new AliMUONGeometryTransformer();
    fgTransformer->LoadGeometryData();
  }

  Init(chamber);
}

//______________________________________________________________________________
AliEveMUONChamberData::~AliEveMUONChamberData()
{
  //
  // destructor
  //

}

//______________________________________________________________________________
void AliEveMUONChamberData::DropData()
{
  //
  // release the chamber data
  //

  fNDigits   = 0;
  fNClusters = 0;
  fNHits     = 0;

  return;

}

//______________________________________________________________________________
void AliEveMUONChamberData::Init(Int_t chamber)
{
  //
  // initialize the drawing coordinates of the chamber
  //

  Float_t locP[3], gloP[3], locD[3], gloD[3];
  Float_t deltax, deltay;
  AliMpDEIterator it;
  const AliMpVSegmentation *vseg;
  const AliMpSector *sector;
  TVector2 position;
  TVector2 dimension;

  for ( it.First(chamber); ! it.IsDone(); it.Next() ) {

    Int_t detElemId = it.CurrentDEId();

    if (chamber < 4) {

      sector = AliMpSegmentation::Instance()->GetSector(detElemId,AliMp::kCath0);

      position  = sector->Position();
      dimension = sector->Dimensions(); // half length

      locP[0] =  position.Px();
      locP[1] =  position.Py();
      locD[0] =  dimension.Px() * 2.;
      locD[1] =  dimension.Py() * 2.;

      locP[2] = 0.0;
      locD[2] = 0.0;

      fgTransformer->Local2Global(detElemId,
				  locP[0], locP[1], locP[2],
				  gloP[0], gloP[1], gloP[2]);

      fgTransformer->Local2Global(detElemId,
				  locD[0], locD[1], locD[2],
				  gloD[0], gloD[1], gloD[2]);

      fFrameCoord[fNDetElem][0] = gloP[0];
      fFrameCoord[fNDetElem][1] = gloP[1];
      fFrameCoord[fNDetElem][2] = gloD[0];
      fFrameCoord[fNDetElem][3] = gloD[1];
      fFrameCoord[fNDetElem][4] = gloP[2]; // Z position

      fChamberBox[0] = TMath::Min(fChamberBox[0],gloP[0]-gloD[0]);
      fChamberBox[1] = TMath::Max(fChamberBox[1],gloP[0]+gloD[0]);
      fChamberBox[2] = TMath::Min(fChamberBox[2],gloP[1]-gloD[1]);
      fChamberBox[3] = TMath::Max(fChamberBox[3],gloP[1]+gloD[1]);
      fChamberBox[4] = TMath::Min(fChamberBox[4],gloP[2]);
      fChamberBox[5] = TMath::Max(fChamberBox[5],gloP[2]);

    } else {

//      if (!fgSegmentation->HasDE(detElemId)) {
//	printf("Segmentation has no %d detElemId! \n",detElemId);
//	continue;
//      }

      vseg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0);

      if (vseg == 0) {
	printf("No MpVSegmentation for %d detElemId! \n",detElemId);
	continue;
      }

      deltax = vseg->Dimensions().X();
      deltay = vseg->Dimensions().Y();
      locP[0] =  -deltax;
      locP[1] =  -deltay;
      locD[0] =  +deltax;
      locD[1] =  +deltay;

      locP[2] = 0.0;
      locD[2] = 0.0;

      fgTransformer->Local2Global(detElemId,
				  locP[0], locP[1], locP[2],
				  gloP[0], gloP[1], gloP[2]);

      fgTransformer->Local2Global(detElemId,
				  locD[0], locD[1], locD[2],
				  gloD[0], gloD[1], gloD[2]);

      fFrameCoord[fNDetElem][0] = gloP[0];
      fFrameCoord[fNDetElem][1] = gloP[1];
      fFrameCoord[fNDetElem][2] = gloD[0];
      fFrameCoord[fNDetElem][3] = gloD[1];
      fFrameCoord[fNDetElem][4] = gloP[2]; // Z position

      fChamberBox[0] = TMath::Min(fChamberBox[0],gloP[0]);
      fChamberBox[0] = TMath::Min(fChamberBox[0],gloD[0]);
      fChamberBox[1] = TMath::Max(fChamberBox[1],gloP[0]);
      fChamberBox[1] = TMath::Max(fChamberBox[1],gloD[0]);
      fChamberBox[2] = TMath::Min(fChamberBox[0],gloP[1]);
      fChamberBox[2] = TMath::Min(fChamberBox[0],gloD[1]);
      fChamberBox[3] = TMath::Max(fChamberBox[1],gloP[1]);
      fChamberBox[3] = TMath::Max(fChamberBox[1],gloD[1]);
      fChamberBox[4] = TMath::Min(fChamberBox[4],gloP[2]);
      fChamberBox[5] = TMath::Max(fChamberBox[5],gloP[2]);

    }

    fNDetElem++;

  }  // end detElemId loop

}

//______________________________________________________________________________
void AliEveMUONChamberData::RegisterDigit(Int_t detElemId, Int_t cathode, Int_t ix, Int_t iy, Int_t charge)
{
  //
  // add a digit to this chamber
  //

  if ((fNDigits/7) == (4096-1)) return;

  Float_t locP[3], gloP[3], locD[3], gloD[3];

  const AliMpVSegmentation* vseg = AliMpSegmentation::Instance()
    ->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));

  AliMpPad pad = vseg->PadByIndices(AliMpIntPair(ix,iy),kTRUE);

  locP[0] = pad.Position().X();
  locP[1] = pad.Position().Y();
  locD[0] = pad.Dimensions().X();
  locD[1] = pad.Dimensions().Y();

  locP[2] = 0.0;
  locD[2] = 0.0;

  fgTransformer->Local2Global(detElemId,
			      locP[0], locP[1], locP[2],
			      gloP[0], gloP[1], gloP[2]);

  gloD[0] = locD[0];
  gloD[1] = locD[1];
  gloD[2] = gloP[2];

  if (cathode == 0) gloP[2] += 0.1;
  if (cathode == 1) gloP[2] -= 0.1;

  fDigitBuffer[fNDigits  ] = gloP[0];
  fDigitBuffer[fNDigits+1] = gloP[1];
  fDigitBuffer[fNDigits+2] = gloD[0];
  fDigitBuffer[fNDigits+3] = gloD[1];
  fDigitBuffer[fNDigits+4] = gloP[2];
  fDigitBuffer[fNDigits+5] = charge;
  fDigitBuffer[fNDigits+6] = cathode;

  fNDigits += 7;

}

//______________________________________________________________________________
void AliEveMUONChamberData::RegisterCluster(Int_t /*detElemId*/, Int_t cathode, Float_t clsX, Float_t clsY, Float_t clsZ, Float_t charge)
{
  //
  // add a reconstructed point (cluster) to this chamber
  //
  // identical clusters are registered for both cathode planes ...
  //

  if ((fNClusters/5) == (256-1)) return;

  fClusterBuffer[fNClusters  ] = clsX;
  fClusterBuffer[fNClusters+1] = clsY;
  fClusterBuffer[fNClusters+2] = clsZ;
  fClusterBuffer[fNClusters+3] = charge;
  fClusterBuffer[fNClusters+4] = cathode;

  fNClusters += 5;

}

//______________________________________________________________________________
void AliEveMUONChamberData::RegisterHit(Int_t /*detElemId*/, Float_t hitX, Float_t hitY, Float_t hitZ)
{
  //
  // add a simulation hit to this chamber
  //

  if ((fNHits/3) == (256-1)) return;

  fHitBuffer[fNHits  ] = hitX;
  fHitBuffer[fNHits+1] = hitY;
  fHitBuffer[fNHits+2] = hitZ;

  fNHits += 3;

}
<commit_msg>Including appropriate header<commit_after>// $Id$
// Main authors: Matevz Tadel & Alja Mrak-Tadel & Bogdan Vulpescu: 2006, 2007

/**************************************************************************
 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
 * full copyright notice.                                                 *
 **************************************************************************/

#include "AliMpVSegmentation.h"
#include "AliEveMUONChamberData.h"

#include <AliMUONGeometryTransformer.h>
#include <mapping/AliMpDEIterator.h>
#include <mapping/AliMpSector.h>
#include <mapping/AliMpPad.h>
#include <mapping/AliMpSegmentation.h>

#include <TVector2.h>

#include <EveBase/AliEveEventManager.h>

///////////////////////////////////////////////////////////////////////////////
///
/// AliEveMUONChamberData: geometry and digits
///
///////////////////////////////////////////////////////////////////////////////

ClassImp(AliEveMUONChamberData)

AliMUONGeometryTransformer* AliEveMUONChamberData::fgTransformer = 0;

//______________________________________________________________________________
AliEveMUONChamberData::AliEveMUONChamberData(Int_t chamber) :
  TObject(),
  fChamberID(0),
  fNDetElem(0),
  fNDigits(0),
  fNClusters(0),
  fNHits(0)
{
  //
  // constructor
  //

  fChamberID = chamber;
  fNDetElem  = 0;
  fNDigits   = 0;
  fNClusters = 0;
  fNHits     = 0;

  for (Int_t i = 0; i < 26; i++) {
    for (Int_t j = 0; j < 4; j++) {
      fFrameCoord[i][j] = 0.0;
    }
  }
  for (Int_t i = 0; i < 7*4096; i++) {
    fDigitBuffer[i] = 0.0;
  }
  for (Int_t i = 0; i < 5*256; i++) {
    fClusterBuffer[i] = 0.0;
  }
  for (Int_t i = 0; i < 3*256; i++) {
    fHitBuffer[i] = 0.0;
  }

  for (Int_t i = 0; i < 3; i++) {
    fChamberBox[i*2  ] = +9999;
    fChamberBox[i*2+1] = -9999;
  }

  if (fgTransformer == 0) {
    AliEveEventManager::AssertGeometry();
    fgTransformer = new AliMUONGeometryTransformer();
    fgTransformer->LoadGeometryData();
  }

  Init(chamber);
}

//______________________________________________________________________________
AliEveMUONChamberData::~AliEveMUONChamberData()
{
  //
  // destructor
  //

}

//______________________________________________________________________________
void AliEveMUONChamberData::DropData()
{
  //
  // release the chamber data
  //

  fNDigits   = 0;
  fNClusters = 0;
  fNHits     = 0;

  return;

}

//______________________________________________________________________________
void AliEveMUONChamberData::Init(Int_t chamber)
{
  //
  // initialize the drawing coordinates of the chamber
  //

  Float_t locP[3], gloP[3], locD[3], gloD[3];
  Float_t deltax, deltay;
  AliMpDEIterator it;
  const AliMpVSegmentation *vseg;
  const AliMpSector *sector;
  TVector2 position;
  TVector2 dimension;

  for ( it.First(chamber); ! it.IsDone(); it.Next() ) {

    Int_t detElemId = it.CurrentDEId();

    if (chamber < 4) {

      sector = AliMpSegmentation::Instance()->GetSector(detElemId,AliMp::kCath0);

      position  = sector->Position();
      dimension = sector->Dimensions(); // half length

      locP[0] =  position.Px();
      locP[1] =  position.Py();
      locD[0] =  dimension.Px() * 2.;
      locD[1] =  dimension.Py() * 2.;

      locP[2] = 0.0;
      locD[2] = 0.0;

      fgTransformer->Local2Global(detElemId,
				  locP[0], locP[1], locP[2],
				  gloP[0], gloP[1], gloP[2]);

      fgTransformer->Local2Global(detElemId,
				  locD[0], locD[1], locD[2],
				  gloD[0], gloD[1], gloD[2]);

      fFrameCoord[fNDetElem][0] = gloP[0];
      fFrameCoord[fNDetElem][1] = gloP[1];
      fFrameCoord[fNDetElem][2] = gloD[0];
      fFrameCoord[fNDetElem][3] = gloD[1];
      fFrameCoord[fNDetElem][4] = gloP[2]; // Z position

      fChamberBox[0] = TMath::Min(fChamberBox[0],gloP[0]-gloD[0]);
      fChamberBox[1] = TMath::Max(fChamberBox[1],gloP[0]+gloD[0]);
      fChamberBox[2] = TMath::Min(fChamberBox[2],gloP[1]-gloD[1]);
      fChamberBox[3] = TMath::Max(fChamberBox[3],gloP[1]+gloD[1]);
      fChamberBox[4] = TMath::Min(fChamberBox[4],gloP[2]);
      fChamberBox[5] = TMath::Max(fChamberBox[5],gloP[2]);

    } else {

//      if (!fgSegmentation->HasDE(detElemId)) {
//	printf("Segmentation has no %d detElemId! \n",detElemId);
//	continue;
//      }

      vseg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0);

      if (vseg == 0) {
	printf("No MpVSegmentation for %d detElemId! \n",detElemId);
	continue;
      }

      deltax = vseg->Dimensions().X();
      deltay = vseg->Dimensions().Y();
      locP[0] =  -deltax;
      locP[1] =  -deltay;
      locD[0] =  +deltax;
      locD[1] =  +deltay;

      locP[2] = 0.0;
      locD[2] = 0.0;

      fgTransformer->Local2Global(detElemId,
				  locP[0], locP[1], locP[2],
				  gloP[0], gloP[1], gloP[2]);

      fgTransformer->Local2Global(detElemId,
				  locD[0], locD[1], locD[2],
				  gloD[0], gloD[1], gloD[2]);

      fFrameCoord[fNDetElem][0] = gloP[0];
      fFrameCoord[fNDetElem][1] = gloP[1];
      fFrameCoord[fNDetElem][2] = gloD[0];
      fFrameCoord[fNDetElem][3] = gloD[1];
      fFrameCoord[fNDetElem][4] = gloP[2]; // Z position

      fChamberBox[0] = TMath::Min(fChamberBox[0],gloP[0]);
      fChamberBox[0] = TMath::Min(fChamberBox[0],gloD[0]);
      fChamberBox[1] = TMath::Max(fChamberBox[1],gloP[0]);
      fChamberBox[1] = TMath::Max(fChamberBox[1],gloD[0]);
      fChamberBox[2] = TMath::Min(fChamberBox[0],gloP[1]);
      fChamberBox[2] = TMath::Min(fChamberBox[0],gloD[1]);
      fChamberBox[3] = TMath::Max(fChamberBox[1],gloP[1]);
      fChamberBox[3] = TMath::Max(fChamberBox[1],gloD[1]);
      fChamberBox[4] = TMath::Min(fChamberBox[4],gloP[2]);
      fChamberBox[5] = TMath::Max(fChamberBox[5],gloP[2]);

    }

    fNDetElem++;

  }  // end detElemId loop

}

//______________________________________________________________________________
void AliEveMUONChamberData::RegisterDigit(Int_t detElemId, Int_t cathode, Int_t ix, Int_t iy, Int_t charge)
{
  //
  // add a digit to this chamber
  //

  if ((fNDigits/7) == (4096-1)) return;

  Float_t locP[3], gloP[3], locD[3], gloD[3];

  const AliMpVSegmentation* vseg = AliMpSegmentation::Instance()
    ->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));

  AliMpPad pad = vseg->PadByIndices(AliMpIntPair(ix,iy),kTRUE);

  locP[0] = pad.Position().X();
  locP[1] = pad.Position().Y();
  locD[0] = pad.Dimensions().X();
  locD[1] = pad.Dimensions().Y();

  locP[2] = 0.0;
  locD[2] = 0.0;

  fgTransformer->Local2Global(detElemId,
			      locP[0], locP[1], locP[2],
			      gloP[0], gloP[1], gloP[2]);

  gloD[0] = locD[0];
  gloD[1] = locD[1];
  gloD[2] = gloP[2];

  if (cathode == 0) gloP[2] += 0.1;
  if (cathode == 1) gloP[2] -= 0.1;

  fDigitBuffer[fNDigits  ] = gloP[0];
  fDigitBuffer[fNDigits+1] = gloP[1];
  fDigitBuffer[fNDigits+2] = gloD[0];
  fDigitBuffer[fNDigits+3] = gloD[1];
  fDigitBuffer[fNDigits+4] = gloP[2];
  fDigitBuffer[fNDigits+5] = charge;
  fDigitBuffer[fNDigits+6] = cathode;

  fNDigits += 7;

}

//______________________________________________________________________________
void AliEveMUONChamberData::RegisterCluster(Int_t /*detElemId*/, Int_t cathode, Float_t clsX, Float_t clsY, Float_t clsZ, Float_t charge)
{
  //
  // add a reconstructed point (cluster) to this chamber
  //
  // identical clusters are registered for both cathode planes ...
  //

  if ((fNClusters/5) == (256-1)) return;

  fClusterBuffer[fNClusters  ] = clsX;
  fClusterBuffer[fNClusters+1] = clsY;
  fClusterBuffer[fNClusters+2] = clsZ;
  fClusterBuffer[fNClusters+3] = charge;
  fClusterBuffer[fNClusters+4] = cathode;

  fNClusters += 5;

}

//______________________________________________________________________________
void AliEveMUONChamberData::RegisterHit(Int_t /*detElemId*/, Float_t hitX, Float_t hitY, Float_t hitZ)
{
  //
  // add a simulation hit to this chamber
  //

  if ((fNHits/3) == (256-1)) return;

  fHitBuffer[fNHits  ] = hitX;
  fHitBuffer[fNHits+1] = hitY;
  fHitBuffer[fNHits+2] = hitZ;

  fNHits += 3;

}
<|endoftext|>


<commit_before>// @(#)root/rootd:$Name:  $:$Id: netpar.cxx,v 1.1 2001/02/06 19:12:35 rdm Exp $
// Author: Fons Rademakers   06/02/2001

/*************************************************************************
 * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// netpar                                                               //
//                                                                      //
// Set of parallel network routines for rootd daemon process. To be     //
// used when remote uses TPSocket to connect to rootd.                  //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#include <errno.h>

#if defined(linux)
#   include <features.h>
#   if __GNU_LIBRARY__ == 6
#      ifndef R__GLIBC
#         define R__GLIBC
#      endif
#   endif
#endif

#include "rootdp.h"

#if defined(_AIX) || (defined(__FreeBSD__) && !defined(__alpha__))
#   define USE_SIZE_T
#elif defined(R__GLIBC) || (defined(__FreeBSD__) && defined(__alpha__))
#   define USE_SOCKLEN_T
#endif

int gParallel = 0;

static int    gMaxFd;
static int   *gPSockFd;
static int   *gWriteBytesLeft;
static int   *gReadBytesLeft;
static char **gWritePtr;
static char **gReadPtr;
static fd_set gFdSet;

//______________________________________________________________________________
static void InitSelect(int nsock)
{
   // Setup select masks.

   FD_ZERO(&gFdSet);
   gMaxFd = -1;
   for (int i = 0; i < nsock; i++) {
      FD_SET(gPSockFd[i], &gFdSet);
      if (gPSockFd[i] > gMaxFd)
         gMaxFd = gPSockFd[i];
   }
}

//______________________________________________________________________________
int NetParSend(const void *buf, int len)
{
   // Send buffer of specified length over the parallel sockets.
   // Returns len in case of success and -1 in case of error.

   int i, alen = len, nsock = gParallel;

   // If data buffer is < 4K use only one socket
   if (len < 4096)
      nsock = 1;

   for (i = 0; i < nsock; i++) {
      gWriteBytesLeft[i] = len/nsock;
      gWritePtr[i] = (char *)buf + (i*gWriteBytesLeft[i]);
   }
   gWriteBytesLeft[i-1] += len%nsock;

   InitSelect(nsock);

   ErrorInfo("NetParSend: sending %d bytes using %d sockets", len, nsock);

   // Send the data on the parallel sockets
   while (len > 0) {

      fd_set writeReady = gFdSet;

      int isel = select(gMaxFd+1, 0, &writeReady, 0, 0);
      if (isel < 0) {
         ErrorInfo("NetParSend: error on select");
         return -1;
      }

      for (i = 0; i < nsock; i++) {
         if (FD_ISSET(gPSockFd[i], &writeReady)) {
            if (gWriteBytesLeft[i] > 0) {
               int ilen = send(gPSockFd[i], gWritePtr[i], gWriteBytesLeft[i], 0);
               if (ilen < 0) {
                  ErrorInfo("NetParSend: error sending for socket %d (%d)",
                            i, gPSockFd[i]);
                  ilen = 0;
               }
               gWriteBytesLeft[i] -= ilen;
               gWritePtr[i] += ilen;
               len -= ilen;
            }
         }
      }
   }

   return alen;
}

//______________________________________________________________________________
int NetParRecv(void *buf, int len)
{
   // Receive buffer of specified length over parallel sockets.
   // Returns len in case of success and -1 in case of error.

   int i, alen = len, nsock = gParallel;

   // If data buffer is < 4K use only one socket
   if (len < 4096)
      nsock = 1;

   for (i = 0; i < nsock; i++) {
      gReadBytesLeft[i] = len/nsock;
      gReadPtr[i] = (char *)buf + (i*gReadBytesLeft[i]);
   }
   gReadBytesLeft[i-1] += len%nsock;

   InitSelect(nsock);

   ErrorInfo("NetParRecv: receiving %d bytes using %d sockets", len, nsock);

   // Recieve the data on the parallel sockets
   while (len > 0) {

      fd_set readReady = gFdSet;

      int isel = select(gMaxFd+1, &readReady, 0, 0, 0);
      if (isel < 0) {
         ErrorInfo("NetParRecv: error on select");
         return -1;
      }

      for (i = 0; i < nsock; i++) {
         if (FD_ISSET(gPSockFd[i], &readReady)) {
            if (gReadBytesLeft[i] > 0) {
               int ilen = recv(gPSockFd[i], gReadPtr[i], gReadBytesLeft[i], 0);
               if (ilen < 0) {
                  ErrorInfo("NetParRecv: error receiving for socket %d (%d)",
                            i, gPSockFd[i]);
                  ilen = 0;
               }
               gReadBytesLeft[i] -= ilen;
               gReadPtr[i] += ilen;
               len -= ilen;
            }
         }
      }
   }

   return alen;
}

//______________________________________________________________________________
int NetParOpen(int port, int size)
{
   // Open size parallel sockets back to client. Returns 0 in case of error,
   // and number of parallel sockets in case of success.

   struct sockaddr_in remote_addr;
   memset(&remote_addr, 0, sizeof(remote_addr));

#if defined(USE_SIZE_T)
   size_t remlen = sizeof(remote_addr);
#elif defined(USE_SOCKLEN_T)
   socklen_t remlen = sizeof(remote_addr);
#else
   int remlen = sizeof(remote_addr);
#endif

   if (!getpeername(gSockFd, (struct sockaddr *)&remote_addr, &remlen)) {
      remote_addr.sin_family = AF_INET;
      remote_addr.sin_port   = htons(port);

      gPSockFd = new int[size];

      for (int i = 0; i < size; i++) {
         if ((gPSockFd[i] = socket(AF_INET, SOCK_STREAM, 0)) < 0)
            ErrorSys(kErrFatal, "NetParOpen: can't create socket %d (%d)",
                     i, gPSockFd[i]);

         NetSetOptions(gPSockFd[i], 65535);

         if (connect(gPSockFd[i], (struct sockaddr *)&remote_addr, remlen) < 0)
            ErrorSys(kErrFatal, "NetParOpen: can't connect socket %d (%d)",
                     i, gPSockFd[i]);

         // Set non-blocking
         int val;
         if ((val = fcntl(gPSockFd[i], F_GETFL, 0)) < 0)
            ErrorSys(kErrFatal, "NetParOpen: can't get control flags");
         val |= O_NONBLOCK;
         if (fcntl(gPSockFd[i], F_SETFL, val) < 0)
            ErrorSys(kErrFatal, "NetParOpen: can't make socket non blocking");
      }

      gWriteBytesLeft = new int[size];
      gReadBytesLeft  = new int[size];
      gWritePtr       = new char*[size];
      gReadPtr        = new char*[size];

      // Close initial setup socket
      NetClose();

      gParallel = size;

      if (gDebug > 0)
         ErrorInfo("NetParOpen: %d parallel connections established", size);

   } else
      ErrorSys(kErrFatal, "NetParOpen: can't get peer name");

   return gParallel;
}

//______________________________________________________________________________
void NetParClose()
{
   // Close parallel sockets.

   for (int i = 0; i < gParallel; i++)
      close(gPSockFd[i]);

   delete [] gPSockFd;
   delete [] gWriteBytesLeft;
   delete [] gReadBytesLeft;
   delete [] gWritePtr;
   delete [] gReadPtr;

   gParallel = 0;

   if (gDebug > 0)
      ErrorInfo("NetParClose: file = %s", gFile);
}
<commit_msg>remove print statement.<commit_after>// @(#)root/rootd:$Name:  $:$Id: netpar.cxx,v 1.2 2001/02/07 11:00:20 rdm Exp $
// Author: Fons Rademakers   06/02/2001

/*************************************************************************
 * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// netpar                                                               //
//                                                                      //
// Set of parallel network routines for rootd daemon process. To be     //
// used when remote uses TPSocket to connect to rootd.                  //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#include <errno.h>

#if defined(linux)
#   include <features.h>
#   if __GNU_LIBRARY__ == 6
#      ifndef R__GLIBC
#         define R__GLIBC
#      endif
#   endif
#endif

#include "rootdp.h"

#if defined(_AIX) || (defined(__FreeBSD__) && !defined(__alpha__))
#   define USE_SIZE_T
#elif defined(R__GLIBC) || (defined(__FreeBSD__) && defined(__alpha__))
#   define USE_SOCKLEN_T
#endif

int gParallel = 0;

static int    gMaxFd;
static int   *gPSockFd;
static int   *gWriteBytesLeft;
static int   *gReadBytesLeft;
static char **gWritePtr;
static char **gReadPtr;
static fd_set gFdSet;

//______________________________________________________________________________
static void InitSelect(int nsock)
{
   // Setup select masks.

   FD_ZERO(&gFdSet);
   gMaxFd = -1;
   for (int i = 0; i < nsock; i++) {
      FD_SET(gPSockFd[i], &gFdSet);
      if (gPSockFd[i] > gMaxFd)
         gMaxFd = gPSockFd[i];
   }
}

//______________________________________________________________________________
int NetParSend(const void *buf, int len)
{
   // Send buffer of specified length over the parallel sockets.
   // Returns len in case of success and -1 in case of error.

   int i, alen = len, nsock = gParallel;

   // If data buffer is < 4K use only one socket
   if (len < 4096)
      nsock = 1;

   for (i = 0; i < nsock; i++) {
      gWriteBytesLeft[i] = len/nsock;
      gWritePtr[i] = (char *)buf + (i*gWriteBytesLeft[i]);
   }
   gWriteBytesLeft[i-1] += len%nsock;

   InitSelect(nsock);

   // Send the data on the parallel sockets
   while (len > 0) {

      fd_set writeReady = gFdSet;

      int isel = select(gMaxFd+1, 0, &writeReady, 0, 0);
      if (isel < 0) {
         ErrorInfo("NetParSend: error on select");
         return -1;
      }

      for (i = 0; i < nsock; i++) {
         if (FD_ISSET(gPSockFd[i], &writeReady)) {
            if (gWriteBytesLeft[i] > 0) {
               int ilen = send(gPSockFd[i], gWritePtr[i], gWriteBytesLeft[i], 0);
               if (ilen < 0) {
                  ErrorInfo("NetParSend: error sending for socket %d (%d)",
                            i, gPSockFd[i]);
                  ilen = 0;
               }
               gWriteBytesLeft[i] -= ilen;
               gWritePtr[i] += ilen;
               len -= ilen;
            }
         }
      }
   }

   return alen;
}

//______________________________________________________________________________
int NetParRecv(void *buf, int len)
{
   // Receive buffer of specified length over parallel sockets.
   // Returns len in case of success and -1 in case of error.

   int i, alen = len, nsock = gParallel;

   // If data buffer is < 4K use only one socket
   if (len < 4096)
      nsock = 1;

   for (i = 0; i < nsock; i++) {
      gReadBytesLeft[i] = len/nsock;
      gReadPtr[i] = (char *)buf + (i*gReadBytesLeft[i]);
   }
   gReadBytesLeft[i-1] += len%nsock;

   InitSelect(nsock);

   // Recieve the data on the parallel sockets
   while (len > 0) {

      fd_set readReady = gFdSet;

      int isel = select(gMaxFd+1, &readReady, 0, 0, 0);
      if (isel < 0) {
         ErrorInfo("NetParRecv: error on select");
         return -1;
      }

      for (i = 0; i < nsock; i++) {
         if (FD_ISSET(gPSockFd[i], &readReady)) {
            if (gReadBytesLeft[i] > 0) {
               int ilen = recv(gPSockFd[i], gReadPtr[i], gReadBytesLeft[i], 0);
               if (ilen < 0) {
                  ErrorInfo("NetParRecv: error receiving for socket %d (%d)",
                            i, gPSockFd[i]);
                  ilen = 0;
               }
               gReadBytesLeft[i] -= ilen;
               gReadPtr[i] += ilen;
               len -= ilen;
            }
         }
      }
   }

   return alen;
}

//______________________________________________________________________________
int NetParOpen(int port, int size)
{
   // Open size parallel sockets back to client. Returns 0 in case of error,
   // and number of parallel sockets in case of success.

   struct sockaddr_in remote_addr;
   memset(&remote_addr, 0, sizeof(remote_addr));

#if defined(USE_SIZE_T)
   size_t remlen = sizeof(remote_addr);
#elif defined(USE_SOCKLEN_T)
   socklen_t remlen = sizeof(remote_addr);
#else
   int remlen = sizeof(remote_addr);
#endif

   if (!getpeername(gSockFd, (struct sockaddr *)&remote_addr, &remlen)) {
      remote_addr.sin_family = AF_INET;
      remote_addr.sin_port   = htons(port);

      gPSockFd = new int[size];

      for (int i = 0; i < size; i++) {
         if ((gPSockFd[i] = socket(AF_INET, SOCK_STREAM, 0)) < 0)
            ErrorSys(kErrFatal, "NetParOpen: can't create socket %d (%d)",
                     i, gPSockFd[i]);

         NetSetOptions(gPSockFd[i], 65535);

         if (connect(gPSockFd[i], (struct sockaddr *)&remote_addr, remlen) < 0)
            ErrorSys(kErrFatal, "NetParOpen: can't connect socket %d (%d)",
                     i, gPSockFd[i]);

         // Set non-blocking
         int val;
         if ((val = fcntl(gPSockFd[i], F_GETFL, 0)) < 0)
            ErrorSys(kErrFatal, "NetParOpen: can't get control flags");
         val |= O_NONBLOCK;
         if (fcntl(gPSockFd[i], F_SETFL, val) < 0)
            ErrorSys(kErrFatal, "NetParOpen: can't make socket non blocking");
      }

      gWriteBytesLeft = new int[size];
      gReadBytesLeft  = new int[size];
      gWritePtr       = new char*[size];
      gReadPtr        = new char*[size];

      // Close initial setup socket
      NetClose();

      gParallel = size;

      if (gDebug > 0)
         ErrorInfo("NetParOpen: %d parallel connections established", size);

   } else
      ErrorSys(kErrFatal, "NetParOpen: can't get peer name");

   return gParallel;
}

//______________________________________________________________________________
void NetParClose()
{
   // Close parallel sockets.

   for (int i = 0; i < gParallel; i++)
      close(gPSockFd[i]);

   delete [] gPSockFd;
   delete [] gWriteBytesLeft;
   delete [] gReadBytesLeft;
   delete [] gWritePtr;
   delete [] gReadPtr;

   gParallel = 0;

   if (gDebug > 0)
      ErrorInfo("NetParClose: file = %s", gFile);
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: dialogcustomcontrols.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: obo $ $Date: 2006-10-12 10:51:59 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_fpicker.hxx"

#ifndef _DIALOGCUSTOMCONTROLS_CXX_
#include "dialogcustomcontrols.hxx"
#endif

#ifndef _OSL_DIAGNOSE_H_
#include <osl/diagnose.h>
#endif

//-----------------------------------
//
//-----------------------------------

CDialogCustomControlBase::CDialogCustomControlBase(HWND aControlHandle, HWND aParentHandle) :
    m_CustomControlHandle(aControlHandle),
    m_ParentHandle(aParentHandle)
{
}

//-----------------------------------
//
//-----------------------------------

void SAL_CALL CDialogCustomControlBase::SetFont(HFONT hFont)
{
    SendMessage(
        m_CustomControlHandle,
        WM_SETFONT,
        (WPARAM)hFont,
        (LPARAM)TRUE);
}

//-----------------------------------
//
//-----------------------------------

void SAL_CALL CDialogCustomControlBase::AlignToBuddy(HWND aBuddyHandle)
{
    OSL_PRECOND(IsWindow(aBuddyHandle),"Invalid buddy window handle");

    RECT rcBuddy;
    GetWindowRect(aBuddyHandle,&rcBuddy);

    POINT pt = {rcBuddy.left,rcBuddy.top};
    ScreenToClient(m_ParentHandle,&pt);

    int cx_new = rcBuddy.right - rcBuddy.left;
    int cy_new = rcBuddy.bottom - rcBuddy.top;

    // keep the vertical position because
    // the Windows dialog controler does
    // this job
    RECT rcMe;
    GetWindowRect(m_CustomControlHandle,&rcMe);

    POINT ptMe = {rcMe.left,rcMe.top};
    ScreenToClient(m_ParentHandle,&ptMe);

    SetWindowPos(
        m_CustomControlHandle,
        HWND_TOP,
        pt.x,
        ptMe.y,
        cx_new,
        cy_new,
        SWP_NOACTIVATE);
}

//-----------------------------------
//
//-----------------------------------

CDummyCustomControl::CDummyCustomControl(HWND, HWND)
{
}

//-----------------------------------
//
//-----------------------------------

void SAL_CALL CDummyCustomControl::Align()
{
    // do nothing
}

//-----------------------------------
//
//-----------------------------------

void SAL_CALL CDummyCustomControl::SetFont(HFONT)
{
    // do nothing
}

//-----------------------------------
//
//-----------------------------------

CStaticCustomControl::CStaticCustomControl(HWND aControlHandle, HWND aParentHandle) :
    CDialogCustomControlBase(aControlHandle,aParentHandle)
{
}

//-----------------------------------
// Align to the "File name" static
// text of the standard FileOpen dlg
//-----------------------------------

void SAL_CALL CStaticCustomControl::Align()
{
    AlignToBuddy(GetDlgItem(m_ParentHandle,stc3));
}

//-----------------------------------
//
//-----------------------------------

CPushButtonCustomControl::CPushButtonCustomControl(HWND aControlHandle, HWND aParentHandle) :
    CDialogCustomControlBase(aControlHandle,aParentHandle)
{
}

//-----------------------------------
// Align to the "OK" button of the
// standard FileOpen dlg
//-----------------------------------

void SAL_CALL CPushButtonCustomControl::Align()
{
    AlignToBuddy(GetDlgItem(m_ParentHandle,IDCANCEL));
}

//-----------------------------------
//
//-----------------------------------

CComboboxCustomControl::CComboboxCustomControl(HWND aControlHandle, HWND aParentHandle) :
    CDialogCustomControlBase(aControlHandle,aParentHandle)
{
}

//-----------------------------------
// Align to the "File name" combobox
// of the standard FileOpen dlg
//-----------------------------------

void SAL_CALL CComboboxCustomControl::Align()
{
    AlignToBuddy(GetDlgItem(m_ParentHandle,cmb1));
}

//-----------------------------------
//
//-----------------------------------

CCheckboxCustomControl::CCheckboxCustomControl(HWND aControlHandle, HWND aParentHandle) :
    CDialogCustomControlBase(aControlHandle,aParentHandle)
{
}

//-----------------------------------
// Align to the "File name" combobox
// of the standard FileOpen dlg
//-----------------------------------

void SAL_CALL CCheckboxCustomControl::Align()
{
    AlignToBuddy(GetDlgItem(m_ParentHandle,cmb1));
}
<commit_msg>INTEGRATION: CWS changefileheader (1.5.154); FILE MERGED 2008/04/01 15:17:05 thb 1.5.154.2: #i85898# Stripping all external header guards 2008/03/31 13:13:18 rt 1.5.154.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: dialogcustomcontrols.cxx,v $
 * $Revision: 1.6 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_fpicker.hxx"

#ifndef _DIALOGCUSTOMCONTROLS_CXX_
#include "dialogcustomcontrols.hxx"
#endif
#include <osl/diagnose.h>

//-----------------------------------
//
//-----------------------------------

CDialogCustomControlBase::CDialogCustomControlBase(HWND aControlHandle, HWND aParentHandle) :
    m_CustomControlHandle(aControlHandle),
    m_ParentHandle(aParentHandle)
{
}

//-----------------------------------
//
//-----------------------------------

void SAL_CALL CDialogCustomControlBase::SetFont(HFONT hFont)
{
    SendMessage(
        m_CustomControlHandle,
        WM_SETFONT,
        (WPARAM)hFont,
        (LPARAM)TRUE);
}

//-----------------------------------
//
//-----------------------------------

void SAL_CALL CDialogCustomControlBase::AlignToBuddy(HWND aBuddyHandle)
{
    OSL_PRECOND(IsWindow(aBuddyHandle),"Invalid buddy window handle");

    RECT rcBuddy;
    GetWindowRect(aBuddyHandle,&rcBuddy);

    POINT pt = {rcBuddy.left,rcBuddy.top};
    ScreenToClient(m_ParentHandle,&pt);

    int cx_new = rcBuddy.right - rcBuddy.left;
    int cy_new = rcBuddy.bottom - rcBuddy.top;

    // keep the vertical position because
    // the Windows dialog controler does
    // this job
    RECT rcMe;
    GetWindowRect(m_CustomControlHandle,&rcMe);

    POINT ptMe = {rcMe.left,rcMe.top};
    ScreenToClient(m_ParentHandle,&ptMe);

    SetWindowPos(
        m_CustomControlHandle,
        HWND_TOP,
        pt.x,
        ptMe.y,
        cx_new,
        cy_new,
        SWP_NOACTIVATE);
}

//-----------------------------------
//
//-----------------------------------

CDummyCustomControl::CDummyCustomControl(HWND, HWND)
{
}

//-----------------------------------
//
//-----------------------------------

void SAL_CALL CDummyCustomControl::Align()
{
    // do nothing
}

//-----------------------------------
//
//-----------------------------------

void SAL_CALL CDummyCustomControl::SetFont(HFONT)
{
    // do nothing
}

//-----------------------------------
//
//-----------------------------------

CStaticCustomControl::CStaticCustomControl(HWND aControlHandle, HWND aParentHandle) :
    CDialogCustomControlBase(aControlHandle,aParentHandle)
{
}

//-----------------------------------
// Align to the "File name" static
// text of the standard FileOpen dlg
//-----------------------------------

void SAL_CALL CStaticCustomControl::Align()
{
    AlignToBuddy(GetDlgItem(m_ParentHandle,stc3));
}

//-----------------------------------
//
//-----------------------------------

CPushButtonCustomControl::CPushButtonCustomControl(HWND aControlHandle, HWND aParentHandle) :
    CDialogCustomControlBase(aControlHandle,aParentHandle)
{
}

//-----------------------------------
// Align to the "OK" button of the
// standard FileOpen dlg
//-----------------------------------

void SAL_CALL CPushButtonCustomControl::Align()
{
    AlignToBuddy(GetDlgItem(m_ParentHandle,IDCANCEL));
}

//-----------------------------------
//
//-----------------------------------

CComboboxCustomControl::CComboboxCustomControl(HWND aControlHandle, HWND aParentHandle) :
    CDialogCustomControlBase(aControlHandle,aParentHandle)
{
}

//-----------------------------------
// Align to the "File name" combobox
// of the standard FileOpen dlg
//-----------------------------------

void SAL_CALL CComboboxCustomControl::Align()
{
    AlignToBuddy(GetDlgItem(m_ParentHandle,cmb1));
}

//-----------------------------------
//
//-----------------------------------

CCheckboxCustomControl::CCheckboxCustomControl(HWND aControlHandle, HWND aParentHandle) :
    CDialogCustomControlBase(aControlHandle,aParentHandle)
{
}

//-----------------------------------
// Align to the "File name" combobox
// of the standard FileOpen dlg
//-----------------------------------

void SAL_CALL CCheckboxCustomControl::Align()
{
    AlignToBuddy(GetDlgItem(m_ParentHandle,cmb1));
}
<|endoftext|>


<commit_before>// ======================================================================== //
// Copyright 2009-2019 Intel Corporation                                    //
//                                                                          //
// Licensed under the Apache License, Version 2.0 (the "License");          //
// you may not use this file except in compliance with the License.         //
// You may obtain a copy of the License at                                  //
//                                                                          //
//     http://www.apache.org/licenses/LICENSE-2.0                           //
//                                                                          //
// Unless required by applicable law or agreed to in writing, software      //
// distributed under the License is distributed on an "AS IS" BASIS,        //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and      //
// limitations under the License.                                           //
// ======================================================================== //

#include "Volume.h"
// stl
#include <random>
#include <vector>
// ospcommon
#include "ospcommon/box.h"
#include "ospcommon/tasking/parallel_for.h"
using namespace ospcommon;

namespace ospray {
  namespace testing {

    struct GravitySpheresVolume : public Volume
    {
      GravitySpheresVolume()           = default;
      ~GravitySpheresVolume() override = default;

      OSPTestingVolume createVolume() const override;

     private:
      size_t volumeDimension{256};
      size_t numPoints{10};
    };

    // Inlined definitions ////////////////////////////////////////////////////

    OSPTestingVolume GravitySpheresVolume::createVolume() const
    {
      struct Point
      {
        vec3f center;
        float weight;
      };

      // create random number distributions for point center and weight
      std::random_device rd;
      std::mt19937 gen(rd());

      std::uniform_real_distribution<float> centerDistribution(-1.f, 1.f);
      std::uniform_real_distribution<float> weightDistribution(0.1f, 0.3f);

      // populate the points
      std::vector<Point> points(numPoints);

      for (auto &p : points) {
        p.center.x = centerDistribution(gen);
        p.center.y = centerDistribution(gen);
        p.center.z = centerDistribution(gen);

        p.weight = weightDistribution(gen);
      }

      // create a structured volume and assign attributes
      OSPVolume volume = ospNewVolume("block_bricked_volume");

      ospSetVec3i(volume,
               "dimensions",
               volumeDimension,
               volumeDimension,
               volumeDimension);
      ospSetString(volume, "voxelType", "float");
      ospSetVec3f(volume, "gridOrigin", -1.f, -1.f, -1.f);

      const float gridSpacing = 2.f / float(volumeDimension);
      ospSetVec3f(volume, "gridSpacing", gridSpacing, gridSpacing, gridSpacing);

      // get world coordinate in [-1.f, 1.f] from logical coordinates in [0,
      // volumeDimension)
      auto logicalToWorldCoordinates = [&](size_t i, size_t j, size_t k) {
        return vec3f(-1.f + float(i) / float(volumeDimension - 1) * 2.f,
                     -1.f + float(j) / float(volumeDimension - 1) * 2.f,
                     -1.f + float(k) / float(volumeDimension - 1) * 2.f);
      };

      // generate volume values
      std::vector<float> voxels(volumeDimension * volumeDimension *
                                volumeDimension);

      tasking::parallel_for(volumeDimension, [&](size_t k) {
        for (size_t j = 0; j < volumeDimension; j++) {
          for (size_t i = 0; i < volumeDimension; i++) {
            // index in array
            size_t index =
                k * volumeDimension * volumeDimension + j * volumeDimension + i;

            // compute volume value
            float value = 0.f;

            for (auto &p : points) {
              vec3f pointCoordinate = logicalToWorldCoordinates(i, j, k);
              const float distance  = length(pointCoordinate - p.center);

              // contribution proportional to weighted inverse-square distance
              // (i.e. gravity)
              value += p.weight / (distance * distance);
            }

            voxels[index] = value;
          }
        }
      });

      vec3i regionStart{0, 0, 0};
      vec3i regionEnd{
          int(volumeDimension), int(volumeDimension), int(volumeDimension)};

      // set the volume data
      ospSetRegion(volume, voxels.data(), &regionStart.x, &regionEnd.x);

      // create OSPRay objects and return results

      const auto range = vec2f(0.f, 10.f);
      const auto bounds =
          box3f(vec3f(-1.f), vec3f(-1.f) + volumeDimension * gridSpacing);

      OSPTestingVolume retval;
      retval.volume     = volume;
      retval.voxelRange = reinterpret_cast<const osp_vec2f &>(range);
      retval.bounds     = reinterpret_cast<const osp_box3f &>(bounds);

      ospCommit(volume);

      return retval;
    }

    OSP_REGISTER_TESTING_VOLUME(GravitySpheresVolume, gravity_spheres_volume);

  }  // namespace testing
}  // namespace ospray
<commit_msg>split voxel generation into separate function<commit_after>// ======================================================================== //
// Copyright 2009-2019 Intel Corporation                                    //
//                                                                          //
// Licensed under the Apache License, Version 2.0 (the "License");          //
// you may not use this file except in compliance with the License.         //
// You may obtain a copy of the License at                                  //
//                                                                          //
//     http://www.apache.org/licenses/LICENSE-2.0                           //
//                                                                          //
// Unless required by applicable law or agreed to in writing, software      //
// distributed under the License is distributed on an "AS IS" BASIS,        //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and      //
// limitations under the License.                                           //
// ======================================================================== //

#include "Volume.h"
// stl
#include <random>
#include <vector>
// ospcommon
#include "ospcommon/box.h"
#include "ospcommon/tasking/parallel_for.h"
using namespace ospcommon;

namespace ospray {
  namespace testing {

    struct GravitySpheresVolume : public Volume
    {
      GravitySpheresVolume()           = default;
      ~GravitySpheresVolume() override = default;

      std::vector<float> generateVoxels() const;
      OSPTestingVolume createVolume() const override;

     private:
      size_t volumeDimension{256};
      size_t numPoints{10};
    };

    // Inlined definitions ////////////////////////////////////////////////////

    std::vector<float> GravitySpheresVolume::generateVoxels() const
    {
      struct Point
      {
        vec3f center;
        float weight;
      };

      // create random number distributions for point center and weight
      std::random_device rd;
      std::mt19937 gen(rd());

      std::uniform_real_distribution<float> centerDistribution(-1.f, 1.f);
      std::uniform_real_distribution<float> weightDistribution(0.1f, 0.3f);

      // populate the points
      std::vector<Point> points(numPoints);

      for (auto &p : points) {
        p.center.x = centerDistribution(gen);
        p.center.y = centerDistribution(gen);
        p.center.z = centerDistribution(gen);

        p.weight = weightDistribution(gen);
      }

      // get world coordinate in [-1.f, 1.f] from logical coordinates in [0,
      // volumeDimension)
      auto logicalToWorldCoordinates = [&](size_t i, size_t j, size_t k) {
        return vec3f(-1.f + float(i) / float(volumeDimension - 1) * 2.f,
                     -1.f + float(j) / float(volumeDimension - 1) * 2.f,
                     -1.f + float(k) / float(volumeDimension - 1) * 2.f);
      };

      // generate voxels
      std::vector<float> voxels(volumeDimension * volumeDimension *
                                volumeDimension);

      tasking::parallel_for(volumeDimension, [&](size_t k) {
        for (size_t j = 0; j < volumeDimension; j++) {
          for (size_t i = 0; i < volumeDimension; i++) {
            // index in array
            size_t index =
                k * volumeDimension * volumeDimension + j * volumeDimension + i;

            // compute volume value
            float value = 0.f;

            for (auto &p : points) {
              vec3f pointCoordinate = logicalToWorldCoordinates(i, j, k);
              const float distance  = length(pointCoordinate - p.center);

              // contribution proportional to weighted inverse-square distance
              // (i.e. gravity)
              value += p.weight / (distance * distance);
            }

            voxels[index] = value;
          }
        }
      });

      return voxels;
    }

    OSPTestingVolume GravitySpheresVolume::createVolume() const
    {
      // create a structured volume and assign attributes
      OSPVolume volume = ospNewVolume("block_bricked_volume");

      ospSetVec3i(volume,
               "dimensions",
               volumeDimension,
               volumeDimension,
               volumeDimension);
      ospSetString(volume, "voxelType", "float");
      ospSetVec3f(volume, "gridOrigin", -1.f, -1.f, -1.f);

      const float gridSpacing = 2.f / float(volumeDimension);
      ospSetVec3f(volume, "gridSpacing", gridSpacing, gridSpacing, gridSpacing);

      // generate volume values
      std::vector<float> voxels = generateVoxels();

      vec3i regionStart{0, 0, 0};
      vec3i regionEnd{
          int(volumeDimension), int(volumeDimension), int(volumeDimension)};

      // set the volume data
      ospSetRegion(volume, voxels.data(), &regionStart.x, &regionEnd.x);

      // create OSPRay objects and return results

      const auto range = vec2f(0.f, 10.f);
      const auto bounds =
          box3f(vec3f(-1.f), vec3f(-1.f) + volumeDimension * gridSpacing);

      OSPTestingVolume retval;
      retval.volume     = volume;
      retval.voxelRange = reinterpret_cast<const osp_vec2f &>(range);
      retval.bounds     = reinterpret_cast<const osp_box3f &>(bounds);

      ospCommit(volume);

      return retval;
    }

    OSP_REGISTER_TESTING_VOLUME(GravitySpheresVolume, gravity_spheres_volume);

  }  // namespace testing
}  // namespace ospray
<|endoftext|>