CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes

HcalTBSource Class Reference

#include <HcalTBSource.h>

Inheritance diagram for HcalTBSource:
edm::ExternalInputSource edm::ConfigurableInputSource edm::InputSource edm::ProductRegistryHelper

List of all members.

Public Member Functions

 HcalTBSource (const edm::ParameterSet &pset, edm::InputSourceDescription const &desc)
virtual ~HcalTBSource ()

Protected Member Functions

virtual bool produce (edm::Event &e)
virtual void setRunAndEventInfo ()

Private Member Functions

void openFile (const std::string &filename)
void unpackSetup (const std::vector< std::string > &params)

Private Attributes

int m_chunkIds [CHUNK_COUNT]
CDFChunkm_chunks [CHUNK_COUNT]
CDFEventInfom_eventInfo
int m_eventNumberOffset
TFile * m_file
int m_fileCounter
int m_i
bool m_onlyRemapped
bool m_quiet
std::map< std::string, int > m_sourceIdRemap
TTree * m_tree
int n_chunks

Static Private Attributes

static const int CHUNK_COUNT = 64

Detailed Description

Note:
Notice that there is a hack to renumber events from runs where the first event number was zero.
Date:
2008/10/16 08:09:12
Revision:
1.7
Author:
J. Mans - Minnesota

Definition at line 27 of file HcalTBSource.h.


Constructor & Destructor Documentation

HcalTBSource::HcalTBSource ( const edm::ParameterSet pset,
edm::InputSourceDescription const &  desc 
) [explicit]

Definition at line 17 of file HcalTBSource.cc.

                                                                                              : 
  edm::ExternalInputSource(pset,desc),
  m_quiet( pset.getUntrackedParameter<bool>("quiet",true)),
  m_onlyRemapped( pset.getUntrackedParameter<bool>("onlyRemapped",false))
{
  m_tree=0;
  m_fileCounter=-1;
  m_file=0;
  m_i=0;

  unpackSetup(pset.getUntrackedParameter<std::vector<std::string> >("streams",std::vector<std::string>()));
  produces<FEDRawDataCollection>();
}
HcalTBSource::~HcalTBSource ( ) [virtual]

Definition at line 47 of file HcalTBSource.cc.

References m_file, and m_tree.

                            {
  if (m_file!=0) {
    m_file->Close();
    m_file=0;
    m_tree=0;
  }
}

Member Function Documentation

void HcalTBSource::openFile ( const std::string &  filename) [private]

Definition at line 55 of file HcalTBSource.cc.

References b, i, m_chunkIds, m_chunks, m_eventInfo, m_file, m_i, m_onlyRemapped, m_quiet, m_sourceIdRemap, m_tree, and n_chunks.

Referenced by setRunAndEventInfo().

                                                     {
  if (m_file!=0) {
    m_file->Close();
    m_file=0;
    m_tree=0;
  }
  
  //  try {
  m_file=TFile::Open(filename.c_str());
  if (m_file==0) {
    edm::LogError("HCAL") << "Unable to open " << filename << endl;
    m_tree=0;
    return;
  } 
  
  m_tree=(TTree*)m_file->Get("CMSRAW");
  
  if (m_tree==0) {
    m_file->Close();
    m_file=0;
    edm::LogError("HCAL") << "Unable to find CMSRAW tree" << endl;
    return;
  }
  
  if (!m_quiet) {
    edm::LogInfo("HCAL") << "Opening '" << filename << "' with " << m_tree->GetEntries() << " events.\n";
  }
  
  TObjArray* lb=m_tree->GetListOfBranches();
  n_chunks=0;
  for (int i=0; i<lb->GetSize(); i++) {
    TBranch* b=(TBranch*)lb->At(i);
    if (b==0) continue;
    if (!strcmp(b->GetClassName(),"CDFEventInfo")) {
      m_eventInfo=0;
      b->SetAddress(&m_eventInfo);
    } else {
      if (strcmp(b->GetClassName(),"CDFChunk")) continue;
      if (m_sourceIdRemap.find(b->GetName())==m_sourceIdRemap.end()) {
        if (m_onlyRemapped) continue;
        m_sourceIdRemap.insert(std::pair<std::string,int>(b->GetName(),-1));
        if (!m_quiet)
          edm::LogInfo("HCAL") << "Also reading branch " << b->GetName();
      }
      
      m_chunks[n_chunks]=0; // allow ROOT to allocate 
      b->SetAddress(&(m_chunks[n_chunks]));
      m_chunkIds[n_chunks]=m_sourceIdRemap[b->GetName()];
      n_chunks++;
    }
  }
  m_i=0;
}
bool HcalTBSource::produce ( edm::Event e) [protected, virtual]

Implements edm::ConfigurableInputSource.

Definition at line 148 of file HcalTBSource.cc.

References FEDRawData::data(), AlCaHLTBitMon_QueryRunRegistry::data, edm::ExternalInputSource::fileNames(), AlCaHLTBitMon_QueryRunRegistry::getData(), CDFChunk::getDataLength(), CDFChunk::getSourceId(), i, m_chunkIds, m_chunks, m_fileCounter, m_quiet, m_tree, n_chunks, edm::Event::put(), FEDRawData::resize(), and findQualityFiles::size.

                                      {

  if (m_fileCounter>=int(fileNames().size())) return false; // all done!

  if (m_tree==0) {
    edm::LogError("HCAL") << "Null TTree";
    return false;
  }

  std::auto_ptr<FEDRawDataCollection> bare_product(new  FEDRawDataCollection());
  for (int i=0; i<n_chunks; i++) {
    const unsigned char* data=(const unsigned char*)m_chunks[i]->getData();
    int len=m_chunks[i]->getDataLength()*8;

    int natId=m_chunks[i]->getSourceId(); 
    int id=(m_chunkIds[i]>0)?(m_chunkIds[i]):(natId);
    
    FEDRawData& fed=bare_product->FEDData(id);
    fed.resize(len);
    memcpy(fed.data(),data,len);

    // patch the SourceId...
    if (natId!=id) {
      unsigned int* header=(unsigned int*)fed.data();
      header[0]=(header[0]&0xFFF000FFu)|(id<<8);
      // TODO: patch CRC after this change!
    }
    if (!m_quiet) 
      edm::LogInfo("HCAL") << "Reading " << len << " bytes for FED " << id << std::endl;
  }

  e.put(bare_product);

  return true;
}
void HcalTBSource::setRunAndEventInfo ( ) [protected, virtual]

Reimplemented from edm::ConfigurableInputSource.

Definition at line 109 of file HcalTBSource.cc.

References edm::ExternalInputSource::fileNames(), CDFEventInfo::getEventNumber(), CDFEventInfo::getRunNumber(), m_eventInfo, m_eventNumberOffset, m_file, m_fileCounter, m_i, m_tree, openFile(), edm::ConfigurableInputSource::presentTime(), edm::ConfigurableInputSource::setEventNumber(), edm::InputSource::setRunNumber(), edm::ConfigurableInputSource::setTime(), findQualityFiles::size, and edm::ConfigurableInputSource::timeBetweenEvents().

                                      {
  bool is_new=false;

  while (m_tree==0 || m_i==m_tree->GetEntries()) {
    m_fileCounter++;
    if (m_file!=0) {
       m_file->Close();
       m_file=0; 
       m_tree=0;
    }
    if (m_fileCounter>=int(fileNames().size())) return; // nothing good
    openFile(fileNames()[m_fileCounter]);
    is_new=true;
  }

  if (m_tree==0 || m_i==m_tree->GetEntries()) return; //nothing good

  m_tree->GetEntry(m_i);
  m_i++;

  if (m_eventInfo!=0) {
    if (is_new) {
      if (m_eventInfo->getEventNumber()==0) m_eventNumberOffset=1;
      else m_eventNumberOffset=0;
    }
    if (m_eventInfo->getRunNumber()==0) setRunNumber(1); // ZERO is unacceptable from a technical point of view
    else setRunNumber(m_eventInfo->getRunNumber());
    setEventNumber(m_eventInfo->getEventNumber()+m_eventNumberOffset);
  } else {
    setRunNumber(m_fileCounter+10);
    setEventNumber(m_i+1);
  }  
  // time is a hack
  edm::TimeValue_t present_time = presentTime();
  unsigned long time_between_events = timeBetweenEvents();

  setTime(present_time + time_between_events);
}
void HcalTBSource::unpackSetup ( const std::vector< std::string > &  params) [private]

Definition at line 31 of file HcalTBSource.cc.

References i, m_sourceIdRemap, and pos.

                                                                 {
  for (std::vector<std::string>::const_iterator i=params.begin(); i!=params.end(); i++) {
    unsigned long pos=i->find(':');
    std::string streamName=i->substr(0,pos);
    int remapTo=-1;
    if (pos!=std::string::npos) 
      remapTo=atoi(i->c_str()+pos+1);
    
    m_sourceIdRemap.insert(std::pair<std::string,int>(streamName,remapTo));
    if (remapTo!=-1) 
      edm::LogInfo("HCAL") << streamName << " --> " << remapTo << endl;
    else
      edm::LogInfo("HCAL") << streamName << " using fedid in file" << endl;
  }
}

Member Data Documentation

const int HcalTBSource::CHUNK_COUNT = 64 [static, private]

Definition at line 42 of file HcalTBSource.h.

Definition at line 44 of file HcalTBSource.h.

Referenced by openFile(), and produce().

Definition at line 43 of file HcalTBSource.h.

Referenced by openFile(), and produce().

Definition at line 46 of file HcalTBSource.h.

Referenced by openFile(), and setRunAndEventInfo().

Definition at line 47 of file HcalTBSource.h.

Referenced by setRunAndEventInfo().

TFile* HcalTBSource::m_file [private]

Definition at line 38 of file HcalTBSource.h.

Referenced by openFile(), setRunAndEventInfo(), and ~HcalTBSource().

Definition at line 39 of file HcalTBSource.h.

Referenced by produce(), and setRunAndEventInfo().

int HcalTBSource::m_i [private]

Definition at line 39 of file HcalTBSource.h.

Referenced by openFile(), and setRunAndEventInfo().

Definition at line 40 of file HcalTBSource.h.

Referenced by openFile().

bool HcalTBSource::m_quiet [private]

Definition at line 40 of file HcalTBSource.h.

Referenced by openFile(), and produce().

std::map<std::string,int> HcalTBSource::m_sourceIdRemap [private]

Definition at line 45 of file HcalTBSource.h.

Referenced by openFile(), and unpackSetup().

TTree* HcalTBSource::m_tree [private]

Definition at line 37 of file HcalTBSource.h.

Referenced by openFile(), produce(), setRunAndEventInfo(), and ~HcalTBSource().

int HcalTBSource::n_chunks [private]

Definition at line 41 of file HcalTBSource.h.

Referenced by openFile(), and produce().