| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

StatisticsSvc Class Reference

#include <StatisticsSvc.h>

Inheritance diagram for StatisticsSvc:

[legend]
Collaboration diagram for StatisticsSvc:
[legend]
List of all members.

Public Types

 SUCCESS
 NO_INTERFACE
 VERSMISMATCH
 LAST_ERROR
enum  Status

Public Member Functions

 StatisticsSvc (const std::string &name, ISvcLocator *svc)
 ~StatisticsSvc ()
virtual StatusCode initialize ()
virtual StatusCode finalize ()
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface)
virtual StatusCode put (const std::string &path, TObject *object)
 Place the object at the specified path.
virtual TObject * get (const std::string &path)
 Return the object which exists at this path If there is no object, or if the path does not exist, return 0.
virtual bool exists (const std::string &path)
 Return true if a folder or object exists at the given path.
virtual std::vector< std::string > getContents (const std::string &path)
 Return a list of the names of the objects which exist in the folder An empty list is returned if the path does not exist, or contains no objects.
virtual std::vector< std::string > getSubFolders (const std::string &path)
 Return a list of the names of the subfolders which exist in the folder An empty list is returned if the folder does not exist, or contains no subfolders.
virtual TH1F * getTH1F (const std::string &path)
 Return the TH1F which exists at this path Return 0 if unsuccessful.
virtual TH2F * getTH2F (const std::string &path)
 Return the TH2F which exists at this path Return 0 if unsuccessful.
virtual TH3F * getTH3F (const std::string &path)
 Return the TH3F which exists at this path Return 0 if unsuccessful.
virtual TTree * getTree (const std::string &path)
 Return the TTree which exists at this path Return 0 if unsuccessful.
virtual TGraph * getGraph (const std::string &path)
 Return the TGraph which exists at this path Return 0 if unsuccessful.
virtual unsigned long addRef ()
virtual unsigned long release ()
virtual const std::string & name () const
virtual const InterfaceIDtype () const
virtual StatusCode configure ()
virtual StatusCode start ()
virtual StatusCode stop ()
virtual StatusCode terminate ()
virtual Gaudi::StateMachine::State FSMState () const
virtual Gaudi::StateMachine::State targetFSMState () const
virtual StatusCode reinitialize ()
virtual StatusCode restart ()
virtual StatusCode sysInitialize ()
virtual StatusCode sysStart ()
virtual StatusCode sysStop ()
virtual StatusCode sysFinalize ()
virtual StatusCode sysReinitialize ()
virtual StatusCode sysRestart ()
virtual StatusCode setProperty (const Property &p)
virtual StatusCode setProperty (const std::string &s)
virtual StatusCode setProperty (const std::string &n, const std::string &v)
StatusCode setProperty (const std::string &name, const TYPE &value)
virtual StatusCode getProperty (Property *p) const
virtual const PropertygetProperty (const std::string &name) const
virtual StatusCode getProperty (const std::string &n, std::string &v) const
virtual const std::vector<
Property * > & 
getProperties () const
ISvcLocatorserviceLocator () const
IMessageSvcmsgSvc ()
IMessageSvcmsgSvc () const
IMessageSvcmessageService ()
IMessageSvcmessageService () const
StatusCode setProperties ()
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
IAuditorSvcauditorSvc () const

Static Public Member Functions

static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()

Public Attributes

 SUCCESS
 NO_INTERFACE
 VERSMISMATCH
 LAST_ERROR

Protected Member Functions

int outputLevel () const

Protected Attributes

IntegerProperty m_outputLevel
Gaudi::StateMachine::State m_state
Gaudi::StateMachine::State m_targetState
IMessageSvcm_messageSvc

Private Member Functions

StatusCode checkOptions (std::string &handle, std::string &filename)
StatusCode parsePath (const std::string &fullpath, std::string &top, std::string &rest)
StatusCode reverseParsePath (const std::string &fullpath, std::string &rest, std::string &bottom)
StatusCode getManager (const std::string &path, HistMan *&hm, std::string &localPath, bool report=true)
void dump ()
void dumpPath (const std::string &path, std::ostringstream &dumpStr)

Private Attributes

std::map< std::string, std::string > m_input
 Property: Input List of path, input files pairs {"path0": "myfile0.root", <etc.
std::map< std::string, std::string > m_output
 Property: Output List of path, output file pairs {"path1": "myfile1.root", <etc.
IMessageSvcm_msgSvc
std::map< std::string, TFile * > m_files
std::map< std::string, HistMan * > m_histMan

Friends

friend class ServiceManager

Detailed Description

Definition at line 25 of file StatisticsSvc.h.


Constructor & Destructor Documentation

StatisticsSvc::StatisticsSvc ( const std::string &  name,
ISvcLocator svc 
)

Definition at line 12 of file StatisticsSvc.cc.

00013   : Service(name,svc),
00014     m_msgSvc(0)
00015 {
00016   
00017   declareProperty("Input",m_input /*map<string,string>*/,
00018                   "List of path, input file pairs.");
00019   declareProperty("Output",m_output /*map<string,string>*/,
00020                   "List of path, output file pairs.");
00021 }

StatisticsSvc::~StatisticsSvc (  ) 

Definition at line 23 of file StatisticsSvc.cc.

00024 {
00025 }


Member Function Documentation

StatusCode StatisticsSvc::initialize (  )  [virtual]

Reimplemented from Service.

Definition at line 52 of file StatisticsSvc.cc.

00053 {
00054   StatusCode sc = this->Service::initialize();
00055   if( sc.isFailure() ) return sc;
00056   
00057   m_msgSvc = msgSvc();
00058   if( !m_msgSvc ) return StatusCode::FAILURE;
00059 
00060   {
00061     std::ostringstream msgStr;
00062     msgStr << "initialize()";
00063     m_msgSvc->reportMessage("StatisticsSvc",MSG::INFO,msgStr.str()); 
00064   }
00065 
00066   std::map<std::string, std::string> fileModeByFilename;
00067   std::vector<std::string> inHandles;
00068   std::vector<std::string> inFiles;
00069   std::vector<std::string> outHandles;
00070   std::vector<std::string> outFiles;
00071 
00072   m_input = xrootdify_map(m_input);
00073   m_output = xrootdify_map(m_output);
00074 
00075   // Parse the input files 
00076   std::map<std::string,std::string>::const_iterator inputIter, 
00077     inputEnd = m_input.end();
00078   for(inputIter=m_input.begin(); inputIter != inputEnd; inputIter++){
00079     std::string handle = inputIter->first;
00080     std::string filename = inputIter->second;
00081     sc = checkOptions(handle, filename);    
00082     if( sc.isFailure() ) return sc;
00083 
00084     // Check if handle already exists
00085     if( std::find(inHandles.begin(), inHandles.end(), handle) 
00086         != inHandles.end() ){
00087         std::ostringstream msgStr;
00088         msgStr << "initialize(): File handle " 
00089                << handle << " already associated with input file " 
00090                << m_input[handle];
00091         m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str()); 
00092         return StatusCode::FAILURE;
00093     }
00094     // Check if filename already exists
00095     if( std::find(inFiles.begin(), inFiles.end(), filename) != inFiles.end() ){
00096         std::ostringstream msgStr;
00097         msgStr << "initialize(): Filename " 
00098                << filename << " already associated with an input handle.";
00099         m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str()); 
00100         return StatusCode::FAILURE;
00101     }
00102     // Add handle, filename to file lists
00103     inHandles.push_back(handle);
00104     inFiles.push_back(filename);
00105     m_histMan[handle] = 0;
00106     // Default to Read-only
00107     fileModeByFilename[filename]="READ";
00108   }
00109 
00110   // Parse the output files 
00111   std::map<std::string,std::string>::const_iterator outputIter, 
00112     outputEnd = m_output.end();
00113   for(outputIter=m_output.begin(); outputIter != outputEnd; outputIter++){
00114     std::string handle = outputIter->first;
00115     std::string filename = outputIter->second;
00116     sc = checkOptions(handle, filename);
00117     if( sc.isFailure() ) return sc;
00118     // Check if output handle already exists
00119     if( std::find(outHandles.begin(), outHandles.end(), handle) 
00120         != outHandles.end() ){
00121         std::ostringstream msgStr;
00122         msgStr << "initialize(): Output File handle " 
00123                << handle << " already associated with file " 
00124                << m_output[handle];
00125         m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str()); 
00126         return StatusCode::FAILURE;
00127     }
00128     // Check if output filename already exists
00129     if( std::find(outFiles.begin(), outFiles.end(), filename) 
00130         != outFiles.end() ){
00131         std::ostringstream msgStr;
00132         msgStr << "initialize(): Output Filename " 
00133                << filename << " already associated with an output handle.";
00134         m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str()); 
00135         return StatusCode::FAILURE;
00136     }
00137 
00138     // Check if output filename is same as input filename
00139     if( std::find(inFiles.begin(), inFiles.end(), filename) != inFiles.end()){
00140       // Check if associated with the same handle
00141       std::map<std::string, std::string>::iterator inputIter
00142         = m_input.find(handle);
00143       if( inputIter == m_input.end() || m_input[handle] != m_output[handle] ){
00144         std::ostringstream msgStr;
00145         msgStr << "initialize(): Output Filename " 
00146                << filename << " already associated with separate input handle";
00147         m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00148         return StatusCode::FAILURE;
00149       }
00150       // Filenames and Input/Output handles match.  Open file in UPDATE mode
00151       fileModeByFilename[filename] = "UPDATE";
00152     }else{
00153       // If file not present in input files, default to RECREATE file
00154       fileModeByFilename[filename]="RECREATE";
00155       m_histMan[handle] = 0;
00156     }
00157 
00158     // Add handle, filename to outputs
00159     outHandles.push_back(handle);
00160     outFiles.push_back(filename);
00161   }
00162 
00163   // Open all the files
00164   TDirectory* prevDirectory = gDirectory; // Catch current directory
00165   std::map<std::string, std::string>::iterator fileIter, 
00166     fileEnd = fileModeByFilename.end();
00167   for(fileIter = fileModeByFilename.begin(); fileIter != fileEnd; fileIter++){
00168     std::string filename = fileIter->first;
00169     std::string fileMode = fileIter->second;
00170     // FIXME: Should we check if this file is already known to gROOT?
00171     TFile* file = TFile::Open(filename.c_str(), fileMode.c_str());
00172     if( !file || file->IsZombie() || !file->IsOpen() ){
00173       std::ostringstream msgStr;
00174       msgStr << "initialize(): Failed to open file " 
00175              << filename << " with mode " << fileMode;
00176       m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str()); 
00177       return StatusCode::FAILURE;
00178     }
00179     m_files[filename] = file;
00180   }
00181 
00182   // Initialize the HistMan instances for each handle
00183   std::map<std::string, HistMan*>::iterator hmIter, 
00184     hmEnd = m_histMan.end();
00185   for(hmIter = m_histMan.begin(); hmIter != hmEnd; hmIter++){
00186     std::string handle = hmIter->first;
00187     TFile* file = 0;
00188     if(m_input.find(handle) != m_input.end()){
00189       // Associate with input file
00190       file = m_files[ m_input[handle] ];
00191       std::ostringstream msgStr;
00192       msgStr << "initialize(): Reading handle " << handle
00193              << " from file " << file->GetName() << " with mode " 
00194              << fileModeByFilename[file->GetName()];
00195       m_msgSvc->reportMessage("StatisticsSvc",MSG::INFO,msgStr.str());
00196     }else if( m_output.find(handle) != m_output.end() ){
00197       // Associate with output file
00198       file = m_files[ m_output[handle] ];
00199     }else{
00200       std::ostringstream msgStr;
00201       msgStr << "initialize(): Error associating " << handle
00202              << " with either input or output file.";
00203       m_msgSvc->reportMessage("StatisticsSvc",MSG::INFO,msgStr.str());
00204       return StatusCode::FAILURE;
00205     }
00206     HistMan* histMan = new HistMan( *file, false );
00207     if(!histMan){
00208       std::ostringstream msgStr;
00209       msgStr << "initialize(): Failed to create HistMan for " 
00210              << handle;
00211       m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str()); 
00212       return StatusCode::FAILURE;
00213     }
00214     m_histMan[ handle ] = histMan;
00215   }
00216 
00217   gDirectory = prevDirectory; // Restore ROOT's current directory
00218   {
00219     std::ostringstream msgStr;
00220     msgStr << "initialize(): finished";
00221     m_msgSvc->reportMessage("StatisticsSvc",MSG::INFO,msgStr.str()); 
00222   }
00223   return sc;
00224 }

StatusCode StatisticsSvc::finalize (  )  [virtual]

Reimplemented from Service.

Definition at line 226 of file StatisticsSvc.cc.

00227 {
00228 
00229   {
00230     std::ostringstream msgStr;
00231     msgStr << "finalize():";
00232     m_msgSvc->reportMessage("StatisticsSvc",MSG::INFO,msgStr.str()); 
00233   }
00234 
00235   // DEBUG: dump the statistics store contents
00236   this->dump();
00237 
00238   // Write output files
00239   std::map<std::string, std::string>::iterator outputIter, 
00240     outputEnd = m_output.end();
00241   for(outputIter=m_output.begin(); outputIter != outputEnd; outputIter++){
00242     std::string handle = outputIter->first;
00243     std::string filename = outputIter->second;
00244     TFile* file = m_files[filename];
00245     HistMan* histMan = m_histMan[handle];
00246     if( !file ){
00247       std::ostringstream msgStr;
00248       msgStr << "finalize(): Unexpected Err! Bad file handle: "
00249              << handle;
00250       m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str()); 
00251       return StatusCode::FAILURE;
00252     }
00253     if( !histMan ){
00254       std::ostringstream msgStr;
00255       msgStr << "finalize(): Unexpected Error! "
00256              << "Bad HistMan handle: " << handle;
00257       m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str()); 
00258       return StatusCode::FAILURE;
00259     }
00260     // Write out histman contents to correct file
00261     {
00262       std::ostringstream msgStr;
00263       msgStr << "finalize(): Writing handle " << handle
00264              << " to file " << file->GetName();
00265       m_msgSvc->reportMessage("StatisticsSvc",MSG::INFO,msgStr.str()); 
00266     }
00267     histMan->WriteOut( *file );
00268   }
00269 
00270   // Delete all HistMan instances
00271   std::map<std::string, HistMan*>::iterator hmIter, hmEnd = m_histMan.end();
00272   for(hmIter=m_histMan.begin(); hmIter != hmEnd; hmIter++){
00273     std::string handle = hmIter->first;
00274     HistMan* histMan = hmIter->second;
00275     delete histMan;
00276     m_histMan[handle] = 0;
00277   }
00278   m_histMan.clear();
00279 
00280   // Close all input and output files
00281   std::map<std::string, TFile*>::iterator fileIter, fileEnd = m_files.end();
00282   for(fileIter=m_files.begin(); fileIter != fileEnd; fileIter++){
00283     std::string filename = fileIter->first;
00284     TFile* file = fileIter->second;
00285     if( !file ){
00286       std::ostringstream msgStr;
00287       msgStr << "finalize(): Unexpected Err! Bad file: "
00288              << filename;
00289       m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str()); 
00290       return StatusCode::FAILURE;
00291     }
00292     file->Close();
00293     delete file;
00294     m_files[filename] = 0;
00295   }
00296   m_files.clear();
00297 
00298   {
00299     std::ostringstream msgStr;
00300     msgStr << "finalize(): done";
00301     m_msgSvc->reportMessage("StatisticsSvc",MSG::INFO,msgStr.str()); 
00302   }
00303 
00304   return this->Service::finalize();
00305 }

StatusCode StatisticsSvc::queryInterface ( const InterfaceID riid,
void **  ppvInterface 
) [virtual]

Reimplemented from Service.

Definition at line 307 of file StatisticsSvc.cc.

00309 {
00310   StatusCode sc = StatusCode::FAILURE;
00311   if (ppvInterface) {
00312     *ppvInterface = 0;
00313     
00314     if (IStatisticsSvc::interfaceID().versionMatch(riid)) {
00315       *ppvInterface = static_cast<IStatisticsSvc*>(this);
00316       sc = StatusCode::SUCCESS;
00317       addRef();
00318     }
00319     else sc = Service::queryInterface( riid, ppvInterface );    
00320   }
00321   return sc;
00322 }

StatusCode StatisticsSvc::put ( const std::string &  path,
TObject *  object 
) [virtual]

Place the object at the specified path.

if the subdirectories do not exist, they will be automatically created. If the location is occupied by another object, it is deleted and replaced by the new object. StatusCode::SUCCESS is returned if the object was successfully placed.

Implements IStatisticsSvc.

Definition at line 326 of file StatisticsSvc.cc.

00326                                                                    {
00327   // Check if object is valid
00328   if(!object){
00329     std::ostringstream msgStr;
00330     msgStr << "put(): Invalid object at: " << path;
00331     m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str()); 
00332     return StatusCode::FAILURE;
00333   }
00334   // Check path
00335   std::string localPathPlusName, localPath, name;
00336   HistMan* histMan = 0;
00337   StatusCode sc = getManager(path, histMan, localPathPlusName);
00338   if( sc.isFailure() ) return sc;
00339   // Break object name off end of path
00340   sc = reverseParsePath(localPathPlusName, localPath, name);
00341   if( sc.isFailure() ){
00342     std::ostringstream msgStr;
00343     msgStr << "put(): Invalid path + name: " << localPathPlusName;
00344     m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str()); 
00345     return sc;
00346   }
00347   // Reset object name to name at path end
00348   if(name != object->GetName()){
00349     std::ostringstream msgStr;
00350     TNamed* namedObj = dynamic_cast<TNamed*>(object);
00351     if(!namedObj){
00352       msgStr << "put(): Cannot put unnamed object (" << name << "," 
00353              << object->GetName() << " in statistics service.";  
00354       m_msgSvc->reportMessage("StatisticsSvc",MSG::WARNING,msgStr.str());
00355       return StatusCode::FAILURE;
00356     }else{
00357       msgStr << "put(): Changing object name: " << namedObj->GetName() 
00358              << " to " << name;
00359       m_msgSvc->reportMessage("StatisticsSvc",MSG::WARNING,msgStr.str()); 
00360       namedObj->SetName(name.c_str());
00361     }
00362   }
00363   // Add object to store
00364   TObject* checkObj = histMan->Adopt(localPath.c_str(), object);
00365   if(!checkObj){
00366     // Path location is occupied.  Replacing...
00367     std::ostringstream msgStr;
00368     msgStr << "put(): Replacing object at " << path;
00369     m_msgSvc->reportMessage("StatisticsSvc",MSG::WARNING,msgStr.str()); 
00370     histMan->Adopt(localPath.c_str(), object);
00371   }
00372   return StatusCode::SUCCESS;
00373 }

TObject * StatisticsSvc::get ( const std::string &  path  )  [virtual]

Return the object which exists at this path If there is no object, or if the path does not exist, return 0.

Implements IStatisticsSvc.

Definition at line 375 of file StatisticsSvc.cc.

00375                                                 {
00376   if(path.size()==1 && path[0]=='/') return 0;  // Root path has no object
00377   std::string localPath;
00378   HistMan* histMan = 0;
00379   StatusCode sc = this->getManager(path, histMan, localPath);
00380   if( sc.isFailure() ) return 0;
00381   TObject* obj = histMan->GetObject(localPath.c_str());
00382   if(!obj){
00383     std::ostringstream msgStr;
00384     msgStr << "get(): No entry at " << path;
00385     m_msgSvc->reportMessage("StatisticsSvc",MSG::WARNING,msgStr.str());
00386     return 0;
00387   }  
00388   return obj;
00389 }

bool StatisticsSvc::exists ( const std::string &  path  )  [virtual]

Return true if a folder or object exists at the given path.

Implements IStatisticsSvc.

Definition at line 391 of file StatisticsSvc.cc.

00391                                                {
00392   if(path.size()==1 && path[0]=='/') return true;  // Root path always exists
00393   std::string localPath;
00394   HistMan* histMan = 0;
00395   bool report = false; // Don't report errors if path doesn't exists
00396   StatusCode sc = this->getManager(path, histMan, localPath, report);
00397   if( sc.isFailure() ) return false;
00398   TObject* obj = histMan->GetObjectOrFolder(localPath.c_str());
00399   if(!obj) return false;
00400   return true;
00401 }

std::vector< std::string > StatisticsSvc::getContents ( const std::string &  path  )  [virtual]

Return a list of the names of the objects which exist in the folder An empty list is returned if the path does not exist, or contains no objects.

Implements IStatisticsSvc.

Definition at line 403 of file StatisticsSvc.cc.

00403                                                                     {
00404   std::vector<std::string> empty, contents;
00405   if(path.size()==1 && path[0]=='/') return empty; // Root path has not objects
00406   std::string localPath;
00407   HistMan* histMan = 0;
00408   StatusCode sc = getManager(path, histMan, localPath);
00409   if( sc.isFailure() ) return empty;
00410   // Get objects
00411   std::vector<TObject*> objects = histMan->GetObjects(localPath.c_str());
00412   std::vector<TObject*>::iterator objIter, objEnd = objects.end();
00413   for(objIter=objects.begin(); objIter!=objEnd; objIter++){
00414     TObject* object = *objIter;
00415     if(!object){
00416       std::ostringstream msgStr;
00417       msgStr << "getContents(): Broken object at " << localPath;
00418       m_msgSvc->reportMessage("StatisticsSvc",MSG::WARNING,msgStr.str());
00419       return empty;
00420     }
00421     contents.push_back( object->GetName() );
00422   }
00423   return contents;
00424 }

std::vector< std::string > StatisticsSvc::getSubFolders ( const std::string &  path  )  [virtual]

Return a list of the names of the subfolders which exist in the folder An empty list is returned if the folder does not exist, or contains no subfolders.

Implements IStatisticsSvc.

Definition at line 426 of file StatisticsSvc.cc.

00426                                                                       {
00427   std::vector<std::string> empty, contents;
00428   if(path.size()==1 && path[0]=='/'){
00429     // Catch request for root path
00430     std::map<std::string, HistMan*>::iterator hmIter, hmEnd = m_histMan.end();
00431     std::ostringstream msgStr;
00432     msgStr << "Adding root folders: ";
00433     for(hmIter = m_histMan.begin(); hmIter != hmEnd; hmIter++){
00434       contents.push_back( hmIter->first );
00435       msgStr << " " << hmIter->first;
00436     }
00437     m_msgSvc->reportMessage("StatisticsSvc",MSG::WARNING,msgStr.str());
00438     return contents;
00439   }
00440   std::string localPath;
00441   HistMan* histMan = 0;
00442   StatusCode sc = getManager(path, histMan, localPath);
00443   if( sc.isFailure() ) return empty;
00444   // Get sub-folders
00445   std::vector<TFolder*> folders = 
00446     histMan->GetSubFolders(localPath.c_str());
00447   std::vector<TFolder*>::iterator folderIter, folderEnd = folders.end();
00448   for(folderIter=folders.begin(); folderIter!=folderEnd; folderIter++){
00449     TFolder* folder = *folderIter;
00450     if(!folder){
00451       std::ostringstream msgStr;
00452       msgStr << "getSubFolders(): Broken folder at " << localPath;
00453       m_msgSvc->reportMessage("StatisticsSvc",MSG::WARNING,msgStr.str());
00454       return empty;
00455     }
00456     contents.push_back( folder->GetName() );
00457   }
00458   return contents;
00459 }

TH1F * StatisticsSvc::getTH1F ( const std::string &  path  )  [virtual]

Return the TH1F which exists at this path Return 0 if unsuccessful.

Implements IStatisticsSvc.

Definition at line 462 of file StatisticsSvc.cc.

00462                                                  {
00463   TObject* obj = this->get(path);
00464   if(!obj) return 0;
00465   TH1F* hist = dynamic_cast<TH1F*>(obj);
00466   if(!hist){
00467     std::string msgStr ="Failed to cast object at "+path+" to histogram (TH1F)";
00468     m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr);
00469     return 0;
00470   }
00471   return hist;
00472 }

TH2F * StatisticsSvc::getTH2F ( const std::string &  path  )  [virtual]

Return the TH2F which exists at this path Return 0 if unsuccessful.

Implements IStatisticsSvc.

Definition at line 474 of file StatisticsSvc.cc.

00474                                                  {
00475   TObject* obj = this->get(path);
00476   if(!obj) return 0;
00477   TH2F* hist = dynamic_cast<TH2F*>(obj);
00478   if(!hist){
00479     std::string msgStr ="Failed to cast object at "+path+" to histogram (TH2F)";
00480     m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr);
00481     return 0;
00482   }
00483   return hist;
00484 }

TH3F * StatisticsSvc::getTH3F ( const std::string &  path  )  [virtual]

Return the TH3F which exists at this path Return 0 if unsuccessful.

Implements IStatisticsSvc.

Definition at line 486 of file StatisticsSvc.cc.

00486                                                  {
00487   TObject* obj = this->get(path);
00488   if(!obj) return 0;
00489   TH3F* hist = dynamic_cast<TH3F*>(obj);
00490   if(!hist){
00491     std::string msgStr ="Failed to cast object at "+path+" to histogram (TH3F)";
00492     m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr);
00493     return 0;
00494   }
00495   return hist;
00496 }

TTree * StatisticsSvc::getTree ( const std::string &  path  )  [virtual]

Return the TTree which exists at this path Return 0 if unsuccessful.

Implements IStatisticsSvc.

Definition at line 498 of file StatisticsSvc.cc.

00498                                                   {
00499   TObject* obj = this->get(path);
00500   if(!obj) return 0;
00501   TTree* tree = dynamic_cast<TTree*>(obj);
00502   if(!tree){
00503     std::string msgStr ="Failed to cast object at "+path+" to tree";
00504     m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr);
00505     return 0;
00506   }
00507   return tree;
00508 }

TGraph * StatisticsSvc::getGraph ( const std::string &  path  )  [virtual]

Return the TGraph which exists at this path Return 0 if unsuccessful.

Implements IStatisticsSvc.

Definition at line 510 of file StatisticsSvc.cc.

00510                                                     {
00511   TObject* obj = this->get(path);
00512   if(!obj) return 0;
00513   TGraph* graph = dynamic_cast<TGraph*>(obj);
00514   if(!graph){
00515     std::string msgStr ="Failed to cast object at "+path+" to graph (TGraph)";
00516     m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr);
00517     return 0;
00518   }
00519   return graph;
00520 }

StatusCode StatisticsSvc::checkOptions ( std::string &  handle,
std::string &  filename 
) [private]

Definition at line 524 of file StatisticsSvc.cc.

00525                                                            {
00526   // No double slashes in filename
00527   if( filename.find("root://") == std::string::npos && 
00528       filename.find("//")      != std::string::npos ) {
00529     std::ostringstream msgStr;
00530     msgStr << "checkOptions(): filename "  
00531            << filename << " is not supported (cannot contain '//').";
00532     m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00533     return StatusCode::FAILURE;
00534   }
00535   // Slashes '/' not allowed in handle name
00536   if( handle.find('/') != std::string::npos){
00537     std::ostringstream msgStr;
00538     msgStr << "checkOptions(): handle "  
00539            << handle << " is not supported (cannot contain '/').";
00540     m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00541     return StatusCode::FAILURE;
00542   }
00543   // handle or filename cannot be empty strings
00544   if( handle.size()==0 || filename.size()==0 ){
00545     std::ostringstream msgStr;
00546     msgStr << "checkOptions(): Null handle \"" << handle 
00547            << "\" or filename \"" << filename << "\"";
00548     m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00549     return StatusCode::FAILURE;
00550   }
00551   return StatusCode::SUCCESS;
00552 }

StatusCode StatisticsSvc::parsePath ( const std::string &  fullpath,
std::string &  top,
std::string &  rest 
) [private]

Definition at line 554 of file StatisticsSvc.cc.

00555                                                                     {
00556   // Break top level directory off of path:
00557   // Input:
00558   //   fullpath = /path1/path2/path3
00559   // Output:
00560   //   top = path1
00561   //   rest = /path2/path3
00562   char sep = '/';
00563   if(fullpath.length()<1 || fullpath[0] != sep) return StatusCode::FAILURE;
00564   std::string::size_type pos = fullpath.find(sep, 1);
00565   if(pos == std::string::npos){
00566     // If top level directory
00567     top = std::string(fullpath, 1, std::string::npos);
00568     rest = "";
00569   }else{
00570     top = std::string(fullpath, 1, pos-1);
00571     rest = std::string(fullpath, pos, std::string::npos);
00572   }
00573   return StatusCode::SUCCESS;
00574 }

StatusCode StatisticsSvc::reverseParsePath ( const std::string &  fullpath,
std::string &  rest,
std::string &  bottom 
) [private]

Definition at line 576 of file StatisticsSvc.cc.

00578                                                              {
00579   // Break bottom level directory off of path:
00580   // Input:
00581   //   fullpath = /path1/path2/path3
00582   // Output:
00583   //   rest = /path1/path2
00584   //   bottom = path3
00585   char sep = '/';
00586   if(fullpath.length()<1 || fullpath[fullpath.length()-1] == sep) 
00587     return StatusCode::FAILURE;
00588   std::string::size_type pos = fullpath.rfind(sep);
00589   if(pos == std::string::npos || pos == 0
00590      || pos == (fullpath.length()-1) ) return StatusCode::FAILURE;
00591   rest = std::string(fullpath, 0, pos);
00592   bottom = std::string(fullpath, pos+1, std::string::npos);
00593   return StatusCode::SUCCESS;
00594 }

StatusCode StatisticsSvc::getManager ( const std::string &  path,
HistMan *&  hm,
std::string &  localPath,
bool  report = true 
) [private]

Definition at line 596 of file StatisticsSvc.cc.

00598                                                                     {
00599   // Internal function to get the correct histman and localpath for
00600   // the requested path.
00601   std::string handle, subPath;
00602   StatusCode sc = parsePath(path, handle, subPath);
00603   if( sc.isFailure() ){
00604     std::ostringstream msgStr;
00605     msgStr << "getManager(): Invalid path: " << path;
00606     m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str()); 
00607     return StatusCode::FAILURE;
00608   }
00609   // Find the hist manager for this handle
00610   HistMan* hm = 0;
00611   std::map<std::string, HistMan*>::iterator hmIter = m_histMan.find(handle);
00612   if( hmIter == m_histMan.end() ){
00613     if(report){
00614       std::ostringstream msgStr;
00615       msgStr << "getManager(): Creating transient path for unknown handle " 
00616              << handle 
00617              << " used in full path "
00618              << path;
00619       m_msgSvc->reportMessage("StatisticsSvc",MSG::WARNING,msgStr.str());
00620     }
00621     std::string transientPath = "//root/transient_";
00622     transientPath.append( handle );
00623     TFolder* folder = new TFolder(transientPath.c_str(),
00624                                   "Transient Statistics Folder");
00625     hm = new HistMan(folder, false);
00626     m_histMan[handle] = hm;
00627   }else{
00628     hm = hmIter->second;
00629     if(!hm){
00630       std::ostringstream msgStr;
00631       msgStr << "getManager(): Invalid HistMan for " << handle 
00632              << " used in full path " << path;
00633       m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00634       return StatusCode::FAILURE;
00635     }
00636   }
00637   // Remove '/' from start of local pathname
00638   if( subPath.length() > 0 && subPath[0] == '/' )
00639     localPath = std::string(subPath, 1, std::string::npos);
00640   else
00641     localPath = subPath;
00642   histMan = hm;
00643   return StatusCode::SUCCESS;
00644 }

void StatisticsSvc::dump (  )  [private]

Definition at line 646 of file StatisticsSvc.cc.

00646                         {
00647   // Print the statistics store contents
00648   std::ostringstream dumpStr;
00649   dumpStr << "StatisticsSvc contents:\n";
00650   std::map<std::string, HistMan*>::iterator hmIter, hmEnd = m_histMan.end();
00651   for(hmIter = m_histMan.begin(); hmIter != hmEnd; hmIter++){
00652     std::string handle = hmIter->first;
00653     std::string filename = "[TRANSIENT ONLY]";
00654     std::map<std::string, std::string>::iterator outputIter 
00655       = m_output.find(handle);
00656     if( outputIter != m_output.end() )
00657       filename = outputIter->second;
00658     dumpStr << "\nPATH=" << handle << " written to: " << filename << "\n";
00659     std::string currentPath = "/"+handle;
00660     dumpStr << currentPath << "\n";
00661     this->dumpPath(currentPath, dumpStr);
00662   }
00663   m_msgSvc->reportMessage("StatisticsSvc",MSG::DEBUG,dumpStr.str());
00664 }

void StatisticsSvc::dumpPath ( const std::string &  path,
std::ostringstream &  dumpStr 
) [private]

Definition at line 666 of file StatisticsSvc.cc.

00667                                                        {
00668   // Append objects
00669   std::vector<std::string> names = this->getContents(path);
00670   std::vector<std::string>::iterator nameIter, nameEnd = names.end();
00671   for(nameIter=names.begin(); nameIter != nameEnd; nameIter++){
00672     std::string fullpath = path + "/" + (*nameIter);
00673     std::string type;
00674     TObject* obj = this->get(fullpath);
00675     if(!obj) type = "BROKEN";
00676     else     type = obj->ClassName();
00677     dumpStr << fullpath << " (" << type << ")\n";
00678   }
00679   // Descend directories
00680   names = this->getSubFolders(path);
00681   nameEnd = names.end();
00682   for(nameIter=names.begin(); nameIter != nameEnd; nameIter++){
00683     std::string fullpath = path + "/" + (*nameIter);
00684     dumpStr << fullpath << "\n";
00685     this->dumpPath(fullpath,dumpStr);
00686   }
00687   return;
00688 }

static const InterfaceID& IStatisticsSvc::interfaceID (  )  [inline, static, inherited]

Reimplemented from IInterface.

Definition at line 38 of file IStatisticsSvc.h.

00038                                          {
00039     return IID_IStatisticsSvc;
00040   }


Member Data Documentation

std::map<std::string,std::string> StatisticsSvc::m_input [private]

Property: Input List of path, input files pairs {"path0": "myfile0.root", <etc.

>} If file is present in input and output, it is opened in "UPDATE" mode. 'path' must be a simple name; it cannot contain '/'.

Definition at line 94 of file StatisticsSvc.h.

std::map<std::string,std::string> StatisticsSvc::m_output [private]

Property: Output List of path, output file pairs {"path1": "myfile1.root", <etc.

>} If file is present in input and output, it is opened in "UPDATE" mode. 'path' must be a simple name; it cannot contain '/'.

Definition at line 100 of file StatisticsSvc.h.

IMessageSvc* StatisticsSvc::m_msgSvc [private]

Definition at line 103 of file StatisticsSvc.h.

std::map<std::string, TFile*> StatisticsSvc::m_files [private]

Definition at line 106 of file StatisticsSvc.h.

std::map<std::string, HistMan*> StatisticsSvc::m_histMan [private]

Definition at line 109 of file StatisticsSvc.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:10:02 2011 for StatisticsSvc by doxygen 1.4.7