Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 72 additions & 67 deletions DataFormats/SiPixelDigi/interface/PixelDigi.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,89 +11,94 @@
* Persistent digi for the Pixels.
*/

class PixelDigi {
public:
typedef unsigned int PackedDigiType;
typedef unsigned int ChannelType;
namespace io_v1 {
class PixelDigi {
public:
typedef unsigned int PackedDigiType;
typedef unsigned int ChannelType;

explicit PixelDigi(PackedDigiType packed_value) : theData(packed_value) {}
explicit PixelDigi(PackedDigiType packed_value) : theData(packed_value) {}

PixelDigi(int row, int col, int adc) { init(row, col, adc); }
PixelDigi(int row, int col, int adc, int flag) { init(row, col, adc, flag); }
PixelDigi(int row, int col, int adc) { init(row, col, adc); }
PixelDigi(int row, int col, int adc, int flag) { init(row, col, adc, flag); }

PixelDigi(int chan, int adc) {
std::pair<int, int> rc = channelToPixel(chan);
init(rc.first, rc.second, adc);
}
PixelDigi(int chan, int adc) {
std::pair<int, int> rc = channelToPixel(chan);
init(rc.first, rc.second, adc);
}

PixelDigi() : theData(0) {}
PixelDigi() : theData(0) {}

void init(int row, int col, int adc, int flag = 0) {
void init(int row, int col, int adc, int flag = 0) {
#ifdef FIXME_DEBUG
// This check is for the maximal row or col number that can be packed
// in a PixelDigi. The actual number of rows or columns in a detector
// may be smaller!
// it is done much better in Raw2Digi...
if (row < 0 || row > PixelChannelIdentifier::thePacking.max_row || col < 0 ||
col > PixelChannelIdentifier::thePacking.max_column) {
std::cout << "PixelDigi constructor: row or column out packing range " << row << ' ' << col << std::endl;
}
// This check is for the maximal row or col number that can be packed
// in a PixelDigi. The actual number of rows or columns in a detector
// may be smaller!
// it is done much better in Raw2Digi...
if (row < 0 || row > PixelChannelIdentifier::thePacking.max_row || col < 0 ||
col > PixelChannelIdentifier::thePacking.max_column) {
std::cout << "PixelDigi constructor: row or column out packing range " << row << ' ' << col << std::endl;
}
#endif

// Set adc to max_adc in case of overflow
adc = (adc > PixelChannelIdentifier::thePacking.max_adc) ? PixelChannelIdentifier::thePacking.max_adc
: std::max(adc, 0);

theData = (row << PixelChannelIdentifier::thePacking.row_shift) |
(col << PixelChannelIdentifier::thePacking.column_shift) |
(adc << PixelChannelIdentifier::thePacking.adc_shift) |
(flag << PixelChannelIdentifier::thePacking.flag_shift);
}
// Set adc to max_adc in case of overflow
adc = (adc > PixelChannelIdentifier::thePacking.max_adc) ? PixelChannelIdentifier::thePacking.max_adc
: std::max(adc, 0);

// Access to digi information
int row() const {
return (theData >> PixelChannelIdentifier::thePacking.row_shift) & PixelChannelIdentifier::thePacking.row_mask;
}
int column() const {
return (theData >> PixelChannelIdentifier::thePacking.column_shift) &
PixelChannelIdentifier::thePacking.column_mask;
}
int flag() const {
return (theData >> PixelChannelIdentifier::thePacking.flag_shift) & PixelChannelIdentifier::thePacking.flag_mask;
}
unsigned short adc() const {
return (theData >> PixelChannelIdentifier::thePacking.adc_shift) & PixelChannelIdentifier::thePacking.adc_mask;
}
PackedDigiType packedData() const { return theData; }
theData = (row << PixelChannelIdentifier::thePacking.row_shift) |
(col << PixelChannelIdentifier::thePacking.column_shift) |
(adc << PixelChannelIdentifier::thePacking.adc_shift) |
(flag << PixelChannelIdentifier::thePacking.flag_shift);
}

static std::pair<int, int> channelToPixel(int ch) {
int row = (ch >> PixelChannelIdentifier::thePacking.column_width) & PixelChannelIdentifier::thePacking.row_mask;
int col = ch & PixelChannelIdentifier::thePacking.column_mask;
return std::pair<int, int>(row, col);
}
// Access to digi information
int row() const {
return (theData >> PixelChannelIdentifier::thePacking.row_shift) & PixelChannelIdentifier::thePacking.row_mask;
}
int column() const {
return (theData >> PixelChannelIdentifier::thePacking.column_shift) &
PixelChannelIdentifier::thePacking.column_mask;
}
int flag() const {
return (theData >> PixelChannelIdentifier::thePacking.flag_shift) & PixelChannelIdentifier::thePacking.flag_mask;
}
unsigned short adc() const {
return (theData >> PixelChannelIdentifier::thePacking.adc_shift) & PixelChannelIdentifier::thePacking.adc_mask;
}
PackedDigiType packedData() const { return theData; }

static int pixelToChannel(int row, int col) { return (row << PixelChannelIdentifier::thePacking.column_width) | col; }
static std::pair<int, int> channelToPixel(int ch) {
int row = (ch >> PixelChannelIdentifier::thePacking.column_width) & PixelChannelIdentifier::thePacking.row_mask;
int col = ch & PixelChannelIdentifier::thePacking.column_mask;
return std::pair<int, int>(row, col);
}

int channel() const { return PixelChannelIdentifier::pixelToChannel(row(), column()); }
static int pixelToChannel(int row, int col) {
return (row << PixelChannelIdentifier::thePacking.column_width) | col;
}

private:
PackedDigiType theData;
};
int channel() const { return PixelChannelIdentifier::pixelToChannel(row(), column()); }

// Comparison operators
private:
PackedDigiType theData;
};

//inline bool operator<( const PixelDigi& one, const PixelDigi& other) {
// return one.channel() < other.channel();
//}
// Comparison operators

inline bool operator<(const PixelDigi& one, const PixelDigi& other) {
return (one.packedData() & PixelChannelIdentifier::thePacking.rowcol_mask) <
(other.packedData() & PixelChannelIdentifier::thePacking.rowcol_mask);
}
//inline bool operator<( const PixelDigi& one, const PixelDigi& other) {
// return one.channel() < other.channel();
//}

inline bool operator<(const PixelDigi& one, const PixelDigi& other) {
return (one.packedData() & PixelChannelIdentifier::thePacking.rowcol_mask) <
(other.packedData() & PixelChannelIdentifier::thePacking.rowcol_mask);
}
} // namespace io_v1
#include <iostream>
inline std::ostream& operator<<(std::ostream& o, const PixelDigi& digi) {
return o << " " << digi.channel() << " " << digi.adc();
}

namespace io_v1 {
inline std::ostream& operator<<(std::ostream& o, const PixelDigi& digi) {
return o << " " << digi.channel() << " " << digi.adc();
}
} // namespace io_v1
using PixelDigi = io_v1::PixelDigi;
#endif
33 changes: 18 additions & 15 deletions DataFormats/SiPixelDigi/interface/PixelDigiCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,26 @@
#include <map>
#include <utility>

class PixelDigiCollection {
public:
typedef std::vector<PixelDigi>::const_iterator ContainerIterator;
typedef std::pair<ContainerIterator, ContainerIterator> Range;
typedef std::pair<unsigned int, unsigned int> IndexRange;
typedef std::map<unsigned int, IndexRange> Registry;
typedef std::map<unsigned int, IndexRange>::const_iterator RegistryIterator;
namespace io_v1 {
class PixelDigiCollection {
public:
typedef std::vector<PixelDigi>::const_iterator ContainerIterator;
typedef std::pair<ContainerIterator, ContainerIterator> Range;
typedef std::pair<unsigned int, unsigned int> IndexRange;
typedef std::map<unsigned int, IndexRange> Registry;
typedef std::map<unsigned int, IndexRange>::const_iterator RegistryIterator;

PixelDigiCollection() {}
PixelDigiCollection() {}

void put(Range input, unsigned int detID);
const Range get(unsigned int detID) const;
const std::vector<unsigned int> detIDs() const;
void put(Range input, unsigned int detID);
const Range get(unsigned int detID) const;
const std::vector<unsigned int> detIDs() const;

private:
std::vector<PixelDigi> container_;
Registry map_;
};
private:
std::vector<PixelDigi> container_;
Registry map_;
};
} // namespace io_v1
using PixelDigiCollection = io_v1::PixelDigiCollection;

#endif // TRACKINGOBJECTS_PIXELDIGICOLLECTION_H
5 changes: 4 additions & 1 deletion DataFormats/SiPixelDigi/interface/PixelDigiFwd.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef DataFormats_SiPixelDigi_PixelDigiFwd_h
#define DataFormats_SiPixelDigi_PixelDigiFwd_h

class PixelDigi;
namespace io_v1 {
class PixelDigi;
}
using PixelDigi = io_v1::PixelDigi;

#endif
98 changes: 50 additions & 48 deletions DataFormats/SiPixelDigi/src/PixelDigiCollection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,69 @@
#include <iostream>
#include <algorithm>

void PixelDigiCollection::put(Range input, unsigned int detID) {
// put in Digis of detID
namespace io_v1 {
void PixelDigiCollection::put(Range input, unsigned int detID) {
// put in Digis of detID

// store size of vector before put
IndexRange inputRange;
// store size of vector before put
IndexRange inputRange;

// put in PixelDigis from input
bool first = true;
// put in PixelDigis from input
bool first = true;

// fill input in temporary vector for sorting
std::vector<PixelDigi> temporary;
PixelDigiCollection::ContainerIterator sort_begin = input.first;
PixelDigiCollection::ContainerIterator sort_end = input.second;
for (; sort_begin != sort_end; ++sort_begin) {
temporary.push_back(*sort_begin);
}
std::sort(temporary.begin(), temporary.end());
// fill input in temporary vector for sorting
std::vector<PixelDigi> temporary;
PixelDigiCollection::ContainerIterator sort_begin = input.first;
PixelDigiCollection::ContainerIterator sort_end = input.second;
for (; sort_begin != sort_end; ++sort_begin) {
temporary.push_back(*sort_begin);
}
std::sort(temporary.begin(), temporary.end());

// iterators over input
PixelDigiCollection::ContainerIterator begin = temporary.begin();
PixelDigiCollection::ContainerIterator end = temporary.end();
for (; begin != end; ++begin) {
container_.push_back(*begin);
if (first) {
inputRange.first = container_.size() - 1;
first = false;
// iterators over input
PixelDigiCollection::ContainerIterator begin = temporary.begin();
PixelDigiCollection::ContainerIterator end = temporary.end();
for (; begin != end; ++begin) {
container_.push_back(*begin);
if (first) {
inputRange.first = container_.size() - 1;
first = false;
}
}
inputRange.second = container_.size() - 1;

// fill map
map_[detID] = inputRange;
}
inputRange.second = container_.size() - 1;

// fill map
map_[detID] = inputRange;
}
const PixelDigiCollection::Range PixelDigiCollection::get(unsigned int detID) const {
// get Digis of detID

auto found = map_.find(detID);
PixelDigiCollection::IndexRange returnIndexRange{};
if (found != map_.end()) {
returnIndexRange = found->second;
}

const PixelDigiCollection::Range PixelDigiCollection::get(unsigned int detID) const {
// get Digis of detID
PixelDigiCollection::Range returnRange;
returnRange.first = container_.begin() + returnIndexRange.first;
returnRange.second = container_.begin() + returnIndexRange.second + 1;

auto found = map_.find(detID);
PixelDigiCollection::IndexRange returnIndexRange{};
if (found != map_.end()) {
returnIndexRange = found->second;
return returnRange;
}

PixelDigiCollection::Range returnRange;
returnRange.first = container_.begin() + returnIndexRange.first;
returnRange.second = container_.begin() + returnIndexRange.second + 1;

return returnRange;
}
const std::vector<unsigned int> PixelDigiCollection::detIDs() const {
// returns vector of detIDs in map

const std::vector<unsigned int> PixelDigiCollection::detIDs() const {
// returns vector of detIDs in map
PixelDigiCollection::RegistryIterator begin = map_.begin();
PixelDigiCollection::RegistryIterator end = map_.end();

PixelDigiCollection::RegistryIterator begin = map_.begin();
PixelDigiCollection::RegistryIterator end = map_.end();
std::vector<unsigned int> output;

std::vector<unsigned int> output;
for (; begin != end; ++begin) {
output.push_back(begin->first);
}

for (; begin != end; ++begin) {
output.push_back(begin->first);
return output;
}

return output;
}
} // namespace io_v1
40 changes: 20 additions & 20 deletions DataFormats/SiPixelDigi/src/classes_def.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<lcgdict>
<class name="PixelDigi" ClassVersion="10">
<version ClassVersion="10" checksum="3516592386"/>
<class name="io_v1::PixelDigi" ClassVersion="3">
<version ClassVersion="3" checksum="3522132610"/>
</class>
<class name="PixelDigiCollection" ClassVersion="10">
<version ClassVersion="10" checksum="544759626"/>
<class name="io_v1::PixelDigiCollection" ClassVersion="3">
<version ClassVersion="3" checksum="2939008250"/>
</class>
<class name="edm::DetSet<PixelDigi>"/>
<class name="std::vector<PixelDigi>"/>
<class name="edm::DetSetVector<PixelDigi>"/>
<class name="std::vector<edm::DetSet<PixelDigi> >"/>
<class name="edm::Wrapper< edm::DetSet<PixelDigi> >" splitLevel="0"/>
<class name="edm::Wrapper< std::vector<edm::DetSet<PixelDigi> > >" splitLevel="0"/>
<class name="edm::Wrapper< edm::DetSetVector<PixelDigi> >" splitLevel="0"/>
<class name="edm::Wrapper<PixelDigiCollection>" splitLevel="0"/>
<class name="edm::DetSet<io_v1::PixelDigi>"/>
<class name="std::vector<io_v1::PixelDigi>"/>
<class name="edm::DetSetVector<io_v1::PixelDigi>"/>
<class name="std::vector<edm::DetSet<io_v1::PixelDigi> >"/>
<class name="edm::Wrapper< edm::DetSet<io_v1::PixelDigi> >" splitLevel="0"/>
<class name="edm::Wrapper< std::vector<edm::DetSet<io_v1::PixelDigi> > >" splitLevel="0"/>
<class name="edm::Wrapper< edm::DetSetVector<io_v1::PixelDigi> >" splitLevel="0"/>
<class name="edm::Wrapper<io_v1::PixelDigiCollection>" splitLevel="0"/>

<class name="edmNew::DetSetVector<PixelDigi>"/>
<class name="edm::Wrapper< edmNew::DetSetVector<PixelDigi> >"/>
<class name="edmNew::DetSetVector<io_v1::PixelDigi>"/>
<class name="edm::Wrapper< edmNew::DetSetVector<io_v1::PixelDigi> >"/>

<class name="SiPixelCalibDigi::datacontainer" ClassVersion="10">
<version ClassVersion="10" checksum="3289693280"/>
<class name="SiPixelCalibDigi::datacontainer" ClassVersion="3">
<version ClassVersion="3" checksum="3289693280"/>
</class>
<class name="std::vector<SiPixelCalibDigi::datacontainer>"/>
<class name="SiPixelCalibDigi" ClassVersion="10">
<version ClassVersion="10" checksum="3382452939"/>
<class name="SiPixelCalibDigi" ClassVersion="3">
<version ClassVersion="3" checksum="3382452939"/>
</class>
<class name="std::vector<SiPixelCalibDigi>"/>
<class name="edm::DetSet<SiPixelCalibDigi>"/>
Expand All @@ -35,8 +35,8 @@
<class name="edmNew::DetSetVector<SiPixelCalibDigi>"/>
<class name="edm::Wrapper< edmNew::DetSetVector<SiPixelCalibDigi> >"/>

<class name="SiPixelCalibDigiError" ClassVersion="10">
<version ClassVersion="10" checksum="1495440127"/>
<class name="SiPixelCalibDigiError" ClassVersion="3">
<version ClassVersion="3" checksum="1495440127"/>
</class>
<class name="edm::DetSet<SiPixelCalibDigiError>"/>
<class name="std::vector<SiPixelCalibDigiError>"/>
Expand Down