CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/EventFilter/StorageManager/src/I2OChain.cc

Go to the documentation of this file.
00001 // $Id: I2OChain.cc,v 1.22.4.1 2011/03/07 11:33:05 mommsen Exp $
00003 
00004 #include <algorithm>
00005 
00006 #include "EventFilter/StorageManager/interface/DQMKey.h"
00007 #include "EventFilter/StorageManager/interface/Exception.h"
00008 #include "EventFilter/StorageManager/interface/I2OChain.h"
00009 #include "EventFilter/StorageManager/interface/QueueID.h"
00010 
00011 #include "EventFilter/StorageManager/src/ChainData.h"
00012 
00013 #include "EventFilter/Utilities/interface/i2oEvfMsgs.h"
00014 
00015 #include "IOPool/Streamer/interface/MsgHeader.h"
00016 
00017 #include "interface/evb/i2oEVBMsgs.h"
00018 #include "interface/shared/i2oXFunctionCodes.h"
00019 #include "interface/shared/version.h"
00020 
00021 
00022 namespace stor
00023 {
00024 
00025   // A default-constructed I2OChain has a null (shared) pointer.
00026   I2OChain::I2OChain():
00027     data_()
00028   {}
00029 
00030   I2OChain::I2OChain(toolbox::mem::Reference* pRef)
00031   {
00032     if (pRef)
00033       {
00034         I2O_PRIVATE_MESSAGE_FRAME *pvtMsg =
00035           (I2O_PRIVATE_MESSAGE_FRAME*) pRef->getDataLocation();
00036         if (!pvtMsg)
00037           {
00038             data_.reset(new detail::ChainData());
00039             data_->addFirstFragment(pRef);
00040             return;
00041           }
00042 
00043         unsigned short i2oMessageCode = pvtMsg->XFunctionCode;
00044         switch (i2oMessageCode)
00045           {
00046 
00047           case I2O_SM_PREAMBLE:
00048             {
00049               data_.reset(new detail::InitMsgData(pRef));
00050               break;
00051             }
00052 
00053           case I2O_SM_DATA:
00054             {
00055               data_.reset(new detail::EventMsgData(pRef));
00056               break;
00057             }
00058 
00059           case I2O_SM_DQM:
00060             {
00061               data_.reset(new detail::DQMEventMsgData(pRef));
00062               break;
00063             }
00064 
00065           case I2O_EVM_LUMISECTION:
00066             {
00067               data_.reset(new detail::EndLumiSectMsgData(pRef));
00068               break;
00069             }
00070 
00071           case I2O_SM_ERROR:
00072             {
00073               data_.reset(new detail::ErrorEventMsgData(pRef));
00074               break;
00075             }
00076 
00077           default:
00078             {
00079               data_.reset(new detail::ChainData());
00080               data_->addFirstFragment(pRef);
00081               data_->markCorrupt();
00082               break;
00083             }
00084 
00085           }
00086       }
00087   }
00088 
00089   I2OChain::I2OChain(I2OChain const& other) :
00090     data_(other.data_)
00091   { }
00092 
00093   I2OChain::~I2OChain()
00094   { }
00095 
00096   I2OChain& I2OChain::operator=(I2OChain const& rhs)
00097   {
00098     // This is the standard copy/swap algorithm, to obtain the strong
00099     // exception safety guarantee.
00100     I2OChain temp(rhs);
00101     swap(temp);
00102     return *this;
00103   }
00104   
00105   void I2OChain::swap(I2OChain& other)
00106   {
00107     data_.swap(other.data_);
00108   }
00109 
00110   bool I2OChain::empty() const
00111   {
00112     // We're empty if we have no ChainData, or if the ChainData object
00113     // we have is empty.
00114     return !data_ || data_->empty();
00115   }
00116 
00117 
00118   bool I2OChain::complete() const
00119   {
00120     if (!data_) return false;
00121     return data_->complete();
00122   }
00123 
00124 
00125   bool I2OChain::faulty() const
00126   {
00127     if (!data_) return false;
00128     return data_->faulty();
00129   }
00130 
00131 
00132   unsigned int I2OChain::faultyBits() const
00133   {
00134     if (!data_) return 0;
00135     return data_->faultyBits();
00136   }
00137 
00138 
00139   void I2OChain::addToChain(I2OChain &newpart)
00140   {
00141     // fragments can not be added to empty, complete, or faulty chains.
00142     if (empty())
00143       {
00144         XCEPT_RAISE(stor::exception::I2OChain,
00145                     "A fragment may not be added to an empty chain.");
00146       }
00147     if (complete())
00148       {
00149         XCEPT_RAISE(stor::exception::I2OChain,
00150                     "A fragment may not be added to a complete chain.");
00151       }
00152 
00153     // empty, complete, or faulty new parts can not be added to chains
00154     if (newpart.empty())
00155       {
00156         XCEPT_RAISE(stor::exception::I2OChain,
00157                     "An empty chain may not be added to an existing chain.");
00158       }
00159     if (newpart.complete())
00160       {
00161         XCEPT_RAISE(stor::exception::I2OChain,
00162                     "A complete chain may not be added to an existing chain.");
00163       }
00164 
00165     // require the new part and this chain to have the same fragment key
00166     FragKey thisKey = fragmentKey();
00167     FragKey thatKey = newpart.fragmentKey();
00168     // should change this to != once we implement that operator in FragKey
00169     if (thisKey < thatKey || thatKey < thisKey)
00170       {
00171         std::stringstream msg;
00172         msg << "A fragment key mismatch was detected when trying to add "
00173             << "a chain link to an existing chain. "
00174             << "Existing key values = ("
00175             << ((int)thisKey.code_) << "," << thisKey.run_ << ","
00176             << thisKey.event_ << "," << thisKey.secondaryId_ << ","
00177             << thisKey.originatorPid_ << "," << thisKey.originatorGuid_
00178             << "), new key values = ("
00179             << ((int)thatKey.code_) << "," << thatKey.run_ << ","
00180             << thatKey.event_ << "," << thatKey.secondaryId_ << ","
00181             << thatKey.originatorPid_ << "," << thatKey.originatorGuid_
00182             << ").";
00183         XCEPT_RAISE(stor::exception::I2OChain, msg.str());
00184       }
00185 
00186     // add the fragment to the current chain
00187     data_->addToChain(*(newpart.data_));
00188     newpart.release();
00189   }
00190 
00191   //void I2OChain::markComplete()
00192   //{
00193   //  // TODO:: Should we throw an exception if data_ is null? If so, what
00194   //  // type? Right now, we do nothing if data_ is null.
00195   //  if (data_) data_->markComplete();
00196   //}
00197 
00198   void I2OChain::markFaulty()
00199   {
00200     // TODO:: Should we throw an exception if data_ is null? If so, what
00201     // type? Right now, we do nothing if data_ is null.
00202     if (data_) data_->markFaulty();
00203   }
00204 
00205   unsigned long* I2OChain::getBufferData() const
00206   {
00207     return data_ ?  data_->getBufferData() : 0UL;
00208   }
00209 
00210   void I2OChain::release()
00211   {
00212     // A default-constructed chain controls no resources; we can
00213     // relinquish our control over any controlled Reference by
00214     // becoming like a default-constructed chain.
00215     I2OChain().swap(*this);
00216   }
00217 
00218   unsigned int I2OChain::messageCode() const
00219   {
00220     if (!data_) return Header::INVALID;
00221     return data_->messageCode();
00222   }
00223 
00224   unsigned short I2OChain::i2oMessageCode() const
00225   {
00226     if (!data_) return 0xffff;
00227     return data_->i2oMessageCode();
00228   }
00229 
00230   unsigned int I2OChain::rbBufferId() const
00231   {
00232     if (!data_) return 0;
00233     return data_->rbBufferId();
00234   }
00235 
00236   unsigned int I2OChain::hltLocalId() const
00237   {
00238     if (!data_) return 0;
00239     return data_->hltLocalId();
00240   }
00241 
00242   unsigned int I2OChain::hltInstance() const
00243   {
00244     if (!data_) return 0;
00245     return data_->hltInstance();
00246   }
00247 
00248   unsigned int I2OChain::hltTid() const
00249   {
00250     if (!data_) return 0;
00251     return data_->hltTid();
00252   }
00253 
00254   std::string I2OChain::hltURL() const
00255   {
00256     if (!data_) return "";
00257     return data_->hltURL();
00258   }
00259 
00260   std::string I2OChain::hltClassName() const
00261   {
00262     if (!data_) return "";
00263     return data_->hltClassName();
00264   }
00265 
00266   unsigned int I2OChain::fuProcessId() const
00267   {
00268     if (!data_) return 0;
00269     return data_->fuProcessId();
00270   }
00271 
00272   unsigned int I2OChain::fuGuid() const
00273   {
00274     if (!data_) return 0;
00275     return data_->fuGuid();
00276   }
00277 
00278   FragKey I2OChain::fragmentKey() const
00279   {
00280     if (!data_) return FragKey(Header::INVALID,0,0,0,0,0);
00281     return data_->fragmentKey();
00282   }
00283 
00284   unsigned int I2OChain::fragmentCount() const
00285   {
00286     if (!data_) return 0;
00287     return data_->fragmentCount();
00288   }
00289 
00290   utils::TimePoint_t I2OChain::creationTime() const
00291   {
00292     if (!data_) return boost::posix_time::not_a_date_time;
00293     return data_->creationTime();
00294   }
00295 
00296   utils::TimePoint_t I2OChain::lastFragmentTime() const
00297   {
00298     if (!data_) return boost::posix_time::not_a_date_time;
00299     return data_->lastFragmentTime();
00300   }
00301 
00302   utils::TimePoint_t I2OChain::staleWindowStartTime() const
00303   {
00304     if (!data_) return boost::posix_time::not_a_date_time;
00305     return data_->staleWindowStartTime();
00306   }
00307 
00308   void I2OChain::addToStaleWindowStartTime(const utils::Duration_t duration)
00309   {
00310     if (!data_) return;
00311     data_->addToStaleWindowStartTime(duration);
00312   }
00313 
00314   void I2OChain::resetStaleWindowStartTime()
00315   {
00316     if (!data_) return;
00317     data_->resetStaleWindowStartTime();
00318   }
00319 
00320   void I2OChain::tagForStream(StreamID streamId)
00321   {
00322     if (!data_)
00323       {
00324         std::stringstream msg;
00325         msg << "An empty chain can not be tagged for a specific ";
00326         msg << "event stream.";
00327         XCEPT_RAISE(stor::exception::I2OChain, msg.str());
00328       }
00329     data_->tagForStream(streamId);
00330   }
00331 
00332   void I2OChain::tagForEventConsumer(QueueID queueId)
00333   {
00334     if (!data_)
00335       {
00336         std::stringstream msg;
00337         msg << "An empty chain can not be tagged for a specific ";
00338         msg << "event consumer.";
00339         XCEPT_RAISE(stor::exception::I2OChain, msg.str());
00340       }
00341     data_->tagForEventConsumer(queueId);
00342   }
00343 
00344   void I2OChain::tagForDQMEventConsumer(QueueID queueId)
00345   {
00346     if (!data_)
00347       {
00348         std::stringstream msg;
00349         msg << "An empty chain can not be tagged for a specific ";
00350         msg << "DQM event consumer.";
00351         XCEPT_RAISE(stor::exception::I2OChain, msg.str());
00352       }
00353     data_->tagForDQMEventConsumer(queueId);
00354   }
00355 
00356   bool I2OChain::isTaggedForAnyStream() const
00357   {
00358     if (!data_) return false;
00359     return data_->isTaggedForAnyStream();
00360   }
00361 
00362   bool I2OChain::isTaggedForAnyEventConsumer() const
00363   {
00364     if (!data_) return false;
00365     return data_->isTaggedForAnyEventConsumer();
00366   }
00367 
00368   bool I2OChain::isTaggedForAnyDQMEventConsumer() const
00369   {
00370     if (!data_) return false;
00371     return data_->isTaggedForAnyDQMEventConsumer();
00372   }
00373 
00374   std::vector<StreamID> I2OChain::getStreamTags() const
00375   {
00376     if (!data_)
00377       {
00378         std::vector<StreamID> tmpList;
00379         return tmpList;
00380       }
00381     return data_->getStreamTags();
00382   }
00383 
00384   QueueIDs I2OChain::getEventConsumerTags() const
00385   {
00386     if (!data_)
00387       {
00388         QueueIDs tmpList;
00389         return tmpList;
00390       }
00391     return data_->getEventConsumerTags();
00392   }
00393 
00394   QueueIDs I2OChain::getDQMEventConsumerTags() const
00395   {
00396     if (!data_)
00397       {
00398         QueueIDs tmpList;
00399         return tmpList;
00400       }
00401     return data_->getDQMEventConsumerTags();
00402   }
00403 
00404   size_t I2OChain::memoryUsed() const
00405   {
00406     if (!data_) return 0;
00407     return data_->memoryUsed();
00408   }
00409 
00410   unsigned long I2OChain::totalDataSize() const
00411   {
00412     if (!data_) return 0UL;
00413     return data_->totalDataSize();
00414   }
00415 
00416   unsigned long I2OChain::dataSize(int fragmentIndex) const
00417   {
00418     if (!data_) return 0UL;
00419     return data_->dataSize(fragmentIndex);
00420   }
00421 
00422   unsigned char* I2OChain::dataLocation(int fragmentIndex) const
00423   {
00424     if (!data_) return 0UL;
00425     return data_->dataLocation(fragmentIndex);
00426   }
00427 
00428   unsigned int I2OChain::getFragmentID(int fragmentIndex) const
00429   {
00430     if (!data_) return 0;
00431     return data_->getFragmentID(fragmentIndex);
00432   }
00433 
00434   unsigned long I2OChain::headerSize() const
00435   {
00436     if (!data_) return 0UL;
00437     return data_->headerSize();
00438   }
00439 
00440   unsigned char* I2OChain::headerLocation() const
00441   {
00442     if (!data_) return 0UL;
00443     return data_->headerLocation();
00444   }
00445 
00446   unsigned int I2OChain::
00447   copyFragmentsIntoBuffer(std::vector<unsigned char>& targetBuffer) const
00448   {
00449     if (!data_) return 0;
00450     return data_->copyFragmentsIntoBuffer(targetBuffer);
00451   }
00452 
00453   std::string I2OChain::outputModuleLabel() const
00454   {
00455     if (!data_)
00456       {
00457         XCEPT_RAISE(stor::exception::I2OChain,
00458           "The output module label can not be determined from an empty I2OChain.");
00459       }
00460     return data_->outputModuleLabel();
00461   }
00462 
00463   std::string I2OChain::topFolderName() const
00464   {
00465     if( !data_ )
00466       {
00467         XCEPT_RAISE( stor::exception::I2OChain,
00468                      "The top folder name can not be determined from an empty I2OChain." );
00469       }
00470     return data_->topFolderName();
00471   }
00472 
00473   DQMKey I2OChain::dqmKey() const
00474   {
00475     if( !data_ )
00476       {
00477         XCEPT_RAISE( stor::exception::I2OChain,
00478                      "The DQM key can not be determined from an empty I2OChain." );
00479       }
00480     return data_->dqmKey();
00481   }
00482 
00483   uint32_t I2OChain::outputModuleId() const
00484   {
00485     if (!data_)
00486       {
00487         XCEPT_RAISE(stor::exception::I2OChain,
00488           "The output module ID can not be determined from an empty I2OChain.");
00489       }
00490     return data_->outputModuleId();
00491   }
00492 
00493   void I2OChain::hltTriggerNames(Strings& nameList) const
00494   {
00495     if (!data_)
00496       {
00497         XCEPT_RAISE(stor::exception::I2OChain,
00498           "HLT trigger names can not be determined from an empty I2OChain.");
00499       }
00500     data_->hltTriggerNames(nameList);
00501   }
00502 
00503   void I2OChain::hltTriggerSelections(Strings& nameList) const
00504   {
00505     if (!data_)
00506       {
00507         XCEPT_RAISE(stor::exception::I2OChain,
00508           "HLT trigger selections can not be determined from an empty I2OChain.");
00509       }
00510     data_->hltTriggerSelections(nameList);
00511   }
00512 
00513   void I2OChain::l1TriggerNames(Strings& nameList) const
00514   {
00515     if (!data_)
00516       {
00517         XCEPT_RAISE(stor::exception::I2OChain,
00518           "L1 trigger names can not be determined from an empty I2OChain.");
00519       }
00520     data_->l1TriggerNames(nameList);
00521   }
00522 
00523   uint32_t I2OChain::hltTriggerCount() const
00524   {
00525     if (!data_)
00526       {
00527         XCEPT_RAISE(stor::exception::I2OChain,
00528           "The number of HLT trigger bits can not be determined from an empty I2OChain.");
00529       }
00530     return data_->hltTriggerCount();
00531   }
00532 
00533   void I2OChain::hltTriggerBits(std::vector<unsigned char>& bitList) const
00534   {
00535     if (!data_)
00536       {
00537         XCEPT_RAISE(stor::exception::I2OChain,
00538           "HLT trigger bits can not be determined from an empty I2OChain.");
00539       }
00540     data_->hltTriggerBits(bitList);
00541   }
00542 
00543   void I2OChain::assertRunNumber(uint32_t runNumber)
00544   {
00545     if (!data_)
00546       {
00547         XCEPT_RAISE(stor::exception::I2OChain,
00548           "The run number can not be checked for an empty I2OChain.");
00549       }
00550     return data_->assertRunNumber(runNumber);
00551   }
00552 
00553   uint32_t I2OChain::runNumber() const
00554   {
00555     if (!data_)
00556       {
00557         XCEPT_RAISE(stor::exception::I2OChain,
00558           "The run number can not be determined from an empty I2OChain.");
00559       }
00560     return data_->runNumber();
00561   }
00562 
00563   uint32_t I2OChain::lumiSection() const
00564   {
00565     if (!data_)
00566       {
00567         XCEPT_RAISE(stor::exception::I2OChain,
00568           "The luminosity section can not be determined from an empty I2OChain.");
00569       }
00570     return data_->lumiSection();
00571   }
00572 
00573   uint32_t I2OChain::eventNumber() const
00574   {
00575     if (!data_)
00576       {
00577         XCEPT_RAISE(stor::exception::I2OChain,
00578           "The event number can not be determined from an empty I2OChain.");
00579       }
00580     return data_->eventNumber();
00581   }
00582 
00583   uint32_t I2OChain::adler32Checksum() const
00584   {
00585     if (!data_)
00586       {
00587         XCEPT_RAISE(stor::exception::I2OChain,
00588           "The adler32 checksum can not be determined from an empty I2OChain.");
00589       }
00590     return data_->adler32Checksum();
00591   }
00592 
00593   bool I2OChain::isEndOfLumiSectionMessage() const
00594   {
00595     if (!data_) return false;
00596     return data_->isEndOfLumiSectionMessage();
00597   }
00598 
00599 } // namespace stor
00600