00001 #ifndef FWCore_Framework_Group_h
00002 #define FWCore_Framework_Group_h
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "DataFormats/Common/interface/ProductData.h"
00012 #include "DataFormats/Common/interface/WrapperHolder.h"
00013 #include "DataFormats/Common/interface/WrapperOwningHolder.h"
00014 #include "DataFormats/Provenance/interface/ConstBranchDescription.h"
00015 #include "DataFormats/Provenance/interface/Provenance.h"
00016 #include "FWCore/Utilities/interface/TypeID.h"
00017
00018 #include "boost/shared_ptr.hpp"
00019 #include "boost/utility.hpp"
00020
00021 #include <string>
00022
00023 namespace edm {
00024 class BranchMapper;
00025 class DelayedReader;
00026 class WrapperInterfaceBase;
00027
00028 class Group : private boost::noncopyable {
00029 public:
00030 Group();
00031 virtual ~Group();
00032
00033 ProductData const& productData() const {
00034 return getProductData();
00035 }
00036
00037 ProductData& productData() {
00038 return getProductData();
00039 }
00040
00041 void resetStatus () {
00042 resetStatus_();
00043 }
00044
00045 void setProductDeleted () {
00046 setProductDeleted_();
00047 }
00048
00049 void resetProductData() {
00050 getProductData().resetProductData();
00051 resetStatus_();
00052 }
00053
00054 void deleteProduct() {
00055 getProductData().resetProductData();
00056 setProductDeleted_();
00057 }
00058
00059
00060 bool productUnavailable() const {return productUnavailable_();}
00061
00062
00063 bool provenanceAvailable() const;
00064
00065
00066 bool onDemand() const {return onDemand_();}
00067
00068
00069 bool productWasDeleted() const {return productWasDeleted_();}
00070
00071
00072 boost::shared_ptr<void const> product() const { return getProductData().wrapper_; }
00073
00074
00075 WrapperHolder wrapper() const { return WrapperHolder(getProductData().wrapper_.get(), getProductData().getInterface()); }
00076
00077
00078 ProductProvenance* productProvenancePtr() const {
00079 return provenance()->productProvenance();
00080 }
00081
00082
00083 void setProductProvenance(ProductProvenance const& prov) const;
00084
00085
00086 ConstBranchDescription const& branchDescription() const {return branchDescription_();}
00087
00088
00089 void resetBranchDescription(boost::shared_ptr<ConstBranchDescription> bd) {resetBranchDescription_(bd);}
00090
00091
00092 std::string const& moduleLabel() const {return branchDescription().moduleLabel();}
00093
00094
00095 std::string const& productInstanceName() const {return branchDescription().productInstanceName();}
00096
00097
00098 std::string const& processName() const {return branchDescription().processName();}
00099
00100
00101 Provenance* provenance() const;
00102
00103
00104 void setProvenance(boost::shared_ptr<BranchMapper> mapper, ProcessHistoryID const& phid, ProductID const& pid);
00105
00106
00107 void setProvenance(boost::shared_ptr<BranchMapper> mapper, ProcessHistoryID const& phid);
00108
00109
00110 void setProcessHistoryID(ProcessHistoryID const& phid);
00111
00112
00113 void write(std::ostream& os) const;
00114
00115
00116
00117
00118 TypeID productType() const;
00119
00120
00121 ProductID const& productID() const {return getProductData().prov_.productID();}
00122
00123
00124 void putProduct(WrapperOwningHolder const& edp, ProductProvenance const& productProvenance) {
00125 putProduct_(edp, productProvenance);
00126 }
00127
00128
00129 void putProduct(WrapperOwningHolder const& edp) const {
00130 putProduct_(edp);
00131 }
00132
00133
00134 bool putOrMergeProduct() const {
00135 return putOrMergeProduct_();
00136 }
00137
00138
00139 void mergeProduct(WrapperOwningHolder const& edp, ProductProvenance& productProvenance) {
00140 mergeProduct_(edp, productProvenance);
00141 }
00142
00143 void mergeProduct(WrapperOwningHolder const& edp) const {
00144 mergeProduct_(edp);
00145 }
00146
00147
00148 void mergeTheProduct(WrapperOwningHolder const& edp) const;
00149
00150 void reallyCheckType(WrapperOwningHolder const& prod) const;
00151
00152 void checkType(WrapperOwningHolder const& prod) const {
00153 checkType_(prod);
00154 }
00155
00156 void swap(Group& rhs) {swap_(rhs);}
00157
00158 private:
00159 virtual ProductData const& getProductData() const = 0;
00160 virtual ProductData& getProductData() = 0;
00161 virtual void swap_(Group& rhs) = 0;
00162 virtual bool onDemand_() const = 0;
00163 virtual bool productUnavailable_() const = 0;
00164 virtual bool productWasDeleted_() const = 0;
00165 virtual void putProduct_(WrapperOwningHolder const& edp, ProductProvenance const& productProvenance) = 0;
00166 virtual void putProduct_(WrapperOwningHolder const& edp) const = 0;
00167 virtual void mergeProduct_(WrapperOwningHolder const& edp, ProductProvenance& productProvenance) = 0;
00168 virtual void mergeProduct_(WrapperOwningHolder const& edp) const = 0;
00169 virtual bool putOrMergeProduct_() const = 0;
00170 virtual void checkType_(WrapperOwningHolder const& prod) const = 0;
00171 virtual void resetStatus_() = 0;
00172 virtual void setProductDeleted_() = 0;
00173 virtual ConstBranchDescription const& branchDescription_() const = 0;
00174 virtual void resetBranchDescription_(boost::shared_ptr<ConstBranchDescription> bd) = 0;
00175 };
00176
00177 inline
00178 std::ostream&
00179 operator<<(std::ostream& os, Group const& g) {
00180 g.write(os);
00181 return os;
00182 }
00183
00184 class InputGroup : public Group {
00185 public:
00186 explicit InputGroup(boost::shared_ptr<ConstBranchDescription> bd) :
00187 Group(), productData_(bd), productIsUnavailable_(false),
00188 productHasBeenDeleted_(false) {}
00189 virtual ~InputGroup();
00190
00191
00192
00193
00194 void setProduct(WrapperOwningHolder const& prod) const;
00195 bool productIsUnavailable() const {return productIsUnavailable_;}
00196 void setProductUnavailable() const {productIsUnavailable_ = true;}
00197
00198 private:
00199 virtual void swap_(Group& rhs) {
00200 InputGroup& other = dynamic_cast<InputGroup&>(rhs);
00201 edm::swap(productData_, other.productData_);
00202 std::swap(productIsUnavailable_, other.productIsUnavailable_);
00203 }
00204 virtual void putProduct_(WrapperOwningHolder const& edp, ProductProvenance const& productProvenance);
00205 virtual void putProduct_(WrapperOwningHolder const& edp) const;
00206 virtual void mergeProduct_(WrapperOwningHolder const& edp, ProductProvenance& productProvenance);
00207 virtual void mergeProduct_(WrapperOwningHolder const& edp) const;
00208 virtual bool putOrMergeProduct_() const;
00209 virtual void checkType_(WrapperOwningHolder const&) const {}
00210 virtual void resetStatus_() {productIsUnavailable_ = false;
00211 productHasBeenDeleted_=false;}
00212 virtual bool onDemand_() const {return false;}
00213 virtual bool productUnavailable_() const;
00214 virtual bool productWasDeleted_() const {return productHasBeenDeleted_;}
00215 virtual ProductData const& getProductData() const {return productData_;}
00216 virtual ProductData& getProductData() {return productData_;}
00217 virtual void setProductDeleted_() {productHasBeenDeleted_ = true;}
00218 virtual ConstBranchDescription const& branchDescription_() const {return *productData().branchDescription();}
00219 virtual void resetBranchDescription_(boost::shared_ptr<ConstBranchDescription> bd) {productData().resetBranchDescription(bd);}
00220
00221 ProductData productData_;
00222 mutable bool productIsUnavailable_;
00223 mutable bool productHasBeenDeleted_;
00224 };
00225
00226
00227 inline void swap(InputGroup& a, InputGroup& b) {
00228 a.swap(b);
00229 }
00230
00231 class ProducedGroup : public Group {
00232 public:
00233 enum GroupStatus {
00234 Present = 0,
00235 NotRun = 3,
00236 NotCompleted = 4,
00237 NotPut = 5,
00238 UnscheduledNotRun = 6,
00239 ProductDeleted =7,
00240 Uninitialized = 0xff
00241 };
00242 ProducedGroup() : Group() {}
00243 virtual ~ProducedGroup();
00244 void producerStarted();
00245 void producerCompleted();
00246 GroupStatus& status() const {return status_();}
00247 private:
00248 virtual void putProduct_(WrapperOwningHolder const& edp, ProductProvenance const& productProvenance);
00249 virtual void putProduct_(WrapperOwningHolder const& edp) const;
00250 virtual void mergeProduct_(WrapperOwningHolder const& edp, ProductProvenance& productProvenance);
00251 virtual void mergeProduct_(WrapperOwningHolder const& edp) const;
00252 virtual bool putOrMergeProduct_() const;
00253 virtual void checkType_(WrapperOwningHolder const& prod) const {
00254 reallyCheckType(prod);
00255 }
00256 virtual GroupStatus& status_() const = 0;
00257 virtual bool productUnavailable_() const;
00258 virtual bool productWasDeleted_() const;
00259 virtual void setProductDeleted_();
00260 virtual ConstBranchDescription const& branchDescription_() const {return *productData().branchDescription();}
00261 virtual void resetBranchDescription_(boost::shared_ptr<ConstBranchDescription> bd) {productData().resetBranchDescription(bd);}
00262 };
00263
00264 class ScheduledGroup : public ProducedGroup {
00265 public:
00266 explicit ScheduledGroup(boost::shared_ptr<ConstBranchDescription> bd) : ProducedGroup(), productData_(bd), theStatus_(NotRun) {}
00267 virtual ~ScheduledGroup();
00268 private:
00269 virtual void swap_(Group& rhs) {
00270 ScheduledGroup& other = dynamic_cast<ScheduledGroup&>(rhs);
00271 edm::swap(productData_, other.productData_);
00272 std::swap(theStatus_, other.theStatus_);
00273 }
00274 virtual void resetStatus_() {theStatus_ = NotRun;}
00275 virtual bool onDemand_() const {return false;}
00276 virtual ProductData const& getProductData() const {return productData_;}
00277 virtual ProductData& getProductData() {return productData_;}
00278 virtual GroupStatus& status_() const {return theStatus_;}
00279 ProductData productData_;
00280 mutable GroupStatus theStatus_;
00281 };
00282
00283
00284 inline void swap(ScheduledGroup& a, ScheduledGroup& b) {
00285 a.swap(b);
00286 }
00287
00288 class UnscheduledGroup : public ProducedGroup {
00289 public:
00290 explicit UnscheduledGroup(boost::shared_ptr<ConstBranchDescription> bd) : ProducedGroup(), productData_(bd), theStatus_(UnscheduledNotRun) {}
00291 virtual ~UnscheduledGroup();
00292 private:
00293 virtual void swap_(Group& rhs) {
00294 UnscheduledGroup& other = dynamic_cast<UnscheduledGroup&>(rhs);
00295 edm::swap(productData_, other.productData_);
00296 std::swap(theStatus_, other.theStatus_);
00297 }
00298 virtual void resetStatus_() {theStatus_ = UnscheduledNotRun;}
00299 virtual bool onDemand_() const {return status() == UnscheduledNotRun;}
00300 virtual ProductData const& getProductData() const {return productData_;}
00301 virtual ProductData& getProductData() {return productData_;}
00302 virtual GroupStatus& status_() const {return theStatus_;}
00303 ProductData productData_;
00304 mutable GroupStatus theStatus_;
00305 };
00306
00307
00308 inline void swap(UnscheduledGroup& a, UnscheduledGroup& b) {
00309 a.swap(b);
00310 }
00311
00312 class SourceGroup : public ProducedGroup {
00313 public:
00314 explicit SourceGroup(boost::shared_ptr<ConstBranchDescription> bd) : ProducedGroup(), productData_(bd), theStatus_(NotPut) {}
00315 virtual ~SourceGroup();
00316 private:
00317 virtual void swap_(Group& rhs) {
00318 SourceGroup& other = dynamic_cast<SourceGroup&>(rhs);
00319 edm::swap(productData_, other.productData_);
00320 std::swap(theStatus_, other.theStatus_);
00321 }
00322 virtual void resetStatus_() {theStatus_ = NotPut;}
00323 virtual bool onDemand_() const {return false;}
00324 virtual ProductData const& getProductData() const {return productData_;}
00325 virtual ProductData& getProductData() {return productData_;}
00326 virtual GroupStatus& status_() const {return theStatus_;}
00327 ProductData productData_;
00328 mutable GroupStatus theStatus_;
00329 };
00330
00331 class AliasGroup : public Group {
00332 public:
00333 typedef ProducedGroup::GroupStatus GroupStatus;
00334 explicit AliasGroup(boost::shared_ptr<ConstBranchDescription> bd, ProducedGroup& realGroup) : Group(), realGroup_(realGroup), bd_(bd) {}
00335 virtual ~AliasGroup();
00336 private:
00337 virtual void swap_(Group& rhs) {
00338 AliasGroup& other = dynamic_cast<AliasGroup&>(rhs);
00339 realGroup_.swap(other.realGroup_);
00340 std::swap(bd_, other.bd_);
00341 }
00342 virtual bool onDemand_() const {return realGroup_.onDemand();}
00343 virtual GroupStatus& status_() const {return realGroup_.status();}
00344 virtual void resetStatus_() {realGroup_.resetStatus();}
00345 virtual bool productUnavailable_() const {return realGroup_.productUnavailable();}
00346 virtual bool productWasDeleted_() const {return realGroup_.productWasDeleted();}
00347 virtual void checkType_(WrapperOwningHolder const& prod) const {realGroup_.checkType(prod);}
00348 virtual ProductData const& getProductData() const {return realGroup_.productData();}
00349 virtual ProductData& getProductData() {return realGroup_.productData();}
00350 virtual void setProductDeleted_() {realGroup_.setProductDeleted();}
00351 virtual void putProduct_(WrapperOwningHolder const& edp, ProductProvenance const& productProvenance) {
00352 realGroup_.putProduct(edp, productProvenance);
00353 }
00354 virtual void putProduct_(WrapperOwningHolder const& edp) const {
00355 realGroup_.putProduct(edp);
00356 }
00357 virtual void mergeProduct_(WrapperOwningHolder const& edp, ProductProvenance& productProvenance) {
00358 realGroup_.mergeProduct(edp, productProvenance);
00359 }
00360 virtual void mergeProduct_(WrapperOwningHolder const& edp) const {
00361 realGroup_.mergeProduct(edp);
00362 }
00363 virtual bool putOrMergeProduct_() const {
00364 return realGroup_.putOrMergeProduct();
00365 }
00366 virtual ConstBranchDescription const& branchDescription_() const {return *bd_;}
00367 virtual void resetBranchDescription_(boost::shared_ptr<ConstBranchDescription> bd) {bd_ = bd;}
00368
00369 ProducedGroup& realGroup_;
00370 boost::shared_ptr<ConstBranchDescription> bd_;
00371 };
00372
00373
00374 inline void swap(SourceGroup& a, SourceGroup& b) {
00375 a.swap(b);
00376 }
00377 }
00378
00379 #endif