CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/CondCore/Utilities/interface/PayLoadInspector.h

Go to the documentation of this file.
00001 #ifndef  PayLoadInspector_H
00002 #define  PayLoadInspector_H
00003 #include "CondCore/ORA/interface/Object.h"
00004 #include "CondCore/IOVService/interface/IOVProxy.h"
00005 #include "CondCore/DBCommon/interface/DbSession.h"
00006 #include "CondCore/Utilities/interface/CondPyInterface.h"
00007 #include "TFile.h"
00008 #include "Cintex/Cintex.h"
00009 #include <sstream>
00010 #include <iostream>
00011 //#include <fstream>
00012 #include <string>
00013 #include <utility>
00014 #include <vector>
00015 
00016 namespace cond {
00017 
00018   template<typename T>
00019   class BaseValueExtractor {
00020   public:
00021     typedef T Class;
00022 
00023     BaseValueExtractor(){}
00024     
00025     virtual ~BaseValueExtractor(){}
00026     void computeW(Class const &o){
00027       reset();
00028       compute(o);
00029     }
00030     std::vector<float> const & values() const { return m_values;}
00031   protected:
00032     void add(float v) { m_values.push_back(v); }
00033     void swap(std::vector<float> & v) {m_values.swap(v);}
00034   private:
00035     void reset() { m_values.clear();}
00036     virtual void compute(Class const &){}
00037     
00038     
00039   private:
00040     std::vector<float> m_values;
00041   };
00042 
00043 
00044   // a collection of enumerators, strings, ints
00045   template<typename T>
00046   struct ExtractWhat {
00047 
00048   };
00049 
00050 
00051 
00052   template<typename T>
00053   class ValueExtractor : public  BaseValueExtractor<T> {
00054   public:
00055     typedef T Class;
00056     typedef ExtractWhat<Class> What;
00057     ValueExtractor(){}
00058     ValueExtractor(What const &){}
00059     static What what() { return What();}
00060   private:
00061     void compute(Class const &){}
00062   private:
00063   };
00064 
00065   template<typename DataT>
00066   class PayLoadInspector {
00067   public:
00068     typedef DataT Class;
00069     typedef ValueExtractor<DataT> Extractor;
00070     
00071     PayLoadInspector(): m_since(0) {}
00072     
00073     ~PayLoadInspector() {
00074       if(m_object.address()) m_object.destruct();
00075     }
00076     
00077     PayLoadInspector(cond::CondDB const & conddb): m_session(conddb.session()), m_since(cond::invalidTime), m_token("") {
00078       ROOT::Cintex::Cintex::Enable();
00079     } 
00080 
00081     std::string dumpXML(std::string filename) const {
00082       size_t pos = filename.find(".xml");
00083       if(pos == std::string::npos)
00084         filename.append(".xml");
00086       TFile * xml =0;
00087       xml = TFile::Open(filename.c_str(), "recreate");
00088       xml->WriteObjectAny(m_object.address(), m_object.typeName().c_str(), filename.c_str());
00089       xml->Close();
00090       return filename;
00091     }
00092     
00093     std::string dump() const {
00094       std::ostringstream ss; 
00095       //token parser
00096       std::pair<std::string,int> oidData = parseToken( m_token );
00097       ss << m_since << "_"<< oidData.first << "_" << oidData.second;
00098       //std::string filename(ss.str()+".xml");
00099       return this->dumpXML(ss.str()+".xml");
00100     }
00101     
00102     // specialize...
00103     std::string summary() const {
00104       std::ostringstream os;
00105       os << std::endl;
00106       return os.str();
00107     }
00108 
00109     // return the real name of the file including extension...
00110     std::string plot(std::string const & /* filename */,
00111                      std::string const &, 
00112                      std::vector<int> const&, std::vector<float> const& ) const {return "";}
00113 
00114 
00115     // return the real name of the file including extension...
00116     std::string trend_plot(std::string const & /* filename */,//
00117                            std::string const &, 
00118                            std::vector<int> const&, std::vector<float> const&, std::vector<std::string> const&) const {return "";}
00119 
00120     // summary, which takes arguments
00121     std::string summary_adv(//int const &,
00122                             std::string const &, 
00123                             std::vector<int> const&, std::vector<float> const&, std::vector<std::string> const&) const {return "";}
00124     
00125     //returns a file in the format chosen by the user (typically root)
00126     std::string dumpFile(std::string const & /* filename */,//
00127                          std::string const &, 
00128                          std::vector<int> const&, std::vector<float> const&, std::vector<std::string> const&) const {return "";}
00129     
00130     void extract(Extractor & extractor) const {extractor.computeW(object()); }
00131 
00132     Class const & object() const {
00133       return *(m_object.cast<Class>());
00134     }
00135     
00136     ora::Object const & ora_object() const { 
00137       return m_object; 
00138     }
00139     
00140     bool load( cond::IOVElementProxy const& elem ) {
00141       bool ok = false;
00142       m_since = elem.since();
00143       m_token = elem.token();
00144       m_object = m_session.getObject(m_token);
00145       if(m_object.address()) ok = true;    
00146       return ok;
00147     }
00148     
00149   private:
00150     cond::DbSession m_session;
00151     cond::Time_t m_since;
00152     std::string m_token;
00153     ora::Object m_object;
00154   };
00155 
00156 }
00157 
00158 #endif //   PayLoadInspector_H