CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/CondCore/EcalPlugins/plugins/EcalPyWrapperFunctions.h

Go to the documentation of this file.
00001 #ifndef CondCore_EcalPlugins_plugins_EcalPyWrapperFunctions_H
00002 #define CondCore_EcalPlugins_plugins_EcalPyWrapperFunctions_H
00003 
00004 #include <sstream>
00005 
00006 //inherit this class, override getValues() function
00007 //virtual class EcalPyWrapperStrategy {
00008 //
00009 //};
00010 //class EcalMeanStrategy: EcalPyWrapperStrategy{
00011 //      
00012 //};
00013 //class EcalMeanStrategy: EcalPyWrapperStrategy{
00014 //      
00015 //};
00016 
00017 template <class T>
00018 class EcalPyWrapperHelper{
00019 public:
00020     static const unsigned int MEAN    = 0;
00021     static const unsigned int STATUS  = 1;
00022 
00023         EcalPyWrapperHelper(unsigned int totalValues, unsigned int status = 0, std::string names = "-Means: "):total_values(totalValues), status(status), names(names){}
00024         //~EcalPyWrapperHelper();
00025         std::string printBarrelsEndcaps( const std::vector<T> & barrelItems, const std::vector<T> & endcapItems) {
00026                 std::stringstream ss;
00027 
00028                 //print barrels:
00029                 type_vValues barrelsVec = getValues(barrelItems);
00030                 unsigned int barrelsTotal = barrelItems.size();
00031                 ss << std::endl << "---Barrels. Total: " << barrelsTotal << std::endl;
00032                         switch (status){
00033                                 case (MEAN)  : ss << names << std::endl; break;
00034                                 case (STATUS): ss << "-With errors: " << std::endl; break;// << ecalcond::bad(barrelItems) << std::endl; break;
00035                                 default      : break;
00036                         }
00037                 ss << printValues(barrelsVec, barrelsTotal);
00038 
00039                 //print endcaps:
00040                 type_vValues endcapVec = getValues(endcapItems);
00041                 unsigned int endcapTotal = endcapItems.size();
00042                 ss << std::endl << "---Endcaps. Total: " << endcapTotal << std::endl;
00043                         switch (status){
00044                                 case (MEAN)  : ss << names << std::endl; break;
00045                                 case (STATUS): ss << "-With errors: " << std::endl; break;// << ecalcond::bad(endcapItems) << std::endl; break;
00046                                 default      : break;
00047                         }
00048                 ss << printValues(endcapVec, endcapTotal);      
00049 
00050                 return ss.str();
00051         }
00052 protected:
00053         unsigned int total_values;
00054         unsigned int status;
00055     std::string names; 
00056         typedef std::vector<std::pair< std::string, float> > type_vValues;
00057 
00058         //this needs to be overriden in inherited class:
00059         virtual type_vValues getValues( const std::vector<T> & vItems) = 0;
00060         /*EXAMPLE:
00061         class EcalPedestalsHelper: public EcalPyWrapperHelper<EcalPedestal>{
00062         public:
00063                 type_vValues getValues( const std::vector<EcalPedestal> & vItems)
00064                 {
00065                         unsigned int totalValues = 6; 
00066                         type_vValues vValues(totalValues);
00067 
00068                         vValues[0].first = "mean_x12";
00069                         vValues[1].first = "rms_x12";
00070                         vValues[2].first = "mean_x6";
00071                         vValues[3].first = "rms_x6";
00072                         vValues[4].first = "mean_x1";
00073                         vValues[5].first = "rms_x1";
00074                         
00075                         vValues[0].second = .0;
00076                         vValues[1].second = .0;
00077                         vValues[2].second = .0;
00078                         vValues[3].second = .0;
00079                         vValues[4].second = .0;
00080                         vValues[5].second = .0;
00081                         
00082                         //get info:
00083                         for(std::vector<EcalPedestal>::const_iterator iItems = vItems.begin(); iItems != vItems.end(); ++iItems){
00084                                 vValues[0].second += iItems->mean(1);
00085                                 vValues[1].second += iItems->rms(1);
00086                                 vValues[2].second += iItems->mean(2);
00087                                 vValues[3].second += iItems->rms(2);
00088                                 vValues[4].second += iItems->mean(3);
00089                                 vValues[5].second += iItems->rms(3);
00090                         }
00091                         return vValues;
00092                 }
00093                 */
00094 private:
00095         std::string printValues(const type_vValues & vValues, const unsigned int & total) {
00096                 std::stringstream ss;
00097 
00098                 for (type_vValues::const_iterator iVal = vValues.begin(); iVal != vValues.end(); ++iVal){
00099                         switch (status){
00100                                 case (MEAN)  : ss << iVal->first << ": " << ((iVal->second)/total) << std::endl; break;
00101                                 case (STATUS): if (iVal->second != 0) {ss << iVal->first << ": " << ((iVal->second)) << std::endl; break;} else {break; }
00102                                 default      : break;
00103                         }
00104                         
00105                 }
00106                 return ss.str();
00107         }
00108 
00109 };
00110 #endif