CMS 3D CMS Logo

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

CDFRunInfo Class Reference

Per-run or per-file information. More...

#include <CDFRunInfo.h>

List of all members.

Public Member Functions

 CDFRunInfo ()
 CDFRunInfo (TFile *fromFile)
const char * get (const char *key) const
 Get some run info by name.
double getDouble (const char *key) const
 Get a run info item by name and convert it to a double.
int getInt (const char *key) const
 Get a run info item by name and convert it to an integer.
int getKeys (const char **buffer, int nbufs)
 fill the given array with key name pointers
int getSize () const
 get the number of items
bool hasKey (const char *key) const
 test for thr presence of given key
void print () const
 print all information to the terminal
void setInfo (const char *key, const char *value)
 add some information to the run info
void store (TFile *toFile)

Private Member Functions

bool load (TFile *fromFile)

Private Attributes

std::map< std::string,
std::string > 
m_mapData

Static Private Attributes

static const char * RootVariableName = "CDFRunInfo"

Detailed Description

Per-run or per-file information.

This class allows access to per-run or per-file information as opposed to per-event information such as CDFEventInfo. The information is stored in the form of string -> string pairs. There are utility methods for decoding string values as integers and doubles.

Definition at line 15 of file CDFRunInfo.h.


Constructor & Destructor Documentation

CDFRunInfo::CDFRunInfo ( )

Definition at line 8 of file CDFRunInfo.cc.

                       {
}
CDFRunInfo::CDFRunInfo ( TFile *  fromFile)

Definition at line 11 of file CDFRunInfo.cc.

References load().

                                  {
  load(file);
}

Member Function Documentation

const char * CDFRunInfo::get ( const char *  key) const

Get some run info by name.

Definition at line 15 of file CDFRunInfo.cc.

References i, m_mapData, and NULL.

                                                 {
  std::map<std::string,std::string>::const_iterator i=m_mapData.find(key);
  if (i==m_mapData.end()) return NULL;
  return i->second.c_str();
}
double CDFRunInfo::getDouble ( const char *  key) const

Get a run info item by name and convert it to a double.

Definition at line 27 of file CDFRunInfo.cc.

References gen::k, combine::key, and NULL.

                                                  {
  const char* k=get(key);
  if (k==NULL) return 0;
  return atof(k);
}
int CDFRunInfo::getInt ( const char *  key) const

Get a run info item by name and convert it to an integer.

Definition at line 21 of file CDFRunInfo.cc.

References gen::k, combine::key, and NULL.

                                            {
  const char* k=get(key);
  if (k==NULL) return 0;
  return atoi(k);
}
int CDFRunInfo::getKeys ( const char **  buffer,
int  nbufs 
)

fill the given array with key name pointers

Definition at line 33 of file CDFRunInfo.cc.

References i, j, and m_mapData.

                                                      {
  int j=0;
  for (std::map<std::string,std::string>::const_iterator i=m_mapData.begin(); i!=m_mapData.end() && j<nbufs; i++, j++) {
    buffer[j]=i->first.c_str();
  }
  return j;
}
int CDFRunInfo::getSize ( ) const [inline]

get the number of items

Definition at line 27 of file CDFRunInfo.h.

References m_mapData.

{ return m_mapData.size(); }
bool CDFRunInfo::hasKey ( const char *  key) const

test for thr presence of given key

Definition at line 41 of file CDFRunInfo.cc.

References i, and m_mapData.

                                             {
  std::map<std::string,std::string>::const_iterator i=m_mapData.find(key);
  return (i!=m_mapData.end());
}
bool CDFRunInfo::load ( TFile *  fromFile) [private]

Definition at line 50 of file CDFRunInfo.cc.

References a, b, i, m_mapData, NULL, python::connectstrParser::o, and RootVariableName.

Referenced by CDFRunInfo().

                              {
  m_mapData.clear();
  if (f==NULL) return false;
  TMap* pMap=(TMap*)f->Get(RootVariableName);
  if (pMap==NULL) return false;
  TIterator* i=pMap->MakeIterator();
  TObject* o;

  while ((o=i->Next())!=NULL) {
    std::string a(o->GetName());
    std::string b(pMap->GetValue(o)->GetName());
    m_mapData.insert(std::pair<std::string,std::string>(a,b));
  }
  return true;
}
void CDFRunInfo::print ( void  ) const

print all information to the terminal

Definition at line 76 of file CDFRunInfo.cc.

References i, and m_mapData.

                             {
   for (std::map<std::string,std::string>::const_iterator i=m_mapData.begin(); i!=m_mapData.end(); i++) 
     printf(" '%s' => '%s' \n",i->first.c_str(),i->second.c_str());
  
}
void CDFRunInfo::setInfo ( const char *  key,
const char *  value 
)

add some information to the run info

Definition at line 46 of file CDFRunInfo.cc.

References combine::key, m_mapData, and relativeConstraints::value.

Referenced by HcalTBWriter::analyze(), and HcalTBWriter::endJob().

void CDFRunInfo::store ( TFile *  toFile)

Definition at line 66 of file CDFRunInfo.cc.

References i, m_mapData, and RootVariableName.

Referenced by HcalTBWriter::endJob().

                               {
  f->cd();
  TMap* myMap=new TMap();
  for (std::map<std::string,std::string>::iterator i=m_mapData.begin(); i!=m_mapData.end(); i++) {
    myMap->Add(new TObjString(i->first.c_str()), new TObjString(i->second.c_str()));
  }
  myMap->SetName(RootVariableName);
  myMap->Write(RootVariableName,TObject::kSingleKey);
}

Member Data Documentation

std::map<std::string,std::string> CDFRunInfo::m_mapData [private]

Definition at line 42 of file CDFRunInfo.h.

Referenced by get(), getKeys(), getSize(), hasKey(), load(), print(), setInfo(), and store().

const char * CDFRunInfo::RootVariableName = "CDFRunInfo" [static, private]

Definition at line 41 of file CDFRunInfo.h.

Referenced by load(), and store().