/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

DybBaseAlg.h
Go to the documentation of this file.
00001 
00013 #ifndef DYBBASEALG
00014 #define DYBBASEALG
00015 
00016 #include "Event/HeaderObject.h"
00017 #include "GaudiAlg/GaudiAlgorithm.h"
00018 #include "Event/IHeader.h"
00019 
00020 #include <vector>
00021 
00022 class IJobInfoSvc;
00023 
00024 class DybBaseAlg : public GaudiAlgorithm 
00025 {
00026 public:
00027     DybBaseAlg(const std::string& name, ISvcLocator* pSvcLocator);
00028     virtual ~DybBaseAlg();
00029     
00031     virtual StatusCode sysInitialize();
00032 
00034     virtual StatusCode sysExecute();
00035 
00037     virtual StatusCode preExecute();
00038 
00040     virtual StatusCode postExecute();
00041 
00043     virtual StatusCode sysFinalize();
00044 
00046 
00048     IDataProviderSvc* arcSvc() const;
00049 
00052     void putTES(DataObject* obj, std::string location) const;
00053 
00057     template <class TYPE>
00058     TYPE* getTES(std::string location) const;
00059 
00064     template <class TYPE>
00065     TYPE* getAES(std::string location, int index) const;
00066 
00073     std::vector<DataObject*> getAEScollection(std::string location) const;
00074 
00076     int getExecNum() { return m_execNum; }
00077 
00079     std::string Location() const { return m_location; }
00080 
00081 protected:    
00082     
00084     void InitializeHeader(DayaBay::HeaderObject* header);
00085     
00086     // wrapper of header object constructor, but intializes the header object.
00087     // - MakeHeader()
00088     //       : default initializtion, exec number, job id, E/L time set to BOT
00089     // - MakeHeader(inputHeaders)
00090     //       : set the inputHeaders and set E/L time to cover the time range of the inputHeaders
00091     //       : also set the default context to be the same as the first inputHeader
00092     // - MakeHeader(referenceHeader)
00093     //       : set the inputHeaders to be a size 1 vector containing the ref Header
00094     //       : and set everything to be the same as this single ref Header.
00095     template <class TYPE>
00096     TYPE* MakeHeader();
00097     
00098     template <class TYPE>
00099     TYPE* MakeHeader(std::vector<const DayaBay::IHeader*>& inputHeaders);
00100     
00101     template <class TYPE>
00102     TYPE* MakeHeader(const DayaBay::IHeader* referenceHeader);
00103         
00106     void AppendInputHeader(const DayaBay::HeaderObject* header) const;
00107     
00108     DayaBay::HeaderObject* m_headerObject;
00109 
00111     bool m_pullMode;
00112     
00113 private:
00114 
00118     int m_execNum;
00119 
00123     int m_saveRandomState;
00124 
00125     mutable std::vector<const DayaBay::HeaderObject*> m_inputHeaders;
00126 
00128     std::vector<unsigned long> m_state;
00130     IJobInfoSvc* m_jobInfoSvc;
00131 
00132 protected:
00133 
00137     std::string m_location;
00138 
00139 };
00140 
00141 template <class TYPE>
00142 TYPE* DybBaseAlg::getTES(std::string location) const
00143 {
00144     TYPE* obj = get<TYPE>(location);
00145     // If object happens to be a HeaderObject, save it in the intputHeaders
00146     DayaBay::HeaderObject* header = dynamic_cast<DayaBay::HeaderObject*>(obj);
00147     if (header) {
00148         if (std::find(m_inputHeaders.begin(),m_inputHeaders.end(),header) == m_inputHeaders.end()) {
00149             this->AppendInputHeader(header);
00150             debug() << "Saved " << m_inputHeaders.size() 
00151                    << " input headers from TES, latest: " 
00152                    << header->name() 
00153                    << endreq;
00154         }
00155     }
00156     return obj;
00157 }
00158 
00159 template <class TYPE>
00160 TYPE* DybBaseAlg::getAES(std::string location, int index) const
00161 {
00162     if (index<0) return 0;
00163 
00164     std::vector<DataObject*> vec = this->getAEScollection(location);
00165     if (!vec.size() || index >= vec.size()) return 0;
00166     DataObject* dobj = vec[index];
00167     TYPE* obj = dynamic_cast<TYPE*>(dobj);
00168     if (!obj) return 0;
00169 
00170     DayaBay::HeaderObject* header = dynamic_cast<DayaBay::HeaderObject*>(obj);
00171     if (header) {
00172         if (std::find(m_inputHeaders.begin(),m_inputHeaders.end(),header) == m_inputHeaders.end()) {
00173             this->AppendInputHeader(header);
00174             debug() << "Saved " << m_inputHeaders.size() 
00175                    << " input headers from TES, latest: " 
00176                    << header->name() 
00177                    << endreq;
00178         }
00179     }
00180 
00181     return obj;
00182 }
00183 
00184 template <class TYPE>
00185 TYPE* DybBaseAlg::MakeHeader()
00186 {
00187     TYPE* obj = new TYPE();
00188     InitializeHeader(obj);
00189     return obj;
00190 }
00191 
00192 template <class TYPE>
00193 TYPE* DybBaseAlg::MakeHeader(std::vector<const DayaBay::IHeader*>& inputHeaders)
00194 {
00195     TYPE* obj = MakeHeader<TYPE>();
00196     obj->setInputHeaders(inputHeaders);
00197     size_t size = inputHeaders.size();
00198     if (size == 0) {
00199         warning() << "input header has zero size" << endreq;
00200         return obj; 
00201     }
00202     const DayaBay::HeaderObject* firstHeader = dynamic_cast<const DayaBay::HeaderObject*>(inputHeaders[0]);
00203     obj->setContext(firstHeader->context());
00204     obj->setEarliest(firstHeader->earliest());
00205     if (size > 1) {
00206         const DayaBay::HeaderObject* lastHeader = dynamic_cast<const DayaBay::HeaderObject*>(inputHeaders[size-1]);
00207         obj->setLatest(lastHeader->latest());
00208     }
00209     else {
00210         obj->setLatest(firstHeader->latest());
00211     }
00212     
00213     // make sure the time span covers inputHeaders' range
00214     for (size_t i=1; i<inputHeaders.size(); i++) {
00215         const DayaBay::HeaderObject* inputHdr = dynamic_cast<const DayaBay::HeaderObject*>(inputHeaders[i]);
00216         if (inputHdr->earliest() < obj->earliest()) {
00217             obj->setEarliest(inputHdr->earliest());
00218         }
00219         if (inputHdr->latest() > obj->latest()) {
00220             obj->setLatest(inputHdr->latest());
00221         }
00222     }
00223     
00224     return obj;
00225 }
00226 
00227 template <class TYPE>
00228 TYPE* DybBaseAlg::MakeHeader(const DayaBay::IHeader* referenceHeader)
00229 {
00230     std::vector<const DayaBay::IHeader*> inputHeaders = std::vector<const DayaBay::IHeader*>();
00231     inputHeaders.push_back(referenceHeader);
00232     TYPE* obj = MakeHeader<TYPE>(inputHeaders);
00233     return obj;
00234 }
00235     
00236     
00237 #endif  // DYBBASEALG
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:09:43 for DybAlg by doxygen 1.7.4