CMS 3D CMS Logo

HcalTBSource Class Reference

Note:
Notice that there is a hack to renumber events from runs where the first event number was zero.
More...

#include <IORawData/HcalTBInputService/interface/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, intm_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.

00017                                                                                               : 
00018   edm::ExternalInputSource(pset,desc),
00019   m_quiet( pset.getUntrackedParameter<bool>("quiet",true)),
00020   m_onlyRemapped( pset.getUntrackedParameter<bool>("onlyRemapped",false))
00021 {
00022   m_tree=0;
00023   m_fileCounter=-1;
00024   m_file=0;
00025   m_i=0;
00026 
00027   unpackSetup(pset.getUntrackedParameter<std::vector<std::string> >("streams",std::vector<std::string>()));
00028   produces<FEDRawDataCollection>();
00029 }

HcalTBSource::~HcalTBSource (  )  [virtual]

Definition at line 47 of file HcalTBSource.cc.

References m_file, and m_tree.

00047                             {
00048   if (m_file!=0) {
00049     m_file->Close();
00050     m_file=0;
00051     m_tree=0;
00052   }
00053 }


Member Function Documentation

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

Definition at line 55 of file HcalTBSource.cc.

References b, lat::endl(), 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().

00055                                                      {
00056   if (m_file!=0) {
00057     m_file->Close();
00058     m_file=0;
00059     m_tree=0;
00060   }
00061   
00062   //  try {
00063   m_file=TFile::Open(filename.c_str());
00064   if (m_file==0) {
00065     edm::LogError("HCAL") << "Unable to open " << filename << endl;
00066     m_tree=0;
00067     return;
00068   } 
00069   
00070   m_tree=(TTree*)m_file->Get("CMSRAW");
00071   
00072   if (m_tree==0) {
00073     m_file->Close();
00074     m_file=0;
00075     edm::LogError("HCAL") << "Unable to find CMSRAW tree" << endl;
00076     return;
00077   }
00078   
00079   if (!m_quiet) {
00080     edm::LogInfo("HCAL") << "Opening '" << filename << "' with " << m_tree->GetEntries() << " events.\n";
00081   }
00082   
00083   TObjArray* lb=m_tree->GetListOfBranches();
00084   n_chunks=0;
00085   for (int i=0; i<lb->GetSize(); i++) {
00086     TBranch* b=(TBranch*)lb->At(i);
00087     if (b==0) continue;
00088     if (!strcmp(b->GetClassName(),"CDFEventInfo")) {
00089       m_eventInfo=0;
00090       b->SetAddress(&m_eventInfo);
00091     } else {
00092       if (strcmp(b->GetClassName(),"CDFChunk")) continue;
00093       if (m_sourceIdRemap.find(b->GetName())==m_sourceIdRemap.end()) {
00094         if (m_onlyRemapped) continue;
00095         m_sourceIdRemap.insert(std::pair<std::string,int>(b->GetName(),-1));
00096         edm::LogInfo("HCAL") << "Also reading branch " << b->GetName();
00097       }
00098       
00099       m_chunks[n_chunks]=0; // allow ROOT to allocate 
00100       b->SetAddress(&(m_chunks[n_chunks]));
00101       m_chunkIds[n_chunks]=m_sourceIdRemap[b->GetName()];
00102       n_chunks++;
00103     }
00104   }
00105   m_i=0;
00106 }

bool HcalTBSource::produce ( edm::Event e  )  [protected, virtual]

Implements edm::ConfigurableInputSource.

Definition at line 147 of file HcalTBSource.cc.

References FEDRawData::data(), data, lat::endl(), SiStripThreshold::getData(), CDFChunk::getDataLength(), CDFChunk::getSourceId(), header, i, len, m_chunkIds, m_chunks, m_quiet, m_tree, n_chunks, edm::Event::put(), and FEDRawData::resize().

00147                                       {
00148 
00149   if (m_tree==0) {
00150     edm::LogError("HCAL") << "Null TTree";
00151     return false;
00152   }
00153 
00154   std::auto_ptr<FEDRawDataCollection> bare_product(new  FEDRawDataCollection());
00155   for (int i=0; i<n_chunks; i++) {
00156     const unsigned char* data=(const unsigned char*)m_chunks[i]->getData();
00157     int len=m_chunks[i]->getDataLength()*8;
00158 
00159     int natId=m_chunks[i]->getSourceId(); 
00160     int id=(m_chunkIds[i]>0)?(m_chunkIds[i]):(natId);
00161     
00162     FEDRawData& fed=bare_product->FEDData(id);
00163     fed.resize(len);
00164     memcpy(fed.data(),data,len);
00165 
00166     // patch the SourceId...
00167     if (natId!=id) {
00168       unsigned int* header=(unsigned int*)fed.data();
00169       header[0]=(header[0]&0xFFF000FFu)|(id<<8);
00170       // TODO: patch CRC after this change!
00171     }
00172     if (!m_quiet) 
00173       edm::LogInfo("HCAL") << "Reading " << len << " bytes for FED " << id << std::endl;
00174   }
00175 
00176   e.put(bare_product);
00177 
00178   return true;
00179 }

void HcalTBSource::setRunAndEventInfo (  )  [protected, virtual]

Reimplemented from edm::ConfigurableInputSource.

Definition at line 108 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(), size, and edm::ConfigurableInputSource::timeBetweenEvents().

00108                                       {
00109   bool is_new=false;
00110 
00111   while (m_tree==0 || m_i==m_tree->GetEntries()) {
00112     m_fileCounter++;
00113     if (m_file!=0) {
00114        m_file->Close();
00115        m_file=0; 
00116        m_tree=0;
00117     }
00118     if (m_fileCounter>=int(fileNames().size())) return; // nothing good
00119     openFile(fileNames()[m_fileCounter]);
00120     is_new=true;
00121   }
00122 
00123   if (m_tree==0 || m_i==m_tree->GetEntries()) return; //nothing good
00124 
00125   m_tree->GetEntry(m_i);
00126   m_i++;
00127 
00128   if (m_eventInfo!=0) {
00129     if (is_new) {
00130       if (m_eventInfo->getEventNumber()==0) m_eventNumberOffset=1;
00131       else m_eventNumberOffset=0;
00132     }
00133     if (m_eventInfo->getRunNumber()==0) setRunNumber(1); // ZERO is unacceptable from a technical point of view
00134     else setRunNumber(m_eventInfo->getRunNumber());
00135     setEventNumber(m_eventInfo->getEventNumber()+m_eventNumberOffset);
00136   } else {
00137     setRunNumber(m_fileCounter+10);
00138     setEventNumber(m_i+1);
00139   }  
00140   // time is a hack
00141   edm::TimeValue_t present_time = presentTime();
00142   unsigned long time_between_events = timeBetweenEvents();
00143 
00144   setTime(present_time + time_between_events);
00145 }

void HcalTBSource::unpackSetup ( const std::vector< std::string > &  params  )  [private]

Definition at line 31 of file HcalTBSource.cc.

References lat::endl(), i, and m_sourceIdRemap.

00031                                                                  {
00032   for (std::vector<std::string>::const_iterator i=params.begin(); i!=params.end(); i++) {
00033     unsigned long pos=i->find(':');
00034     std::string streamName=i->substr(0,pos);
00035     int remapTo=-1;
00036     if (pos!=std::string::npos) 
00037       remapTo=atoi(i->c_str()+pos+1);
00038     
00039     m_sourceIdRemap.insert(std::pair<std::string,int>(streamName,remapTo));
00040     if (remapTo!=-1) 
00041       edm::LogInfo("HCAL") << streamName << " --> " << remapTo << endl;
00042     else
00043       edm::LogInfo("HCAL") << streamName << " using fedid in file" << endl;
00044   }
00045 }


Member Data Documentation

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

Definition at line 42 of file HcalTBSource.h.

int HcalTBSource::m_chunkIds[CHUNK_COUNT] [private]

Definition at line 44 of file HcalTBSource.h.

Referenced by openFile(), and produce().

CDFChunk* HcalTBSource::m_chunks[CHUNK_COUNT] [private]

Definition at line 43 of file HcalTBSource.h.

Referenced by openFile(), and produce().

CDFEventInfo* HcalTBSource::m_eventInfo [private]

Definition at line 46 of file HcalTBSource.h.

Referenced by openFile(), and setRunAndEventInfo().

int HcalTBSource::m_eventNumberOffset [private]

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().

int HcalTBSource::m_fileCounter [private]

Definition at line 39 of file HcalTBSource.h.

Referenced by setRunAndEventInfo().

int HcalTBSource::m_i [private]

Definition at line 39 of file HcalTBSource.h.

Referenced by openFile(), and setRunAndEventInfo().

bool HcalTBSource::m_onlyRemapped [private]

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().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:23:58 2009 for CMSSW by  doxygen 1.5.4