![]() |
![]() |
00001 /*---------------------------------------------------------------------- 00002 ----------------------------------------------------------------------*/ 00003 #include "FWCore/Framework/interface/Group.h" 00004 00005 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00006 #include "FWCore/Utilities/interface/TypeID.h" 00007 00008 #include <cassert> 00009 00010 namespace edm { 00011 Group::Group() {} 00012 00013 Group::~Group() {} 00014 InputGroup::~InputGroup() {} 00015 ProducedGroup::~ProducedGroup() {} 00016 ScheduledGroup::~ScheduledGroup() {} 00017 UnscheduledGroup::~UnscheduledGroup() {} 00018 SourceGroup::~SourceGroup() {} 00019 AliasGroup::~AliasGroup() {} 00020 00021 void 00022 ProducedGroup::putProduct_( 00023 WrapperOwningHolder const& edp, 00024 ProductProvenance const& productProvenance) { 00025 if(product()) { 00026 throw Exception(errors::InsertFailure) 00027 << "Attempt to insert more than one product on branch " << branchDescription().branchName() << "\n"; 00028 } 00029 assert(branchDescription().produced()); 00030 assert(edp.isValid()); 00031 assert(!provenance()->productProvenanceValid()); 00032 assert(status() != Present); 00033 assert(status() != Uninitialized); 00034 setProductProvenance(productProvenance); 00035 assert(provenance()->productProvenanceValid()); 00036 if(productData().getInterface() != 0) { 00037 assert(productData().getInterface()->sameType(*edp.interface())); 00038 } 00039 productData().wrapper_ = edp.product(); 00040 status_() = Present; 00041 } 00042 00043 void 00044 ProducedGroup::mergeProduct_( 00045 WrapperOwningHolder const& edp, 00046 ProductProvenance& productProvenance) { 00047 assert(provenance()->productProvenanceValid()); 00048 assert(status() == Present); 00049 setProductProvenance(productProvenance); 00050 mergeTheProduct(edp); 00051 } 00052 00053 bool 00054 ProducedGroup::putOrMergeProduct_() const { 00055 return productUnavailable(); 00056 } 00057 00058 void 00059 ProducedGroup::mergeProduct_(WrapperOwningHolder const& edp) const { 00060 assert(status() == Present); 00061 mergeTheProduct(edp); 00062 } 00063 00064 void 00065 ProducedGroup::putProduct_(WrapperOwningHolder const& edp) const { 00066 if(product()) { 00067 throw Exception(errors::InsertFailure) 00068 << "Attempt to insert more than one product on branch " << branchDescription().branchName() << "\n"; 00069 } 00070 assert(branchDescription().produced()); 00071 assert(edp.isValid()); 00072 assert(status() != Present); 00073 assert(status() != Uninitialized); 00074 if(productData().getInterface() != 0) { 00075 assert(productData().getInterface()->sameType(*edp.interface())); 00076 } 00077 productData().wrapper_ = edp.product(); 00078 status_() = Present; 00079 } 00080 00081 void 00082 InputGroup::putProduct_( 00083 WrapperOwningHolder const& edp, 00084 ProductProvenance const& productProvenance) { 00085 assert(!product()); 00086 assert(!provenance()->productProvenanceValid()); 00087 setProductProvenance(productProvenance); 00088 assert(provenance()->productProvenanceValid()); 00089 setProduct(edp); 00090 } 00091 00092 void 00093 InputGroup::mergeProduct_( 00094 WrapperOwningHolder const&, 00095 ProductProvenance&) { 00096 assert(0); 00097 } 00098 00099 void 00100 InputGroup::mergeProduct_(WrapperOwningHolder const& edp) const { 00101 mergeTheProduct(edp); 00102 } 00103 00104 bool 00105 InputGroup::putOrMergeProduct_() const { 00106 return(!product()); 00107 } 00108 00109 void 00110 InputGroup::putProduct_(WrapperOwningHolder const& edp) const { 00111 assert(!product()); 00112 setProduct(edp); 00113 } 00114 00115 void 00116 Group::mergeTheProduct(WrapperOwningHolder const& edp) const { 00117 if(wrapper().isMergeable()) { 00118 wrapper().mergeProduct(edp.wrapper()); 00119 } else if(wrapper().hasIsProductEqual()) { 00120 if(!wrapper().isProductEqual(edp.wrapper())) { 00121 LogError("RunLumiMerging") 00122 << "Group::mergeGroup\n" 00123 << "Two run/lumi products for the same run/lumi which should be equal are not\n" 00124 << "Using the first, ignoring the second\n" 00125 << "className = " << branchDescription().className() << "\n" 00126 << "moduleLabel = " << moduleLabel() << "\n" 00127 << "instance = " << productInstanceName() << "\n" 00128 << "process = " << processName() << "\n"; 00129 } 00130 } else { 00131 LogWarning("RunLumiMerging") 00132 << "Group::mergeGroup\n" 00133 << "Run/lumi product has neither a mergeProduct nor isProductEqual function\n" 00134 << "Using the first, ignoring the second in merge\n" 00135 << "className = " << branchDescription().className() << "\n" 00136 << "moduleLabel = " << moduleLabel() << "\n" 00137 << "instance = " << productInstanceName() << "\n" 00138 << "process = " << processName() << "\n"; 00139 } 00140 } 00141 00142 void 00143 InputGroup::setProduct(WrapperOwningHolder const& prod) const { 00144 assert (!product()); 00145 if(!prod.isValid() || !prod.isPresent()) { 00146 setProductUnavailable(); 00147 } 00148 assert(!prod.isValid() || productData().getInterface()->sameType(*prod.interface())); 00149 productData().wrapper_ = prod.product(); 00150 } 00151 00152 void 00153 Group::setProductProvenance(ProductProvenance const& prov) const { 00154 productData().prov_.setProductProvenance(prov); 00155 } 00156 00157 // This routine returns true if it is known that currently there is no real product. 00158 // If there is a real product, it returns false. 00159 // If it is not known if there is a real product, it returns false. 00160 bool 00161 InputGroup::productUnavailable_() const { 00162 if(productIsUnavailable()) { 00163 return true; 00164 } 00165 // If there is a product, we know if it is real or a dummy. 00166 if(product()) { 00167 bool unavailable = !(wrapper().isPresent()); 00168 if(unavailable) { 00169 setProductUnavailable(); 00170 } 00171 return unavailable; 00172 } 00173 return false; 00174 } 00175 00176 // This routine returns true if it is known that currently there is no real product. 00177 // If there is a real product, it returns false. 00178 // If it is not known if there is a real product, it returns false. 00179 bool 00180 ProducedGroup::productUnavailable_() const { 00181 // If unscheduled production, the product is potentially available. 00182 if(onDemand()) return false; 00183 // The product is available if and only if a product has been put. 00184 bool unavailable = !(product() && wrapper().isPresent()); 00185 return unavailable; 00186 } 00187 00188 // This routine returns true if the product was deleted early in order to save memory 00189 bool 00190 ProducedGroup::productWasDeleted_() const { 00191 return status() == ProductDeleted; 00192 } 00193 00194 void 00195 ProducedGroup::setProductDeleted_() { 00196 status() = ProductDeleted; 00197 } 00198 00199 00200 bool 00201 Group::provenanceAvailable() const { 00202 // If this product is from a the current process, 00203 // the provenance is available if and only if a product has been put. 00204 if(branchDescription().produced()) { 00205 return product() && wrapper().isPresent(); 00206 } 00207 // If this product is from a prior process, the provenance is available, 00208 // although the per event part may have been dropped. 00209 return true; 00210 } 00211 00212 TypeID 00213 Group::productType() const { 00214 return TypeID(wrapper().interface()->wrappedTypeInfo()); 00215 } 00216 00217 void 00218 Group::reallyCheckType(WrapperOwningHolder const& prod) const { 00219 // Check if the types match. 00220 TypeID typeID(prod.dynamicTypeInfo()); 00221 if(typeID != branchDescription().unwrappedTypeID()) { 00222 // Types do not match. 00223 throw Exception(errors::EventCorruption) 00224 << "Product on branch " << branchDescription().branchName() << " is of wrong type.\n" 00225 << "It is supposed to be of type " << branchDescription().className() << ".\n" 00226 << "It is actually of type " << typeID.className() << ".\n"; 00227 } 00228 } 00229 00230 void 00231 Group::setProvenance(boost::shared_ptr<BranchMapper> mapper, ProcessHistoryID const& phid, ProductID const& pid) { 00232 //assert(!productData().prov_); 00233 productData().prov_.setProductID(pid); 00234 productData().prov_.setStore(mapper); 00235 productData().prov_.setProcessHistoryID(phid); 00236 } 00237 00238 void 00239 Group::setProvenance(boost::shared_ptr<BranchMapper> mapper, ProcessHistoryID const& phid) { 00240 productData().prov_.setStore(mapper); 00241 productData().prov_.setProcessHistoryID(phid); 00242 } 00243 00244 void 00245 Group::setProcessHistoryID(ProcessHistoryID const& phid) { 00246 productData().prov_.setProcessHistoryID(phid); 00247 } 00248 00249 Provenance* 00250 Group::provenance() const { 00251 return &(productData().prov_); 00252 } 00253 00254 void 00255 Group::write(std::ostream& os) const { 00256 // This is grossly inadequate. It is also not critical for the 00257 // first pass. 00258 os << std::string("Group for product with ID: ") 00259 << productID(); 00260 } 00261 }