// Author: Thomas Hadig (Group EB SLAC Stanford CA USA)
// Last update: $Date: 2003/08/22 22:31:12 $
// Copyright: Thomas Hadig, hadig@slac.stanford.edu

#ifndef __CRTTDC2277BOARD_CXX
#define __CRTTDC2277BOARD_CXX

////////////////////////////////////////////////////////////////////////////////
//
// Cosmic Ray Telescope Data Aquisition Software
//
// generic driver for Camac module: LeCroy 2277 TDC
//
// This module features:
// - 32 channels, 16 bit each
// - read-out is sequentially, i.e. 32 times reading of "channel" 0 
//   gives the 32 values
// - has a status register (encoded here as channel 1)
//
////////////////////////////////////////////////////////////////////////////////

#include <gendriver/tdc2277board.hh>
#include <gendriver/camaccrate.hh>

namespace CRT
 { 
  //{{{}}}
  //{{{  default constructor
   CrtTdc2277Board::CrtTdc2277Board() : CrtTdcAdcBoard()
   {
    // default constructor
    fOk=0;
   }
  //}}}
  //{{{  constructor CrtTdc2277Board(const Char_t *inName, Int_t inBoardNumber, CrtCamacCrate *inCrate)
   CrtTdc2277Board::CrtTdc2277Board(const Char_t *inName, Int_t inBoardNumber, CrtCamacCrate *inCrate)
    : CrtTdcAdcBoard(inName, inBoardNumber, inCrate)
   {
    // constructor
    // inBoardNumber is the number of the Camac slot
    // inCrate       is a pointer to the Camac crate object
    Int_t i=0;
    while (i<2)
     //{{{  fill identity array
     {
      fIdents[i]=inCrate->GetIdentity(inBoardNumber, i);
      i++;
     }
     //}}}
    fOk=1;
   }
  //}}}
  //{{{  destructor
   CrtTdc2277Board::~CrtTdc2277Board()
   {
    // destructor
   }
  //}}}
  
  //{{{  Send
   Int_t CrtTdc2277Board::Send(Int_t inCommand) const
   {
    // sends command to board
    // available commands:
    // CrtTdc2277Board::C_TDC2277_ClearModule 
    // CrtTdc2277Board::C_TDC2277_TestModule
   
    if (fOk!=1) return -1;
    switch (inCommand)
     {
      case C_TDC2277_ClearModule:
        return fInCrate->Send(fIdents[0], 9, 0);
      case C_TDC2277_TestModule:
        return fInCrate->Send(fIdents[0], 25, 0);
     }
    return -1;
   }
  //}}}
  //{{{  Enable
   Int_t CrtTdc2277Board::Enable(Int_t inFlag, Int_t) const
   {
    // enables board features
    // Available features:
    // CrtTdc2277Board::F_TDC2277_LAM (Look-At-Me)
   
    if (fOk!=1) return -1;
    switch(inFlag)
     {
      case F_TDC2277_LAM: 
        return fInCrate->Send(fIdents[0], 26, 0);
     }
    return -1;
   }
  //}}}
  //{{{  Disable
   Int_t CrtTdc2277Board::Disable(Int_t inFlag, Int_t) const
   {
    // disables board features
    // Available features:
    // CrtTdc2277Board::F_TDC2277_LAM (Look-At-Me)
   
    if (fOk!=1) return -1;
    switch(inFlag)
     {
      case F_TDC2277_LAM: 
        return fInCrate->Send(fIdents[0], 24, 0);
     }
    return -1;
   }
  //}}}
  //{{{  Clear
   Int_t CrtTdc2277Board::Clear(Int_t inFlag, Int_t) const
   {
    // clears board features
    // Available features:
    // CrtTdc2277Board::F_TDC2277_LAM (Look-At-Me)
   
    if (fOk!=1) return -1;
    switch(inFlag)
     {
      case F_TDC2277_LAM: 
        return fInCrate->Send(fIdents[0], 10, 0);
     }
    return -1;
   }
  //}}}
  //{{{  Test
   Int_t CrtTdc2277Board::Test(Int_t inFlag, Int_t) const
   {
    // tests board features
    // Available features:
    // CrtTdc2277Board::F_TDC2277_LAM (Look-At-Me)
    // CrtTdc2277Board::F_TDC2277_BufferingInProgress
    // CrtTdc2277Board::F_TDC2277_BUSY
   
    if (fOk!=1) return -1;
    switch(inFlag)
     {
      case F_TDC2277_LAM: 
        return fInCrate->Test(fIdents[0], 8);
      case F_TDC2277_BufferingInProgress: 
        return fInCrate->Test(fIdents[0], 27);
      case F_TDC2277_BUSY: 
        return fInCrate->Test(fIdents[1], 27);
     }
    return -1;
   }
  //}}}
  //{{{  Query
   Int_t CrtTdc2277Board::Query(Int_t inChannel, Int_t *outValue) const
   {
    // queries channels
    // available channels:
    // 0: sequentially read data of all 32 channels
    //    return value encodes the value and the channel number
    // 1: status register
    //    bits  1,2: tester hit bit (00: 1 hit, 01: 2 hits, 10: 4 hits, 11: 8 hits)
    //    bits  3,4: tester hit duration (00: 128, 01: 256, 10: 1024, 11: 2048 ns)
    //    bit     8: trigger mode (0: pulse, 1: latch)
    //    bit     9: odd channel test input (1: enable) 
    //    bit    10: even channel test input (1: enable) 
    //    bit    11: hit trailing edge recoding: (1: enable) 
    //    bit    12: hit leading edge recoding: (1: enable) 
    //    bit 13-15: common start timeout (000: front panel, 001-111: 1024, 2048, 4096, 8192, 16384, 32768, 65536 ns)
    //    bit    16: mode (0: common stop, 1: common start)
   
    if (fOk!=1) return -1;
    if ((inChannel<0)||(inChannel>1)) return -1;
    return fInCrate->Read(fIdents[0], inChannel, outValue);
   }
  //}}}
  //{{{  Assign
   Int_t CrtTdc2277Board::Assign(Int_t inChannel, Int_t inValue) const
   {
    // assigns channels
    // available channels:
    // 1: status register (for bit information see Query)
   
   if (fOk!=1) return -1;
    if (inChannel!=1) return -1;
    return fInCrate->Send(fIdents[0], 17, inValue);
   }
  //}}}
  
  //{{{  Initialize
   Int_t CrtTdc2277Board::Initialize() const
   {
    // initializes the board
    return Send(C_TDC2277_ClearModule);
   }
  //}}}
  //{{{  Prepare
   Int_t CrtTdc2277Board::Prepare() const
   {
    // prepares the board for data taking

    if (Assign(1, 0x9800)==0) return 0;
    if (Clear(F_TDC2277_LAM)==0) return 0;   // clear LAMs
    if (Enable(F_TDC2277_LAM)==0) return 0;   // enable LAMs
    return 1;
   }
  //}}}
  //{{{  HasData
   Int_t CrtTdc2277Board::HasData() const
   {
    // tests whether the module has data available
    return Test(F_TDC2277_LAM);
   }
  //}}}
  //{{{  ReadModule
   Int_t CrtTdc2277Board::ReadModuleAndClear(Int_t *outChannels) const
   {
    // reads all channels and clears the data afterwards.
    // returns only first hit in each channel
    Int_t i=0, value, channel, data, count=0;
    while (i<32)
     {
      outChannels[i++]=0;
     }
    while (Test(CrtTdc2277Board::F_TDC2277_BUSY)!=0) 
     {
      if (Query(0,&value)==0) break;
      // data structure is 16 bit data, 1 bit edge polarity, 5 bit channel 
      data = value & 0xFFFF;
      channel = (value & 0x3E0000) >>17;
      if (outChannels[channel]<20)
       { 
        outChannels[channel]=data;
        count++;
       }
      else if ((data>=20)&&(data<outChannels[channel]))
       {
        outChannels[channel]=data;
       }
     }
    return count;
   }
  //}}}
  //{{{  ReadModuleAllHits
   Int_t CrtTdc2277Board::ReadModuleAllHitsAndClear(Int_t *outChannels) const
   {
    // reads all hits on all channels and clears the data afterwards.
    // The array given has to have the size 
    // MAX_HITS * MAX_CHANNELS = 16 * 32 = 512,
    // the data will be ordered: hit_in_channel * 32 + channel_no
    
    Int_t i=0, value, channel, data, count=0;
    Int_t currentnum[32];
    while (i<32*16)
     {
      outChannels[i++]=0;
     }
    i=0;
    while (i<32)
     {
      currentnum[i++]=0;
     }
    while (Test(CrtTdc2277Board::F_TDC2277_BUSY)!=0) 
     {
      if (Query(0,&value)==0) break;
      // data structure is 16 bit data, 1 bit edge polarity, 5 bit channel 
      data = value & 0xFFFF;
      if (data==0) continue;
      if (data<20) continue;
      if ((value & 0x10000) ==0) data *= -1; // check edge polarity
      channel = (value & 0x3E0000) >>17;
      if (currentnum[channel]<16)
       {
        if (currentnum[channel]>0)
          if (outChannels[(currentnum[channel]-1)*32+channel]==data)
            continue;  // suppress multiple hits at same time
        outChannels[currentnum[channel]*32+channel]=data;
        currentnum[channel]++;
        count++;
       }
     }
    return count;
   }
  //}}}
  //{{{  GetNumberOfChannels
   Int_t CrtTdc2277Board::GetNumberOfChannels() const
   {
    return 32;
   }
  //}}}
 }
 
ClassImp(CRT::CrtTdc2277Board) //LeCroy 2277 TDC module driver

#endif


ROOT page - Class index - Class Hierarchy - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.