Commit 94d478a4 authored by cvs2svn's avatar cvs2svn
Browse files

This commit was manufactured by cvs2svn to create tag 'COOL_2_6-patches'.

git-svn-id: file:///git/lcgcool.svndb/cool/tags/COOL_2_6-patches@15137 4525493e-7705-40b1-a816-d608a930855b
parent f5ef5720
// $Id: ChannelId.h,v 1.3 2007-01-17 14:48:12 avalassi Exp $
#ifndef COOLKERNEL_CHANNELID_H
#define COOLKERNEL_CHANNELID_H
// Include files
#include "CoolKernel/types.h"
namespace cool {
/** @file ChannelId.h
*
* Type definition for the 'ID' of a channel in a COOL folder.
*
* @author Sven A. Schmidt and Andrea Valassi
* @date 2004-11-05
*/
// ChannelId.
typedef UInt32 ChannelId;
}
#endif
// $Id: ChannelSelection.h,v 1.17 2008-11-04 09:20:57 avalassi Exp $
#ifndef COOLKERNEL_CHANNELSELECTION_H
#define COOLKERNEL_CHANNELSELECTION_H
// Include files
#include <limits>
#include <vector>
#include "CoolKernel/ChannelId.h"
#include "CoolKernel/Exception.h"
namespace cool {
/** @class ChannelSelection ChannelSelection.h
*
* Helper class to specify a selection of channels and their ordering
* for multi-channel bulk retrieval of IOVs.
*
* So far, only selection of IOVs _within a given tag_ is supported (the
* choice of the selected tag is made outside the ChannelSelection class).
* Within each channel, IOVs can be browsed ordered by 'iovSince',
* and there is only one IOV valid at any given validity time.
*
* @author Sven A. Schmidt, Andrea Valassi and Marco Clemencic
* @date 2005-08-08
*/
class ChannelSelection {
friend class ChannelSelectionTest;
public:
/// Internal helper class for channel ranges. Ideally this class should
/// be private but PyCool dictionary generation does not like that!
class ChannelRange {
public:
// Required by PyCool
ChannelRange() {}
ChannelRange( const ChannelId& firstChannel,
const ChannelId& lastChannel )
: m_firstChannel( firstChannel )
, m_lastChannel( lastChannel )
{
if ( firstChannel > lastChannel )
throw InvalidChannelRange
( firstChannel, lastChannel, "ChannelSelection" );
}
ChannelId firstChannel() const
{
return m_firstChannel;
}
ChannelId lastChannel() const
{
return m_lastChannel;
}
bool inRange( const ChannelId& channel ) const
{
return firstChannel() <= channel && channel <= lastChannel();
}
private:
ChannelId m_firstChannel;
ChannelId m_lastChannel;
};
public:
/// There are two possible orders to browse IOVs (within a tag) across
/// many channels: 'order by channel, since' and 'order by since, channel'.
/// The second set of the ordering scheme lists the IOVs in reverse order.
enum Order {
channelBeforeSince, sinceBeforeChannel,
channelBeforeSinceDesc, sinceDescBeforeChannel
};
/// Constructor to (implicitly) select IOVs from *all* channels
/// with the given order (default is 'order by channel, since').
explicit ChannelSelection( const Order& order = channelBeforeSince )
: m_isNumeric( true )
, m_allChannels( true )
, m_order( order )
{
#ifndef WIN32
m_ranges.push_back
( ChannelRange( std::numeric_limits<ChannelId>::min(),
std::numeric_limits<ChannelId>::max() ) );
#else
// Port to VC9 on Windows
m_ranges.push_back
( ChannelRange( UInt32Min, UInt32Max ) );
#endif
}
/// Constructor to select IOVs for a given channel. This constructor is
/// intended to be used to autoconvert ChannelId to a ChannelSelection.
ChannelSelection( const ChannelId& channel )
: m_isNumeric( true )
, m_allChannels( false )
, m_order( channelBeforeSince )
{
m_ranges.push_back( ChannelRange( channel, channel ) );
}
/// Constructor to select IOVs for channels within a given range
/// with the given order (default is 'order by channel, since').
ChannelSelection( const ChannelId& firstChannel,
const ChannelId& lastChannel,
const Order& order = channelBeforeSince )
: m_isNumeric( true )
, m_allChannels( false )
, m_order( order )
{
if ( firstChannel > lastChannel )
throw InvalidChannelRange
( firstChannel, lastChannel, "ChannelSelection" );
m_ranges.push_back( ChannelRange( firstChannel, lastChannel ) );
}
/// Constructor to select IOVs with a given channel name.
ChannelSelection( const std::string& channelName,
const Order& order = channelBeforeSince )
: m_isNumeric( false )
, m_allChannels( false )
, m_channelName( channelName )
, m_order( order ) {
}
/// Returns true if selecting all channels.
bool allChannels() const
{
return m_allChannels;
}
/// Returns the first selected channel
/// [std::numeric_limits<ChannelId>::min() if selecting all channels].
ChannelId firstChannel() const
{
if ( ! isNumeric() ) {
throw Exception( "Numeric method called for "
"non-numeric ChannelSelection",
"ChannelSelection" );
}
return m_ranges[0].firstChannel();
}
/// Returns the last selected channel
/// [std::numeric_limits<ChannelId>::max() if selecting all channels].
ChannelId lastChannel() const
{
if ( ! isNumeric() ) {
throw Exception( "Numeric method called for "
"non-numeric ChannelSelection",
"ChannelSelection" );
}
return m_ranges[m_ranges.size()-1].lastChannel();
}
/// Returns the selection order.
Order order() const
{
return m_order;
}
/// Construct a selection to select *all* channels with the given order.
static
const ChannelSelection all( const Order& order = channelBeforeSince )
{
return ChannelSelection( order );
}
/// Returns true if the given channel is in the selection
bool inSelection( const ChannelId& channel ) const
{
if ( ! isNumeric() ) {
throw Exception( "Numeric method called for "
"non-numeric ChannelSelection",
"ChannelSelection" );
}
for ( std::vector<ChannelRange>::const_iterator
i = m_ranges.begin(); i != m_ranges.end(); ++i ) {
if ( i->inRange( channel ) ) return true;
}
return false;
}
/// Returns true if the given channelName is in the selection
bool inSelection( const std::string& channelName ) const
{
if ( isNumeric() ) {
throw Exception( "Non-numeric method called for "
"numeric ChannelSelection",
"ChannelSelection" );
}
return channelName == m_channelName;
}
/// Returns true if the selection is contiguous
/// This is the case if every channel between the very first and the
/// last of the selection ranges is in the selection.
/// This method does not make any assumption about the granularity. The
/// only requirement is that operator++ at the end of an internal channel
/// range will step to the first channel of the next range and not 'land'
/// on a ChannelId outside the selection.
bool isContiguous() const
{
if ( ! isNumeric() ) {
throw Exception( "Numeric method called for "
"non-numeric ChannelSelection",
"ChannelSelection" );
}
if ( m_ranges.size() == 0 ) {
return true;
}
for ( unsigned int i = 1; i < m_ranges.size(); ++i ) {
ChannelId prev = m_ranges[i-1].lastChannel();
// specifically avoid +1 to be independant of ChannelId granularity
++prev;
if ( prev < m_ranges[i].firstChannel() )
return false;
}
return true;
}
/// Adds a channel range to the selection
/// For sake of simplicity, it is required that the range is added
/// to the front or the back of the existing selection without overlap.
void addRange( const ChannelId& firstChannel,
const ChannelId& lastChannel )
{
if ( ! isNumeric() ) {
throw Exception( "Numeric method called for "
"non-numeric ChannelSelection",
"ChannelSelection" );
}
if ( firstChannel > lastChannel ) {
throw InvalidChannelRange( firstChannel, lastChannel,
"ChannelSelection" );
}
if ( lastChannel < this->firstChannel() ) {
m_ranges.insert( m_ranges.begin(),
ChannelRange( firstChannel, lastChannel ) );
} else if ( this->lastChannel() < firstChannel ) {
m_ranges.push_back( ChannelRange( firstChannel, lastChannel ) );
} else {
std::stringstream s;
s << "Cannot add range [" << firstChannel << "," << lastChannel
<< "], because it overlaps with selection";
throw Exception( s.str(), "ChannelSelection" );
}
}
/// Adds a channel to the selection
void addChannel( const ChannelId& channel )
{
if ( ! isNumeric() ) {
throw Exception( "Numeric method called for "
"non-numeric ChannelSelection",
"ChannelSelection" );
}
addRange( channel, channel );
}
/// Returns true is the ChannelSelection is numeric.
bool isNumeric() const {
return m_isNumeric;
}
/// Returns the channel name list
const std::string& channelName() const {
return m_channelName;
}
private:
bool m_isNumeric;
bool m_allChannels;
std::vector<ChannelRange> m_ranges;
std::string m_channelName;
Order m_order;
};
}
#endif // COOLKERNEL_CHANNELSELECTION_H
// $Id: CompositeSelection.h,v 1.6 2008-11-04 10:18:30 avalassi Exp $
#ifndef COOLKERNEL_COMPOSITESELECTION_H
#define COOLKERNEL_COMPOSITESELECTION_H 1
// Include files
#include <vector>
#include "CoolKernel/IRecordSelection.h"
namespace cool
{
//--------------------------------------------------------------------------
/** @class CompositeSelection CompositeSelection.h
*
* Composite selection on a data record obtained by the conjuction (AND)
* or disjunction (OR) of several simplere record selections.
*
* @author Andrea Valassi and Martin Wache
* @date 2008-07-30
*/
class CompositeSelection : virtual public IRecordSelection
{
public:
/// Logical connectives (logical operations).
enum Connective{ AND, OR };
/// Describe a logical connective.
static const std::string describe( Connective conn );
public:
/// Destructor.
virtual ~CompositeSelection();
/// Constructor for connecting two selections.
/// Each input selection is cloned (the clone is owned by this instance).
CompositeSelection( const IRecordSelection* sel1,
Connective conn,
const IRecordSelection* sel2 );
/// Constructor for connecting any number of selections.
/// The vector must contain at least two selections.
/// Each input selection is cloned (the clone is owned by this instance).
CompositeSelection( Connective conn,
const std::vector<const IRecordSelection*>& selVec );
/// Connect another selection.
/// The input selection is cloned (the clone is owned by this instance).
void connect( Connective conn,
const IRecordSelection* sel );
/// Can the selection be applied to a record with the given specification?
bool canSelect( const IRecordSpecification& spec ) const;
/// Apply the selection to the given record.
bool select( const IRecord& record ) const;
/// Clone the record selection (and any objects referenced therein).
IRecordSelection* clone() const;
/// Logical connective between all connected selections.
Connective connective() const;
/// The number N of connected selections.
unsigned int size() const;
/// Return one of the connected selections by its index in [0, N-1].
const IRecordSelection* operator[] ( unsigned int index ) const;
private:
/// Standard constuctor is private
CompositeSelection();
/// Copy constructor - reimplemented for the clone() method
CompositeSelection( const CompositeSelection& rhs );
/// Assignment operator is private
CompositeSelection& operator=( const CompositeSelection& rhs );
/// Constructor with a default connective and no selections - for connect()
CompositeSelection( Connective conn );
private:
/// The logical connective between connected selections.
Connective m_conn;
/// The vector of connected selections.
/// These are clones (owned by this instance) of the user-given selections.
std::vector<IRecordSelection*> m_selVec;
};
}
#endif // COOLKERNEL_COMPOSITESELECTION_H
// $Id: ConstRecordAdapter.h,v 1.21 2008-11-04 10:18:30 avalassi Exp $
#ifndef RELATIONALCOOL_CONSTRECORDADAPTER_H
#define RELATIONALCOOL_CONSTRECORDADAPTER_H 1
// Include files
#include "CoolKernel/IRecord.h"
#include "CoolKernel/RecordSpecification.h"
#include "CoralBase/AttributeList.h"
namespace cool
{
//--------------------------------------------------------------------------
/** @class ConstRecordAdapter ConstRecordAdapter.h
*
* Read-only wrapper of a constant coral::AttributeList reference,
* implementing the cool::IRecord interface. The adapter can only be
* used as long as the AttributeList is alive. The adapter creates
* its own RecordSpecification from one specified at construction time.
*
* All non-const methods throw: this is effectively a read-only class.
*
* The StorageType constraints on the data values of all fields
* are enforced in all copy constructors and assignment operators.
*
* @author Andrea Valassi and Marco Clemencic
* @date 2006-12-01
*/
class ConstRecordAdapter : public IRecord {
public:
virtual ~ConstRecordAdapter();
/// Constructor from a record spec and a _const_ AttributeList reference.
/// The AttributeList must have at least all the fields required by the
/// IRecordSpecification (with the correct name and storage type), but it
/// may have more: it is reinterpreted according to the new specification.
/// String attributes equal to NULL are considered equal to "".
ConstRecordAdapter( const IRecordSpecification& spec,
const coral::AttributeList& al );
/// Return the specification of this record.
const IRecordSpecification& specification() const;
/// Return a field in this record by its name (const).
const IField& operator[] ( const std::string& name ) const;
/// Return a field in this record by its index in [0, N-1] (const).
const IField& operator[] ( UInt32 index ) const;
/// Explicit conversion to a constant coral AttributeList reference.
/// The AttributeList returned by this method contains only the attributes
/// listed in the input IRecordSpecification, which may be fewer than
/// those contained in the wrapped constant AttributeList reference.
const coral::AttributeList& attributeList() const;
private:
/// Return a field in this record by its index in [0, N-1] (const).
const IField& field( UInt32 index ) const;
/// This method THROWS an exception because this is a read-only class.
IField& field( UInt32 index ); // THROWS...
private:
/// Default constructor is private
ConstRecordAdapter();
/// Copy constructor is private
ConstRecordAdapter( const ConstRecordAdapter& rhs );
/// Assignment operator is private
ConstRecordAdapter& operator=( const ConstRecordAdapter& rhs );
private:
/// The record specification.
RecordSpecification m_spec;
/// The record data (as an AttributeList const reference).
/// CONST REFERENCE: the adapter can only be used as long as this is alive!
const coral::AttributeList& m_attrList;
/// The IField wrappers for the individual data Attribute's.
std::vector< IField* > m_fields;
/// The AttributeList accessible via the attributeList public method.
coral::AttributeList m_publicAttrList;
};
}
#endif // RELATIONALCOOL_CONSTRECORDADAPTER_H
// $Id: DatabaseId.h,v 1.6 2006-04-03 17:02:19 avalassi Exp $
#ifndef COOLKERNEL_DATABASEID_H
#define COOLKERNEL_DATABASEID_H 1
#include <string>
namespace cool
{
/** @class DatabaseId DatabaseId.h
*
* Globally unique identifier of one "conditions database" instance.
*
* Recommended syntax without CORAL alias:
* "oracle://aTnsHost;schema=aUserName;dbname=aDbname";
* "mysql://aTcpHost;schema=aDatabase;dbname=aDbname";
* "sqlite://;schema=aFileName.db;dbname=aDbname";
*
* Recommended syntax with CORAL alias:
* "anAlias/aDbname";
*
* @author Andrea Valassi, Sven A. Schmidt and Marco Clemencic
* @date 2004-11-09
*/
typedef std::string DatabaseId;
}
#endif // COOLKERNEL_DATABASEID_H
This diff is collapsed.
// $Id: FieldSelection.h,v 1.14 2008-11-04 10:18:30 avalassi Exp $
#ifndef COOLKERNEL_FIELDSELECTION_H
#define COOLKERNEL_FIELDSELECTION_H 1
// Include files
#include "CoolKernel/FieldSpecification.h"
#include "CoolKernel/IRecordSelection.h"
#include "CoolKernel/Record.h"
namespace cool
{
//--------------------------------------------------------------------------
/** @class FieldSelection FieldSelection.h
*
* Simple selection on a data field.
*
* @author Andrea Valassi and Martin Wache
* @date 2008-07-28
*/
class FieldSelection : virtual public IRecordSelection
{
public:
/// Binary relation operator (comparison to a reference value).
enum Relation{ EQ, NE, GT, GE, LT, LE };
/// Unary nullness operator (comparison to NULL).
enum Nullness{ IS_NULL, IS_NOT_NULL };
/// Describe a binary relation operator.
static const std::string describe( Relation relation );
/// Describe a unary nullness operator.
static const std::string describe( Nullness nullness );
public:
/// Destructor.
virtual ~FieldSelection();
/// Constructor for comparison to non-NULL reference values.
template<typename T>
FieldSelection( const std::string& name,
const StorageType::TypeId typeId,
Relation relation,
const T& refValue );
/// Constructor for comparison to NULL.
FieldSelection( const std::string& name,
const StorageType::TypeId typeId,
Nullness nullness );